@@ -266,19 +266,13 @@ class StatusbarTextButton final : public TextButton {
266266};
267267
268268class LatencyDisplayButton final : public Component
269- , public MultiTimer
270269 , public SettableTooltipClient {
271270 Label latencyValue;
272271 Label icon;
273- bool isHover = false ;
272+ bool isHovered = false ;
274273 Colour bgColour;
275274 int currentLatencyValue = 0 ;
276275
277- enum TimerRoutine { Timeout,
278- Animate };
279- float alpha = 1 .0f ;
280- bool fading = false ;
281-
282276public:
283277 std::function<void ()> onClick = [] { };
284278 LatencyDisplayButton ()
@@ -310,35 +304,6 @@ class LatencyDisplayButton final : public Component
310304 buttonStateChanged ();
311305 }
312306
313- void timerCallback (int const ID) override
314- {
315- switch (ID) {
316- case Timeout:
317- startTimer (Animate, 1000 / 30 .0f );
318- break ;
319- case Animate:
320- alpha = pow (alpha, 1 .0f / 2 .2f );
321- alpha -= 0 .02f ;
322- alpha = pow (alpha, 2 .2f );
323- alpha = std::clamp (alpha, 0 .0f , 1 .0f );
324- alpha = std::isfinite (alpha) ? alpha : 0 .0f ;
325- fading = true ;
326- if (alpha <= 0 .01f ) {
327- alpha = 0 .0f ;
328- stopTimer (Animate);
329- setVisible (false );
330- if (auto * parent = getParentComponent ())
331- {
332- parent->resized ();
333- }
334- }
335- buttonStateChanged ();
336- break ;
337- default :
338- break ;
339- }
340- }
341-
342307 void paint (Graphics& g) override
343308 {
344309 auto const b = getLocalBounds ().reduced (1 , 6 ).toFloat ();
@@ -349,27 +314,12 @@ class LatencyDisplayButton final : public Component
349314 void setLatencyValue (int const value)
350315 {
351316 currentLatencyValue = value;
352- updateValue ();
353- if (value == 0 ) {
354- startTimer (Timeout, 1000 / 3 .0f );
355- } else {
356- stopTimer (Timeout);
357- stopTimer (Animate);
358- fading = false ;
359- setVisible (true );
360- alpha = 1 .0f ;
361- buttonStateChanged ();
362- }
363- }
364-
365- void updateValue ()
366- {
367- if (isHover && !fading) {
368- latencyValue.setJustificationType (Justification::centredLeft);
369- latencyValue.setText (" Reset" , dontSendNotification);
370- } else {
371- latencyValue.setJustificationType (Justification::centredRight);
372- latencyValue.setText (String (currentLatencyValue) + " smpl" , dontSendNotification);
317+ setVisible (value != 0 );
318+ buttonStateChanged ();
319+
320+ if (auto * parent = getParentComponent ())
321+ {
322+ parent->resized ();
373323 }
374324 }
375325
@@ -382,25 +332,29 @@ class LatencyDisplayButton final : public Component
382332
383333 void buttonStateChanged ()
384334 {
385- bgColour = getLookAndFeel ().findColour (isHover ? PlugDataColour::toolbarHoverColourId : PlugDataColour::toolbarActiveColourId). withAlpha (alpha );
386- auto const textColour = bgColour.contrasting (). withAlpha (alpha) ;
335+ bgColour = getLookAndFeel ().findColour (isHovered ? PlugDataColour::toolbarHoverColourId : PlugDataColour::toolbarActiveColourId);
336+ auto const textColour = bgColour.contrasting ();
387337 icon.setColour (Label::textColourId, textColour);
388338 latencyValue.setColour (Label::textColourId, textColour);
389339
390- updateValue ();
391-
392- repaint ();
340+ if (isHovered) {
341+ latencyValue.setJustificationType (Justification::centredLeft);
342+ latencyValue.setText (" Reset" , dontSendNotification);
343+ } else {
344+ latencyValue.setJustificationType (Justification::centredRight);
345+ latencyValue.setText (String (currentLatencyValue) + " smpl" , dontSendNotification);
346+ }
393347 }
394348
395349 void mouseEnter (MouseEvent const & e) override
396350 {
397- isHover = true ;
351+ isHovered = true ;
398352 buttonStateChanged ();
399353 }
400354
401355 void mouseExit (MouseEvent const & e) override
402356 {
403- isHover = false ;
357+ isHovered = false ;
404358 buttonStateChanged ();
405359 }
406360
@@ -1144,10 +1098,12 @@ class CPUMeter final : public Component
11441098 void timerCallback () override
11451099 {
11461100 auto const lastCpuUsage = cpuUsage.last ();
1101+ auto const oldCpuUsage = cpuUsageToDraw;
11471102 cpuUsageToDraw = round (lastCpuUsage);
11481103 cpuUsageLongHistory.push (lastCpuUsage);
11491104 updateCPUGraphLong ();
1150- repaint ();
1105+ if (oldCpuUsage != cpuUsageToDraw)
1106+ repaint ();
11511107 }
11521108
11531109 void mouseDown (MouseEvent const & e) override
0 commit comments