Skip to content

Commit

Permalink
libgui|GuiApp: Changing or hiding the mouse cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent e9c7a8f commit 25c7c32
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
23 changes: 15 additions & 8 deletions doomsday/libs/gui/include/de/gui/guiapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class Thread;
class LIBGUI_PUBLIC GuiApp : public App
, DE_OBSERVES(Loop, Iteration)
{
public:
enum MouseCursor { None, Arrow, ResizeHorizontal, ResizeVertical };

/// Emitted when the display mode has changed.
DE_DEFINE_AUDIENCE2(DisplayModeChange, void displayModeChanged())

public:
GuiApp(const StringList &args);

Expand All @@ -68,6 +74,14 @@ class LIBGUI_PUBLIC GuiApp : public App
const String &appName,
const String &appVersion);

int exec(const std::function<void()> &startup = {});

void quit(int code = 0);

GuiLoop &loop();

void setMouseCursor(MouseCursor cursor);

/**
* Emits the displayModeChanged() signal.
*
Expand All @@ -77,11 +91,7 @@ class LIBGUI_PUBLIC GuiApp : public App
*/
void notifyDisplayModeChanged();

int exec(const std::function<void ()> &startup = {});
void quit(int code = 0);

GuiLoop &loop();

public:
/**
* Determines if the currently executing thread is the rendering thread.
* This may be the same thread as the main thread.
Expand All @@ -90,9 +100,6 @@ class LIBGUI_PUBLIC GuiApp : public App

static void setRenderThread(Thread *thread);

/// Emitted when the display mode has changed.
DE_DEFINE_AUDIENCE2(DisplayModeChange, void displayModeChanged())

protected:
NativePath appDataPath() const override;

Expand Down
24 changes: 24 additions & 0 deletions doomsday/libs/gui/src/guiapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_mouse.h>

namespace de {

Expand All @@ -43,6 +44,9 @@ DE_PIMPL(GuiApp)
GuiLoop loop;
Thread * renderThread;
double dpiFactor = 1.0;
SDL_Cursor *arrowCursor;
SDL_Cursor *vsizeCursor;
SDL_Cursor *hsizeCursor;

Impl(Public *i) : Base(i)
{
Expand All @@ -51,10 +55,17 @@ DE_PIMPL(GuiApp)

// The default render thread is the main thread.
renderThread = Thread::currentThread();

arrowCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
vsizeCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
hsizeCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
}

~Impl()
{
SDL_FreeCursor(arrowCursor);
SDL_FreeCursor(vsizeCursor);
SDL_FreeCursor(hsizeCursor);
DisplayMode_Shutdown();
SDL_Quit();
}
Expand Down Expand Up @@ -269,6 +280,19 @@ GuiLoop &GuiApp::loop()
return d->loop;
}

void GuiApp::setMouseCursor(MouseCursor cursor)
{
SDL_ShowCursor(cursor != None ? SDL_ENABLE : SDL_DISABLE);

switch (cursor)
{
case None: break;
case Arrow: SDL_SetCursor(d->arrowCursor); break;
case ResizeHorizontal: SDL_SetCursor(d->hsizeCursor); break;
case ResizeVertical: SDL_SetCursor(d->vsizeCursor); break;
}
}

bool GuiApp::inRenderThread()
{
if (!App::appExists())
Expand Down

0 comments on commit 25c7c32

Please sign in to comment.