Cleanup Window stuff, move calls into the UI directly
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
4f8db21a9e
commit
4a5e71eb7f
3 changed files with 59 additions and 71 deletions
|
|
@ -35,13 +35,6 @@ GLFWAPI int glfwGetKeyScancode(int key) { return 0; }
|
||||||
namespace rack {
|
namespace rack {
|
||||||
namespace window {
|
namespace window {
|
||||||
DISTRHO_NAMESPACE::UI* lastUI = nullptr;
|
DISTRHO_NAMESPACE::UI* lastUI = nullptr;
|
||||||
|
|
||||||
void mouseButtonCallback(Context* ctx, int button, int action, int mods);
|
|
||||||
void cursorPosCallback(Context* ctx, double xpos, double ypos);
|
|
||||||
void cursorEnterCallback(Context* ctx, int entered);
|
|
||||||
void scrollCallback(Context* ctx, double x, double y);
|
|
||||||
void charCallback(Context* ctx, unsigned int codepoint);
|
|
||||||
void keyCallback(Context* ctx, int key, int scancode, int action, int mods);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,6 +47,7 @@ rack::Context* getRackContextFromPlugin(void* ptr);
|
||||||
class CardinalUI : public UI
|
class CardinalUI : public UI
|
||||||
{
|
{
|
||||||
rack::Context* const fContext;
|
rack::Context* const fContext;
|
||||||
|
rack::math::Vec fLastMousePos;
|
||||||
ResizeHandle fResizeHandle;
|
ResizeHandle fResizeHandle;
|
||||||
|
|
||||||
struct ScopedContext {
|
struct ScopedContext {
|
||||||
|
|
@ -93,6 +87,12 @@ public:
|
||||||
|
|
||||||
delete fContext->window;
|
delete fContext->window;
|
||||||
fContext->window = nullptr;
|
fContext->window = nullptr;
|
||||||
|
|
||||||
|
delete fContext->scene;
|
||||||
|
fContext->scene = nullptr;
|
||||||
|
|
||||||
|
delete fContext->event;
|
||||||
|
fContext->event = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onNanoDisplay() override
|
void onNanoDisplay() override
|
||||||
|
|
@ -127,7 +127,7 @@ protected:
|
||||||
|
|
||||||
int button;
|
int button;
|
||||||
int mods = 0;
|
int mods = 0;
|
||||||
int action = ev.press;
|
int action = ev.press ? GLFW_PRESS : GLFW_RELEASE;
|
||||||
|
|
||||||
if (ev.mod & kModifierControl)
|
if (ev.mod & kModifierControl)
|
||||||
mods |= GLFW_MOD_CONTROL;
|
mods |= GLFW_MOD_CONTROL;
|
||||||
|
|
@ -176,36 +176,58 @@ protected:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rack::window::mouseButtonCallback(fContext, button, action, mods);
|
/*
|
||||||
return true;
|
#if defined ARCH_MAC
|
||||||
|
// Remap Ctrl-left click to right click on Mac
|
||||||
|
if (button == GLFW_MOUSE_BUTTON_LEFT && (mods & RACK_MOD_MASK) == GLFW_MOD_CONTROL) {
|
||||||
|
button = GLFW_MOUSE_BUTTON_RIGHT;
|
||||||
|
mods &= ~GLFW_MOD_CONTROL;
|
||||||
|
}
|
||||||
|
// Remap Ctrl-shift-left click to middle click on Mac
|
||||||
|
if (button == GLFW_MOUSE_BUTTON_LEFT && (mods & RACK_MOD_MASK) == (GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) {
|
||||||
|
button = GLFW_MOUSE_BUTTON_MIDDLE;
|
||||||
|
mods &= ~(GLFW_MOD_CONTROL | GLFW_MOD_SHIFT);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
return fContext->event->handleButton(fLastMousePos, button, action, mods);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onMotion(const MotionEvent& ev) override
|
bool onMotion(const MotionEvent& ev) override
|
||||||
{
|
{
|
||||||
const ScopedContext sc(this);
|
const ScopedContext sc(this);
|
||||||
|
|
||||||
rack::window::cursorPosCallback(fContext, ev.pos.getX(), ev.pos.getY());
|
rack::math::Vec mousePos = rack::math::Vec(ev.pos.getX(), ev.pos.getY());
|
||||||
return true;
|
// .div(ctx->window->pixelRatio / ctx->window->windowRatio).round();
|
||||||
|
rack::math::Vec mouseDelta = mousePos.minus(fLastMousePos);
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Workaround for GLFW warping mouse to a different position when the cursor is locked or unlocked.
|
||||||
|
if (ctx->window->internal->ignoreNextMouseDelta)
|
||||||
|
{
|
||||||
|
ctx->window->internal->ignoreNextMouseDelta = false;
|
||||||
|
mouseDelta = math::Vec();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
fLastMousePos = mousePos;
|
||||||
|
return fContext->event->handleHover(mousePos, mouseDelta);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onScroll(const ScrollEvent& ev) override
|
bool onScroll(const ScrollEvent& ev) override
|
||||||
{
|
{
|
||||||
const ScopedContext sc(this);
|
const ScopedContext sc(this);
|
||||||
|
|
||||||
rack::window::scrollCallback(fContext, ev.delta.getX(), ev.delta.getY());
|
rack::math::Vec scrollDelta = rack::math::Vec(ev.delta.getX(), ev.delta.getY());
|
||||||
return true;
|
#ifdef DISTRHO_OS_MAC
|
||||||
|
scrollDelta = scrollDelta.mult(10.0);
|
||||||
|
#else
|
||||||
|
scrollDelta = scrollDelta.mult(50.0);
|
||||||
|
#endif
|
||||||
|
return fContext->event->handleScroll(fLastMousePos, scrollDelta);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
void onResize(const ResizeEvent& ev) override
|
|
||||||
{
|
|
||||||
UI::onResize(ev);
|
|
||||||
// APP->window->setSize(rack::math::Vec(ev.size.getWidth(), ev.size.getHeight()));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO uiFocus
|
|
||||||
|
|
||||||
bool onCharacterInput(const CharacterInputEvent& ev) override
|
bool onCharacterInput(const CharacterInputEvent& ev) override
|
||||||
{
|
{
|
||||||
if (ev.character == 0)
|
if (ev.character == 0)
|
||||||
|
|
@ -213,8 +235,7 @@ protected:
|
||||||
|
|
||||||
const ScopedContext sc(this);
|
const ScopedContext sc(this);
|
||||||
|
|
||||||
rack::window::charCallback(fContext, ev.character);
|
return fContext->event->handleText(fLastMousePos, ev.character);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onKeyboard(const KeyboardEvent& ev) override
|
bool onKeyboard(const KeyboardEvent& ev) override
|
||||||
|
|
@ -223,7 +244,7 @@ protected:
|
||||||
|
|
||||||
int key;
|
int key;
|
||||||
int mods = 0;
|
int mods = 0;
|
||||||
int action = ev.press;
|
int action = ev.press ? GLFW_PRESS : GLFW_RELEASE;
|
||||||
|
|
||||||
/* These are unsupported in pugl right now
|
/* These are unsupported in pugl right now
|
||||||
#define GLFW_KEY_KP_0 320
|
#define GLFW_KEY_KP_0 320
|
||||||
|
|
@ -297,9 +318,15 @@ protected:
|
||||||
if (ev.mod & kModifierAlt)
|
if (ev.mod & kModifierAlt)
|
||||||
mods |= GLFW_MOD_ALT;
|
mods |= GLFW_MOD_ALT;
|
||||||
|
|
||||||
// TODO special key conversion
|
return fContext->event->handleKey(fLastMousePos, key, ev.keycode, action, mods);
|
||||||
rack::window::keyCallback(fContext, key, ev.keycode, action, mods);
|
}
|
||||||
return true;
|
|
||||||
|
void uiFocus(const bool focus, CrossingMode) override
|
||||||
|
{
|
||||||
|
const ScopedContext sc(this);
|
||||||
|
|
||||||
|
if (! focus)
|
||||||
|
fContext->event->handleLeave();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -107,8 +107,8 @@ BASE_FLAGS += -pthread
|
||||||
|
|
||||||
ifeq ($(WINDOWS),true)
|
ifeq ($(WINDOWS),true)
|
||||||
BASE_FLAGS += -D_USE_MATH_DEFINES
|
BASE_FLAGS += -D_USE_MATH_DEFINES
|
||||||
BASE_FLAGS += -Imingw-compat
|
BASE_FLAGS += -I../include/mingw-compat
|
||||||
BASE_FLAGS += -Imingw-std-threads
|
BASE_FLAGS += -I../include/mingw-std-threads
|
||||||
endif
|
endif
|
||||||
|
|
||||||
BUILD_C_FLAGS += -std=gnu11
|
BUILD_C_FLAGS += -std=gnu11
|
||||||
|
|
|
||||||
|
|
@ -81,8 +81,6 @@ struct Window::Internal {
|
||||||
double frameTime = 0.0;
|
double frameTime = 0.0;
|
||||||
double lastFrameDuration = 0.0;
|
double lastFrameDuration = 0.0;
|
||||||
|
|
||||||
math::Vec lastMousePos;
|
|
||||||
|
|
||||||
std::map<std::string, std::shared_ptr<Font>> fontCache;
|
std::map<std::string, std::shared_ptr<Font>> fontCache;
|
||||||
std::map<std::string, std::shared_ptr<Image>> imageCache;
|
std::map<std::string, std::shared_ptr<Image>> imageCache;
|
||||||
|
|
||||||
|
|
@ -364,37 +362,10 @@ bool& Window::fbDirtyOnSubpixelChange() {
|
||||||
|
|
||||||
|
|
||||||
void mouseButtonCallback(Context* ctx, int button, int action, int mods) {
|
void mouseButtonCallback(Context* ctx, int button, int action, int mods) {
|
||||||
/*
|
|
||||||
#if defined ARCH_MAC
|
|
||||||
// Remap Ctrl-left click to right click on Mac
|
|
||||||
if (button == GLFW_MOUSE_BUTTON_LEFT && (mods & RACK_MOD_MASK) == GLFW_MOD_CONTROL) {
|
|
||||||
button = GLFW_MOUSE_BUTTON_RIGHT;
|
|
||||||
mods &= ~GLFW_MOD_CONTROL;
|
|
||||||
}
|
|
||||||
// Remap Ctrl-shift-left click to middle click on Mac
|
|
||||||
if (button == GLFW_MOUSE_BUTTON_LEFT && (mods & RACK_MOD_MASK) == (GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) {
|
|
||||||
button = GLFW_MOUSE_BUTTON_MIDDLE;
|
|
||||||
mods &= ~(GLFW_MOD_CONTROL | GLFW_MOD_SHIFT);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
ctx->event->handleButton(ctx->window->internal->lastMousePos, button, action, mods);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cursorPosCallback(Context* ctx, double xpos, double ypos) {
|
void cursorPosCallback(Context* ctx, double xpos, double ypos) {
|
||||||
math::Vec mousePos = math::Vec(xpos, ypos).div(ctx->window->pixelRatio / ctx->window->windowRatio).round();
|
|
||||||
math::Vec mouseDelta = mousePos.minus(ctx->window->internal->lastMousePos);
|
|
||||||
|
|
||||||
// Workaround for GLFW warping mouse to a different position when the cursor is locked or unlocked.
|
|
||||||
if (ctx->window->internal->ignoreNextMouseDelta) {
|
|
||||||
ctx->window->internal->ignoreNextMouseDelta = false;
|
|
||||||
mouseDelta = math::Vec();
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->window->internal->lastMousePos = mousePos;
|
|
||||||
|
|
||||||
ctx->event->handleHover(mousePos, mouseDelta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cursorEnterCallback(Context* ctx, int entered) {
|
void cursorEnterCallback(Context* ctx, int entered) {
|
||||||
|
|
@ -404,22 +375,12 @@ void cursorEnterCallback(Context* ctx, int entered) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void scrollCallback(Context* ctx, double x, double y) {
|
void scrollCallback(Context* ctx, double x, double y) {
|
||||||
math::Vec scrollDelta = math::Vec(x, y);
|
|
||||||
#if defined ARCH_MAC
|
|
||||||
scrollDelta = scrollDelta.mult(10.0);
|
|
||||||
#else
|
|
||||||
scrollDelta = scrollDelta.mult(50.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ctx->event->handleScroll(ctx->window->internal->lastMousePos, scrollDelta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void charCallback(Context* ctx, unsigned int codepoint) {
|
void charCallback(Context* ctx, unsigned int codepoint) {
|
||||||
ctx->event->handleText(ctx->window->internal->lastMousePos, codepoint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void keyCallback(Context* ctx, int key, int scancode, int action, int mods) {
|
void keyCallback(Context* ctx, int key, int scancode, int action, int mods) {
|
||||||
ctx->event->handleKey(ctx->window->internal->lastMousePos, key, scancode, action, mods);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue