Skip to content

Commit

Permalink
Added option to XY-Dragger for radius and sensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
ffAudio committed Dec 3, 2020
1 parent 234a64b commit b069da1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
14 changes: 14 additions & 0 deletions General/foleys_MagicJUCEFactories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ class XYDraggerItem : public GuiItem

static const juce::Identifier pCrosshair;
static const juce::StringArray pCrosshairTypes;
static const juce::Identifier pRadius;
static const juce::Identifier pSenseFactor;

XYDraggerItem (MagicGUIBuilder& builder, const juce::ValueTree& node)
: GuiItem (builder, node)
Expand Down Expand Up @@ -523,6 +525,14 @@ class XYDraggerItem : public GuiItem
dragger.setCrossHair (false, true);
else
dragger.setCrossHair (true, true);

auto radius = getProperty (pRadius);
if (! radius.isVoid())
dragger.setRadius (radius);

auto factor = getProperty (pSenseFactor);
if (! factor.isVoid())
dragger.setSenseFactor (factor);
}

std::vector<SettableProperty> getSettableProperties() const override
Expand All @@ -533,6 +543,8 @@ class XYDraggerItem : public GuiItem
props.push_back ({ configNode, IDs::parameterY, SettableProperty::Choice, {}, magicBuilder.createParameterMenuLambda() });
props.push_back ({ configNode, "right-click", SettableProperty::Choice, {}, magicBuilder.createParameterMenuLambda() });
props.push_back ({ configNode, pCrosshair, SettableProperty::Choice, {}, magicBuilder.createChoicesMenuLambda (pCrosshairTypes) });
props.push_back ({ configNode, pRadius, SettableProperty::Number, {}, {}});
props.push_back ({ configNode, pSenseFactor, SettableProperty::Number, {}, {}});

return props;
}
Expand All @@ -549,6 +561,8 @@ class XYDraggerItem : public GuiItem
};
const juce::Identifier XYDraggerItem::pCrosshair { "xy-crosshair" };
const juce::StringArray XYDraggerItem::pCrosshairTypes { "no-crosshair", "vertical", "horizontal", "crosshair" };
const juce::Identifier XYDraggerItem::pRadius { "xy-radius" };
const juce::Identifier XYDraggerItem::pSenseFactor { "xy-sense-factor" };

//==============================================================================

Expand Down
1 change: 1 addition & 0 deletions VERSION.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PluginGuiMagic - Versions history
- Implemented margin and padding with different values on each edge
- Averted an assert in DropShadow with Sliders (or Components in General)
becoming only one pixel
- Added option to XY-Dragger for radius and sensitivity

1.2.6
-----
Expand Down
26 changes: 17 additions & 9 deletions Widgets/foleys_XYDragComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
namespace foleys
{


float XYDragComponent::radius = 4.0f;

XYDragComponent::XYDragComponent()
{
setOpaque (false);
Expand Down Expand Up @@ -113,13 +110,24 @@ void XYDragComponent::setRightClickParameter (juce::RangedAudioParameter* parame
contextMenuParameter = parameter;
}

void XYDragComponent::setRadius (float radiusToUse)
{
radius = radiusToUse;
repaint();
}

void XYDragComponent::setSenseFactor (float factor)
{
senseFactor = factor;
}

void XYDragComponent::updateWhichToDrag (juce::Point<float> pos)
{
const auto centre = juce::Point<int> (getXposition(), getYposition()).toFloat();

mouseOverDot = (centre.getDistanceFrom (pos) < radius * 1.5f);
mouseOverX = (wantsHorizontalDrag && std::abs (pos.getX() - centre.getX()) < 3.0f);
mouseOverY = (wantsVerticalDrag && std::abs (pos.getY() - centre.getY()) < 3.0f);
mouseOverDot = (centre.getDistanceFrom (pos) < radius * senseFactor);
mouseOverX = (wantsHorizontalDrag && std::abs (pos.getX() - centre.getX()) < senseFactor + 1.0f);
mouseOverY = (wantsVerticalDrag && std::abs (pos.getY() - centre.getY()) < senseFactor + 1.0f);

repaint();
}
Expand All @@ -129,13 +137,13 @@ bool XYDragComponent::hitTest (int x, int y)
const auto click = juce::Point<int> (x, y).toFloat ();
const auto centre = juce::Point<int> (getXposition (), getYposition ()).toFloat ();

if (centre.getDistanceFrom (click) < radius * 1.5f)
if (centre.getDistanceFrom (click) < radius * senseFactor)
return true;

if (wantsHorizontalDrag && std::abs (click.getX() - centre.getX()) < 3.0f)
if (wantsHorizontalDrag && std::abs (click.getX() - centre.getX()) < senseFactor + 1.0f)
return true;

if (wantsVerticalDrag && std::abs (click.getY() - centre.getY()) < 3.0f)
if (wantsVerticalDrag && std::abs (click.getY() - centre.getY()) < senseFactor + 1.0f)
return true;

return false;
Expand Down
6 changes: 5 additions & 1 deletion Widgets/foleys_XYDragComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class XYDragComponent : public juce::Component

void setRightClickParameter (juce::RangedAudioParameter* parameter);

void setRadius (float radius);
void setSenseFactor (float factor);

bool hitTest (int x, int y) override;
void mouseDown (const juce::MouseEvent&) override;
void mouseMove (const juce::MouseEvent&) override;
Expand Down Expand Up @@ -93,7 +96,8 @@ class XYDragComponent : public juce::Component

juce::RangedAudioParameter* contextMenuParameter = nullptr;

static float radius;
float radius = 4.0f;
float senseFactor = 2.0f;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (XYDragComponent)
};
Expand Down

0 comments on commit b069da1

Please sign in to comment.