Skip to content

Commit cae86ed

Browse files
committed
Updates to mouse drag zooming algorithms
2 parents 9570972 + 8a05214 commit cae86ed

2 files changed

Lines changed: 52 additions & 40 deletions

File tree

Source/Plugins/LfpDisplayNodeAlpha/LfpDisplayCanvas.cpp

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,9 +1355,9 @@ void LfpDisplayOptions::setSpreadSelection(int spread, bool canvasMustUpdate, bo
13551355
}
13561356
}
13571357

1358-
void LfpDisplayOptions::togglePauseButton()
1358+
void LfpDisplayOptions::togglePauseButton(bool sendUpdate)
13591359
{
1360-
pauseButton->setToggleState(!pauseButton->getToggleState(), sendNotification);
1360+
pauseButton->setToggleState(!pauseButton->getToggleState(), sendUpdate ? sendNotification : dontSendNotification);
13611361
}
13621362

13631363
void LfpDisplayOptions::buttonClicked(Button* b)
@@ -2119,7 +2119,7 @@ LfpDisplay::LfpDisplay(LfpDisplayCanvas* c, Viewport* v)
21192119

21202120
LfpDisplay::~LfpDisplay()
21212121
{
2122-
deleteAllChildren();
2122+
// deleteAllChildren();
21232123
}
21242124

21252125

@@ -2154,7 +2154,8 @@ void LfpDisplay::setNumChannels(int numChannels)
21542154
numChans = numChannels;
21552155

21562156

2157-
deleteAllChildren();
2157+
// deleteAllChildren();
2158+
removeAllChildren();
21582159

21592160
channels.clear();
21602161
channelInfo.clear();
@@ -2310,6 +2311,7 @@ void LfpDisplay::paint(Graphics& g)
23102311

23112312
void LfpDisplay::refresh()
23122313
{
2314+
23132315
// X-bounds of this update
23142316
int fillfrom = canvas->lastScreenBufferIndex[0];
23152317
int fillto = (canvas->screenBufferIndex[0]);
@@ -2711,26 +2713,34 @@ void LfpDisplay::toggleSingleChannel(int chan)
27112713
LfpChannelTrack lfpChannelTrack{drawableChannels[chan].channel, drawableChannels[chan].channelInfo};
27122714
lfpChannelTrack.channelInfo->setEnabledState(true);
27132715
lfpChannelTrack.channelInfo->setSingleChannelState(true);
2714-
setChannelHeight(newHeight, false);
2715-
setSize(getWidth(), numChans*getChannelHeight());
27162716

2717-
viewport->setScrollBarsShown(false, false);
2718-
viewport->setViewPosition(Point<int>(0, chan*newHeight));
2717+
removeAllChildren();
27192718

27202719
// disable unused channels
2721-
for (int i = 0; i < drawableChannels.size(); i++)
2720+
for (int i = 0; i < getNumChannels(); i++)
27222721
{
2723-
if (i != chan) drawableChannels[i].channel->setEnabledState(false);
2722+
if (i != chan)
2723+
{
2724+
drawableChannels[i].channel->setEnabledState(false);
2725+
}
27242726
}
27252727

27262728
// update drawableChannels, give only the single channel to focus on
27272729
Array<LfpChannelTrack> channelsToDraw{lfpChannelTrack};
27282730
drawableChannels = channelsToDraw;
27292731

2730-
// remove all other children and show this one channel
2731-
removeAllChildren();
27322732
addAndMakeVisible(lfpChannelTrack.channel);
27332733
addAndMakeVisible(lfpChannelTrack.channelInfo);
2734+
2735+
// set channel height and position (so that we allocate the smallest
2736+
// necessary image size for drawing)
2737+
setChannelHeight(newHeight, false);
2738+
2739+
lfpChannelTrack.channel->setTopLeftPosition(canvas->leftmargin, 0);
2740+
lfpChannelTrack.channelInfo->setTopLeftPosition(0, 0);
2741+
setSize(getWidth(), getChannelHeight());
2742+
2743+
viewport->setViewPosition(0, 0);
27342744

27352745
}
27362746
// else if (chan == singleChan || chan == -2)
@@ -2893,9 +2903,7 @@ void LfpDisplay::mouseDown(const MouseEvent& event)
28932903
{
28942904
// if (singleChan != -1)
28952905
if (event.getNumberOfClicks() == 2) {
2896-
std::cout << "singleChan = " << singleChan << std::endl;
28972906
toggleSingleChannel(closest);
2898-
std::cout << "singleChan = " << singleChan << std::endl;
28992907
}
29002908

29012909
if (getSingleChannelState())
@@ -2910,21 +2918,9 @@ void LfpDisplay::mouseDown(const MouseEvent& event)
29102918
}
29112919
}
29122920

2913-
// if (event.getNumberOfClicks() == 2) {
2914-
// toggleSingleChannel(closest);
2915-
// return;
2916-
// }
2917-
2918-
// if (event.mods.isRightButtonDown())
2919-
// {
2920-
// PopupMenu channelMenu = channels[closest]->getOptions();
2921-
// const int result = channelMenu.show();
2922-
// drawableChannels[closest].channel->changeParameter(result);
2923-
// }
2921+
// canvas->fullredraw = true;//issue full redraw
29242922

2925-
canvas->fullredraw = true;//issue full redraw
2926-
2927-
refresh();
2923+
// refresh();
29282924

29292925
}
29302926

@@ -3599,12 +3595,16 @@ void LfpChannelDisplayInfo::mouseDrag(const MouseEvent &e)
35993595
// init state in our track zooming info struct
36003596
if (!display->trackZoomInfo.isScrollingY)
36013597
{
3602-
display->trackZoomInfo.isScrollingY = true;
3603-
display->trackZoomInfo.componentStartHeight = getChannelHeight();
3604-
display->trackZoomInfo.zoomPivotRatioY = (getY() + e.getMouseDownY())/(float)display->getHeight();
3605-
display->trackZoomInfo.zoomPivotRatioX = (getX() + e.getMouseDownX())/(float)display->getWidth();
3606-
display->trackZoomInfo.zoomPivotViewportOffset = getPosition() + e.getMouseDownPosition() - canvas->viewport->getViewPosition();
3598+
auto & zoomInfo = display->trackZoomInfo;
3599+
3600+
zoomInfo.isScrollingY = true;
3601+
zoomInfo.componentStartHeight = getChannelHeight();
3602+
zoomInfo.zoomPivotRatioY = (getY() + e.getMouseDownY())/(float)display->getHeight();
3603+
zoomInfo.zoomPivotRatioX = (getX() + e.getMouseDownX())/(float)display->getWidth();
3604+
zoomInfo.zoomPivotViewportOffset = getPosition() + e.getMouseDownPosition() - canvas->viewport->getViewPosition();
36073605

3606+
zoomInfo.unpauseOnScrollEnd = !display->isPaused;
3607+
if (!display->isPaused) display->options->togglePauseButton(true);
36083608
}
36093609

36103610
int h = display->trackZoomInfo.componentStartHeight;
@@ -3637,6 +3637,12 @@ void LfpChannelDisplayInfo::mouseDrag(const MouseEvent &e)
36373637
newHeight = display->trackZoomInfo.maxZoomHeight;
36383638
}
36393639

3640+
// return early if the
3641+
if (newHeight == getChannelHeight())
3642+
{
3643+
return;
3644+
}
3645+
36403646
// set channel heights for all channel
36413647
// display->setChannelHeight(newHeight);
36423648
for (int i = 0; i < display->getNumChannels(); ++i)
@@ -3655,16 +3661,20 @@ void LfpChannelDisplayInfo::mouseDrag(const MouseEvent &e)
36553661
if (newViewportY < 0) newViewportY = 0; // make sure we don't adjust beyond the edge of the actual view
36563662

36573663
canvas->viewport->setViewPosition(0, newViewportY);
3658-
36593664
}
36603665
}
36613666
}
36623667

36633668
void LfpChannelDisplayInfo::mouseUp(const MouseEvent &e)
36643669
{
3665-
if (e.mods.isLeftButtonDown())
3670+
if (e.mods.isLeftButtonDown() && display->trackZoomInfo.isScrollingY)
36663671
{
36673672
display->trackZoomInfo.isScrollingY = false;
3673+
if (display->trackZoomInfo.unpauseOnScrollEnd)
3674+
{
3675+
display->isPaused = false;
3676+
display->options->togglePauseButton(false);
3677+
}
36683678
}
36693679
}
36703680

Source/Plugins/LfpDisplayNodeAlpha/LfpDisplayCanvas.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class LfpDisplayOptions : public Component,
273273
//void setRangeSelection(float range, bool canvasMustUpdate);
274274
void setSpreadSelection();
275275

276-
void togglePauseButton();
276+
void togglePauseButton(bool sendUpdate = true);
277277

278278
void saveParameters(XmlElement* xml);
279279
void loadParameters(XmlElement* xml);
@@ -574,8 +574,8 @@ class LfpDisplay : public Component
574574

575575
Array<Colour> channelColours;
576576

577-
Array<LfpChannelDisplay*> channels; // all channels
578-
Array<LfpChannelDisplayInfo*> channelInfo; // all channelInfos
577+
OwnedArray<LfpChannelDisplay> channels; // all channels
578+
OwnedArray<LfpChannelDisplayInfo> channelInfo; // all channelInfos
579579

580580
/** Convenience struct for holding a channel and its info in drawableChannels */
581581
struct LfpChannelTrack
@@ -606,8 +606,10 @@ class LfpDisplay : public Component
606606
float zoomPivotRatioX; // a cache for calculating the anchor point when adjusting viewport
607607
float zoomPivotRatioY;
608608
Point<int> zoomPivotViewportOffset; // similar to above, but pixel-wise offset
609-
}
610-
trackZoomInfo; // and create an instance here
609+
bool unpauseOnScrollEnd;
610+
};
611+
612+
TrackZoomInfo_Struct trackZoomInfo; // and create an instance here
611613

612614

613615
private:

0 commit comments

Comments
 (0)