From f7155ed34a8906df16d788c5b993371bb7f21b0e Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 17 Mar 2009 23:26:28 +0000 Subject: (svn r15756) -Codechange: remove the assumption that the second windget is always the title bar. Also replace a few magic numbers with a const. --- src/window.cpp | 30 ++++++++++++++++++------------ 1 file 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; } } } -- cgit v1.2.3-54-g00ecf