diff options
author | alberth <alberth@openttd.org> | 2009-08-01 12:42:27 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2009-08-01 12:42:27 +0000 |
commit | 9734c0922c810b1be8f4acbfcfa6c959b1234653 (patch) | |
tree | 300f47139525ed26b87808ca3c23abbd892f5829 | |
parent | 1cd07265f8ced5de94e950c80fca7fdc072a02db (diff) | |
download | openttd-9734c0922c810b1be8f4acbfcfa6c959b1234653.tar.xz |
(svn r17021) -Codechange: Use nested widgets for the main window.
-rw-r--r-- | src/main_gui.cpp | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/main_gui.cpp b/src/main_gui.cpp index ceaa94788..0e04b6045 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -185,18 +185,38 @@ void ZoomInOrOutToCursorWindow(bool in, Window *w) extern void UpdateAllStationVirtCoords(); +/** Widgets of the main window. */ +enum MainWindowWidgets { + MW_VIEWPORT, ///< Main window viewport. +}; + +static const struct NWidgetPart _nested_main_window_widgets[] = { + NWidget(NWID_VIEWPORT, INVALID_COLOUR, MW_VIEWPORT), SetResize(1, 1), +}; + +static const WindowDesc _main_window_desc( + 0, 0, 0, 0, 0, 0, + WC_MAIN_WINDOW, WC_NONE, + 0, + NULL, _nested_main_window_widgets, lengthof(_nested_main_window_widgets) +); + struct MainWindow : Window { - MainWindow(int width, int height) : Window(0, 0, width, height, WC_MAIN_WINDOW, NULL) + MainWindow() : Window() { - InitializeWindowViewport(this, 0, 0, width, height, TileXY(32, 32), ZOOM_LVL_VIEWPORT); + this->InitNested(&_main_window_desc, 0); + ResizeWindow(this, _screen.width, _screen.height); + + NWidgetViewport *nvp = (NWidgetViewport *)this->nested_array[MW_VIEWPORT]; + nvp->InitializeViewport(this, TileXY(32, 32), ZOOM_LVL_VIEWPORT); } virtual void OnPaint() { - this->DrawViewport(); + this->DrawWidgets(); if (_game_mode == GM_MENU) { - int off_x = _screen.width / 2; + int off_x = this->width / 2; DrawSprite(SPR_OTTD_O, PAL_NONE, off_x - 120, 50); DrawSprite(SPR_OTTD_P, PAL_NONE, off_x - 86, 50); @@ -356,6 +376,14 @@ struct MainWindow : Window ZoomInOrOutToCursorWindow(wheel < 0, this); } + virtual void OnResize(Point delta) + { + if (this->viewport != NULL) { + NWidgetViewport *nvp = (NWidgetViewport *)this->nested_array[MW_VIEWPORT]; + nvp->UpdateViewportCoordinates(this); + } + } + virtual void OnInvalidateData(int data) { /* Forward the message to the appropiate toolbar (ingame or scenario editor) */ @@ -375,7 +403,7 @@ void SetupColoursAndInitialWindow() memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i])); } - new MainWindow(_screen.width, _screen.height); + new MainWindow; /* XXX: these are not done */ switch (_game_mode) { |