Skip to content

Commit 3ab6ba4

Browse files
committed
Hide mouse pointer when closing the UI.
1 parent 77bb68b commit 3ab6ba4

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

src/RenderLoop.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ void RenderLoop::KeyEvent(const SDL_KeyboardEvent& event, bool down)
172172
{
173173
case SDLK_ESCAPE:
174174
_projectMGui.Toggle();
175+
_sdlRenderingWindow.ShowCursor(_projectMGui.Visible());
175176
break;
176177

177178
case SDLK_a: {

src/SDLRenderingWindow.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ void SDLRenderingWindow::Windowed()
111111
_fullscreen = false;
112112
}
113113

114+
void SDLRenderingWindow::ShowCursor(bool visible)
115+
{
116+
SDL_ShowCursor(visible);
117+
}
118+
114119
void SDLRenderingWindow::NextDisplay()
115120
{
116121
auto numDisplays = SDL_GetNumVideoDisplays();

src/SDLRenderingWindow.h

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ class SDLRenderingWindow : public Poco::Util::Subsystem
5656
*/
5757
void Windowed();
5858

59+
/**
60+
* @brief Sets the visibility of the mouse cursor
61+
* @param visible true if the cursor should be displayed, false otherwise.
62+
*/
63+
void ShowCursor(bool visible);
64+
5965
/**
6066
* @brief Moves the current window to the next display.
6167
*

src/gui/ProjectMGUI.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ void ProjectMGUI::Toggle()
125125
_visible = !_visible;
126126
}
127127

128+
void ProjectMGUI::Visible(bool visible)
129+
{
130+
_visible = visible;
131+
}
132+
133+
bool ProjectMGUI::Visible() const
134+
{
135+
return _visible;
136+
}
137+
128138
void ProjectMGUI::Draw()
129139
{
130140
// Don't render UI at all if there's no need.
@@ -231,4 +241,4 @@ void ProjectMGUI::DisplayToastNotificationHandler(const Poco::AutoPtr<DisplayToa
231241
{
232242
_toast = std::make_unique<ToastMessage>(notification->ToastText(), 3.0f);
233243
}
234-
}
244+
}

src/gui/ProjectMGUI.h

+12
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ class ProjectMGUI : public Poco::Util::Subsystem
6969
*/
7070
void Toggle();
7171

72+
/**
73+
* @brief Sets the visibility of the UI.
74+
* @param visible true if the UI will be rendered, false if not.
75+
*/
76+
void Visible(bool visible);
77+
78+
/**
79+
* @brief Returns the visibiity of the UI.
80+
* @return true if the UI is visible, false if not.
81+
*/
82+
bool Visible() const;
83+
7284
/**
7385
* @brief Draws the UI, including toasts.
7486
* If neither a toast nor the UI are visible, this is basically a no-op.

0 commit comments

Comments
 (0)