summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-03-17 23:26:28 +0000
committerrubidium <rubidium@openttd.org>2009-03-17 23:26:28 +0000
commit022a929e2dd7e697d0f9039f0ac3079cd79b8a71 (patch)
tree2633a92715a971bd42d94379f1ffa5c04982ecbb /src
parentc7345c6db077abd490011df9a8241509ba8064e2 (diff)
downloadopenttd-022a929e2dd7e697d0f9039f0ac3079cd79b8a71.tar.xz
(svn r15756) -Codechange: remove the assumption that the second windget is always the title bar. Also replace a few magic numbers with a const.
Diffstat (limited to 'src')
-rw-r--r--src/window.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/window.cpp b/src/window.cpp
index a1b69e2d7..b73c4a6ba 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1375,8 +1375,6 @@ static bool HandleWindowDragging()
Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
if (w->flags4 & WF_DRAGGING) {
- const Widget *t = &w->widget[1]; // the title bar ... ugh
-
/* Stop the dragging if the left mouse button was released */
if (!_left_button_down) {
w->flags4 &= ~WF_DRAGGING;
@@ -1466,10 +1464,18 @@ static bool HandleWindowDragging()
}
}
- /* Make sure the window doesn't leave the screen
- * 13 is the height of the title bar */
- nx = Clamp(nx, 13 - t->right, _screen.width - 13 - t->left);
- ny = Clamp(ny, 0, _screen.height - 13);
+ /* Search for the title bar */
+ const Widget *t = w->widget;
+ while (t->type != WWT_CAPTION && t->type != WWT_LAST) t++;
+ assert(t->type == WWT_CAPTION);
+
+ /* The minimum number of pixels of the title bar must be visible
+ * in both the X or Y direction */
+ static const int MIN_VISIBLE_TITLE_BAR = 13;
+
+ /* Make sure the window doesn't leave the screen */
+ nx = Clamp(nx, MIN_VISIBLE_TITLE_BAR - t->right, _screen.width - MIN_VISIBLE_TITLE_BAR - t->left);
+ ny = Clamp(ny, 0, _screen.height - MIN_VISIBLE_TITLE_BAR);
/* Make sure the title bar isn't hidden by behind the main tool bar */
Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0);
@@ -1477,18 +1483,18 @@ static bool HandleWindowDragging()
int v_bottom = v->top + v->height;
int v_right = v->left + v->width;
if (ny + t->top >= v->top && ny + t->top < v_bottom) {
- if ((v->left < 13 && nx + t->left < v->left) ||
- (v_right > _screen.width - 13 && nx + t->right > v_right)) {
+ if ((v->left < MIN_VISIBLE_TITLE_BAR && nx + t->left < v->left) ||
+ (v_right > _screen.width - MIN_VISIBLE_TITLE_BAR && nx + t->right > v_right)) {
ny = v_bottom;
} else {
- if (nx + t->left > v->left - 13 &&
- nx + t->right < v_right + 13) {
+ if (nx + t->left > v->left - MIN_VISIBLE_TITLE_BAR &&
+ nx + t->right < v_right + MIN_VISIBLE_TITLE_BAR) {
if (w->top >= v_bottom) {
ny = v_bottom;
} else if (w->left < nx) {
- nx = v->left - 13 - t->left;
+ nx = v->left - MIN_VISIBLE_TITLE_BAR - t->left;
} else {
- nx = v_right + 13 - t->right;
+ nx = v_right + MIN_VISIBLE_TITLE_BAR - t->right;
}
}
}