summaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-02-06 09:18:04 +0000
committertron <tron@openttd.org>2006-02-06 09:18:04 +0000
commit087fe86ed28fb6ac5885cac7f64d34ccd5a9c140 (patch)
tree3a4002304d8204d11c37ba706d6ffbd2e5dfac1b /window.c
parent75a70e1def8c677d2340a49e9f12e4c2a5d65aee (diff)
downloadopenttd-087fe86ed28fb6ac5885cac7f64d34ccd5a9c140.tar.xz
(svn r3564) Several smaller changes:
- Don't treat non-booleans as booleans - Reduce variable scope - Bracing - Use DeMorgan's law to make conditionals easier to read - if cascade -> switch - Replace some magic numbers by symbolic names - Avoid assignments within other statements
Diffstat (limited to 'window.c')
-rw-r--r--window.c76
1 files changed, 46 insertions, 30 deletions
diff --git a/window.c b/window.c
index 8a44832ff..69f7bb961 100644
--- a/window.c
+++ b/window.c
@@ -1144,8 +1144,8 @@ static bool HandleScrollbarScrolling(void)
static bool HandleViewportScroll(void)
{
Window *w;
- ViewPort *vp;
- int dx,dy, x, y, sub;
+ int dx;
+ int dy;
if (!_scrolling_viewport) return true;
@@ -1168,17 +1168,18 @@ stop_capt:;
}
if (w->window_class != WC_SMALLMAP) {
- vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y);
+ ViewPort* vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y);
+
if (vp == NULL)
goto stop_capt;
WP(w,vp_d).scrollpos_x += dx << vp->zoom;
WP(w,vp_d).scrollpos_y += dy << vp->zoom;
- _cursor.delta.x = _cursor.delta.y = 0;
- return false;
} else {
- // scroll the smallmap ?
+ int x;
+ int y;
+ int sub;
int hx;
int hy;
int hvx;
@@ -1233,11 +1234,12 @@ stop_capt:;
WP(w,smallmap_d).scroll_y = y;
WP(w,smallmap_d).subscroll = sub;
- _cursor.delta.x = _cursor.delta.y = 0;
-
SetWindowDirty(w);
- return false;
}
+
+ _cursor.delta.x = 0;
+ _cursor.delta.y = 0;
+ return false;
}
static Window *MaybeBringWindowToFront(Window *w)
@@ -1376,7 +1378,7 @@ static void MouseLoop(int click, int mousewheel)
w = FindWindowFromPt(x, y);
if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return;
vp = IsPtInWindowViewport(w, x, y);
- if (vp) {
+ if (vp != NULL) {
x -= vp->left;
y -= vp->top;
//here allows scrolling in both x and y axis
@@ -1662,26 +1664,40 @@ void RelocateAllWindows(int neww, int newh)
IConsoleResize();
- if (w->window_class == WC_MAIN_TOOLBAR) {
- top = w->top;
- left = PositionMainToolbar(w); // changes toolbar orientation
- } else if (w->window_class == WC_SELECT_GAME || w->window_class == WC_GAME_OPTIONS || w->window_class == WC_NETWORK_WINDOW){
- top = (newh - w->height) >> 1;
- left = (neww - w->width) >> 1;
- } else if (w->window_class == WC_NEWS_WINDOW) {
- top = newh - w->height;
- left = (neww - w->width) >> 1;
- } else if (w->window_class == WC_STATUS_BAR) {
- top = newh - w->height;
- left = (neww - w->width) >> 1;
- } else if (w->window_class == WC_SEND_NETWORK_MSG) {
- top = (newh - 26); // 26 = height of status bar + height of chat bar
- left = (neww - w->width) >> 1;
- } else {
- left = w->left;
- if (left + (w->width>>1) >= neww) left = neww - w->width;
- top = w->top;
- if (top + (w->height>>1) >= newh) top = newh - w->height;
+ switch (w->window_class) {
+ case WC_MAIN_TOOLBAR:
+ top = w->top;
+ left = PositionMainToolbar(w); // changes toolbar orientation
+ break;
+
+ case WC_SELECT_GAME:
+ case WC_GAME_OPTIONS:
+ case WC_NETWORK_WINDOW:
+ top = (newh - w->height) >> 1;
+ left = (neww - w->width) >> 1;
+ break;
+
+ case WC_NEWS_WINDOW:
+ top = newh - w->height;
+ left = (neww - w->width) >> 1;
+ break;
+
+ case WC_STATUS_BAR:
+ top = newh - w->height;
+ left = (neww - w->width) >> 1;
+ break;
+
+ case WC_SEND_NETWORK_MSG:
+ top = (newh - 26); // 26 = height of status bar + height of chat bar
+ left = (neww - w->width) >> 1;
+ break;
+
+ default:
+ left = w->left;
+ if (left + (w->width >> 1) >= neww) left = neww - w->width;
+ top = w->top;
+ if (top + (w->height >> 1) >= newh) top = newh - w->height;
+ break;
}
if (w->viewport != NULL) {