(svn r17997) -Codechange: Introduce functions for querying top and bottom of the main view.

This commit is contained in:
alberth 2009-11-07 17:24:04 +00:00
parent b500170ac2
commit 0bc03c25f4
4 changed files with 31 additions and 17 deletions

View File

@ -588,13 +588,11 @@ public:
return pt; 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. * Add a fixed distance 20 to make it less cluttered.
*/ */
const Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0); int scr_top = GetMainViewTop() + 20;
int scr_top = ((w != NULL) ? w->top + w->height : 0) + 20; int scr_bot = GetMainViewBottom() - 20;
w = FindWindowById(WC_STATUS_BAR, 0);
int scr_bot = ((w != NULL) ? w->top : _screen.height) - 20;
Point pt = RemapCoords2(this->position.x, this->position.y); Point pt = RemapCoords2(this->position.x, this->position.y);
const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport; 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) 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. * Add a fixed distance 2 so the tooltip floats free from both bars.
*/ */
const Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0); int scr_top = GetMainViewTop() + 2;
int scr_top = ((w != NULL) ? w->top + w->height : 0) + 2; int scr_bot = GetMainViewBottom() - 2;
w = FindWindowById(WC_STATUS_BAR, 0);
int scr_bot = ((w != NULL) ? w->top : _screen.height) - 2;
Point pt; Point pt;

View File

@ -377,18 +377,13 @@ void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, u
int height = list_height; int height = list_height;
/* Check if the status bar is visible, as we don't want to draw over it */ /* 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 = GetMainViewBottom();
int screen_bottom = w3 == NULL ? _screen.height : w3->top;
bool scroll = false; bool scroll = false;
/* Check if the dropdown will fully fit below the widget */ /* Check if the dropdown will fully fit below the widget */
if (top + height + 4 >= screen_bottom) { 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 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; top = w->top + wi_rect.top - height - 4;
} else { } else {
/* ... and lastly if it won't, enable the scroll bar and fit the /* ... and lastly if it won't, enable the scroll bar and fit the

View File

@ -1602,6 +1602,26 @@ void ResizeWindow(Window *w, int delta_x, int delta_y)
w->SetDirty(); 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 */ /** 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; static const int MIN_VISIBLE_TITLE_BAR = 13;

View File

@ -21,6 +21,9 @@ void ChangeWindowOwner(Owner old_owner, Owner new_owner);
void ResizeWindow(Window *w, int x, int y); void ResizeWindow(Window *w, int x, int y);
int PositionMainToolbar(Window *w); int PositionMainToolbar(Window *w);
int GetMainViewTop();
int GetMainViewBottom();
void InitWindowSystem(); void InitWindowSystem();
void UnInitWindowSystem(); void UnInitWindowSystem();
void ResetWindowSystem(); void ResetWindowSystem();