Skip to content

Commit 7aa3556

Browse files
committed
Add timescale zooming animation upon interaction
1 parent 3c5897f commit 7aa3556

3 files changed

Lines changed: 35 additions & 13 deletions

File tree

Source/Plugins/LfpDisplayNodeAlpha/LfpDisplayCanvas.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,18 +1858,24 @@ void LfpTimescale::paint(Graphics& g)
18581858

18591859
g.drawText("ms:",5,0,100,getHeight(),Justification::left, false);
18601860

1861-
for (int i = 1; i < 10; i++)
1861+
const int steps = labels.size() + 1;
1862+
for (int i = 1; i < steps; i++)
18621863
{
1863-
if (i == 5)
1864-
g.drawLine(getWidth()/10*i,0,getWidth()/10*i,getHeight(),3.0f);
1864+
if (i != 0 && i % 5 == 0)
1865+
g.drawLine(getWidth()/steps*i,0,getWidth()/steps*i,getHeight(),3.0f);
18651866
else
1866-
g.drawLine(getWidth()/10*i,0,getWidth()/10*i,getHeight(),1.0f);
1867+
g.drawLine(getWidth()/steps*i,0,getWidth()/steps*i,getHeight(),1.0f);
18671868

1868-
g.drawText(labels[i-1],getWidth()/10*i+3,0,100,getHeight(),Justification::left, false);
1869+
g.drawText(labels[i-1],getWidth()/steps*i+3,0,100,getHeight(),Justification::left, false);
18691870
}
18701871

18711872
}
18721873

1874+
void LfpTimescale::resized()
1875+
{
1876+
setTimebase(timebase);
1877+
}
1878+
18731879
void LfpTimescale::mouseDrag(const juce::MouseEvent &e)
18741880
{
18751881
if (e.mods.isLeftButtonDown()) // double check that we initiate only for left click and hold
@@ -1887,7 +1893,7 @@ void LfpTimescale::mouseDrag(const juce::MouseEvent &e)
18871893
float dTimescale=0;
18881894
int dragDeltaX = (e.getScreenPosition().getX() - e.getMouseDownScreenX()); // invert so drag up -> scale up
18891895

1890-
std::cout << dragDeltaX << std::endl;
1896+
// std::cout << dragDeltaX << std::endl;
18911897
if (dragDeltaX > 0)
18921898
{
18931899
dTimescale = 0.01 * dragDeltaX;
@@ -1911,10 +1917,9 @@ void LfpTimescale::mouseDrag(const juce::MouseEvent &e)
19111917
dTimescale = ((dTimescale + (0.005/2)) / 0.005) * 0.005;
19121918

19131919
float newTimescale = timescale+dTimescale;
1914-
std::cout << "new timescale: " << newTimescale << std::endl;
1920+
19151921
if (newTimescale < 0.25) newTimescale = 0.250;
19161922
if (newTimescale > 20) newTimescale = 20;
1917-
std::cout << "new timescale: " << newTimescale << std::endl;
19181923

19191924
// don't bother updating if the new timebase is the same as the old (if clipped, for example)
19201925
if (timescale != newTimescale)
@@ -1939,11 +1944,24 @@ void LfpTimescale::setTimebase(float t)
19391944
timebase = t;
19401945

19411946
labels.clear();
1942-
1943-
for (float i = 1.0f; i < 10.0; i++)
1947+
1948+
const int minWidth = 60;
1949+
labelIncrement = 0.025f;
1950+
1951+
1952+
while (getWidth() != 0 && // setTimebase can be called before LfpTimescale has width
1953+
getWidth() / (timebase / labelIncrement) < minWidth) // so, if width is 0 then don't iterate for scale factor
19441954
{
1945-
String labelString = String(timebase/10.0f*1000.0f*i);
1946-
1955+
// std::cout << getWidth() / (timebase / labelIncrement) << " is smaller than minimum width, calculating new step size" << std::endl;
1956+
if (labelIncrement < 0.2)
1957+
labelIncrement *= 2;
1958+
else
1959+
labelIncrement += 0.2;
1960+
}
1961+
1962+
for (float i = labelIncrement; i < timebase; i += labelIncrement)
1963+
{
1964+
String labelString = String(i * 1000.0f);
19471965
labels.add(labelString.substring(0,6));
19481966
}
19491967

Source/Plugins/LfpDisplayNodeAlpha/LfpDisplayCanvas.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ class LfpTimescale : public Component
402402

403403
void paint(Graphics& g);
404404

405+
virtual void resized();
406+
405407
/** Handles the drag to zoom feature on the timescale. The display must
406408
be paused to zoom */
407409
virtual void mouseDrag(const MouseEvent &e) override;
@@ -416,6 +418,8 @@ class LfpTimescale : public Component
416418
LfpDisplay* lfpDisplay;
417419

418420
float timebase;
421+
float labelIncrement;
422+
float numIncrements;
419423

420424
Font font;
421425

Source/Plugins/LfpDisplayNodeAlpha/LfpDisplayEditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ LfpDisplayEditor::LfpDisplayEditor(GenericProcessor* parentNode, bool useDefault
4747
addAndMakeVisible(subprocessorSelectionLabel);
4848

4949
subprocessorSampleRateLabel = new Label("Subprocessor sample rate label", "Sample Rate:");
50-
subprocessorSampleRateLabel->setFont(Font(Font::getDefaultSerifFontName(), 14, italic));
50+
subprocessorSampleRateLabel->setFont(Font(Font::getDefaultSerifFontName(), 14, Font::plain));
5151
subprocessorSampleRateLabel->setBounds(subprocessorSelection->getX(), subprocessorSelection->getBottom() + 10, 200, 40);
5252
addAndMakeVisible(subprocessorSampleRateLabel);
5353
}

0 commit comments

Comments
 (0)