Browse Source

Platform: Emscripten support for cursors in Sdl2Application.

pull/388/head
Vladimír Vondruš 7 years ago
parent
commit
04827d3743
  1. 34
      src/Magnum/Platform/Sdl2Application.cpp
  2. 16
      src/Magnum/Platform/Sdl2Application.h

34
src/Magnum/Platform/Sdl2Application.cpp

@ -885,9 +885,9 @@ bool Sdl2Application::mainLoopIteration() {
return !(_flags & Flag::Exit);
}
#ifndef CORRADE_TARGET_EMSCRIPTEN
namespace {
#ifndef CORRADE_TARGET_EMSCRIPTEN
constexpr SDL_SystemCursor CursorMap[] {
SDL_SYSTEM_CURSOR_ARROW,
SDL_SYSTEM_CURSOR_IBEAM,
@ -902,10 +902,29 @@ constexpr SDL_SystemCursor CursorMap[] {
SDL_SYSTEM_CURSOR_NO,
SDL_SYSTEM_CURSOR_HAND
};
#else
constexpr const char* CursorMap[] {
"default",
"text",
"wait",
"crosshair",
"progress",
"nwse-resize",
"nesw-resize",
"ew-resize",
"ns-resize",
"move",
"not-allowed",
"pointer",
"none"
/* Hidden & locked not supported yet */
};
#endif
}
void Sdl2Application::setCursor(Cursor cursor) {
#ifndef CORRADE_TARGET_EMSCRIPTEN
CORRADE_INTERNAL_ASSERT(UnsignedInt(cursor) < Containers::arraySize(_cursors));
if(cursor == Cursor::Hidden) {
@ -927,9 +946,18 @@ void Sdl2Application::setCursor(Cursor cursor) {
_cursors[UnsignedInt(cursor)] = SDL_CreateSystemCursor(CursorMap[UnsignedInt(cursor)]);
SDL_SetCursor(_cursors[UnsignedInt(cursor)]);
#else
_cursor = cursor;
CORRADE_INTERNAL_ASSERT(UnsignedInt(cursor) < Containers::arraySize(CursorMap));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
EM_ASM_({document.getElementById('canvas').style.cursor = AsciiToString($0);}, CursorMap[UnsignedInt(cursor)]);
#pragma GCC diagnostic pop
#endif
}
Sdl2Application::Cursor Sdl2Application::cursor() {
#ifndef CORRADE_TARGET_EMSCRIPTEN
if(SDL_GetRelativeMouseMode())
return Cursor::HiddenLocked;
else if(!SDL_ShowCursor(SDL_QUERY))
@ -941,8 +969,10 @@ Sdl2Application::Cursor Sdl2Application::cursor() {
if(_cursors[i] == cursor) return Cursor(i);
return Cursor::Arrow;
#else
return _cursor;
#endif
}
#endif
void Sdl2Application::setMouseLocked(bool enabled) {
/** @todo Implement this in Emscripten */

16
src/Magnum/Platform/Sdl2Application.h

@ -832,7 +832,6 @@ class Sdl2Application {
/** @{ @name Mouse handling */
public:
#ifndef CORRADE_TARGET_EMSCRIPTEN
/**
* @brief Cursor type
*
@ -852,11 +851,17 @@ class Sdl2Application {
No, /**< Slashed circle or crossbones */
Hand, /**< Hand */
Hidden, /**< Hidden */
HiddenLocked /**< Hidden and locked */
#ifndef CORRADE_TARGET_EMSCRIPTEN
/**
* Hidden and locked.
*
* @note Not available in @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten".
*/
HiddenLocked
#endif
};
#endif
#ifndef CORRADE_TARGET_EMSCRIPTEN
/**
* @brief Set cursor type
*
@ -866,7 +871,6 @@ class Sdl2Application {
/** @brief Get current cursor type */
Cursor cursor();
#endif
#ifndef CORRADE_TARGET_EMSCRIPTEN
/**
@ -1064,6 +1068,8 @@ class Sdl2Application {
#ifndef CORRADE_TARGET_EMSCRIPTEN
SDL_Cursor* _cursors[14]{};
#else
Cursor _cursor;
#endif
/* These are saved from command-line arguments */

Loading…
Cancel
Save