From 51c37936a9187304f2233d33aa133139152cf473 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 22 Apr 2019 18:33:28 -0400 Subject: [PATCH] Make RackRails positioned correctly to prevent blank frames. --- include/event.hpp | 2 +- include/widget/Widget.hpp | 2 +- src/app/RackRail.cpp | 10 +++++----- src/app/RackWidget.cpp | 22 ++++++++++------------ src/widget/FramebufferWidget.cpp | 8 +++++--- src/widget/Widget.cpp | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/event.hpp b/include/event.hpp index 287767d8..96330cdc 100644 --- a/include/event.hpp +++ b/include/event.hpp @@ -291,7 +291,7 @@ struct Zoom : Base { }; -/** Occurs after a Widget's position is set by Widget::setPos(). +/** Occurs after a Widget's position is set by Widget::setPosition(). */ struct Reposition : Base { }; diff --git a/include/widget/Widget.hpp b/include/widget/Widget.hpp index 681c29c2..3a74a8e5 100644 --- a/include/widget/Widget.hpp +++ b/include/widget/Widget.hpp @@ -32,7 +32,7 @@ struct Widget { virtual ~Widget(); - void setPos(math::Vec pos); + void setPosition(math::Vec pos); void setSize(math::Vec size); void show(); void hide(); diff --git a/src/app/RackRail.cpp b/src/app/RackRail.cpp index ae522eef..e2dd0602 100644 --- a/src/app/RackRail.cpp +++ b/src/app/RackRail.cpp @@ -5,19 +5,19 @@ namespace rack { namespace app { void RackRail::draw(const DrawArgs &args) { - const float railHeight = RACK_GRID_WIDTH; + const float railHeight = 15; // Background color nvgBeginPath(args.vg); nvgRect(args.vg, 0.0, 0.0, box.size.x, box.size.y); - nvgFillColor(args.vg, nvgRGBf(0.2, 0.2, 0.2)); + nvgFillColor(args.vg, nvgRGB(0x30, 0x30, 0x30)); nvgFill(args.vg); // Rails - nvgFillColor(args.vg, nvgRGBf(0.85, 0.85, 0.85)); + nvgFillColor(args.vg, nvgRGB(0xc9, 0xc9, 0xc9)); nvgStrokeWidth(args.vg, 1.0); - nvgStrokeColor(args.vg, nvgRGBf(0.7, 0.7, 0.7)); - float holeRadius = 3.5; + nvgStrokeColor(args.vg, nvgRGB(0x9d, 0x9f, 0xa2)); + float holeRadius = 4.0; for (float railY = 0; railY < box.size.y; railY += RACK_GRID_HEIGHT) { // Top rail nvgBeginPath(args.vg); diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index ddcf2ca5..e0eceadc 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -97,22 +97,19 @@ RackWidget::~RackWidget() { } void RackWidget::step() { - // Adjust size and position of railFb - math::Rect bound = getViewport(math::Rect(math::Vec(), box.size)); - if (!railFb->box.isContaining(bound)) { - math::Vec margin = math::Vec(200, 200); - railFb->box.pos = bound.pos.minus(margin).div(RACK_GRID_SIZE).floor().mult(RACK_GRID_SIZE); - railFb->box.size = bound.size.plus(margin.mult(2)); - railFb->dirty = true; - - RackRail *rail = railFb->getFirstDescendantOfType(); - rail->box.size = railFb->box.size; - } - Widget::step(); } void RackWidget::draw(const DrawArgs &args) { + // Resize and reposition the RackRail to align on the grid. + math::Rect railBox; + railBox.pos = args.clipBox.pos.div(RACK_GRID_SIZE).floor().mult(RACK_GRID_SIZE); + railBox.size = args.clipBox.size.div(RACK_GRID_SIZE).floor().plus(math::Vec(25, 2)).mult(RACK_GRID_SIZE); + railFb->box = railBox; + + RackRail *rail = railFb->getFirstDescendantOfType(); + rail->box.size = railFb->box.size; + Widget::draw(args); } @@ -140,6 +137,7 @@ void RackWidget::onHoverKey(const event::HoverKey &e) { } void RackWidget::onDragHover(const event::DragHover &e) { + // Set before calling children's onDragHover() mousePos = e.pos; OpaqueWidget::onDragHover(e); } diff --git a/src/widget/FramebufferWidget.cpp b/src/widget/FramebufferWidget.cpp index 7da418ce..71f46704 100644 --- a/src/widget/FramebufferWidget.cpp +++ b/src/widget/FramebufferWidget.cpp @@ -71,7 +71,7 @@ void FramebufferWidget::step() { } if (!fb) { - WARN("Framebuffer of size (%f, %f) * %f could not be created for FramebufferWidget", VEC_ARGS(fbSize), oversample); + WARN("Framebuffer of size (%f, %f) * %f could not be created for FramebufferWidget.", VEC_ARGS(fbSize), oversample); return; } @@ -83,7 +83,7 @@ void FramebufferWidget::step() { if (oversample != 1.0) { NVGLUframebuffer *newFb = nvgluCreateFramebuffer(vg, fbSize.x, fbSize.y, 0); if (!newFb) { - WARN("Non-oversampled framebuffer of size (%f, %f) could not be created for FramebufferWidget", VEC_ARGS(fbSize)); + WARN("Non-oversampled framebuffer of size (%f, %f) could not be created for FramebufferWidget.", VEC_ARGS(fbSize)); return; } @@ -125,8 +125,10 @@ void FramebufferWidget::draw(const DrawArgs &args) { float xform[6]; nvgCurrentTransform(args.vg, xform); // Skew and rotate is not supported - if (!math::isNear(xform[1], 0.f) || !math::isNear(xform[2], 0.f)) + if (!math::isNear(xform[1], 0.f) || !math::isNear(xform[2], 0.f)) { + WARN("Skew and rotation detected but not supported in FramebufferWidget."); return; + } // Extract scale and offset from world transform scale = math::Vec(xform[0], xform[3]); offset = math::Vec(xform[4], xform[5]); diff --git a/src/widget/Widget.cpp b/src/widget/Widget.cpp index 4e294d33..201d9464 100644 --- a/src/widget/Widget.cpp +++ b/src/widget/Widget.cpp @@ -13,7 +13,7 @@ Widget::~Widget() { clearChildren(); } -void Widget::setPos(math::Vec pos) { +void Widget::setPosition(math::Vec pos) { box.pos = pos; // event::Reposition event::Reposition eReposition;