Optimal repaint strategy


#1

Is this an optimal repaint strategy? What happens if i have 10 of these running with different positions in diferent bits of the screen?

class LfoPositionIndicator : public Timer, public Component
{
public:
    LfoPositionIndicator(DuckPumpAudioProcessor & p): processor(p)
    {
        startTimerHz(60);
        setInterceptsMouseClicks(false, false);
    }

    void timerCallback() override
    {
        x = roundToInt(float(getWidth()) * float(processor.getPhasorPosition()));

        repaint(lastX, 0, 1, getHeight());
        repaint(x, 0, 1, getHeight());
        
        lastX = x;
    }

    void paint(Graphics & g) override
    {
        g.setColour(Colours::orange);
        g.drawVerticalLine(x, 0.0f, float(getHeight()));
    }

#2

What do you want to achieve with the two repaint calls? I guess it’s probably more effective to just call repaint() once.


#3

The areas may be spaced apart if the pointer moves by more than one pixel. They usually are moving by 10 - 20 pixels.


#4

is there a thing with how computers paint the display in horizontal scanlines, so calling g.drawVerticalLine might in fact be awful? is that something to think about for repainting?