drawing in xor mode

When programming the mac (QuickDraw) in Pascal and later in C C++ (last century),
I have done a mini CAD that allowed me to draw a line in XOR mode like a rubber band.
There is no xor mode with Xojo. I’ve heard about double buffering but I have no idea how to handle that.
Documentation tells that it is for Windows because the mac already do it natively.
Could you show me a direction to search for a solution?
Thank you

there is no “XOR” draw mode
however what I do (for a “cad” like program)

Draw the MAIN graphic data to an external picture object
then in the Canvas PAINT event

g.drawpicture myPICTURE,0,0
g.drawrect mx,my,(mx1-mx),(my1-my)
return true

The old way was to draw in XOR mode so you didn’t destroy the image underneath the “live” object such as a line being dragged by the mouse. The modern equivalent is to draw 2 separate objects. Hold the “background” as a single image. Draw it first, then draw the “live” object on top of it. It is very fast and does not flicker, even on Windows (just make sure you turn EraseBackground off on everything).

Double buffering basically means your drawing commands are performed invisibly first and once they’re done they are made visible. This is to avoid flicker.

If you want to draw a temporary object like your xor lines I would recommend drawing the stationary things into a picture, then in your canvas’ draw event use Graphics.Drawpicture to show this and add the line(s) directly to the canvas’ graphics. When they are confirmed, add them to your picture.

BTW, which platform are you developing for? For macOS, there are easy means (read this: Declares or use of plugins/libraries incorporating them) to add all kinds of drawing modes the graphics object features natively.

I can relate to your XOR experience! That type of drawing is done very differently in Xojo.

In Xojo, everything is based upon events, so all drawing takes place in the Paint event. So all you do is just draw the line you want. Don’t worry about erasing it. That will happen automatically. If you’re doing animation, you may need to use a Timer to periodically call Refresh on the object (canvas, window, etc.) you want redrawn.

For example, say you’re making a drawing program. The user has drawn several items (square, triangle, etc.). In your Paint event you’d loop through your data structure of drawn elements and draw each one each time the Paint event is called. If the user moves an item, it just gets drawn at the updated location. When the Canvas is refreshed, the element is drawn at the new location – from the user’s perspective it has moved.

So in many ways, this is much easier than in the past. You don’t have to worry about erasing anything. If whatever you are drawing changes, just call Refresh so that the Paint event gets called and the new data is drawn.

fiew… lot of information! Thank you all. I will explore that.
@Ulrich Bogun I am retired and i’m writing a “GIS for dummies” like book. It’s even not a book, just a PDF document and will be available for free. The source code and the data structure will also be available.
my experience was with MapInfo and Oracle Spatial.
Thanks again

Ok, I have understood the principle
it’s working for me now
And it’s very fast!
I have to adapt it to my needs
many thanks to all