DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit 7357d71fa9ce01eab8707e775f862be7e3be0676
parent ed6705a161e13565391e020389b6c1b7bd5ab742
Author: falkTX <falktx@falktx.com>
Date:   Wed, 15 Dec 2021 11:14:06 +0000

Expose cursor API from pugl, with added diagonal resize cursors

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
MMakefile.base.mk | 3+--
Mdgl/Base.hpp | 17+++++++++++++++++
Mdgl/TopLevelWidget.hpp | 1+
Mdgl/Window.hpp | 9+++++++++
Mdgl/src/TopLevelWidget.cpp | 5+++++
Mdgl/src/Window.cpp | 5+++++
6 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/Makefile.base.mk b/Makefile.base.mk @@ -304,8 +304,7 @@ ifeq ($(HAVE_X11),true) DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11) -DHAVE_X11 DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11) ifeq ($(HAVE_XCURSOR),true) -# TODO -DHAVE_XCURSOR -DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xcursor) +DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xcursor) -DHAVE_XCURSOR DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xcursor) endif ifeq ($(HAVE_XEXT),true) diff --git a/dgl/Base.hpp b/dgl/Base.hpp @@ -131,6 +131,23 @@ enum CrossingMode { }; /** + A mouse cursor type. + + This is a portable subset of mouse cursors that exist on X11, MacOS, and Windows. +*/ +enum MouseCursor { + kMouseCursorArrow, ///< Default pointing arrow + kMouseCursorCaret, ///< Caret (I-Beam) for text entry + kMouseCursorCrosshair, ///< Cross-hair + kMouseCursorHand, ///< Hand with a pointing finger + kMouseCursorNotAllowed, ///< Operation not allowed + kMouseCursorLeftRight, ///< Left/right arrow for horizontal resize + kMouseCursorUpDown, ///< Up/down arrow for vertical resize + kMouseCursorDiagonal, ///< Top-left to bottom-right arrow for diagonal resize + kMouseCursorAntiDiagonal ///< Bottom-left to top-right arrow for diagonal resize +}; + +/** Scroll direction. Describes the direction of a scroll event along with whether the scroll is a "smooth" scroll. diff --git a/dgl/TopLevelWidget.hpp b/dgl/TopLevelWidget.hpp @@ -103,6 +103,7 @@ public: // TODO group stuff after here, convenience functions present in Window class bool setClipboard(const char* mimeType, const void* data, size_t dataSize); const void* getClipboard(const char*& mimeType, size_t& dataSize); + bool setCursor(MouseCursor cursor); bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs = 0); bool removeIdleCallback(IdleCallback* callback); double getScaleFactor() const noexcept; diff --git a/dgl/Window.hpp b/dgl/Window.hpp @@ -285,6 +285,15 @@ public: const void* getClipboard(const char*& mimeType, size_t& dataSize); /** + Set the mouse cursor. + + This changes the system cursor that is displayed when the pointer is inside the window. + May fail if setting the cursor is not supported on this system, + for example if compiled on X11 without Xcursor support. + */ + bool setCursor(MouseCursor cursor); + + /** Add a callback function to be triggered on every idle cycle or on a specific timer frequency. You can add more than one, and remove them at anytime with removeIdleCallback(). This can be used to perform some action at a regular interval with relatively low frequency. diff --git a/dgl/src/TopLevelWidget.cpp b/dgl/src/TopLevelWidget.cpp @@ -70,6 +70,11 @@ const void* TopLevelWidget::getClipboard(const char*& mimeType, size_t& dataSize return pData->window.getClipboard(mimeType, dataSize); } +bool TopLevelWidget::setCursor(const MouseCursor cursor) +{ + return pData->window.setCursor(cursor); +} + bool TopLevelWidget::addIdleCallback(IdleCallback* const callback, const uint timerFrequencyInMs) { return pData->window.addIdleCallback(callback, timerFrequencyInMs); diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp @@ -271,6 +271,11 @@ const void* Window::getClipboard(const char*& mimeType, size_t& dataSize) return clipboard; } +bool Window::setCursor(const MouseCursor cursor) +{ + return puglSetCursor(pData->view, static_cast<PuglCursor>(cursor)) == PUGL_SUCCESS; +} + bool Window::addIdleCallback(IdleCallback* const callback, const uint timerFrequencyInMs) { DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr, false)