Browse Source

Platform: minor cleanup, doc++, make cursor LUTs file-local.

pull/388/head
Vladimír Vondruš 7 years ago
parent
commit
a1bca4d8f4
  1. 25
      src/Magnum/Platform/GlfwApplication.cpp
  2. 11
      src/Magnum/Platform/GlfwApplication.h
  3. 43
      src/Magnum/Platform/Sdl2Application.cpp
  4. 11
      src/Magnum/Platform/Sdl2Application.h

25
src/Magnum/Platform/GlfwApplication.cpp

@ -605,6 +605,19 @@ int GlfwApplication::exec() {
return _exitCode; return _exitCode;
} }
namespace {
constexpr Int CursorMap[] {
GLFW_ARROW_CURSOR,
GLFW_IBEAM_CURSOR,
GLFW_CROSSHAIR_CURSOR,
GLFW_HRESIZE_CURSOR,
GLFW_VRESIZE_CURSOR,
GLFW_HAND_CURSOR
};
}
void GlfwApplication::setCursor(Cursor cursor) { void GlfwApplication::setCursor(Cursor cursor) {
CORRADE_INTERNAL_ASSERT(UnsignedInt(cursor) < Containers::arraySize(_cursors)); CORRADE_INTERNAL_ASSERT(UnsignedInt(cursor) < Containers::arraySize(_cursors));
@ -620,18 +633,8 @@ void GlfwApplication::setCursor(Cursor cursor) {
glfwSetInputMode(_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode(_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
} }
if(!_cursors[UnsignedInt(cursor)]) { if(!_cursors[UnsignedInt(cursor)])
constexpr Int CursorMap[] {
GLFW_ARROW_CURSOR,
GLFW_IBEAM_CURSOR,
GLFW_CROSSHAIR_CURSOR,
GLFW_HRESIZE_CURSOR,
GLFW_VRESIZE_CURSOR,
GLFW_HAND_CURSOR
};
_cursors[UnsignedInt(cursor)] = glfwCreateStandardCursor(CursorMap[UnsignedInt(cursor)]); _cursors[UnsignedInt(cursor)] = glfwCreateStandardCursor(CursorMap[UnsignedInt(cursor)]);
}
glfwSetCursor(_window, _cursors[UnsignedInt(cursor)]); glfwSetCursor(_window, _cursors[UnsignedInt(cursor)]);
} }

11
src/Magnum/Platform/GlfwApplication.h

@ -492,7 +492,7 @@ class GlfwApplication {
* *
* @see @ref setCursor() * @see @ref setCursor()
*/ */
enum class Cursor : UnsignedInt { enum class Cursor: UnsignedInt {
Arrow, /**< Arrow */ Arrow, /**< Arrow */
TextInput, /**< Text input */ TextInput, /**< Text input */
Crosshair, /**< Crosshair */ Crosshair, /**< Crosshair */
@ -503,15 +503,14 @@ class GlfwApplication {
HiddenLocked /**< Hidden and locked */ HiddenLocked /**< Hidden and locked */
}; };
public:
/** /**
* @brief Set the cursor to the @p type * @brief Set cursor type
*
* Default is @ref Cursor::Arrow.
*/ */
void setCursor(Cursor cursor); void setCursor(Cursor cursor);
/** /** @brief Get current cursor type */
* @brief Get the current cursor type
*/
Cursor cursor(); Cursor cursor();
/** @brief Warp mouse cursor to given coordinates */ /** @brief Warp mouse cursor to given coordinates */

43
src/Magnum/Platform/Sdl2Application.cpp

@ -886,6 +886,25 @@ bool Sdl2Application::mainLoopIteration() {
} }
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
namespace {
constexpr SDL_SystemCursor CursorMap[] {
SDL_SYSTEM_CURSOR_ARROW,
SDL_SYSTEM_CURSOR_IBEAM,
SDL_SYSTEM_CURSOR_WAIT,
SDL_SYSTEM_CURSOR_CROSSHAIR,
SDL_SYSTEM_CURSOR_WAITARROW,
SDL_SYSTEM_CURSOR_SIZENWSE,
SDL_SYSTEM_CURSOR_SIZENESW,
SDL_SYSTEM_CURSOR_SIZEWE,
SDL_SYSTEM_CURSOR_SIZENS,
SDL_SYSTEM_CURSOR_SIZEALL,
SDL_SYSTEM_CURSOR_NO,
SDL_SYSTEM_CURSOR_HAND
};
}
void Sdl2Application::setCursor(Cursor cursor) { void Sdl2Application::setCursor(Cursor cursor) {
CORRADE_INTERNAL_ASSERT(UnsignedInt(cursor) < Containers::arraySize(_cursors)); CORRADE_INTERNAL_ASSERT(UnsignedInt(cursor) < Containers::arraySize(_cursors));
@ -904,24 +923,8 @@ void Sdl2Application::setCursor(Cursor cursor) {
SDL_SetRelativeMouseMode(SDL_FALSE); SDL_SetRelativeMouseMode(SDL_FALSE);
} }
if(!_cursors[UnsignedInt(cursor)]) { if(!_cursors[UnsignedInt(cursor)])
constexpr SDL_SystemCursor CursorMap[] {
SDL_SYSTEM_CURSOR_ARROW,
SDL_SYSTEM_CURSOR_IBEAM,
SDL_SYSTEM_CURSOR_WAIT,
SDL_SYSTEM_CURSOR_CROSSHAIR,
SDL_SYSTEM_CURSOR_WAITARROW,
SDL_SYSTEM_CURSOR_SIZENWSE,
SDL_SYSTEM_CURSOR_SIZENESW,
SDL_SYSTEM_CURSOR_SIZEWE,
SDL_SYSTEM_CURSOR_SIZENS,
SDL_SYSTEM_CURSOR_SIZEALL,
SDL_SYSTEM_CURSOR_NO,
SDL_SYSTEM_CURSOR_HAND
};
_cursors[UnsignedInt(cursor)] = SDL_CreateSystemCursor(CursorMap[UnsignedInt(cursor)]); _cursors[UnsignedInt(cursor)] = SDL_CreateSystemCursor(CursorMap[UnsignedInt(cursor)]);
}
SDL_SetCursor(_cursors[UnsignedInt(cursor)]); SDL_SetCursor(_cursors[UnsignedInt(cursor)]);
} }
@ -934,10 +937,8 @@ Sdl2Application::Cursor Sdl2Application::cursor() {
SDL_Cursor* cursor = SDL_GetCursor(); SDL_Cursor* cursor = SDL_GetCursor();
if(cursor) if(cursor) for(UnsignedInt i = 0; i < sizeof(_cursors); i++)
for(UnsignedInt i = 0; i < sizeof(_cursors); i++) if(_cursors[i] == cursor) return Cursor(i);
if(_cursors[i] == cursor)
return Cursor(i);
return Cursor::Arrow; return Cursor::Arrow;
} }

11
src/Magnum/Platform/Sdl2Application.h

@ -838,7 +838,7 @@ class Sdl2Application {
* *
* @see @ref setCursor() * @see @ref setCursor()
*/ */
enum class Cursor : UnsignedInt { enum class Cursor: UnsignedInt {
Arrow, /**< Arrow */ Arrow, /**< Arrow */
TextInput, /**< Text input */ TextInput, /**< Text input */
Wait, /**< Wait */ Wait, /**< Wait */
@ -856,16 +856,15 @@ class Sdl2Application {
}; };
#endif #endif
public:
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
/** /**
* @brief Set the cursor to the @p type * @brief Set cursor type
*
* Default is @ref Cursor::Arrow.
*/ */
void setCursor(Cursor cursor); void setCursor(Cursor cursor);
/** /** @brief Get current cursor type */
* @brief Get the current cursor type
*/
Cursor cursor(); Cursor cursor();
#endif #endif

Loading…
Cancel
Save