From ee32654324a7cd4773b59a3445d31599f21abae4 Mon Sep 17 00:00:00 2001 From: pelya Date: Sun, 26 Mar 2017 23:15:55 +0300 Subject: [PATCH] Close windows by dragging them off screen --- src/window.cpp | 25 ++++++++++++++++++++++++- todo.txt | 10 ++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/window.cpp b/src/window.cpp index fcab5348b5..0e5757c176 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2211,7 +2211,7 @@ static void EnsureVisibleCaption(Window *w, int nx, int ny) 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. */ - if (!_settings_client.gui.vertical_toolbar || _game_mode == GM_EDITOR) { + if ((!_settings_client.gui.vertical_toolbar && _settings_client.gui.windows_titlebars) || _game_mode == GM_EDITOR) { // This call hides the window totally with vertical toolbar if you move it slightly off-screen to the left PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR, 0), w->left, PHD_DOWN); } @@ -2291,6 +2291,20 @@ int GetMainViewBottom() return (w == NULL) ? _screen.height : w->top; } +static bool GetWindowDraggedOffScreen(Window *w) +{ + if (_settings_client.gui.windows_titlebars) return false; + Rect edge = { 0, GetMainViewTop(), _screen.width, _screen.height }; + if (_settings_client.gui.vertical_toolbar && _game_mode != GM_EDITOR) { + edge.left += GetMinSizing(NWST_BUTTON, 1); + edge.right -= GetMinSizing(NWST_BUTTON, 1); + } + if (w->left < edge.left && w->left + w->width < edge.right) return true; + if (w->left + w->width > edge.right && w->left > edge.left) return true; + if (w->top < edge.top && w->top + w->height < edge.bottom) return true; + return false; +} + /** * Handle dragging/resizing of a window. * @return State of handling the event. @@ -2310,6 +2324,9 @@ static EventState HandleWindowDragging() /* Stop the dragging if the left mouse button was released */ if (!_left_button_down) { w->flags &= ~WF_DRAGGING; + if (GetWindowDraggedOffScreen(w)) { + delete w; + } break; } @@ -2399,6 +2416,12 @@ static EventState HandleWindowDragging() EnsureVisibleCaption(w, nx, ny); w->SetDirty(); + if (GetWindowDraggedOffScreen(w)) { + GuiShowTooltips(w, STR_TOOLTIP_CLOSE_WINDOW, 0, NULL, TCC_LEFT_CLICK); + } else { + GuiShowTooltips(w, STR_NULL, 0, NULL, TCC_LEFT_CLICK); // Hide tooltip + } + return ES_HANDLED; } else if (w->flags & WF_SIZING) { /* Stop the sizing if the left mouse button was released */ diff --git a/todo.txt b/todo.txt index 3f0bfeb0bf..32f0965dea 100644 --- a/todo.txt +++ b/todo.txt @@ -3,16 +3,14 @@ - Smallmap UI won't fit all FIRS industries. -- 'New game' dialog is broken again. - - Put mouse cursor in the middle between touch points when zooming in and out. - Misclicking station from orders dialog should hide the dialog for 3 times. +- Draggable combo boxes. + +- 'New game' dialog is broken again. + - Fix text input - it should use SDL_ANDROID_GetScreenKeyboardTextInputAsync(), and fix double-backspace bug in SDL. - Tooltip window steals touches, move tooltip window back to the top of the mouse cursor. - -- Move windows by dragging past window edge, close windows by moving them to toolbar. - -- Draggable combo boxes.