How to draw DrawableComposite vs DrawablePath


#1

Hi,

I’ve a little question about the refactoring of the Drawable mechanism. Before removing the “insertDrawable()” method, my drawing object was just few DrawablePath layers combined into a DrawableComposite. Now, with changes i’ve remove my insertDrawable() and add my layers in order into the DrawableComposite by using addChildComponent (DrawablePath* path);

In the documentation Jules says that the draw (Graphics &g, float opacity, AffineTransform::identity …) of DrawableComposite need to be replace for drawing by adding the DrawableComposite as child of the Component where it will be draw. But for some reasons, i always need to use draw.

If I use the draw(…) method of DrawableComposite to draw into my pipeline (Drawable > Graphics > LowLevelGraphics > Image), there nothing in my destination image. But, if I loop for getting childs (DrawablePath) and calling draw layer by layer, there’s no problem.

Maybe i’m confused with the method of Compositing ? I think that the addChildComponent is maybe not enough ?

There’s a sample of my layers compositing method :

[code]DrawableComposite* StringChordDiagramDraw::getDrawable (int x, int y)
{
DrawableComposite* const drawable = new DrawableComposite ();

DrawablePath* const dble_frets = new DrawablePath ();
dble_frets->setName (T("Frets"));
dble_frets->setFill (FillType(Colours::black));
dble_frets->setPath (getFretsPath());

DrawablePath* const dble_strings = new DrawablePath ();
dble_strings->setName (T("Strings"));
dble_strings->setFill (FillType(Colours::black));
dble_strings->setPath (getStringsPath());

DrawablePath* const dble_nut = new DrawablePath ();
dble_nut->setName (T("Nut"));
dble_nut->setFill (FillType(Colours::black));
dble_nut->setPath (getNutPath());

DrawablePath* const dble_chordname = new DrawablePath ();
dble_chordname->setName (T("ChordName"));
dble_chordname->setFill (FillType(Colours::black));
dble_chordname->setPath (getChordNamePath());

DrawablePath* const dble_basefret = new DrawablePath ();
dble_basefret->setName (T("BaseFret"));
dble_basefret->setFill (FillType(Colours::black));
dble_basefret->setPath (getBaseFretPath());

DrawablePath* const dble_fingers = new DrawablePath ();
dble_fingers->setName (T("Fingers"));
dble_fingers->setFill (FillType(Colours::black));
dble_fingers->setPath (getFingersPath());

DrawablePath* const dble_fingername = new DrawablePath ();
dble_fingername->setName (T("FingerName"));
dble_fingername->setFill (FillType(Colours::white));
dble_fingername->setPath (getFingersNamePath());

AffineTransform trans = AffineTransform::identity.translated((float)x, 
															 (float)y)
											        .scaled ((float)width/Global, 
													         (float)height/Global);

drawable->addChildComponent (dble_frets);
drawable->addChildComponent (dble_strings);
drawable->addChildComponent (dble_nut);
drawable->addChildComponent (dble_chordname);
drawable->addChildComponent (dble_basefret);
drawable->addChildComponent (dble_fingers);
drawable->addChildComponent (dble_fingername);

drawable->setTransform (trans);
	
return drawable;

}[/code]


#2

At a brief glance, your structure looks ok, and the draw() method does still work for composites, because I still use it in various places (e.g. the demo draws some SVG drawables like that). Have you tried adding it to a parent component to see if it draws correctly that way?


#3

Hi Jules, thanks for reply. No I don’t have test that, I’m currently work correct my classes with few changes (restart after a long break) and check that soon. Good idea for the demo, it’s right that’s a large source of inspiration and updated with refactoring!


#4

Ok. For information the solution is :

Make visible the DrawablePath inside the DrawableComposite :slight_smile: I’ve just replace the addChildComponent () by addAndMakeVisible () for compositing and it’s ok for me. Not a transformation problem. Ouf! :wink: