MCPcopy Create free account
hub / github.com/ZL-Audio/ZLEqualizer / mouseDrag

Method mouseDrag

source/gui/dragger/dragger_component.cpp:57–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55 }
56
57 void Dragger::mouseDrag(const juce::MouseEvent& e) {
58 // calculate shift and update global position
59 const auto new_global_pos = e.position + button_pos_;
60 auto shift = new_global_pos - global_pos_;
61 const auto old_shift = shift;
62 // apply sensitivity
63 if (e.mods.isShiftDown()) {
64 shift.setX(shift.getX() * base_.getSensitivity(SensitivityIdx::kMouseDragFine));
65 shift.setY(shift.getY() * base_.getSensitivity(SensitivityIdx::kMouseDragFine));
66 }
67 if (e.mods.isCommandDown()) {
68 if (e.mods.isLeftButtonDown()) {
69 shift.setX(0.f);
70 } else {
71 shift.setY(0.f);
72 }
73 }
74 if (!x_enabled_) {
75 shift.setX(0.f);
76 }
77 if (!y_enabled_) {
78 shift.setY(0.f);
79 }
80 // update current position
81 const auto old_current_pos = current_pos_;
82 if (check_center_) {
83 current_pos_ = check_center_(current_pos_, current_pos_ + shift);
84 } else {
85 current_pos_ = current_pos_ + shift;
86 }
87 current_pos_ = button_area_.getConstrainedPoint(current_pos_);
88 // shift global position accordingly
89 const auto actual_shift = current_pos_ - old_current_pos;
90 if (std::abs(shift.x) > 1e-10f) {
91 global_pos_.x += actual_shift.x / shift.x * old_shift.x;
92 }
93 if (std::abs(shift.y) > 1e-10f) {
94 global_pos_.y += actual_shift.y / shift.y * old_shift.y;
95 }
96 // update x/y portion
97 x_portion_ = (current_pos_.getX() - button_area_.getX()) / button_area_.getWidth();
98 y_portion_ = 1.f - (current_pos_.getY() - button_area_.getY()) / button_area_.getHeight();
99 // call listeners
100 const BailOutChecker checker(this);
101 listeners_.callChecked(checker, [&](Listener& l) { l.draggerValueChanged(this); });
102 }
103
104 void Dragger::setButtonArea(const juce::Rectangle<float> bound) {
105 button_area_ = bound;

Callers

nothing calls this directly

Calls 6

getSensitivityMethod · 0.80
getWidthMethod · 0.80
getHeightMethod · 0.80
draggerValueChangedMethod · 0.80
getXMethod · 0.45
getYMethod · 0.45

Tested by

no test coverage detected