summaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2004-11-13 10:53:42 +0000
committertron <tron@openttd.org>2004-11-13 10:53:42 +0000
commit53116247c3898a6ad01de6609ea1a64577908724 (patch)
tree8c749511dc684a2040a586486a5d8952e57dc2c4 /window.c
parent22f627c8e11b2b432f385d107417297e9b237c14 (diff)
downloadopenttd-53116247c3898a6ad01de6609ea1a64577908724.tar.xz
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
While here make clamping against the screen border a bit nicer
Diffstat (limited to 'window.c')
-rw-r--r--window.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/window.c b/window.c
index 588e20ee6..778360aff 100644
--- a/window.c
+++ b/window.c
@@ -701,6 +701,7 @@ bool HandleWindowDragging()
// Otherwise find the window...
for (w = _windows; w != _last_window; w++) {
if (w->flags4 & WF_DRAGGING) {
+ const Widget *t = &w->widget[1]; // the title bar ... ugh
const Window *v;
int x;
int y;
@@ -796,9 +797,34 @@ bool HandleWindowDragging()
// Make sure the window doesn't leave the screen
// 13 is the height of the title bar
- nx = clamp(nx, 13 - w->width, _screen.width - 13);
+ nx = clamp(nx, 13 - t->right, _screen.width - 13 - t->left);
ny = clamp(ny, 0, _screen.height - 13);
+ // Make sure the title bar isn't hidden by behind the main tool bar
+ v = FindWindowById(WC_MAIN_TOOLBAR, 0);
+ if (v != NULL) {
+ 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) {
+ ny = v_bottom;
+ } else if (v_right > _screen.width - 13 &&
+ nx + t->right > v_right) {
+ ny = v_bottom;
+ } else {
+ if (nx + t->left > v->left - 13 &&
+ nx + t->right < v_right + 13) {
+ if (w->top >= v_bottom)
+ ny = v_bottom;
+ else if (w->left < nx)
+ nx = v->left - 13 - t->left;
+ else
+ nx = v_right + 13 - t->right;
+ }
+ }
+ }
+ }
+
if (w->viewport != NULL) {
w->viewport->left += nx - w->left;
w->viewport->top += ny - w->top;