From ee284aa4aa201e6eb0b6c4b31d8990879a362501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 9 May 2023 20:59:53 +0200 Subject: [PATCH] python: expose Application cursor setup and warping. --- doc/python/pages/changelog.rst | 2 ++ src/python/magnum/platform/application.h | 3 +++ src/python/magnum/platform/glfw.cpp | 18 ++++++++++++++++++ src/python/magnum/platform/sdl2.cpp | 15 +++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/doc/python/pages/changelog.rst b/doc/python/pages/changelog.rst index 7b34e2b..f9bacf5 100644 --- a/doc/python/pages/changelog.rst +++ b/doc/python/pages/changelog.rst @@ -126,6 +126,8 @@ Changelog :ref:`platform.glfw.Application.dpi_scaling` - Exposed :ref:`platform.glfw.Application.swap_interval` and :ref:`platform.glfw.Application.main_loop_iteration` +- Exposed :ref:`platform.sdl2.Application.cursor` and + :ref:`platform.sdl2.Application.warp_cursor`, same for GLFW - Exposed :ref:`trade.AbstractImporter.features` and :ref:`trade.AbstractImporter.flags` and corresponding enums - Exposed a basic interface of :ref:`trade.AbstractImageConverter` and diff --git a/src/python/magnum/platform/application.h b/src/python/magnum/platform/application.h index 63a7c6d..11bf9e4 100644 --- a/src/python/magnum/platform/application.h +++ b/src/python/magnum/platform/application.h @@ -88,6 +88,9 @@ template void application(py::class_(&T::dpiScaling), "DPI scaling") + /* Mouse handling */ + .def_property("cursor", &T::cursor, &T::setCursor, "Cursor type") + .def("warp_cursor", &T::warpCursor, "Warp mouse cursor to given coordinates") /* Event handlers */ .def("exit_event", &T::exitEvent, "Exit event") .def("viewport_event", &T::viewportEvent, "Viewport event") diff --git a/src/python/magnum/platform/glfw.cpp b/src/python/magnum/platform/glfw.cpp index d82d487..dd75519 100644 --- a/src/python/magnum/platform/glfw.cpp +++ b/src/python/magnum/platform/glfw.cpp @@ -203,6 +203,24 @@ void glfw(py::module_& m) { py::class_ mouseMoveEvent_{glfwApplication, "MouseMoveEvent", "Mouse move event"}; py::class_ mouseScrollEvent_{glfwApplication, "MouseScrollEvent", "Mouse scroll event"}; + py::enum_{glfwApplication, "Cursor", "Cursor type"} + .value("ARROW", Platform::Application::Cursor::Arrow) + .value("TEXT_INPUT", Platform::Application::Cursor::TextInput) + .value("CROSSHAIR", Platform::Application::Cursor::Crosshair) + #ifdef GLFW_RESIZE_NWSE_CURSOR + .value("RESIZE_NWSE", Platform::Application::Cursor::ResizeNWSE) + .value("RESIZE_NESW", Platform::Application::Cursor::ResizeNESW) + #endif + .value("RESIZE_WE", Platform::Application::Cursor::ResizeWE) + .value("RESIZE_NS", Platform::Application::Cursor::ResizeNS) + #ifdef GLFW_RESIZE_NWSE_CURSOR + .value("RESIZE_ALL", Platform::Application::Cursor::ResizeAll) + .value("NO", Platform::Application::Cursor::No) + #endif + .value("HAND", Platform::Application::Cursor::Hand) + .value("HIDDEN", Platform::Application::Cursor::Hidden) + .value("HIDDEN_LOCKED", Platform::Application::Cursor::HiddenLocked); + application(glfwApplication); exitEvent(exitEvent_); viewportEvent(viewportEvent_); diff --git a/src/python/magnum/platform/sdl2.cpp b/src/python/magnum/platform/sdl2.cpp index 218e364..67e587b 100644 --- a/src/python/magnum/platform/sdl2.cpp +++ b/src/python/magnum/platform/sdl2.cpp @@ -203,6 +203,21 @@ void sdl2(py::module_& m) { py::class_ mouseMoveEvent_{sdl2application, "MouseMoveEvent", "Mouse move event"}; py::class_ mouseScrollEvent_{sdl2application, "MouseScrollEvent", "Mouse scroll event"}; + py::enum_{sdl2application, "Cursor", "Cursor type"} + .value("ARROW", Platform::Application::Cursor::Arrow) + .value("TEXT_INPUT", Platform::Application::Cursor::TextInput) + .value("CROSSHAIR", Platform::Application::Cursor::Crosshair) + .value("WAIT_ARROW", Platform::Application::Cursor::WaitArrow) + .value("RESIZE_NWSE", Platform::Application::Cursor::ResizeNWSE) + .value("RESIZE_NESW", Platform::Application::Cursor::ResizeNESW) + .value("RESIZE_WE", Platform::Application::Cursor::ResizeWE) + .value("RESIZE_NS", Platform::Application::Cursor::ResizeNS) + .value("RESIZE_ALL", Platform::Application::Cursor::ResizeAll) + .value("NO", Platform::Application::Cursor::No) + .value("HAND", Platform::Application::Cursor::Hand) + .value("HIDDEN", Platform::Application::Cursor::Hidden) + .value("HIDDEN_LOCKED", Platform::Application::Cursor::HiddenLocked); + application(sdl2application); exitEvent(exitEvent_); viewportEvent(viewportEvent_);