Hot Door CORE Forum
Placing art in customArt viewable art - Printable Version

+- Hot Door CORE Forum (http://hotdoorcore.com/forum)
+-- Forum: All forums (http://hotdoorcore.com/forum/forumdisplay.php?fid=1)
+--- Forum: General discussion (http://hotdoorcore.com/forum/forumdisplay.php?fid=3)
+--- Thread: Placing art in customArt viewable art (/showthread.php?tid=205)



Placing art in customArt viewable art - Rick Johnson - 01-30-2019

I'm creating a custom art object and placing art in the editable art works fine. Either of these methods works, although one is likely preferable to the other:

Code:
    hdi::core::Art custObj = hdi::core::Art(hdi::core::ArtTypeCustom, hdi::core::PlaceAboveAll);
    hdi::core::ArtAP theRect = hdi::core::draw::rect(hdi::core::ArtboardRect::XYWidthHeight(100,100,50,50));
    hdi::core::ArtAP theEll = hdi::core::draw::ellipse(hdi::core::ArtboardPoint(125,125), 50, 50, true);
    hdi::core::Art* edArt = custObj.customArt()->editableArt().release();
    theEll->reorder(hdi::core::PlaceInsideOnTop, edArt);
    theRect->reorder(hdi::core::PlaceInsideOnTop, custObj.customArt()->editableArt().release());

Similar code, however, fails to move art into the viewableArt group. Using get() or release() on the auto_ptr seems to make no difference.

Code:
    hdi::core::Art custObj = hdi::core::Art(hdi::core::ArtTypeCustom, hdi::core::PlaceAboveAll);
    hdi::core::ArtAP theRect = hdi::core::draw::rect(hdi::core::ArtboardRect::XYWidthHeight(100,100,50,50));
    hdi::core::ArtAP theEll = hdi::core::draw::ellipse(hdi::core::ArtboardPoint(125,125), 50, 50, true);
    hdi::core::Art* vuArt = custObj.customArt()->viewableArt().release();
    theEll->reorder(hdi::core::PlaceInsideOnTop, vuArt);
    theRect->reorder(hdi::core::PlaceInsideOnTop, custObj.customArt()->viewableArt().release());

Any suggestions would be very much appreciated.


RE: Placing art in customArt viewable art - garrett - 01-30-2019

It's been a while since I've done much with custom art. If I remember correctly, the viewable art had to have a group at the root level. I think there might be other nuances to editable/viewable art, but that's where I would start.

Also, be careful with .get() and .release() with auto-pointers. The former acquires the raw pointer inside the auto-pointer, but the auto-pointer is still managing its memory. The latter releases the raw pointer from the auto-pointer, which can result (and definitely is resulting, in your example) in a memory leak.


RE: Placing art in customArt viewable art - Rick Johnson - 01-31-2019

Thanks, Garrett. It took some tinkering, but I found some interesting nuances with the viewable art that weren't there when I last used pluginArt with the SDK about 15 years ago.

- hdi::core::draw can't create art there.
- hdi::core::Art::reorder() can't move art there.
- art can only be duplicated there or built from scratch.

No additional grouping is needed.

I hope this approach to coercing an auto_ptr to plain pointer is correct for creating art there:

Code:
hdi::core::Art newArt = hdi::core::Art(hdi::core::ArtTypePath, hdi::core::PlaceInsideOnTop,custObj.customArt()->viewableArt().get());

Now that I can create the art, it's time to delve into the message data to respond appropriately when the art is moved or modified. It helps that each of the 11 or so customArt message types can register its own callback with the Dispatcher. hdi::core:Big Grinispatcher::lastMessage() returns a message pointer, but how can I obtain a CustomArtMessage to get the relevant customArt() pointer?


RE: Placing art in customArt viewable art - garrett - 02-03-2019

Yeah, your usage of the auto-pointer is right, but this is a smidge shorter:

Code:
hdi::core::Art newArt(hdi::core::ArtTypePath, hdi::core::PlaceInsideOnTop, custObj.customArt()->viewableArt().get());

Cast the Message pointer returned by hdi::core:Big Grinispatcher::lastMessage() to a CustomArtMessage pointer; just make sure you're doing so from within a callback registered as the handler for a custom art message type.