Browse Source

Change zoom only when zoom slider has finished moving (onAction())

tags/v0.5.0
Andrew Belt 7 years ago
parent
commit
580f0db6b4
9 changed files with 27 additions and 10 deletions
  1. +1
    -0
      include/app.hpp
  2. +4
    -0
      include/math.hpp
  3. +3
    -1
      src/app.cpp
  4. +0
    -3
      src/app/RackScene.cpp
  5. +3
    -1
      src/app/SVGPanel.cpp
  6. +8
    -2
      src/app/Toolbar.cpp
  7. +5
    -3
      src/settings.cpp
  8. +1
    -0
      src/widgets/FramebufferWidget.cpp
  9. +2
    -0
      src/widgets/Slider.cpp

+ 1
- 0
include/app.hpp View File

@@ -355,6 +355,7 @@ extern std::string gApplicationVersion;
extern std::string gApiHost;

// Easy access to "singleton" widgets
extern RackScene *gRackScene;
extern RackWidget *gRackWidget;
extern Toolbar *gToolbar;



+ 4
- 0
include/math.hpp View File

@@ -61,6 +61,10 @@ inline float eucmodf(float a, float base) {
return mod < 0.0 ? mod + base : mod;
}

inline float nearf(float a, float b, float epsilon = 1e-6) {
return fabsf(a - b) <= epsilon;
}

/** Limits a value between a minimum and maximum
If min > max, the limits are switched
*/


+ 3
- 1
src/app.cpp View File

@@ -14,10 +14,12 @@ std::string gApiHost = "http://api.vcvrack.com";

RackWidget *gRackWidget = NULL;
Toolbar *gToolbar = NULL;
RackScene *gRackScene = NULL;


void sceneInit() {
gScene = new RackScene();
gRackScene = new RackScene();
gScene = gRackScene;
}

void sceneDestroy() {


+ 0
- 3
src/app/RackScene.cpp View File

@@ -62,9 +62,6 @@ void RackScene::step() {
.plus(Vec(500, 500))
.div(zoomWidget->zoom);

// Set zoom from the toolbar's zoom slider
zoomWidget->setZoom(gToolbar->zoomSlider->value / 100.0);

Scene::step();

zoomWidget->box.size = gRackWidget->box.size.mult(zoomWidget->zoom);


+ 3
- 1
src/app/SVGPanel.cpp View File

@@ -1,4 +1,5 @@
#include "app.hpp"
#include "gui.hpp"


namespace rack {
@@ -17,7 +18,8 @@ struct PanelBorder : TransparentWidget {


SVGPanel::SVGPanel() {
oversample = 2.0;
if (nearf(gPixelRatio, 1.0))
oversample = 2.0;
}

void SVGPanel::setBackground(std::shared_ptr<SVG> svg) {


+ 8
- 2
src/app/Toolbar.cpp View File

@@ -148,12 +148,18 @@ Toolbar::Toolbar() {

xPos += margin;
{
zoomSlider = new Slider();
struct ZoomSlider : Slider {
void onAction() override {
Slider::onAction();
gRackScene->zoomWidget->setZoom(value / 100.0);
}
};
zoomSlider = new ZoomSlider();
zoomSlider->box.pos = Vec(xPos, margin);
zoomSlider->box.size.x = 150;
zoomSlider->label = "Zoom";
zoomSlider->unit = "%";
zoomSlider->setLimits(50.0, 200.0);
zoomSlider->setLimits(25.0, 200.0);
zoomSlider->setDefaultValue(100.0);
addChild(zoomSlider);
xPos += zoomSlider->box.size.x;


+ 5
- 3
src/settings.cpp View File

@@ -28,7 +28,7 @@ static json_t *settingsToJson() {
json_object_set_new(rootJ, "wireTension", tensionJ);

// zoom
float zoom = gToolbar->zoomSlider->value;
float zoom = gRackScene->zoomWidget->zoom;
json_t *zoomJ = json_real(zoom);
json_object_set_new(rootJ, "zoom", zoomJ);

@@ -69,8 +69,10 @@ static void settingsFromJson(json_t *rootJ) {

// zoom
json_t *zoomJ = json_object_get(rootJ, "zoom");
if (zoomJ)
gToolbar->zoomSlider->value = json_number_value(zoomJ);
if (zoomJ) {
gRackScene->zoomWidget->setZoom(clampf(json_number_value(zoomJ), 0.25, 4.0));
gToolbar->zoomSlider->setValue(json_number_value(zoomJ) * 100.0);
}

// allowCursorLock
json_t *allowCursorLockJ = json_object_get(rootJ, "allowCursorLock");


+ 1
- 0
src/widgets/FramebufferWidget.cpp View File

@@ -60,6 +60,7 @@ void FramebufferWidget::draw(NVGcontext *vg) {
if (fbSize.x <= 0.0 || fbSize.y <= 0.0)
return;

// printf("rendering framebuffer %f %f\n", fbSize.x, fbSize.y);
// Delete old one first to free up GPU memory
internal->setFramebuffer(NULL);
// Create a framebuffer from the main nanovg context. We will draw to this in the secondary nanovg context.


+ 2
- 0
src/widgets/Slider.cpp View File

@@ -23,11 +23,13 @@ void Slider::onDragMove(Vec mouseRel) {
void Slider::onDragEnd() {
state = BND_DEFAULT;
guiCursorUnlock();
onAction();
}

void Slider::onMouseDownOpaque(int button) {
if (button == 1) {
setValue(defaultValue);
onAction();
}
}



Loading…
Cancel
Save