Move Oval on Canvas; Restrict Invalidate Area?

I have a canvas on which there are many Object2D things scattered about. All of these things are sitting in a Group2D class. The paint event of the canvas draws all these multiple objects.

The user can select an object like an OvalShape and select it by clicking on it in the MouseDown event. And moving it around in the MouseDrag event. This effect is created by removing the OvalShape from the Group2D and then adding it back with the changed positional parameters (X, Y)

I then call an Invalidate() and all the objects get redrawn including the Oval in its new position.

Would there be any reason to restrict the area of invalidation? By putting some parameters in the Invalidate()? You could specify the area of the canvas that was “dirty” and needed redrawing.

Is there any reason to think this would be faster in the context of a bunch of Obeject2D’s on a canvas? Or is this just something I should just never think about or bother with.?

Perhaps restricting the area of invalidation only makes sense if you are moving something around over a pixel picture.

at least check if mouse got a new position.
i stored the last pos as point in property.

I do that. I figure out what the delta is between the last position and the current position and remove the old Object2D Oval and replace it with a new Oval with the new location parameters.

But then I call Invalidate() and presumably all the objects on the canvas get redrawn even though only one has changed. It works just fine. But…

I wondered if this was was “inefficient” and I should consider putting parameters in the Invalidate() command to restrict the area that is considered “dirty”. Perhaps then Xojo would not have to bother redrawing all the objects which were positioned out of the “dirty” area.

you could use clip but i remember it have a own offset of 0,0 left top.
.Clip
canvas seems to have a second invalidate

.Invalidate(X As Integer, Y As Integer, Width As Integer, Height As Integer [,EraseBackground As Boolean]) 

RectControl.Invalidate

i would only do this if the redraw for all are to slow.

What about the use of an Offscreen Picture where you draw everything and apply the new contents into the Canvas ?

Currently, in my app, it is not to slow. I just wondered that if the number of Object2Ds increased whether it might become a problem and if it became a problem would

.Invalidate(X As Integer, Y As Integer, Width As Integer, Height As Integer [,EraseBackground As Boolean])

help or have no impact.

you could just add some random shapes with a loop to your group to see when it gets slow and test it
with a low end laptop.

you could invalidate the rect where the oval was and then whatever rects it transitions through as its dragged an then the final one when its released

that could reduce the amount needing a complete redraw

Markus: Testing would be an ultimate answer but I am lazy and was trying to avoid that if there was an obvious answer out there. :slight_smile: For example, somebody in the know might tell you that the Invalidate “limited area” does not have any effect on the drawing of Object2D’s. I just do not know if that is true or not. It is an implementation detail.

It would take some effort for Xojo to “figure out” whether some Object2D encroached on some Invalidate area. It might be more efficient to just go ahead and redraw the Object2D regardless.

Experience suggests that it doesnt save you that much Robert