How to draw a GraphicsPath with offsets?

Hi,

I need to draw a GraphicsPath (a polygon made with several appended lines), and the view may be scrolled (in other words, the polygon may be drawn at a different location).

My first attempt was to try with GraphicsPath.MoveToPoint OffsetX,OffsetY, but that doesn’t have any effect. I also tried GraphicsPath.Bounds.Offset OffsetX,OffsetY with the same result.
Since there doesn’t appear to have a way to retrieve the path’s components, I can’t loop thru them to change their location either. It looks like the only way is to re-create the shape every single time the user scrolls, which doesn’t sound practical to me.

Am I missing an existing solution?

Array point

examble Test

graphicspath-DX-Points-test-6.xojo_binary_project.zip (30.3 KB)

1 Like

Thanks for your reply.
So, in effect, you’re reconstructing the path each time something changes (which I mentioned as “not practical” in my original question, but perhaps my words were poorly chosen; I meant it looks weird to rebuild the path each time).

No way to move an existing path?

.Translate ?

If this method existed, it’d be the answer I’m looking for.
Thanks anyway.

He means Graphics.Translate. This lets you move all drawing, not just a single path.

2 Likes

https://documentation.xojo.com/api/graphics/graphics.html#graphics-translate

see also .savestate and .restorestate

.DrawObject could also be useful
https://documentation.xojo.com/api/graphics/graphics.html#graphics-drawobject

Graphics.Translate did the trick; thanks Markus!
Yet another language feature that even long-time users may not notice since introduced :sweat_smile:

2 Likes

hello arnaud
I can’t use graphics.translate properly in my desktop program
can you please show your programming code
enclosed is my test program

erstellelinienpath-test.xojo_binary_project.zip (35.1 KB)