Repaint. Expected Behavior?


#1

Hi All,

My Juce Version :  Git Tip

Platform :  Windows 10

 

In my application, I have a child component which is of the same size as the parent component and I am continuously repainting the child component using a timer. But this is also inducing a call to paint menthod of the parent component. Is this an expected behaviour??

Also In my another application, I had two sibling components which occupy the same position and size in the screen(My intention is one acting as background grid of the graph and another representing the waveform). Even here, on inducing the repaint to one of the siblings(waveform component) indcues a call the another sibling's(background grid) paint method.

I believe it shouldnt be the expected behaviour since changing the graphics of the child component shouldnt interfere with the parent component.

Can you guys please comment on this behaviour?? Is it expected??

 

 

Best Regards,

Ranjith

 


#2
class X
:
public Component,
public Timer
{
public:
    X()
    {
        r.setSeedRandomly();
        startTimer(500);
        setOpaque(true); // set to true for half as many repaintings
    }

    void incrementCounter()
    {
        counter++;
    }

    void paint(Graphics & g) override
    {
        g.fillAll(Colours::red.withBrightness(r.nextFloat() * 0.25f));
        g.setColour(Colours::white);
        g.drawText("Parent repainted count = " + String(counter++), getLocalBounds(), Justification::left);
    }

    void timerCallback() override
    {
        repaint();
    }
private:
    int counter {0};
    Random r;
};
class Y
:
public Component
{
public:
    Y()
    {
        addAndMakeVisible(x);
        resized();
        setOpaque(true);
    }
    void paint(Graphics & g)
    {
        g.fillAll(Colours::red.withHue(r.nextFloat()));
        x.incrementCounter();

    }
    void resized()
    {
        x.setBounds(getLocalBounds().reduced(65));
    }
private:
    X x;
    Random r;
};

I get the same.  

Here's some test code.  

On OSX I get two parent repaints for every call of the timer with setOpaque(false) and one with setOpaque(true).  Perhaps someone can shed some light on why?


#3

This is indeed the expected the behaviour, take a look at http://www.juce.com/forum/topic/repaint-without-parent-repaint for a similar discussion.

Hope this helps!