summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/misc_gui.cpp16
-rw-r--r--src/widgets/dropdown.cpp9
-rw-r--r--src/window.cpp20
-rw-r--r--src/window_func.h3
4 files changed, 31 insertions, 17 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index aad9ecbf8..eea17b11e 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 bd8e3f0a2..409b90966 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 0bffa019e..9af98fb07 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 feadd7a18..4d21c4192 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();