Use a single widget for resize, always show handle

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2022-01-26 18:50:31 +00:00
parent ec15f95f32
commit 5282da24e9
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
6 changed files with 77 additions and 58 deletions

View file

@ -70,6 +70,15 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow*, const char* const text)
context->ui->setClipboard(nullptr, text, std::strlen(text)+1);
}
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);
}
GLFWAPI double glfwGetTime(void)
{
CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
@ -181,7 +190,6 @@ GLFWAPI const char* glfwGetKeyName(const int key, int)
namespace rack {
namespace app {
widget::Widget* createMenuBar(bool isStandalone);
void hideResizeHandle(Scene* scene);
}
namespace window {
void WindowSetPluginUI(Window* window, DISTRHO_NAMESPACE::UI* ui);
@ -231,7 +239,6 @@ class CardinalUI : public CardinalBaseUI,
public WindowParametersCallback
{
rack::math::Vec fLastMousePos;
ResizeHandle fResizeHandle;
WindowParameters fWindowParameters;
int fRateLimitStep = 0;
@ -263,20 +270,13 @@ class CardinalUI : public CardinalBaseUI,
public:
CardinalUI()
: CardinalBaseUI(1228, 666),
fResizeHandle(this)
: CardinalBaseUI(1228, 666)
{
Window& window(getWindow());
window.setIgnoringKeyRepeat(true);
context->nativeWindowId = window.getNativeWindowHandle();
if (isResizable())
{
fResizeHandle.hide();
hideResizeHandle(context->scene);
}
const double scaleFactor = getScaleFactor();
setGeometryConstraints(648 * scaleFactor, 538 * scaleFactor);

View file

@ -49,12 +49,14 @@ void nvgluDeleteFramebuffer(NVGLUframebuffer* fb) {}
extern "C" {
typedef struct GLFWcursor GLFWcursor;
typedef struct GLFWwindow GLFWwindow;
GLFWAPI const char* glfwGetClipboardString(GLFWwindow* window) { return nullptr; }
GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char*) {}
GLFWAPI const char* glfwGetKeyName(int key, int scancode) { return nullptr; }
GLFWAPI int glfwGetKeyScancode(int key) { return 0; }
GLFWAPI const char* glfwGetClipboardString(GLFWwindow*) { return nullptr; }
GLFWAPI void glfwSetClipboardString(GLFWwindow*, const char*) {}
GLFWAPI void glfwSetCursor(GLFWwindow*, GLFWcursor*) {}
GLFWAPI const char* glfwGetKeyName(int, int) { return nullptr; }
GLFWAPI int glfwGetKeyScancode(int) { return 0; }
GLFWAPI double glfwGetTime(void) { return 0.0; }
}

View file

@ -59,6 +59,8 @@ namespace app {
struct ResizeHandle : widget::OpaqueWidget {
math::Vec size;
void draw(const DrawArgs& args) override {
nvgStrokeColor(args.vg, nvgRGBf(1, 1, 1));
nvgStrokeWidth(args.vg, 1);
@ -95,6 +97,27 @@ struct ResizeHandle : widget::OpaqueWidget {
nvgLineTo(args.vg, 0, box.size.y + 11);
nvgStroke(args.vg);
}
void onHover(const HoverEvent& e) override {
e.consume(this);
}
void onEnter(const EnterEvent& e) override {
glfwSetCursor(nullptr, (GLFWcursor*)0x1);
}
void onLeave(const LeaveEvent& e) override {
glfwSetCursor(nullptr, nullptr);
}
void onDragStart(const DragStartEvent&) override {
size = APP->window->getSize();
}
void onDragMove(const DragMoveEvent& e) override {
size = size.plus(e.mouseDelta);
APP->window->setSize(size.round());
}
};
@ -151,11 +174,6 @@ Scene::Scene() {
}
void hideResizeHandle(Scene* scene) {
scene->internal->resizeHandle->hide();
}
Scene::~Scene() {
delete internal;
}

View file

@ -1,5 +1,5 @@
--- ../Rack/src/app/Scene.cpp 2021-12-14 21:35:44.414568198 +0000
+++ Scene.cpp 2022-01-24 11:12:33.268767988 +0000
+++ Scene.cpp 2022-01-26 18:47:48.006168325 +0000
@@ -1,3 +1,30 @@
+/*
+ * DISTRHO Cardinal Plugin
@ -39,7 +39,7 @@
#include <system.hpp>
#include <network.hpp>
#include <history.hpp>
@@ -14,31 +42,58 @@
@@ -14,6 +42,17 @@
#include <patch.hpp>
#include <asset.hpp>
@ -57,11 +57,9 @@
namespace rack {
namespace app {
@@ -23,16 +62,55 @@
math::Vec size;
struct ResizeHandle : widget::OpaqueWidget {
- math::Vec size;
-
void draw(const DrawArgs& args) override {
+ nvgStrokeColor(args.vg, nvgRGBf(1, 1, 1));
+ nvgStrokeWidth(args.vg, 1);
@ -74,12 +72,8 @@
- nvgClosePath(args.vg);
- nvgFillColor(args.vg, nvgRGBAf(1, 1, 1, 0.15));
- nvgFill(args.vg);
- }
+ nvgStroke(args.vg);
- void onDragStart(const DragStartEvent& e) override {
- size = APP->window->getSize();
- }
+
+ nvgBeginPath(args.vg);
+ nvgMoveTo(args.vg, box.size.x + 5, 0);
+ nvgLineTo(args.vg, 0, box.size.y + 5);
@ -91,10 +85,7 @@
+ nvgStroke(args.vg);
+
+ nvgStrokeColor(args.vg, nvgRGBf(0, 0, 0));
- void onDragMove(const DragMoveEvent& e) override {
- size = size.plus(e.mouseDelta);
- APP->window->setSize(size.round());
+
+ nvgBeginPath(args.vg);
+ nvgMoveTo(args.vg, box.size.x+1, 0);
+ nvgLineTo(args.vg, 0, box.size.y+1);
@ -109,10 +100,26 @@
+ nvgMoveTo(args.vg, box.size.x + 11, 0);
+ nvgLineTo(args.vg, 0, box.size.y + 11);
+ nvgStroke(args.vg);
+ }
+
+ void onHover(const HoverEvent& e) override {
+ e.consume(this);
+ }
+
+ void onEnter(const EnterEvent& e) override {
+ glfwSetCursor(nullptr, (GLFWcursor*)0x1);
+ }
+
+ void onLeave(const LeaveEvent& e) override {
+ glfwSetCursor(nullptr, nullptr);
}
};
@@ -46,9 +101,32 @@
- void onDragStart(const DragStartEvent& e) override {
+ void onDragStart(const DragStartEvent&) override {
size = APP->window->getSize();
}
@@ -46,9 +124,32 @@
struct Scene::Internal {
ResizeHandle* resizeHandle;
@ -147,7 +154,7 @@
};
@@ -67,17 +145,17 @@
@@ -67,13 +168,8 @@
browser->hide();
addChild(browser);
@ -162,16 +169,7 @@
addChild(internal->resizeHandle);
}
+void hideResizeHandle(Scene* scene) {
+ scene->internal->resizeHandle->hide();
+}
+
+
Scene::~Scene() {
delete internal;
}
@@ -89,32 +167,13 @@
@@ -89,32 +185,13 @@
void Scene::step() {
@ -205,7 +203,7 @@
// Scroll RackScrollWidget with arrow keys
math::Vec arrowDelta;
if (internal->heldArrowKeys[0]) {
@@ -143,6 +202,22 @@
@@ -143,6 +220,22 @@
rackScroll->offset += arrowDelta * arrowSpeed;
}
@ -228,7 +226,7 @@
Widget::step();
}
@@ -172,7 +247,7 @@
@@ -172,7 +265,7 @@
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) {
// DEBUG("key '%d '%c' scancode %d '%c' keyName '%s'", e.key, e.key, e.scancode, e.scancode, e.keyName.c_str());
if (e.keyName == "n" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
@ -237,7 +235,7 @@
e.consume(this);
}
if (e.keyName == "q" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
@@ -180,19 +255,20 @@
@@ -180,19 +273,20 @@
e.consume(this);
}
if (e.keyName == "o" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
@ -262,7 +260,7 @@
e.consume(this);
}
if (e.keyName == "z" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
@@ -232,10 +308,8 @@
@@ -232,10 +326,8 @@
settings::cpuMeter ^= true;
e.consume(this);
}
@ -275,7 +273,7 @@
e.consume(this);
}
@@ -326,13 +400,6 @@
@@ -326,13 +418,6 @@
// Key commands that can be overridden by children
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) {
@ -289,7 +287,7 @@
if (e.keyName == "v" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
rack->pasteClipboardAction();
e.consume(this);
@@ -351,7 +418,7 @@
@@ -351,7 +436,7 @@
std::string extension = system::getExtension(path);
if (extension == ".vcv") {
@ -298,7 +296,7 @@
e.consume(this);
return;
}
@@ -368,3 +435,73 @@
@@ -368,3 +453,73 @@
} // namespace app
} // namespace rack

View file

@ -1,5 +1,5 @@
--- ../Rack/src/window/Window.cpp 2022-01-05 19:24:25.995101080 +0000
+++ Window.cpp 2022-01-23 17:13:27.375765288 +0000
+++ Window.cpp 2022-01-26 18:35:47.181645555 +0000
@@ -1,33 +1,73 @@
+/*
+ * DISTRHO Cardinal Plugin

View file

@ -1,5 +1,5 @@
--- ../Rack/src/plugin.cpp 2022-01-15 14:44:46.395281005 +0000
+++ plugin.cpp 2022-01-23 22:59:41.770256440 +0000
+++ plugin.cpp 2022-01-24 20:38:11.436099651 +0000
@@ -1,308 +1,40 @@
-#include <thread>
-#include <map>
@ -337,7 +337,7 @@
/** Given slug => fallback slug.
Correctly handles bidirectional fallbacks.
To request fallback slugs to be added to this list, open a GitHub issue.
@@ -352,6 +84,11 @@
@@ -352,6 +84,12 @@
*/
using PluginModuleSlug = std::tuple<std::string, std::string>;
static const std::map<PluginModuleSlug, PluginModuleSlug> moduleSlugFallbacks = {
@ -346,10 +346,11 @@
+ {{"Core", "AudioInterface16"}, {"Cardinal", "HostAudio8"}},
+ {{"Core", "MIDIToCVInterface"}, {"Cardinal", "HostMIDI"}},
+ {{"Core", "CV-MIDI"}, {"Cardinal", "HostMIDI"}},
+ {{"Core", "Notes"}, {"Cardinal", "TextEditor"}},
{{"MindMeld-ShapeMasterPro", "ShapeMasterPro"}, {"MindMeldModular", "ShapeMaster"}},
{{"MindMeldModular", "ShapeMaster"}, {"MindMeld-ShapeMasterPro", "ShapeMasterPro"}},
// {{"", ""}, {"", ""}},
@@ -441,7 +178,6 @@
@@ -441,7 +179,6 @@
}