Adding a drawn Quadrilateral to a Component is not visible

Hello,

I’m new to Juce. I am trying to simply add a yellow box to a component but having no luck. Can anyone tell me why the following doesn’t display the box:

[code]juce::Path quad;
quad.addQuadrilateral(20, 20, 40, 20, 40, 40, 20, 40);

    DrawablePath* const quadPath = new DrawablePath ();
    quadPath->setPath(quad);
    quadPath->setFill(juce::Colours::yellow);
    
    DrawableComposite* const drawable = new DrawableComposite ();

    drawable->addChildComponent (quadPath);
    myComponent->addChildComponent(drawable);[/code]

Thanks, K :?

Probably because you’ve not set the bounds of the composite object. But TBH if you’re just starting, why not just try drawing your rectangle in the paint() method? That’s much easier than messing around with Drawables, which can be a PITA. I rarely use them myself.

BTW your code looks extremely leaky. If you don’t really understand memory management in C++, please stop whatever you’re doing and go and learn about it before attempting to write any more code!

Thanks Jules.

Yes, I’ll take your advice and learn about C++ memory management. These are my first few days with C++ and Juce after some basic Java :oops:

K

Yes, the java programmers are always easy to spot when they try C++!

Sorry to be a pain but any chance you could tell me the basic loc for adding a similar rectangle from the paint method?

Would I still use

[code]juce::Path quad;
quad.addQuadrilateral(20, 20, 40, 20, 40, 40, 20, 40);

DrawablePath* const quadPath = new DrawablePath ();
quadPath->setPath(quad);
quadPath->setFill(juce::Colours::yellow);[/code]

??

Grep for “paint (Graphics&” and you’ll find a billion examples.

Cool. Thanks