(svn r13093) -Codechange: make a class of AboutWindow.

pull/155/head
glx 16 years ago
parent e812c8223f
commit 5704d59314

@ -206,13 +206,36 @@ void PlaceLandBlockInfo()
}
}
struct scroller_d {
int height;
uint16 counter;
static const Widget _about_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 419, 0, 13, STR_015B_OPENTTD, STR_NULL},
{ WWT_PANEL, RESIZE_NONE, 14, 0, 419, 14, 271, 0x0, STR_NULL},
{ WWT_FRAME, RESIZE_NONE, 14, 5, 414, 40, 245, STR_NULL, STR_NULL},
{ WIDGETS_END},
};
static const WindowDesc _about_desc = {
WDP_CENTER, WDP_CENTER, 420, 272, 420, 272,
WC_GAME_OPTIONS, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_about_widgets,
NULL
};
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(scroller_d));
static const char *credits[] = {
struct AboutWindow : public Window {
int scroll_height;
uint16 counter;
AboutWindow() : Window(&_about_desc)
{
this->counter = 5;
this->scroll_height = this->height - 40;
this->FindWindowPlacementAndResize(&_about_desc);
}
virtual void OnPaint()
{
static const char *credits[] = {
/*************************************************************************
* maximum length of string which fits in window -^*/
"Original design by Chris Sawyer",
@ -264,70 +287,45 @@ static const char *credits[] = {
"",
"And last but not least:",
" Chris Sawyer - For an amazing game!"
};
static void AboutWindowProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_CREATE: // Set up window counter and start position of scroller
WP(w, scroller_d).counter = 5;
WP(w, scroller_d).height = w->height - 40;
break;
};
case WE_PAINT: {
int y = WP(w, scroller_d).height;
DrawWindowWidgets(w);
DrawWindowWidgets(this);
/* Show original copyright and revision version */
DrawStringCentered(210, 17, STR_00B6_ORIGINAL_COPYRIGHT, TC_FROMSTRING);
DrawStringCentered(210, 17 + 10, STR_00B7_VERSION, TC_FROMSTRING);
int y = this->scroll_height;
/* Show all scrolling credits */
for (uint i = 0; i < lengthof(credits); i++) {
if (y >= 50 && y < (w->height - 40)) {
if (y >= 50 && y < (this->height - 40)) {
DoDrawString(credits[i], 10, y, TC_BLACK);
}
y += 10;
}
/* If the last text has scrolled start anew from the start */
if (y < 50) WP(w, scroller_d).height = w->height - 40;
/* If the last text has scrolled start a new from the start */
if (y < 50) this->scroll_height = this->height - 40;
DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", TC_BLACK);
DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, TC_FROMSTRING);
} break;
DoDrawStringCentered(210, this->height - 25, "Website: http://www.openttd.org", TC_BLACK);
DrawStringCentered(210, this->height - 15, STR_00BA_COPYRIGHT_OPENTTD, TC_FROMSTRING);
}
case WE_TICK: // Timer to scroll the text and adjust the new top
if (--WP(w, scroller_d).counter == 0) {
WP(w, scroller_d).counter = 5;
WP(w, scroller_d).height--;
w->SetDirty();
virtual void OnTick()
{
if (--this->counter == 0) {
this->counter = 5;
this->scroll_height--;
this->SetDirty();
}
break;
}
}
static const Widget _about_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 419, 0, 13, STR_015B_OPENTTD, STR_NULL},
{ WWT_PANEL, RESIZE_NONE, 14, 0, 419, 14, 271, 0x0, STR_NULL},
{ WWT_FRAME, RESIZE_NONE, 14, 5, 414, 40, 245, STR_NULL, STR_NULL},
{ WIDGETS_END},
};
static const WindowDesc _about_desc = {
WDP_CENTER, WDP_CENTER, 420, 272, 420, 272,
WC_GAME_OPTIONS, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_about_widgets,
AboutWindowProc
};
void ShowAboutWindow()
{
DeleteWindowById(WC_GAME_OPTIONS, 0);
new Window(&_about_desc);
new AboutWindow();
}
static uint64 _errmsg_decode_params[20];

Loading…
Cancel
Save