4141
4242using namespace LfpViewer ;
4343
44+ namespace
45+ {
46+ String formatRangeMarkerValue (float value)
47+ {
48+ if (std::abs (value) < 0 .005f )
49+ {
50+ return " 0" ;
51+ }
52+
53+ const float magnitude = std::abs (value);
54+ const int decimals = magnitude >= 100 .0f ? 0 : magnitude >= 10 .0f ? 1
55+ : 2 ;
56+
57+ return String (value, decimals);
58+ }
59+ } // namespace
60+
4461LfpChannelDisplay::LfpChannelDisplay (LfpDisplaySplitter* c, LfpDisplay* d, LfpDisplayOptions* o, int channelNumber)
4562 : canvasSplit (c), display (d), options (o), isSelected (false ), isRecorded (false ), recordingIsActive (false ), chan (channelNumber), name (" " ), drawableChan (channelNumber), channelOverlap (300 ), channelHeight (30 ), range (250 .0f ), isEnabled (true ), inputInverted (false ), canBeInverted (true ), drawMethod (false ), isHidden (false ), ifrom (0 ), ito (0 ), ifrom_local (0 ), ito_local (0 )
4663{
@@ -178,6 +195,8 @@ void LfpChannelDisplay::pxPaint()
178195
179196 LfpBitmapPlotterInfo plotterInfo; // hold and pass plotting info for each plotting method class
180197
198+ const bool showRangeMarkers = isSelected || display->getSingleChannelState ();
199+
181200 for (int ii = ifrom; ii <= endIndex; ii++)
182201 {
183202 int i = (ifrom_local + ii - ifrom) % getWidth ();
@@ -192,7 +211,7 @@ void LfpChannelDisplay::pxPaint()
192211 }
193212
194213 // draw range markers
195- if (isSelected )
214+ if (showRangeMarkers )
196215 {
197216 int start = getY () + center - channelHeight / 2 ;
198217 int jump = channelHeight / 4 ;
@@ -433,6 +452,8 @@ void LfpChannelDisplay::pxPaintHistory (int playhead, int rightEdge, int maxScre
433452
434453 LfpBitmapPlotterInfo plotterInfo; // hold and pass plotting info for each plotting method class
435454
455+ const bool showRangeMarkers = isSelected || display->getSingleChannelState ();
456+
436457 for (int ii = 0 ; ii < rightEdge; ii++)
437458 {
438459 int i = ii;
@@ -478,7 +499,7 @@ void LfpChannelDisplay::pxPaintHistory (int playhead, int rightEdge, int maxScre
478499 }
479500
480501 // draw range markers
481- if (isSelected )
502+ if (showRangeMarkers )
482503 {
483504 int start = getY () + center - channelHeight / 2 ;
484505 int jump = channelHeight / 4 ;
@@ -675,7 +696,43 @@ void LfpChannelDisplay::drawEventOverlay (const int rawEventState, int x, int yf
675696 }
676697}
677698
678- void LfpChannelDisplay::paint (Graphics& g) {}
699+ void LfpChannelDisplay::paint (Graphics& g)
700+ {
701+ if (! display->getSingleChannelState () || getWidth () < 80 || getHeight () == 0 )
702+ {
703+ return ;
704+ }
705+
706+ const int center = getHeight () / 2 ;
707+ const int start = center - channelHeight / 2 ;
708+ const int jump = channelHeight / 4 ;
709+
710+ if (jump <= 0 )
711+ {
712+ return ;
713+ }
714+
715+ const int labelWidth = 50 ;
716+ const int textHeight = 16 ;
717+ const int labelX = getWidth () - labelWidth - 8 ;
718+ const float markerSign = inputInverted ? -1 .0f : 1 .0f ;
719+
720+ g.setFont (FontOptions (12 .0f ));
721+
722+ for (const int markerIndex : { 1 , 3 })
723+ {
724+ const int markerY = start + jump * markerIndex;
725+ const float markerValue = markerSign * range * (0 .5f - 0 .25f * markerIndex);
726+ const String markerText = formatRangeMarkerValue (markerValue);
727+ const int textY = jlimit (0 , jmax (0 , getHeight () - textHeight), markerY - textHeight / 2 );
728+
729+ g.setColour (Colours::black.withAlpha (0 .55f ));
730+ g.fillRoundedRectangle ((float ) labelX, (float ) textY, (float ) labelWidth, (float ) textHeight, 3 .0f );
731+
732+ g.setColour (Colours::lightgrey.withAlpha (0 .95f ));
733+ g.drawFittedText (markerText, labelX + 4 , textY, labelWidth - 8 , textHeight, Justification::centredRight, 1 , 0 .8f );
734+ }
735+ }
679736
680737PopupMenu LfpChannelDisplay::getOptions ()
681738{
@@ -702,6 +759,7 @@ void LfpChannelDisplay::changeParameter (int id)
702759void LfpChannelDisplay::setRange (float r)
703760{
704761 range = r;
762+ repaint ();
705763}
706764
707765float LfpChannelDisplay::getRange ()
@@ -742,6 +800,7 @@ void LfpChannelDisplay::setChannelHeight (int c)
742800 channelHeightFloat = -channelHeightFloat;
743801
744802 channelOverlap = channelHeight * 2 ;
803+ repaint ();
745804}
746805
747806int LfpChannelDisplay::getChannelHeight ()
0 commit comments