Skip to content

Commit

Permalink
Implement glfwCreateStandardCursor
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Jun 20, 2022
1 parent 9cd3529 commit da61999
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/custom/RemoteNanoVG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef struct GLFWwindow GLFWwindow;

GLFWAPI const char* glfwGetClipboardString(GLFWwindow*) { return nullptr; }
GLFWAPI void glfwSetClipboardString(GLFWwindow*, const char*) {}
GLFWAPI GLFWcursor* glfwCreateStandardCursor(int) { return nullptr; }
GLFWAPI void glfwSetCursor(GLFWwindow*, GLFWcursor*) {}
GLFWAPI const char* glfwGetKeyName(int, int) { return nullptr; }
GLFWAPI int glfwGetKeyScancode(int) { return 0; }
Expand Down
46 changes: 45 additions & 1 deletion src/custom/glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

#include <GLFW/glfw3.h>

typedef struct GLFWcursor {
DGL_NAMESPACE::MouseCursor cursorId;
} GLFWcursor;

GLFWAPI int glfwGetKeyScancode(int) { return 0; }

GLFWAPI const char* glfwGetClipboardString(GLFWwindow*)
Expand All @@ -43,13 +47,53 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow*, const char* const text)
context->ui->setClipboard(nullptr, text, std::strlen(text)+1);
}

GLFWAPI GLFWcursor* glfwCreateStandardCursor(const int shape)
{
static GLFWcursor cursors[] = {
{ kMouseCursorArrow }, // GLFW_ARROW_CURSOR
{ kMouseCursorCaret }, // GLFW_IBEAM_CURSOR
{ kMouseCursorCrosshair }, // GLFW_CROSSHAIR_CURSOR
{ kMouseCursorHand }, // GLFW_POINTING_HAND_CURSOR
{ kMouseCursorNotAllowed }, // GLFW_NOT_ALLOWED_CURSOR
{ kMouseCursorLeftRight }, // GLFW_RESIZE_EW_CURSOR
{ kMouseCursorUpDown }, // GLFW_RESIZE_NS_CURSOR
{ kMouseCursorDiagonal }, // GLFW_RESIZE_NWSE_CURSOR
{ kMouseCursorAntiDiagonal }, // GLFW_RESIZE_NESW_CURSOR
// NOTE GLFW_RESIZE_ALL_CURSOR is unsupported in pugl
};

switch (shape)
{
case GLFW_ARROW_CURSOR:
return &cursors[kMouseCursorArrow];
case GLFW_IBEAM_CURSOR:
return &cursors[kMouseCursorCaret];
case GLFW_CROSSHAIR_CURSOR:
return &cursors[kMouseCursorCrosshair];
case GLFW_POINTING_HAND_CURSOR:
return &cursors[kMouseCursorHand];
case GLFW_NOT_ALLOWED_CURSOR:
return &cursors[kMouseCursorNotAllowed];
case GLFW_RESIZE_EW_CURSOR:
return &cursors[kMouseCursorLeftRight];
case GLFW_RESIZE_NS_CURSOR:
return &cursors[kMouseCursorUpDown];
case GLFW_RESIZE_NWSE_CURSOR:
return &cursors[kMouseCursorDiagonal];
case GLFW_RESIZE_NESW_CURSOR:
return &cursors[kMouseCursorAntiDiagonal];
default:
return nullptr;
}
}

GLFWAPI void glfwSetCursor(GLFWwindow*, GLFWcursor* const cursor)
{
CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
DISTRHO_SAFE_ASSERT_RETURN(context != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(context->ui != nullptr,);

context->ui->setCursor(cursor != nullptr ? kMouseCursorDiagonal : kMouseCursorArrow);
context->ui->setCursor(cursor != nullptr ? cursor->cursorId : kMouseCursorArrow);
}

GLFWAPI double glfwGetTime(void)
Expand Down
4 changes: 2 additions & 2 deletions src/override/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ struct ResizeHandle : widget::OpaqueWidget {
}

void onEnter(const EnterEvent& e) override {
glfwSetCursor(nullptr, (GLFWcursor*)0x1);
glfwSetCursor(APP->window->win, glfwCreateStandardCursor(GLFW_RESIZE_NWSE_CURSOR));
}

void onLeave(const LeaveEvent& e) override {
glfwSetCursor(nullptr, nullptr);
glfwSetCursor(APP->window->win, nullptr);
}

void onDragStart(const DragStartEvent&) override {
Expand Down

0 comments on commit da61999

Please sign in to comment.