Skip to content

Commit

Permalink
fix(two value rotary slider): apply drag sensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Sep 20, 2024
1 parent b93e025 commit 03165f0
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ namespace zlInterface {
} else {
slider2.mouseDown(event);
}
const auto currentShiftPressed = event.mods.isShiftDown();
if (currentShiftPressed != isShiftPressed) {
isShiftPressed = currentShiftPressed;
updateDragDistance();
}
}

void TwoValueRotarySlider::mouseDrag(const juce::MouseEvent &event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace zlInterface {
class TwoValueRotarySlider final : public juce::Component,
private juce::Label::Listener, private juce::Slider::Listener {
private juce::Label::Listener, private juce::Slider::Listener {
public:
explicit TwoValueRotarySlider(const juce::String &labelText, UIBase &base);

Expand Down Expand Up @@ -66,6 +66,11 @@ namespace zlInterface {

inline bool getEditable() const { return editable.load(); }

void setMouseDragSensitivity(const int x) {
dragDistance = x;
updateDragDistance();
}

private:
UIBase &uiBase;

Expand All @@ -85,6 +90,9 @@ namespace zlInterface {
friz::Animator animator;
static constexpr int animationId = 1;

int dragDistance {10};
bool isShiftPressed {false};

static juce::String getDisplayValue(juce::Slider &s);

void labelTextChanged(juce::Label *labelThatHasChanged) override;
Expand All @@ -94,6 +102,19 @@ namespace zlInterface {
void editorHidden(juce::Label *l, juce::TextEditor &editor) override;

void sliderValueChanged(juce::Slider *slider) override;

void updateDragDistance() {
int actualDragDistance;
if (isShiftPressed) {
actualDragDistance = juce::roundToInt(
static_cast<float>(dragDistance) / uiBase.getSensitivity(sensitivityIdx::mouseDragFine));
} else {
actualDragDistance = juce::roundToInt(
static_cast<float>(dragDistance) / uiBase.getSensitivity(sensitivityIdx::mouseDrag));
}
slider1.setMouseDragSensitivity(actualDragDistance);
slider2.setMouseDragSensitivity(actualDragDistance);
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ namespace zlPanel {
void LeftControlPanel::paint(juce::Graphics &g) {
const auto bound = getLocalBounds().toFloat();
uiBase.fillRoundedShadowRectangle(g, bound, 0.5f * uiBase.getFontSize(), {.blurRadius = 0.25f});
const auto style = uiBase.getRotaryStyle();
const auto sensitivity = juce::roundToInt(uiBase.getRotaryDragSensitivity() * uiBase.getFontSize());
for (auto &c: {&freqC, &gainC, &qC}) {
c->getSlider1().setSliderStyle(style);
c->getSlider1().setMouseDragSensitivity(sensitivity);
c->getSlider2().setSliderStyle(style);
c->getSlider2().setMouseDragSensitivity(sensitivity);
}
}

void LeftControlPanel::resized() {
Expand Down Expand Up @@ -139,6 +131,11 @@ namespace zlPanel {
bound.getTopRight().getY(),
1.25f * uiBase.getFontSize(), 1.25f * uiBase.getFontSize());
resetComponent.setBounds(resetBound.toNearestInt());
updateMouseDragSensitivity();
}

void LeftControlPanel::lookAndFeelChanged() {
updateMouseDragSensitivity();
}

void LeftControlPanel::attachGroup(const size_t idx) {
Expand Down Expand Up @@ -240,4 +237,14 @@ namespace zlPanel {
qC.setShowSlider2(qS2Editable.load());
repaint();
}

void LeftControlPanel::updateMouseDragSensitivity() {
const auto style = uiBase.getRotaryStyle();
const auto sensitivity = juce::roundToInt(uiBase.getRotaryDragSensitivity() * uiBase.getFontSize());
for (auto &c: {&freqC, &gainC, &qC}) {
c->getSlider1().setSliderStyle(style);
c->getSlider2().setSliderStyle(style);
c->setMouseDragSensitivity(sensitivity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace zlPanel {

void resized() override;

void lookAndFeelChanged() override;

void attachGroup(size_t idx);

private:
Expand Down Expand Up @@ -59,6 +61,8 @@ namespace zlPanel {
void parameterChanged(const juce::String &parameterID, float newValue) override;

void handleAsyncUpdate() override;

void updateMouseDragSensitivity();
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace zlPanel {
for (auto &c: {&thresC, &kneeC, &attackC, &releaseC}) {
addAndMakeVisible(c);
}
lookAndFeelChanged();
}

RightControlPanel::~RightControlPanel() {
Expand All @@ -80,14 +81,6 @@ namespace zlPanel {
void RightControlPanel::paint(juce::Graphics &g) {
const auto bound = getLocalBounds().toFloat();
uiBase.fillRoundedShadowRectangle(g, bound, 0.5f * uiBase.getFontSize(), {.blurRadius = 0.25f});
const auto style = uiBase.getRotaryStyle();
const auto sensitivity = juce::roundToInt(uiBase.getRotaryDragSensitivity() * uiBase.getFontSize());
for (auto &c: {&sideFreqC, &sideQC}) {
c->getSlider1().setSliderStyle(style);
c->getSlider1().setMouseDragSensitivity(sensitivity);
c->getSlider2().setSliderStyle(style);
c->getSlider2().setMouseDragSensitivity(sensitivity);
}
}

void RightControlPanel::resized() {
Expand Down Expand Up @@ -124,6 +117,11 @@ namespace zlPanel {
auto bound = getLocalBounds().toFloat();
bound = uiBase.getRoundedShadowRectangleArea(bound, 0.5f * uiBase.getFontSize(), {});
grid.performLayout(bound.toNearestInt());
updateMouseDragSensitivity();
}

void RightControlPanel::lookAndFeelChanged() {
updateMouseDragSensitivity();
}

void RightControlPanel::attachGroup(size_t idx) {
Expand Down Expand Up @@ -184,4 +182,14 @@ namespace zlPanel {
dynRelativeC.repaint();
repaint();
}

void RightControlPanel::updateMouseDragSensitivity() {
const auto style = uiBase.getRotaryStyle();
const auto sensitivity = juce::roundToInt(uiBase.getRotaryDragSensitivity() * uiBase.getFontSize());
for (auto &c: {&sideFreqC, &sideQC}) {
c->getSlider1().setSliderStyle(style);
c->getSlider2().setSliderStyle(style);
c->setMouseDragSensitivity(sensitivity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace zlPanel {

void resized() override;

void lookAndFeelChanged() override;

void attachGroup(size_t idx);

private:
Expand All @@ -48,6 +50,8 @@ namespace zlPanel {
void parameterChanged(const juce::String &parameterID, float newValue) override;

void handleAsyncUpdate() override;

void updateMouseDragSensitivity();
};
}

Expand Down
4 changes: 2 additions & 2 deletions source/state/state_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ namespace zlState {
public:
auto static constexpr ID = "wheel_fine_sensitivity";
auto static constexpr name = "";
inline auto static const range = juce::NormalisableRange<float>(0.f, 1.f, 0.01f);
inline auto static const range = juce::NormalisableRange<float>(0.01f, 1.f, 0.01f);
auto static constexpr defaultV = .12f;
};

Expand All @@ -258,7 +258,7 @@ namespace zlState {
public:
auto static constexpr ID = "drag_fine_sensitivity";
auto static constexpr name = "";
inline auto static const range = juce::NormalisableRange<float>(0.f, 1.f, 0.01f);
inline auto static const range = juce::NormalisableRange<float>(0.01f, 1.f, 0.01f);
auto static constexpr defaultV = .25f;
};

Expand Down

0 comments on commit 03165f0

Please sign in to comment.