From c76c67b125d42fc817988b81af23ceb5d10ea92d Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 16 Apr 2021 22:00:33 -0700 Subject: [PATCH 1/2] Axe mouse cursor config option The config option has been removed. I'm going to implement something that automatically shows and hides the mouse cursor whenever appropriate, which is better than a config option. --- desktop_version/src/Game.cpp | 17 ----------------- desktop_version/src/Graphics.cpp | 1 - desktop_version/src/Graphics.h | 2 -- desktop_version/src/Input.cpp | 15 +-------------- desktop_version/src/Render.cpp | 13 +------------ 5 files changed, 2 insertions(+), 46 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 4a6af077..c1796c0b 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -4215,11 +4215,6 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s graphics.translucentroomname = help.Int(pText); } - if (SDL_strcmp(pKey, "showmousecursor") == 0) - { - graphics.showmousecursor = help.Int(pText); - } - if (SDL_strcmp(pKey, "musicvolume") == 0) { music.user_music_volume = help.Int(pText); @@ -4273,15 +4268,6 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s } - if (graphics.showmousecursor) - { - SDL_ShowCursor(SDL_ENABLE); - } - else - { - SDL_ShowCursor(SDL_DISABLE); - } - if (controllerButton_flip.size() < 1) { controllerButton_flip.push_back(SDL_CONTROLLER_BUTTON_A); @@ -4451,8 +4437,6 @@ void Game::serializesettings(tinyxml2::XMLElement* dataNode, const ScreenSetting xml::update_tag(dataNode, "translucentroomname", (int) graphics.translucentroomname); - xml::update_tag(dataNode, "showmousecursor", (int) graphics.showmousecursor); - xml::update_tag(dataNode, "over30mode", (int) over30mode); xml::update_tag(dataNode, "inputdelay", (int) inputdelay); @@ -6062,7 +6046,6 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ ) maxspacing = 15; break; case Menu::advancedoptions: - option("toggle mouse"); option("unfocus pause"); option("room name background"); option("return"); diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index e10af945..55731b6d 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -125,7 +125,6 @@ void Graphics::init(void) warprect = SDL_Rect(); translucentroomname = false; - showmousecursor = true; alpha = 1.0f; diff --git a/desktop_version/src/Graphics.h b/desktop_version/src/Graphics.h index 247c465c..9056cffc 100644 --- a/desktop_version/src/Graphics.h +++ b/desktop_version/src/Graphics.h @@ -323,8 +323,6 @@ public: bool translucentroomname; - bool showmousecursor; - std::map font_positions; SDL_Surface* ghostbuffer; diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index ef3c35ec..dffe9a02 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -601,25 +601,12 @@ static void menuactionpress(void) switch (game.currentmenuoption) { case 0: - //toggle mouse cursor - music.playef(11); - if (graphics.showmousecursor == true) { - SDL_ShowCursor(SDL_DISABLE); - graphics.showmousecursor = false; - } - else { - SDL_ShowCursor(SDL_ENABLE); - graphics.showmousecursor = true; - } - game.savestatsandsettings_menu(); - break; - case 1: // toggle unfocus pause game.disablepause = !game.disablepause; game.savestatsandsettings_menu(); music.playef(11); break; - case 2: + case 1: // toggle translucent roomname BG graphics.translucentroomname = !graphics.translucentroomname; game.savestatsandsettings_menu(); diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index dc8f7b0b..e44739cd 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -595,17 +595,6 @@ static void menurender(void) switch (game.currentmenuoption) { case 0: - graphics.bigprint(-1, 30, "Toggle Mouse Cursor", tr, tg, tb, true); - graphics.Print(-1, 65, "Show/hide the system mouse cursor.", tr, tg, tb, true); - - if (graphics.showmousecursor) { - graphics.Print(-1, 95, "Current mode: SHOW", tr, tg, tb, true); - } - else { - graphics.Print(-1, 95, "Current mode: HIDE", tr/2, tg/2, tb/2, true); - } - break; - case 1: graphics.bigprint( -1, 30, "Unfocus Pause", tr, tg, tb, true); graphics.Print( -1, 65, "Toggle if the game will pause", tr, tg, tb, true); graphics.Print( -1, 75, "when the window is unfocused.", tr, tg, tb, true); @@ -618,7 +607,7 @@ static void menurender(void) graphics.Print(-1, 95, "Unfocus pause is ON", tr, tg, tb, true); } break; - case 2: + case 1: graphics.bigprint(-1, 30, "Room Name BG", tr, tg, tb, true); graphics.Print( -1, 65, "Lets you see through what is behind", tr, tg, tb, true); graphics.Print( -1, 75, "the name at the bottom of the screen.", tr, tg, tb, true); From 83ad5e66dedec2717067eeab6a28406dd1b0b754 Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 16 Apr 2021 22:46:43 -0700 Subject: [PATCH 2/2] Show and hide mouse cursor based on user input This is quite simple - whenever the user uses their keyboard or controller, we hide the mouse cursor. Whenever they move the mouse, we show it again. This makes it so the cursor gets out of the way when they play the game, but reappears when they need it. There is also a timeout, to prevent strobing if the user decides to use the keyboard/controller and mouse at the same time. There is no timeout from hiding the mouse cursor, but there is a timeout from showing the mouse cursor - this because it's okay if the mouse lingers for a few frames when you start using the keyboard, but really annoying if the mouse doesn't instantly appear when you move it. --- desktop_version/src/KeyPoll.cpp | 77 +++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/desktop_version/src/KeyPoll.cpp b/desktop_version/src/KeyPoll.cpp index 5d152171..4fee8a73 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -81,8 +81,60 @@ void KeyPoll::toggleFullscreen(void) } } +static int changemousestate( + int timeout, + const bool show, + const bool hide +) { + int prev; + int new_; + + if (timeout > 0) + { + return --timeout; + } + + /* If we want to both show and hide at the same time, prioritize showing */ + if (show) + { + new_ = SDL_ENABLE; + } + else if (hide) + { + new_ = SDL_DISABLE; + } + else + { + return timeout; + } + + prev = SDL_ShowCursor(SDL_QUERY); + + if (prev == new_) + { + return timeout; + } + + SDL_ShowCursor(new_); + + switch (new_) + { + case SDL_DISABLE: + timeout = 0; + break; + case SDL_ENABLE: + timeout = 30; + break; + } + + return timeout; +} + void KeyPoll::Poll(void) { + static int mousetoggletimeout = 0; + bool showmouse = false; + bool hidemouse = false; bool altpressed = false; bool fullscreenkeybind = false; SDL_Event evt; @@ -324,8 +376,33 @@ void KeyPoll::Poll(void) VVV_exit(0); break; } + + switch (evt.type) + { + case SDL_KEYDOWN: + if (evt.key.repeat == 0) + { + hidemouse = true; + } + break; + case SDL_TEXTINPUT: + case SDL_CONTROLLERBUTTONDOWN: + case SDL_CONTROLLERAXISMOTION: + hidemouse = true; + break; + case SDL_MOUSEMOTION: + case SDL_MOUSEBUTTONDOWN: + showmouse = true; + break; + } } + mousetoggletimeout = changemousestate( + mousetoggletimeout, + showmouse, + hidemouse + ); + if (fullscreenkeybind) { toggleFullscreen();