Skip to content

Commit

Permalink
Update mouse click and drag logic in PopupChannelSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
anjaldoshi committed Oct 18, 2024
1 parent 48bde98 commit a7c8518
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
32 changes: 23 additions & 9 deletions Source/Processors/Editors/PopupChannelSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ ChannelButton::ChannelButton (int _id, PopupChannelSelector* _parent) : Button (

void ChannelButton::mouseDown (const MouseEvent& event)
{
parent->startDragCoords.setX (event.x + this->getX());
parent->startDragCoords.setY (event.y + this->getY());
parent->firstButtonSelectedState = ! this->getToggleState();
parent->mouseDown (event);
}
Expand Down Expand Up @@ -152,7 +150,7 @@ PopupChannelSelector::PopupChannelSelector (Component* parent, PopupChannelSelec

buttonColour = Colours::azure;

auto contentComponent = std::make_unique<Component>();
contentComponent = std::make_unique<Component>();

if (channelNames.isEmpty() || channelNames.size() != nChannels)
{
Expand Down Expand Up @@ -226,7 +224,7 @@ PopupChannelSelector::PopupChannelSelector (Component* parent, PopupChannelSelec
int scrollBarThickness = 15;

viewport = std::make_unique<Viewport>();
viewport->setViewedComponent (contentComponent.release(), true);
viewport->setViewedComponent (contentComponent.get(), false);
viewport->setScrollBarsShown (true, false);
viewport->setScrollBarThickness (scrollBarThickness);

Expand All @@ -250,7 +248,7 @@ PopupChannelSelector::PopupChannelSelector (Component* parent, PopupChannelSelec
setSize (viewport->getWidth(), viewport->getHeight());
}

setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
startDragCoords = Point<int> (-1, -1);
}

void PopupChannelSelector::resized()
Expand Down Expand Up @@ -310,20 +308,28 @@ void PopupChannelSelector::mouseMove (const MouseEvent& event)
void PopupChannelSelector::mouseDown (const MouseEvent& event)
{
if (editable)
{
selectedButtons.clear();
startDragCoords = event.getEventRelativeTo (contentComponent.get()).getPosition();
}
}

void PopupChannelSelector::mouseDrag (const MouseEvent& event)
{
if (editable)
{
mouseDragged = true;
MouseEvent e = event.getEventRelativeTo (contentComponent.get());

int w = event.getDistanceFromDragStartX();
int h = event.getDistanceFromDragStartY();
int w = e.getDistanceFromDragStartX();
int h = e.getDistanceFromDragStartY();
int x = startDragCoords.getX();
int y = startDragCoords.getY();

if (x < 0 || y < 0)
return;

mouseDragged = true;

if (w < 0)
{
x = x + w;
Expand Down Expand Up @@ -396,6 +402,8 @@ void PopupChannelSelector::modifierKeysChanged (const ModifierKeys& modifiers)

void PopupChannelSelector::mouseUp (const MouseEvent& event)
{
bool mouseClicked = false;

if (! mouseDragged && editable)
{
for (auto button : channelButtons)
Expand All @@ -422,11 +430,17 @@ void PopupChannelSelector::mouseUp (const MouseEvent& event)
activeChannels.add (button->getId());
}

mouseClicked = true;

break;
}
}
}
listener->channelStateChanged (activeChannels);

if (mouseClicked || mouseDragged)
listener->channelStateChanged (activeChannels);

startDragCoords = Point<int> (-1, -1);
mouseDragged = false;
}

Expand Down
1 change: 1 addition & 0 deletions Source/Processors/Editors/PopupChannelSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class PLUGIN_API PopupChannelSelector : public PopupComponent,

private:
std::unique_ptr<Viewport> viewport;
std::unique_ptr<Component> contentComponent;
Listener* listener;

/** Methods for parsing range strings*/
Expand Down

0 comments on commit a7c8518

Please sign in to comment.