diff options
author | alberth <alberth@openttd.org> | 2009-11-01 19:19:14 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2009-11-01 19:19:14 +0000 |
commit | df8c655ee66ee2efcb46327cfd2f8c66cc47a3c5 (patch) | |
tree | 7015b8b2a8d48eb1a6dd6e4744bbb7a37f167c9a /src | |
parent | 492a32d31c20ecd95f381c6728b948596f15f4b3 (diff) | |
download | openttd-df8c655ee66ee2efcb46327cfd2f8c66cc47a3c5.tar.xz |
(svn r17940) -Codechange: Use real y position of the main toolbar and status bar instead of hardcoded sizes for tooltip and for error message windows.
Diffstat (limited to 'src')
-rw-r--r-- | src/misc_gui.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 7e7b24cf3..4c373345d 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -589,19 +589,27 @@ public: return pt; } + /* Find the screen part between the main toolbar at the top, and the statusbar at the bottom. + * Add a fixed distance 20 to make it less cluttered. + */ + const Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0); + int scr_top = w->top + w->height + 20; + w = FindWindowById(WC_STATUS_BAR, 0); + int scr_bot = w->top - 20; + Point pt = RemapCoords2(this->position.x, this->position.y); const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport; if (this->detailed_msg != STR_ERROR_OWNED_BY || GetDParamX(this->decode_params, 2) >= MAX_COMPANIES) { /* move x pos to opposite corner */ pt.x = UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left; - pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - sm_width - 20 : 20; + pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - sm_width - 20 : 20; // Stay 20 pixels away from the edge of the screen. /* move y pos to opposite corner */ pt.y = UnScaleByZoom(pt.y - vp->virtual_top, vp->zoom) + vp->top; - pt.y = (pt.y < (_screen.height >> 1)) ? _screen.height - 80 : 100; + pt.y = (pt.y < (_screen.height >> 1)) ? scr_bot - sm_height : scr_top; } else { pt.x = Clamp(UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left - (sm_width / 2), 0, _screen.width - sm_width); - pt.y = Clamp(UnScaleByZoom(pt.y - vp->virtual_top, vp->zoom) + vp->top - (sm_height / 2), 22, _screen.height - sm_height); + pt.y = Clamp(UnScaleByZoom(pt.y - vp->virtual_top, vp->zoom) + vp->top - (sm_height / 2), scr_top, scr_bot - sm_height); } return pt; } @@ -798,13 +806,21 @@ struct TooltipsWindow : public Window virtual Point OnInitialPosition(const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number) { + /* Find the screen part between the main toolbar at the top, and the statusbar at the bottom. + * Add a fixed distance 2 so the tooltip floats free from both bars. + */ + const Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0); + int scr_top = w->top + w->height + 2; + w = FindWindowById(WC_STATUS_BAR, 0); + int scr_bot = w->top - 2; + Point pt; /* Correctly position the tooltip position, watch out for window and cursor size * Clamp value to below main toolbar and above statusbar. If tooltip would * go below window, flip it so it is shown above the cursor */ - pt.y = Clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, 22, _screen.height - 12); - if (pt.y + sm_height > _screen.height - 12) pt.y = min(_cursor.pos.y + _cursor.offs.y - 5, _screen.height - 12) - sm_height; + pt.y = Clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, scr_top, scr_bot); + if (pt.y + sm_height > scr_bot) pt.y = min(_cursor.pos.y + _cursor.offs.y - 5, scr_bot) - sm_height; pt.x = Clamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width); return pt; |