Browse Source

Limit rack zoom when value is changed rather than in RackScrollWidget every frame.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
7832706fdd
4 changed files with 13 additions and 4 deletions
  1. +2
    -0
      include/settings.hpp
  2. +2
    -2
      src/app/MenuBar.cpp
  3. +7
    -2
      src/app/RackScrollWidget.cpp
  4. +2
    -0
      src/app/Scene.cpp

+ 2
- 0
include/settings.hpp View File

@@ -38,6 +38,8 @@ extern math::Vec windowSize;
extern math::Vec windowPos;
/** Rack zoom level, log2. E.g. 100% = 0, 200% = 1, 50% = -1. */
extern float zoom;
static const float zoomMax = 2.f;
static const float zoomMin = -2.f;
/** Reverse the zoom scroll direction */
extern bool invertZoom;
/** Opacity of cables in the range [0, 1] */


+ 2
- 2
src/app/MenuBar.cpp View File

@@ -325,10 +325,10 @@ struct ZoomQuantity : Quantity {
return settings::zoom;
}
float getMinValue() override {
return -2.0;
return settings::zoomMin;
}
float getMaxValue() override {
return 2.0;
return settings::zoomMax;
}
float getDefaultValue() override {
return 0.0;


+ 7
- 2
src/app/RackScrollWidget.cpp View File

@@ -28,8 +28,6 @@ void RackScrollWidget::reset() {


void RackScrollWidget::step() {
// Clamp zoom
settings::zoom = math::clamp(settings::zoom, -2.f, 2.f);
// Compute zoom from exponential zoom
float zoom = std::pow(2.f, settings::zoom);
if (zoom != zoomWidget->zoom) {
@@ -137,6 +135,11 @@ void RackScrollWidget::onHoverScroll(const HoverScrollEvent& e) {
if (settings::invertZoom)
zoomDelta *= -1;
settings::zoom += zoomDelta;
// Limit min/max depending on the direction of zooming
if (zoomDelta > 0.f)
settings::zoom = std::fmin(settings::zoom, settings::zoomMax);
else
settings::zoom = std::fmax(settings::zoom, settings::zoomMin);
zoomPos = e.pos;
e.consume(this);
}
@@ -162,10 +165,12 @@ void RackScrollWidget::onButton(const ButtonEvent& e) {
if (e.action == GLFW_PRESS) {
if (e.button == GLFW_MOUSE_BUTTON_4) {
settings::zoom -= 0.5f;
settings::zoom = std::fmax(settings::zoom, settings::zoomMin);
e.consume(this);
}
if (e.button == GLFW_MOUSE_BUTTON_5) {
settings::zoom += 0.5f;
settings::zoom = std::fmin(settings::zoom, settings::zoomMax);
e.consume(this);
}
}


+ 2
- 0
src/app/Scene.cpp View File

@@ -152,6 +152,7 @@ void Scene::onHoverKey(const HoverKeyEvent& e) {
zoom = std::ceil(zoom - 0.01f) - 1;
zoom /= 2;
settings::zoom = zoom;
settings::zoom = std::fmax(settings::zoom, settings::zoomMin);
e.consume(this);
}
// Numpad has a "+" key, but the main keyboard section hides it under "="
@@ -161,6 +162,7 @@ void Scene::onHoverKey(const HoverKeyEvent& e) {
zoom = std::floor(zoom + 0.01f) + 1;
zoom /= 2;
settings::zoom = zoom;
settings::zoom = std::fmin(settings::zoom, settings::zoomMax);
e.consume(this);
}
if ((e.keyName == "0") && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {


Loading…
Cancel
Save