Group2D objects - could we have some events?

To-date I’ve been doing graphics in my apps as bitmaps. Just looking into using Xojo’s vector graphics… in particular arcShape, ovalShape, rectShape, textShape etc I note there are no events for these. Which means that to handle mouseWithin, key clicks and mouseClicks it’s necessary to maintain an array or dictionary of them, and search to see if an event is within one of the objects to implement cut/copy/paste, clicks and double-clicks, selections and so-on.

But … if we have to do this for basically every event supported in a canvas, it basically negates any point in the Group2D object as it appears I have to do the lot in code, with a custom canvas class, anyway since these objects don’t know where they’re drawn (ie have no topleft coordinates, just a width and height).

IMHO there would be a lot of point in an individual graphic object being able to issue a few basic events.

Does anyone else think it would be nice if, in some future version of Xojo, these classes implemented at a few events for these objects, such as mouseWithin, mouseDown and keyDown ?

That makes no sens at all. An Object2D just stores the params of the thing you want to draw. It is just like any variable used as param in a bitmap drawing. Once drawn, the Object has no meaning or relationship to the graphics or the canvas.

1 Like

If that were true Xojos 2D objects would not support rotation or scaling, but they do.

I made my own class of objects with properties for position (x,y), width and height, scale, rotation plus the object2D as a property AND a set of event definitions to handle selection, grouping, reordering front/back, expanded (or not) and so-on. In effect this is what imho the 2D objects should have been.

I then have a canvas with an array of these and draw the lot to the canvas, the group2D thing seems utterly pointless as I handle the scale and rotation directly in the canvas.

The computed properties rotation and scaling just transform the other computed properties like X, Y, etc. Not a big mistery there.

Does anyone else think it would be nice

I do, but I doubt Xojo do.

at least a new InputShape would be nice, Reactangle, Circle with a Line preview.

In my opinion, that goes beyond what Xojo should do. What they do is give you the building blocks to create something like this. I think you should sell it as a third party component.

1 Like

Maybe…

Maybe not.

Just realised that the textShape objects do not have a width constraint at which the text wraps, or is truncated. Looks like its back to bitmap graphics, and scaling up 4X to print or for drawing to PDF.
I’ll make that a feature request.

Feel free to make a feature request.

That could be to ask the objects to have properties for the position and size they got drawn in, so you know the final position.
Then you could also fill a feature request for a Hit(x,y) function to check for whether mouse hits it.

Done.

Having built two object oriented drawing systems with visual mouse-based editing, I agree with Ivan. Mouse tracking is not a drawing feature and you *really* need to separate the two in your code.

Build classes that draw your objects. Then, build classes to let a canvas edit the drawing classes. Otherwise you’re creating a huge tangled mess.

2 Likes

OK… it’s time this project switched to another environment that can do all the graphics stuff, if I have to do it all in code from the ground up. Xojo is OK for a prototype but can’t build the final thing.

Hello
I’ve been drawing / changing my pictures with pixmap shapes for a long time, of course I have to set and draw the individual objects manually with some programming effort. I can easily create the Pixmapobjects from any image template. They can be rotated, scaled, graphically changed and displayed transparently.
I save all pixmap shapes in a SQL database as a blob and
all parameters like position, angle, scale, view plane and more as well. So I have all the values that are not normally found in the objects.
Since my large images are displayed under zoom and scroll values and the PixmapShapes have to be displayed in a different size, I use 2 view levels for the image background, drawing area of the shapes that are displayed in canvas.backdrop as a resting level.
All operative drawing functions in the canvas are represented in Paint above it. My old iMac from 2014 is fast enough for this, only in full format on the 27 inch does it falter a bit.
Even if it is a bit of an effort to do a lot manually
it’s good brain training not to get rusty and for better ones
hoping for plagues.

OK… something I had missed was the graphics.clip, .clipToPath and .clipToRectangle methods.

So… to truncate text (or anything else) it has to be drawn within the clip region. i.e. ultimately for a complex drawing everything including vector graphics has to be drawn as bitmaps, it cannot be treated as purely vector graphics only as there is no bounding box (width, height) for Object2D things.

So it can draw rotated text, and it can sort-of truncate it using the .clip trick, but that’s going to be very ugly for text on random angles.

But it still cannot wrap vector text within a defined width in the same way that graphics.drawText does.

It implies text that has to be confined to a bounding box, and rotated really has to be drawn as a bitmap using graphics.drawText, then that bitmap rotated and drawn at the desired rotation. I’ve been there before and the results are not pretty (since its bitmaps). And this means a scaled drawing is not going to be WYSIWYG.

As I suggested before, the Object2D classes really need width and height properties such that outside these nothing is drawn, and textShape also needs a wrap property

Rudolf, thousands of canvas objects in a window doesn’t work nicely…

Having used object2ds in the paste, I have always done single line text objects.

To be honest, I’m struggling to imagine a real-world use for a rotated paragraph of text.
Not to say you don’t need it, but I’m curious about the usage.

As a naive suggestion, you might create a pseudo wrapping method that compares your string width in a graphics context, works out when you run out of space, and splits the sentence into suitably sized chunks.

ie in a sentence like ‘This is a sentence that might wrap within the available space’
If This is a sentence that might wr fits in your boundaries but
This is a sentence that might wra does not, then you need to chop at
This is a sentence that might

One method is to work backwards to the previous space,
one is to assemble an array of words and add until the width is too great.

I am aware that the first response to that will be ‘why should I have to?’ … well, don’t shoot the messenger - just trying to think of something that avoids a lot of bitmaps.

Hi Jeff,

One usage I have seen during years is in music monthly magazines (for teens and +) either from UK and France in the 70s thru 80/90s…
They even published rotated photos (and not only 45°)…

NB: I never liked these, but they do that.