summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-11-07 13:06:02 +0000
committerDarkvater <Darkvater@openttd.org>2006-11-07 13:06:02 +0000
commit3a2c773411ccabaaa87130a8499bda4995588a54 (patch)
tree99bc81d869567e52619264b8aa261b56be9836eb
parent501fcb3465bc95744dcc78461d71e822e9c4d5cd (diff)
downloadopenttd-3a2c773411ccabaaa87130a8499bda4995588a54.tar.xz
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
buttons depending on calling window, game-mode); handle it by broadcasting messages to the calling window, because that knows how and what buttons to set.
-rw-r--r--genworld.c11
-rw-r--r--main_gui.c48
-rw-r--r--smallmap_gui.c7
-rw-r--r--viewport.c15
-rw-r--r--viewport.h1
5 files changed, 42 insertions, 40 deletions
diff --git a/genworld.c b/genworld.c
index ae29cddde..51bf8d246 100644
--- a/genworld.c
+++ b/genworld.c
@@ -260,14 +260,11 @@ void GenerateWorld(int mode, uint size_x, uint size_y)
ShowGenerateWorldProgress();
}
- /* Zoom out and center on the map (is pretty ;)) */
+ /* Hide vital windows, because we don't allow to use them */
+ if (_gw.thread != NULL) HideVitalWindows();
+
+ /* Centre the view on the map */
if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) {
- while (DoZoomInOutWindow(ZOOM_OUT, FindWindowById(WC_MAIN_WINDOW, 0) ) ) {}
ScrollMainWindowToTile(TileXY(MapSizeX() / 2, MapSizeY() / 2));
}
-
- /* Hide vital windows, because we don't allow to use them */
- /* XXX -- Ideal it is done after ShowGenerateWorldProgress, but stupid
- * enough, DoZoomInOutWindow _needs_ the toolbar to exist... */
- if (_gw.thread != NULL) HideVitalWindows();
}
diff --git a/main_gui.c b/main_gui.c
index 7a9c06969..8009f28e8 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -855,15 +855,8 @@ static void ToolbarAirClick(Window *w)
bool DoZoomInOutWindow(int how, Window *w)
{
ViewPort *vp;
- int button;
-
- switch (_game_mode) {
- case GM_EDITOR: button = 9; break;
- case GM_NORMAL: button = 17; break;
- default: return false;
- }
- assert(w);
+ assert(w != NULL);
vp = w->viewport;
switch (how) {
@@ -890,31 +883,8 @@ bool DoZoomInOutWindow(int how, Window *w)
}
SetWindowDirty(w);
-
- // routine to disable/enable the zoom buttons. Didn't know where to place these otherwise
- {
- Window *wt = NULL;
-
- switch (w->window_class) {
- case WC_MAIN_WINDOW:
- wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
- break;
-
- case WC_EXTRA_VIEW_PORT:
- wt = FindWindowById(WC_EXTRA_VIEW_PORT, w->window_number);
- button = 5;
- break;
- }
-
- assert(wt);
-
- // update the toolbar button too
- SetWindowWidgetDisabledState(wt, button, vp->zoom == 0);
- SetWindowWidgetDisabledState(wt, button + 1, vp->zoom == 2);
-
- SetWindowDirty(wt);
- }
-
+ /* Update the windows that have zoom-buttons to perhaps disable their buttons */
+ SendWindowMessageClass(w->window_class, how, w->window_number, 0);
return true;
}
@@ -1891,6 +1861,10 @@ static void MainToolbarWndProc(Window *w, WindowEvent *e)
}
break;
}
+
+ case WE_MESSAGE:
+ HandleZoomMessage(w, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, 17, 18);
+ break;
}
}
@@ -2078,6 +2052,9 @@ static void ScenEditToolbarWndProc(Window *w, WindowEvent *e)
}
break;
+ case WE_MESSAGE:
+ HandleZoomMessage(w, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, 9, 10);
+ break;
}
}
@@ -2380,6 +2357,11 @@ static void MainWindowWndProc(Window *w, WindowEvent *e)
case WE_MOUSEWHEEL:
ZoomInOrOutToCursorWindow(e->we.wheel.wheel < 0, w);
break;
+
+ case WE_MESSAGE:
+ /* Forward the message to the appropiate toolbar (ingame or scenario editor) */
+ SendWindowMessage(WC_MAIN_TOOLBAR, 0, e->we.message.msg, e->we.message.wparam, e->we.message.lparam);
+ break;
}
}
diff --git a/smallmap_gui.c b/smallmap_gui.c
index d5a2b5342..fcb80a67b 100644
--- a/smallmap_gui.c
+++ b/smallmap_gui.c
@@ -1070,6 +1070,13 @@ static void ExtraViewPortWndProc(Window *w, WindowEvent *e)
case WE_MOUSEWHEEL:
ZoomInOrOutToCursorWindow(e->we.wheel.wheel < 0, w);
break;
+
+
+ case WE_MESSAGE:
+ /* Only handle zoom message if intended for us (msg ZOOM_IN/ZOOM_OUT) */
+ if (e->we.message.wparam != w->window_number) break;
+ HandleZoomMessage(w, w->viewport, 5, 6);
+ break;
}
}
diff --git a/viewport.c b/viewport.c
index 79ae0b269..6d6f5cf58 100644
--- a/viewport.c
+++ b/viewport.c
@@ -375,6 +375,21 @@ Point GetTileZoomCenterWindow(bool in, Window * w)
return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, x + vp->left, y + vp->top);
}
+/** Update the status of the zoom-buttons according to the zoom-level
+ * of the viewport. This will update their status and invalidate accordingly
+ * @param window pointer to the window that has the zoom buttons
+ * @param vp pointer to the viewport whose zoom-level the buttons represent
+ * @param widget_zoom_in widget index for window with zoom-in button
+ * @param widget_zoom_out widget index for window with zoom-out button */
+void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out)
+{
+ SetWindowWidgetDisabledState(w, widget_zoom_in, vp->zoom == 0);
+ InvalidateWidget(w, widget_zoom_in);
+
+ SetWindowWidgetDisabledState(w, widget_zoom_out, vp->zoom == 2);
+ InvalidateWidget(w, widget_zoom_out);
+}
+
void DrawGroundSpriteAt(uint32 image, int32 x, int32 y, byte z)
{
ViewportDrawer *vd = _cur_vd;
diff --git a/viewport.h b/viewport.h
index ed0d2be3f..9cdcdc3d5 100644
--- a/viewport.h
+++ b/viewport.h
@@ -31,6 +31,7 @@ enum {
bool DoZoomInOutWindow(int how, Window *w);
void ZoomInOrOutToCursorWindow(bool in, Window * w);
Point GetTileZoomCenterWindow(bool in, Window * w);
+void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out);
void OffsetGroundSprite(int x, int y);