From 0e68f9db70d5380ab30e70bd003f35e8bd3679f8 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Fri, 24 Mar 2017 18:55:16 +0000 Subject: [PATCH] (svn r27825) -Feature [FS#4950]: Add option to close windows with right click (Flamefire) --- src/lang/english.txt | 2 ++ src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings.ini | 8 ++++++++ src/window.cpp | 20 ++++++++++++++++---- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 722459c353..5d794483c8 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1372,6 +1372,8 @@ STR_CONFIG_SETTING_RIGHT_MOUSE_BTN_EMU_OFF :Off STR_CONFIG_SETTING_LEFT_MOUSE_BTN_SCROLLING :Left-click scrolling: {STRING2} STR_CONFIG_SETTING_LEFT_MOUSE_BTN_SCROLLING_HELPTEXT :Enable scrolling the map by dragging it with the left mouse button. This is especially useful when using a touch-screen for scrolling +STR_CONFIG_SETTING_RIGHT_MOUSE_WND_CLOSE :Close window on right-click: {STRING2} +STR_CONFIG_SETTING_RIGHT_MOUSE_WND_CLOSE_HELPTEXT :Closes a window by right-clicking inside it. Disables the tooltip on right-click! STR_CONFIG_SETTING_AUTOSAVE :Autosave: {STRING2} STR_CONFIG_SETTING_AUTOSAVE_HELPTEXT :Select interval between automatic game saves diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index e20ac33073..6cde709b06 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1506,6 +1506,7 @@ static SettingsContainer &GetSettingsTree() general->Add(new SettingEntry("gui.errmsg_duration")); general->Add(new SettingEntry("gui.window_snap_radius")); general->Add(new SettingEntry("gui.window_soft_limit")); + general->Add(new SettingEntry("gui.right_mouse_wnd_close")); } SettingsPage *viewports = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_VIEWPORTS)); diff --git a/src/settings_type.h b/src/settings_type.h index 41366a7719..2dc9ec92ec 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -113,6 +113,7 @@ struct GUISettings { uint8 scrollwheel_multiplier; ///< how much 'wheel' per incoming event from the OS? bool timetable_arrival_departure; ///< show arrivals and departures in vehicle timetables bool left_mouse_btn_scrolling; ///< left mouse button scroll + bool right_mouse_wnd_close; ///< close window with right click bool pause_on_newgame; ///< whether to start new games paused or not bool enable_signal_gui; ///< show the signal GUI when the signal button is pressed Year coloured_news_year; ///< when does newspaper become coloured? diff --git a/src/table/settings.ini b/src/table/settings.ini index 8e2aecac15..23fca32a43 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -2583,6 +2583,14 @@ str = STR_CONFIG_SETTING_LEFT_MOUSE_BTN_SCROLLING strhelp = STR_CONFIG_SETTING_LEFT_MOUSE_BTN_SCROLLING_HELPTEXT cat = SC_BASIC +[SDTC_BOOL] +var = gui.right_mouse_wnd_close +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = false +str = STR_CONFIG_SETTING_RIGHT_MOUSE_WND_CLOSE +strhelp = STR_CONFIG_SETTING_RIGHT_MOUSE_WND_CLOSE_HELPTEXT +cat = SC_BASIC + [SDTC_BOOL] var = gui.measure_tooltip flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC diff --git a/src/window.cpp b/src/window.cpp index f1c53f2045..2723612859 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -772,7 +772,15 @@ static void DispatchRightClickEvent(Window *w, int x, int y) if (w->OnRightClick(pt, wid->index)) return; } - if (_settings_client.gui.hover_delay_ms == 0 && wid->tool_tip != 0) GuiShowTooltips(w, wid->tool_tip, 0, NULL, TCC_RIGHT_CLICK); + /* Right-click close is enabled and there is a closebox */ + if (_settings_client.gui.right_mouse_wnd_close && w->nested_root->GetWidgetOfType(WWT_CLOSEBOX)) + { + delete w; + } + else if (_settings_client.gui.hover_delay_ms == 0 && wid->tool_tip != 0) + { + GuiShowTooltips(w, wid->tool_tip, 0, NULL, TCC_RIGHT_CLICK); + } } /** @@ -2825,11 +2833,12 @@ static void MouseLoop(MouseClick click, int mousewheel) switch (click) { case MC_DOUBLE_LEFT: case MC_LEFT: - if (!HandleViewportClicked(vp, x, y) && - !(w->flags & WF_DISABLE_VP_SCROLL) && + if (HandleViewportClicked(vp, x, y)) return; + if (!(w->flags & WF_DISABLE_VP_SCROLL) && _settings_client.gui.left_mouse_btn_scrolling) { _scrolling_viewport = true; _cursor.fix_at = false; + return; } break; @@ -2841,13 +2850,16 @@ static void MouseLoop(MouseClick click, int mousewheel) /* clear 2D scrolling caches before we start a 2D scroll */ _cursor.h_wheel = 0; _cursor.v_wheel = 0; + return; } break; default: break; } - } else { + } + + if (vp == NULL || (w->flags & WF_DISABLE_VP_SCROLL)) { switch (click) { case MC_LEFT: case MC_DOUBLE_LEFT: