Object2D, its subclasses and Group2D

Good evening (o;

Currently experimenting with Object2D and its family classes…

From previous answers in another thread people use separate Arrays to hold the different subclasses of Object2D like PixmapShape, RectShape, TextShape and so on.

Is this really the way to go?

Also for example when I add several PixmapShapes in a Group2D and want to iterate through, I only get Object2D back. So no way to get to the specific Methods/Properties of the PixmapShape stored in that group.

A class based object oriented drawing system is the way to go. I am not sure what others have recommended. You could use the Object2D stuff to execute the drawing, but what you really want is classes that can draw themselves. You can then design your document abstract from whatever ends up drawing it, and send the same document to screen, print, or PDF all with the same code.

You can test to see if an instance is of a class type and then cast it.

if theObject isa PixmapShape then
  var oCast as PixmapShape = PixmapShape(theObject)
  // You can now use oCast and the properties + methods it has that are unique

end

Why is there no “Pro” after your name? :slight_smile:

Heh, that title just relates to whether you have an active $799 license or not.
I do actually consult on Xojo projects professionally.

3 Likes

Group2D is great to add the rectangles around an image:

Now onto detect MouseDown at the smaller outer rectangles and do the scaling…

1 Like

And, I can personally attest to Tims skill!