From 4d369cbeb2597364bcc1ea9c4418369a2e40892d Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Tue, 11 May 2021 01:05:10 +0300 Subject: [PATCH] Option to disable mouse cursor for touchscreen devices --- src/gfx.cpp | 4 ++-- src/lang/english.txt | 2 ++ src/settings_gui.cpp | 21 ++++++++++++++++++++- src/settings_type.h | 1 + src/table/settings.ini | 8 ++++++++ src/widgets/settings_widget.h | 1 + 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/gfx.cpp b/src/gfx.cpp index 5b85476035..bba1b1baa1 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1399,7 +1399,7 @@ void ScreenSizeChanged() void UndrawMouseCursor() { /* Don't undraw mouse cursor if it is handled by the video driver. */ - if (VideoDriver::GetInstance()->UseSystemCursor()) return; + if (VideoDriver::GetInstance()->UseSystemCursor() || !_settings_client.gui.draw_mouse_cursor) return; /* Don't undraw the mouse cursor if the screen is not ready */ if (_screen.dst_ptr == nullptr) return; @@ -1415,7 +1415,7 @@ void UndrawMouseCursor() void DrawMouseCursor() { /* Don't draw mouse cursor if it is handled by the video driver. */ - if (VideoDriver::GetInstance()->UseSystemCursor()) return; + if (VideoDriver::GetInstance()->UseSystemCursor() || !_settings_client.gui.draw_mouse_cursor) return; /* Don't draw the mouse cursor if the screen is not ready */ if (_screen.dst_ptr == nullptr) return; diff --git a/src/lang/english.txt b/src/lang/english.txt index 038f6cc4ea..6d1cd146f6 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1279,6 +1279,8 @@ STR_CONFIG_SETTING_VIDEO_16BPP :{BLACK}16 bit STR_CONFIG_SETTING_VIDEO_16BPP_HELPTEXT :{BLACK}Set video color depth to 16 bits per pixel, this requires restart, this video mode does not support water animation STR_CONFIG_SETTING_VIDEO_24BPP :{BLACK}24 bit STR_CONFIG_SETTING_VIDEO_24BPP_HELPTEXT :{BLACK}Set video color depth to 24 bits per pixel, this video mode supports water animation +STR_CONFIG_SETTING_MOUSE_CURSOR :{BLACK}Mouse cursor +STR_CONFIG_SETTING_MOUSE_CURSOR_HELPTEXT :{BLACK}Show mouse cursor STR_CONFIG_SETTING_SHOWFINANCES :Show finances window at the end of the year: {STRING2} STR_CONFIG_SETTING_SHOWFINANCES_HELPTEXT :If enabled, the finances window pops up at the end of each year to allow easy inspection of the financial status of the company STR_CONFIG_SETTING_NONSTOP_BY_DEFAULT :New orders are 'non-stop' by default: {STRING2} diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index ccf258a17c..dab064372e 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -521,6 +521,15 @@ struct GameOptionsWindow : Window { #endif break; + case WID_GO_MOUSE_CURSOR: + if (_settings_client.gui.draw_mouse_cursor) { + UndrawMouseCursor(); + } + _settings_client.gui.draw_mouse_cursor = !_settings_client.gui.draw_mouse_cursor; + this->SetWidgetLoweredState(WID_GO_MOUSE_CURSOR, _settings_client.gui.draw_mouse_cursor); + this->SetDirty(); + break; + case WID_GO_VIDEO_ACCEL_BUTTON: _video_hw_accel = !_video_hw_accel; ShowErrorMessage(STR_GAME_OPTIONS_VIDEO_ACCELERATION_RESTART, INVALID_STRING_ID, WL_INFO); @@ -696,6 +705,7 @@ struct GameOptionsWindow : Window { this->SetWidgetLoweredState(WID_GO_8BPP_BUTTON, _ini_blitter == "8bpp-optimized"); this->SetWidgetLoweredState(WID_GO_16BPP_BUTTON, _ini_blitter == "16bpp-simple"); this->SetWidgetLoweredState(WID_GO_32BPP_BUTTON, _ini_blitter == "32bpp-anim" || _ini_blitter == ""); + this->SetWidgetLoweredState(WID_GO_MOUSE_CURSOR, _settings_client.gui.draw_mouse_cursor); #if 0 #ifndef __APPLE__ @@ -734,7 +744,9 @@ static const NWidgetPart _nested_game_options_widgets[] = { EndContainer(), NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_CONFIG_SETTING_WINDOWS_TITLEBARS, STR_NULL), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_WINDOWS_TITLEBARS), SetMinimalSize(21, 9), SetDataTip(STR_CONFIG_SETTING_WINDOWS_TITLEBARS, STR_CONFIG_SETTING_WINDOWS_TITLEBARS_HELPTEXT), SetFill(1, 0), + NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetDataTip(STR_CONFIG_SETTING_WINDOWS_TITLEBARS, STR_NULL), + NWidget(NWID_SPACER), SetMinimalSize(1, 0), SetFill(1, 0), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_WINDOWS_TITLEBARS), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_CONFIG_SETTING_WINDOWS_TITLEBARS_HELPTEXT), EndContainer(), EndContainer(), NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_RESOLUTION, STR_NULL), @@ -749,6 +761,13 @@ static const NWidgetPart _nested_game_options_widgets[] = { NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_32BPP_BUTTON), SetMinimalSize(9, 9), SetDataTip(STR_CONFIG_SETTING_VIDEO_24BPP, STR_CONFIG_SETTING_VIDEO_24BPP_HELPTEXT), EndContainer(), EndContainer(), + NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_CONFIG_SETTING_MOUSE_CURSOR, STR_NULL), + NWidget(NWID_HORIZONTAL), + NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetDataTip(STR_CONFIG_SETTING_MOUSE_CURSOR, STR_NULL), + NWidget(NWID_SPACER), SetMinimalSize(1, 0), SetFill(1, 0), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_MOUSE_CURSOR), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_CONFIG_SETTING_MOUSE_CURSOR_HELPTEXT), + EndContainer(), + EndContainer(), EndContainer(), NWidget(NWID_VERTICAL), SetPIP(0, 6, 0), diff --git a/src/settings_type.h b/src/settings_type.h index bf29e6cb6f..fbf36661bd 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -98,6 +98,7 @@ struct GUISettings { bool compact_vertical_toolbar; ///< compact mode for vertical toolbars, with more sub-menus bool build_confirmation; ///< show confirmation dialog when building roads and stations bool windows_titlebars; ///< show or hide titlebars for all windows to increase scrren space + bool draw_mouse_cursor; ///< draw mouse cursor, touchscreen does not generally need a mouse cursor, but mouse cursor shows currently selected build tool bool windows_decorations; ///< draw ornament on all window edges uint min_button; ///< min size of most button widgets bool show_finances; ///< show finances at end of year diff --git a/src/table/settings.ini b/src/table/settings.ini index 65a8ff6175..b61b22d602 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -2748,6 +2748,14 @@ str = STR_CONFIG_SETTING_WINDOWS_TITLEBARS strhelp = STR_CONFIG_SETTING_WINDOWS_TITLEBARS_HELPTEXT cat = SC_BASIC +[SDTC_BOOL] +var = gui.draw_mouse_cursor +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = true +str = STR_CONFIG_SETTING_MOUSE_CURSOR +strhelp = STR_CONFIG_SETTING_MOUSE_CURSOR_HELPTEXT +cat = SC_BASIC + [SDTC_BOOL] var = gui.windows_decorations flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC diff --git a/src/widgets/settings_widget.h b/src/widgets/settings_widget.h index 1f4a928acb..1a6a820287 100644 --- a/src/widgets/settings_widget.h +++ b/src/widgets/settings_widget.h @@ -27,6 +27,7 @@ enum GameOptionsWidgets { WID_GO_VERTICAL_TOOLBAR, ///< Enable vertical toolbar. WID_GO_BUILD_CONFIRMATION, ///< Enable build confirmation dialog. WID_GO_WINDOWS_TITLEBARS, ///< Titlebars for all windows. + WID_GO_MOUSE_CURSOR, ///< Show mouse cursor. WID_GO_GUI_ZOOM_DROPDOWN, ///< Dropdown for the GUI zoom level. WID_GO_BASE_GRF_DROPDOWN, ///< Use to select a base GRF. WID_GO_BASE_GRF_STATUS, ///< Info about missing files etc.