1
0
Fork 0

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

release/0.7
glx 2008-05-14 20:01:06 +00:00
parent 22960e82aa
commit be43bbc3f3
1 changed files with 101 additions and 103 deletions

View File

@ -206,12 +206,35 @@ void PlaceLandBlockInfo()
} }
} }
struct scroller_d { static const Widget _about_widgets[] = {
int height; { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
uint16 counter; { 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},
}; };
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(scroller_d));
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
};
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[] = { static const char *credits[] = {
/************************************************************************* /*************************************************************************
* maximum length of string which fits in window -^*/ * maximum length of string which fits in window -^*/
@ -266,68 +289,43 @@ static const char *credits[] = {
" Chris Sawyer - For an amazing game!" " Chris Sawyer - For an amazing game!"
}; };
static void AboutWindowProc(Window *w, WindowEvent *e) DrawWindowWidgets(this);
{
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);
/* Show original copyright and revision version */ /* Show original copyright and revision version */
DrawStringCentered(210, 17, STR_00B6_ORIGINAL_COPYRIGHT, TC_FROMSTRING); DrawStringCentered(210, 17, STR_00B6_ORIGINAL_COPYRIGHT, TC_FROMSTRING);
DrawStringCentered(210, 17 + 10, STR_00B7_VERSION, TC_FROMSTRING); DrawStringCentered(210, 17 + 10, STR_00B7_VERSION, TC_FROMSTRING);
int y = this->scroll_height;
/* Show all scrolling credits */ /* Show all scrolling credits */
for (uint i = 0; i < lengthof(credits); i++) { 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); DoDrawString(credits[i], 10, y, TC_BLACK);
} }
y += 10; y += 10;
} }
/* If the last text has scrolled start a new from the start */ /* If the last text has scrolled start a new from the start */
if (y < 50) WP(w, scroller_d).height = w->height - 40; if (y < 50) this->scroll_height = this->height - 40;
DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", TC_BLACK); DoDrawStringCentered(210, this->height - 25, "Website: http://www.openttd.org", TC_BLACK);
DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, TC_FROMSTRING); DrawStringCentered(210, this->height - 15, STR_00BA_COPYRIGHT_OPENTTD, TC_FROMSTRING);
} break;
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();
}
break;
}
} }
static const Widget _about_widgets[] = { virtual void OnTick()
{ 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}, if (--this->counter == 0) {
{ WWT_PANEL, RESIZE_NONE, 14, 0, 419, 14, 271, 0x0, STR_NULL}, this->counter = 5;
{ WWT_FRAME, RESIZE_NONE, 14, 5, 414, 40, 245, STR_NULL, STR_NULL}, this->scroll_height--;
{ WIDGETS_END}, this->SetDirty();
}
}
}; };
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() void ShowAboutWindow()
{ {
DeleteWindowById(WC_GAME_OPTIONS, 0); DeleteWindowById(WC_GAME_OPTIONS, 0);
new Window(&_about_desc); new AboutWindow();
} }
static uint64 _errmsg_decode_params[20]; static uint64 _errmsg_decode_params[20];