From 47494b2744a6b7b76833ada2072fd9a1deafbe44 Mon Sep 17 00:00:00 2001 From: yexo Date: Mon, 30 Aug 2010 14:51:11 +0000 Subject: (svn r20696) -Codechange: create a new function to make sure part of the caption bar is visible when creating a window --- src/window.cpp | 58 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/window.cpp b/src/window.cpp index f6930567f..af9c793f4 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1537,6 +1537,40 @@ static void PreventHiding(int *nx, int *ny, const Rect &rect, const Window *v, i } } +/** + * Make sure at least a part of the caption bar is still visible by moving + * the window if necessary. + * @param w The window to check. + * @param nx The proposed new x-location of the window. + * @param ny The proposed new y-location of the window. + */ +static void EnsureVisibleCaption(Window *w, int nx, int ny) +{ + /* Search for the title bar rectangle. */ + Rect caption_rect; + const NWidgetBase *caption = w->nested_root->GetWidgetOfType(WWT_CAPTION); + assert(caption != NULL); + caption_rect.left = caption->pos_x; + caption_rect.right = caption->pos_x + caption->current_x; + caption_rect.top = caption->pos_y; + caption_rect.bottom = caption->pos_y + caption->current_y; + + /* Make sure the window doesn't leave the screen */ + nx = Clamp(nx, MIN_VISIBLE_TITLE_BAR - caption_rect.right, _screen.width - MIN_VISIBLE_TITLE_BAR - caption_rect.left); + ny = Clamp(ny, 0, _screen.height - MIN_VISIBLE_TITLE_BAR); + + /* Make sure the title bar isn't hidden behind the main tool bar or the status bar. */ + PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR, 0), w->left, PHD_DOWN); + PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_STATUS_BAR, 0), w->left, PHD_UP); + + if (w->viewport != NULL) { + w->viewport->left += nx - w->left; + w->viewport->top += ny - w->top; + } + w->left = nx; + w->top = ny; +} + /** * Resize the window. * Update all the widgets of a window based on their resize flags @@ -1695,29 +1729,7 @@ static EventState HandleWindowDragging() } } - /* Search for the title bar rectangle. */ - Rect caption_rect; - const NWidgetBase *caption = w->nested_root->GetWidgetOfType(WWT_CAPTION); - assert(caption != NULL); - caption_rect.left = caption->pos_x; - caption_rect.right = caption->pos_x + caption->current_x; - caption_rect.top = caption->pos_y; - caption_rect.bottom = caption->pos_y + caption->current_y; - - /* Make sure the window doesn't leave the screen */ - nx = Clamp(nx, MIN_VISIBLE_TITLE_BAR - caption_rect.right, _screen.width - MIN_VISIBLE_TITLE_BAR - caption_rect.left); - ny = Clamp(ny, 0, _screen.height - MIN_VISIBLE_TITLE_BAR); - - /* Make sure the title bar isn't hidden behind the main tool bar or the status bar. */ - PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR, 0), w->left, PHD_DOWN); - PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_STATUS_BAR, 0), w->left, PHD_UP); - - if (w->viewport != NULL) { - w->viewport->left += nx - w->left; - w->viewport->top += ny - w->top; - } - w->left = nx; - w->top = ny; + EnsureVisibleCaption(w, nx, ny); w->SetDirty(); return ES_HANDLED; -- cgit v1.2.3-70-g09d2