Toned down window closing by dragging, dim window when it's closed

This commit is contained in:
pelya
2017-04-07 21:29:43 +03:00
parent 99df613d97
commit f2405b6e3e
3 changed files with 31 additions and 8 deletions

View File

@@ -592,6 +592,11 @@ void Window::DrawWidgets() const
GfxFillRect(left, bottom, right, bottom, colour);
}
}
/* Dim the window if it's about to close */
if ((this->flags & WF_DRAGGING) && !_settings_client.gui.windows_titlebars && GetWindowDraggedOffScreen(this)) {
GfxFillRect(2, 2, this->width - 3, this->height - 3, PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR);
}
}
/**

View File

@@ -2055,7 +2055,12 @@ static void HandleMouseDragNoTitlebars()
if (_settings_client.gui.windows_titlebars || _dragging_window ||
!_left_button_down || _focused_window == NULL || _dragging_widget) return;
unsigned distance = abs(_cursor.pos.x - _left_button_down_pos.x) + abs(_cursor.pos.y - _left_button_down_pos.y);
if (distance * 2 > GetMinSizing(NWST_STEP)) {
if (distance * 2 > GetMinSizing(NWST_STEP) &&
_focused_window->window_class != WC_SELECT_GAME &&
_focused_window->window_class != WC_STATUS_BAR &&
_focused_window->window_class != WC_MAIN_TOOLBAR &&
_focused_window->window_class != WC_MAIN_TOOLBAR_RIGHT &&
_focused_window->window_class != WC_BUILD_CONFIRMATION) {
//SendLeftClickEventToWindow(_focused_window, _left_button_down_pos.x, _left_button_down_pos.y, 1);
StartWindowDrag(_focused_window);
_drag_delta.x += _cursor.pos.x - _left_button_down_pos.x;
@@ -2276,18 +2281,29 @@ int GetMainViewBottom()
return (w == NULL) ? _screen.height : w->top;
}
static bool GetWindowDraggedOffScreen(Window *w)
bool GetWindowDraggedOffScreen(const 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) {
if (_settings_client.gui.vertical_toolbar && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
edge.left += GetMinSizing(NWST_BUTTON);
edge.right -= GetMinSizing(NWST_BUTTON);
}
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;
if (w->top + w->height > edge.bottom && w->top > edge.top) return true;
Rect visible = { edge.left + (int)GetMinSizing(NWST_BUTTON) * 4, edge.top + (int)GetMinSizing(NWST_BUTTON) * 2,
edge.right - (int)GetMinSizing(NWST_BUTTON) * 4, edge.bottom - (int)GetMinSizing(NWST_BUTTON) * 2 };
// 1/4 of the window must be hidden to close it when flicking it off to the left/right
if (w->width >= (int)GetMinSizing(NWST_BUTTON) * 4) {
edge.left -= GetMinSizing(NWST_BUTTON) * 2;
edge.right += GetMinSizing(NWST_BUTTON) * 2;
}
if (w->height >= (int)GetMinSizing(NWST_BUTTON) * 4) {
edge.top -= GetMinSizing(NWST_BUTTON);
edge.bottom += GetMinSizing(NWST_BUTTON);
}
if (w->left < edge.left && w->left + w->width < visible.right) return true;
if (w->left + w->width > edge.right && w->left > visible.left) return true;
if (w->top < edge.top && w->top + w->height < visible.bottom) return true;
if (w->top + w->height > edge.bottom && w->top > visible.top) return true;
return false;
}
@@ -2311,7 +2327,7 @@ static EventState HandleWindowDragging()
if (!_left_button_down) {
w->flags &= ~WF_DRAGGING;
if (GetWindowDraggedOffScreen(w)) {
if (w->window_class != WC_SELECT_GAME) delete w;
delete w;
}
break;
}

View File

@@ -914,4 +914,6 @@ void SetFocusedWindow(Window *w);
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y);
bool GetWindowDraggedOffScreen(const Window *w); ///< Return whether window is dragged off screen edge and about to close, for no-titlebars mode
#endif /* WINDOW_GUI_H */