Simple graphic app dosble?

I recall the object2d rotate function has been enhanced recently…

“Can a simple graphic app perform well written in Xojo? ”

Without any doubt, and it can definitely do very well on way more complex graphics apps too.

My next problems are more like how to store the graphic objects as it could be an image, a rectangle/line/circle or text.

Maybe define a custom class with properties like position, rotation, scaling and so on…and the graphic object itself as Variant?

Also when I rotate an object how to check when I clicked if it should be activated…

But so far having really fun (o;

Hi,

You don’t need a custom class - the Object2D class does all this and much more. You build up an array of objects as you add them to an image or load from a file or whatever. Object2D is the base class and you add your objects as different shapes from the Object2D subclasses (arcs, lines, pictures, rectangles, ovals etc). You control the order in which they’re drawn and thereby the layering and transparency effects.

To check which object is activated / needs to be activated - you have the Contains method. When you click, pass the mouse X Y position and select the frontmost object that contains the passed X Y.

Regards - Richard.

hello,
simple representation on canvas with Pixmapshape
container-Canvas-Paint.xojo_binary_project.zip (20.3 KB)

Object2D seems to be the right way to go (o;

Really kuul :slight_smile:

This is odd…

When I drop an image into the Canvas I use the obj.DropLeft/obj.DropTop to position it.
But DropTop/DropLeft is lower than the actual mouse position where I released the mouse.

DropLeft As Integer
Distance from the left side of the control where the object was dropped.

So when I drop it at Canvas location 149,152, DropLeft is 75 and DropTop is 142.

Any ideas?

Even more odd…

obj.DropWidth and obj.DropHeight are always 16, regardless of the picture size being dropped.

Okay…when I iterate through my Object2D in Objects() inside Canvas paint event, all is fine…

But when I want to check in the MouseDown event, if it was clicked in an object with:

For Each o As Object2D in Objects
  If o.Contains(x, y) Then
    TextArea1.AddText("Clicked in Object " + Str(index) + EndOfLine)
  End If
  index = index + 1
Next

It gives me:

This method extends type String, but the base expression is class Object2D.
If o.Contains(x, y) Then

So I can’t just use one Object2D array and fill it with all sorts of Object2D subclasses as only subclasses have the Contains method?

PS: I grew up with vacuum tubes, Z80 assembler and Forth (o;

control your object 2D in your own object list
larger example for testing
B-Demo-paint2024.xojo_binary_project.zip (1.4 MB)

How do you get the Mouse Position ?

After dropping the image I click again in the canvas at the same position :wink:

There are many ways to get that value… What code did you use ?

Report the Mouse position from DesktopCanvas1.DragOver Event into a Label somewhere (window’s bottom for debug)…

Seems in the past there was already a bug with DropLeft and DropTop…and was marked as resolved…

But using the MouseOver event and store X/Y in a property seems the best idea (o;

Currently more struggling with Object2D, its subclasses and Group2D…guess I have to make a new thread for it as the question regarding performance has been answered a time ago (o;

No, you can still keep them in an array of Object2D, but as the Contains method belongs to Object2D subclasses (or some of them), you need to check it’s appropriate with IsA and then cast.

For the subclasses that don’t have the Contains method (CurveShape, FigureShape and TextShape) - you’ll need to create your own method to deal with selecting them if you want this functionality. There’s been discussions about this before on the forum and there’s different options - setting a rectangular min/max bounds for your object; painting a polygon to a picture and testing whether your click is on a painted pixel; testing how close you are to a line segment of a CurveShape to decide whether you would be sufficiently close to select that line - those sort of things. A rectangular bounds is trivial to do, but may not be that satisfactory; the other two approaches are a bit more involved.

Regards - Richard.

I see (o;

The easier the UI should be for the end user, the more complicated it gets for the developer :wink:

How was the saying?

A good user interface is like a joke. If you have to explain it, it’s not good (o;