From 03a4c3362a5f826966d9860d176326a529437986 Mon Sep 17 00:00:00 2001 From: Allison Fleischer Date: Tue, 28 Jan 2020 23:17:13 -0800 Subject: [PATCH] Add graphics option to toggle mouse cursor Adds an option to show or hide the system mouse cursor over the game window. --- desktop_version/src/Game.cpp | 23 +++++++++++++++++++++-- desktop_version/src/Graphics.cpp | 1 + desktop_version/src/Graphics.h | 2 ++ desktop_version/src/Input.cpp | 11 +++++++++++ desktop_version/src/titlerender.cpp | 12 ++++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index b1f76234..22bdd210 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -4448,6 +4448,11 @@ void Game::loadstats( mapclass& map, Graphics& dwgfx ) dwgfx.translucentroomname = atoi(pText); } + if (pKey == "showmousecursor") + { + dwgfx.showmousecursor = atoi(pText); + } + if (pKey == "flipButton") { SDL_GameControllerButton newButton; @@ -4496,6 +4501,14 @@ void Game::loadstats( mapclass& map, Graphics& dwgfx ) } dwgfx.screenbuffer->ResizeScreen(width, height); + if (dwgfx.showmousecursor == true) + { + SDL_ShowCursor(SDL_ENABLE); + } + else { + SDL_ShowCursor(SDL_DISABLE); + } + if (controllerButton_flip.size() < 1) { controllerButton_flip.push_back(SDL_CONTROLLER_BUTTON_A); @@ -4665,6 +4678,10 @@ void Game::savestats( mapclass& _map, Graphics& _dwgfx ) msg->LinkEndChild(new TiXmlText(tu.String((int) _dwgfx.translucentroomname).c_str())); dataNode->LinkEndChild(msg); + msg = new TiXmlElement("showmousecursor"); + msg->LinkEndChild(new TiXmlText(tu.String((int)_dwgfx.showmousecursor).c_str())); + dataNode->LinkEndChild(msg); + for (size_t i = 0; i < controllerButton_flip.size(); i += 1) { msg = new TiXmlElement("flipButton"); @@ -6888,9 +6905,11 @@ void Game::createmenu( std::string t ) menuoptionsactive[2] = true; menuoptions[3] = "toggle analogue"; menuoptionsactive[3] = true; - menuoptions[4] = "return"; + menuoptions[4] = "toggle mouse"; menuoptionsactive[4] = true; - nummenuoptions = 5; + menuoptions[5] = "return"; + menuoptionsactive[5] = true; + nummenuoptions = 6; menuxoff = -50; menuyoff = 8; /* Old stuff, not used anymore diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 7afc923b..f40f0a33 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -124,6 +124,7 @@ Graphics::Graphics() warprect = SDL_Rect(); translucentroomname = false; + showmousecursor = true; } Graphics::~Graphics() diff --git a/desktop_version/src/Graphics.h b/desktop_version/src/Graphics.h index 717a79fd..a2b10d7c 100644 --- a/desktop_version/src/Graphics.h +++ b/desktop_version/src/Graphics.h @@ -278,6 +278,8 @@ public: int warpskip, warpfcol, warpbcol; bool translucentroomname; + + bool showmousecursor; }; #endif /* GRAPHICS_H */ diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 91b6ff16..e4bf705f 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -460,6 +460,17 @@ SDL_assert(0 && "Remove open level dir"); game.savestats(map, dwgfx); game.createmenu("graphicoptions"); game.currentmenuoption = 3; + }else if (game.currentmenuoption == 4) { + //toggle mouse cursor + music.playef(11, 10); + if (dwgfx.showmousecursor == true) { + SDL_ShowCursor(SDL_DISABLE); + dwgfx.showmousecursor = false; + } + else { + SDL_ShowCursor(SDL_ENABLE); + dwgfx.showmousecursor = true; + } } else { diff --git a/desktop_version/src/titlerender.cpp b/desktop_version/src/titlerender.cpp index 65bbc8e2..6473829b 100644 --- a/desktop_version/src/titlerender.cpp +++ b/desktop_version/src/titlerender.cpp @@ -230,6 +230,18 @@ void titlerender(Graphics& dwgfx, mapclass& map, Game& game, entityclass& obj, U dwgfx.Print( -1, 75, "television set. Do not attempt to", tr, tg, tb, true); dwgfx.Print( -1, 85, "adjust the picture.", tr, tg, tb, true); } + else if (game.currentmenuoption == 4) + { + dwgfx.bigprint(-1, 30, "Toggle Mouse Cursor", tr, tg, tb, true); + dwgfx.Print(-1, 65, "Show/hide the system mouse cursor.", tr, tg, tb, true); + + if (dwgfx.showmousecursor) { + dwgfx.Print(-1, 85, "Current mode: SHOW", tr, tg, tb, true); + } + else { + dwgfx.Print(-1, 85, "Current mode: HIDE", tr, tg, tb, true); + } + } } else if (game.currentmenuname == "credits") {