From c7ca4691c41d5f691df63240c3de2398b918ad62 Mon Sep 17 00:00:00 2001 From: alberth Date: Sat, 7 Nov 2009 17:24:04 +0000 Subject: [PATCH] (svn r17997) -Codechange: Introduce functions for querying top and bottom of the main view. --- src/misc_gui.cpp | 16 ++++++---------- src/widgets/dropdown.cpp | 9 ++------- src/window.cpp | 20 ++++++++++++++++++++ src/window_func.h | 3 +++ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index aad9ecbf83..eea17b11ef 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -588,13 +588,11 @@ public: return pt; } - /* Find the screen part between the main toolbar at the top, and the statusbar at the bottom. + /* Find the free screen space 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 != NULL) ? w->top + w->height : 0) + 20; - w = FindWindowById(WC_STATUS_BAR, 0); - int scr_bot = ((w != NULL) ? w->top : _screen.height) - 20; + int scr_top = GetMainViewTop() + 20; + int scr_bot = GetMainViewBottom() - 20; Point pt = RemapCoords2(this->position.x, this->position.y); const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport; @@ -805,13 +803,11 @@ 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. + /* Find the free screen space 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 != NULL) ? w->top + w->height : 0) + 2; - w = FindWindowById(WC_STATUS_BAR, 0); - int scr_bot = ((w != NULL) ? w->top : _screen.height) - 2; + int scr_top = GetMainViewTop() + 2; + int scr_bot = GetMainViewBottom() - 2; Point pt; diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index bd8e3f0a2c..409b909668 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -377,18 +377,13 @@ void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, u int height = list_height; /* Check if the status bar is visible, as we don't want to draw over it */ - Window *w3 = FindWindowById(WC_STATUS_BAR, 0); - int screen_bottom = w3 == NULL ? _screen.height : w3->top; - + int screen_bottom = GetMainViewBottom(); bool scroll = false; /* Check if the dropdown will fully fit below the widget */ if (top + height + 4 >= screen_bottom) { - w3 = FindWindowById(WC_MAIN_TOOLBAR, 0); - int screen_top = w3 == NULL ? 0 : w3->top + w3->height; - /* If not, check if it will fit above the widget */ - if (w->top + wi_rect.top - height > screen_top) { + if (w->top + wi_rect.top - height > GetMainViewTop()) { top = w->top + wi_rect.top - height - 4; } else { /* ... and lastly if it won't, enable the scroll bar and fit the diff --git a/src/window.cpp b/src/window.cpp index 0bffa019e9..9af98fb071 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1602,6 +1602,26 @@ void ResizeWindow(Window *w, int delta_x, int delta_y) w->SetDirty(); } +/** Return the top of the main view available for general use. + * @return Uppermost vertical coordinate available. + * @note Above the upper y coordinate is often the main toolbar. + */ +int GetMainViewTop() +{ + Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0); + return (w == NULL) ? 0 : w->top + w->height; +} + +/** Return the bottom of the main view available for general use. + * @return The vertical coordinate of the first unusable row, so 'top + height <= bottom' gives the correct result. + * @note At and below the bottom y coordinate is often the status bar. + */ +int GetMainViewBottom() +{ + Window *w = FindWindowById(WC_STATUS_BAR, 0); + return (w == NULL) ? _screen.height : w->top; +} + /** 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; diff --git a/src/window_func.h b/src/window_func.h index feadd7a186..4d21c41924 100644 --- a/src/window_func.h +++ b/src/window_func.h @@ -21,6 +21,9 @@ void ChangeWindowOwner(Owner old_owner, Owner new_owner); void ResizeWindow(Window *w, int x, int y); int PositionMainToolbar(Window *w); +int GetMainViewTop(); +int GetMainViewBottom(); + void InitWindowSystem(); void UnInitWindowSystem(); void ResetWindowSystem();