Browse Source

Make maximum zoom level 400%. Store zoom in settings logarithmically instead of linearly.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
a0daf4b480
4 changed files with 21 additions and 20 deletions
  1. +2
    -1
      helper.py
  2. +5
    -5
      src/app/MenuBar.cpp
  3. +4
    -4
      src/app/RackScrollWidget.cpp
  4. +10
    -10
      src/app/Scene.cpp

+ 2
- 1
helper.py View File

@@ -117,7 +117,7 @@ Plugin *pluginInstance;
void init(Plugin *p) {
pluginInstance = p;

// Add modules here, e.g.
// Add modules here
// p->addModel(modelMyModule);

// Any other plugin initialization may go here.
@@ -397,6 +397,7 @@ struct {identifier} : Module {{"""

source += f"""


struct {identifier}Widget : ModuleWidget {{
{identifier}Widget({identifier} *module) {{
setModule(module);


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

@@ -176,16 +176,16 @@ struct EditButton : MenuButton {

struct ZoomQuantity : Quantity {
void setValue(float value) override {
settings::zoom = math::clamp(value, getMinValue(), getMaxValue());
settings::zoom = value;
}
float getValue() override {
return settings::zoom;
}
float getMinValue() override {return 0.25;}
float getMinValue() override {return -2.0;}
float getMaxValue() override {return 2.0;}
float getDefaultValue() override {return 1.0;}
float getDisplayValue() override {return std::round(getValue() * 100);}
void setDisplayValue(float displayValue) override {setValue(displayValue / 100);}
float getDefaultValue() override {return 0.0;}
float getDisplayValue() override {return std::round(std::pow(2.f, getValue()) * 100);}
void setDisplayValue(float displayValue) override {setValue(std::log2(displayValue / 100));}
std::string getLabel() override {return "Zoom";}
std::string getUnit() override {return "%";}
};


+ 4
- 4
src/app/RackScrollWidget.cpp View File

@@ -22,9 +22,9 @@ RackScrollWidget::RackScrollWidget() {

void RackScrollWidget::step() {
// Clamp zoom
settings::zoom = math::clamp(settings::zoom, 0.25f, 2.f);
// Round zoom to nearest percent
float zoom = std::round(settings::zoom / 0.01) * 0.01;
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) {
// Set offset based on zoomPos
offset = offset.plus(zoomPos).div(zoomWidget->zoom).mult(zoom).minus(zoomPos);
@@ -123,7 +123,7 @@ void RackScrollWidget::onHoverScroll(const event::HoverScroll &e) {
float zoomDelta = e.scrollDelta.y / 50 / 4;
if (settings::invertZoom)
zoomDelta *= -1;
settings::zoom *= std::pow(2, zoomDelta);
settings::zoom += zoomDelta;
zoomPos = e.pos;
e.consume(this);
return;


+ 10
- 10
src/app/Scene.cpp View File

@@ -122,21 +122,21 @@ void Scene::onHoverKey(const event::HoverKey &e) {
} break;
case GLFW_KEY_MINUS: {
if ((e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
float z = std::log2(settings::zoom);
z *= 2;
z = std::ceil(z - 0.01) - 1;
z /= 2;
settings::zoom = std::pow(2, z);
float zoom = settings::zoom;
zoom *= 2;
zoom = std::ceil(zoom - 0.01) - 1;
zoom /= 2;
settings::zoom = zoom;
e.consume(this);
}
} break;
case GLFW_KEY_EQUAL: {
if ((e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
float z = std::log2(settings::zoom);
z *= 2;
z = std::floor(z + 0.01) + 1;
z /= 2;
settings::zoom = std::pow(2, z);
float zoom = settings::zoom;
zoom *= 2;
zoom = std::floor(zoom + 0.01) + 1;
zoom /= 2;
settings::zoom = zoom;
e.consume(this);
}
} break;


Loading…
Cancel
Save