Jump to content
  • Advertisement
Sign in to follow this  

[.net] [GDI+] Translating a Region

This topic is 2938 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In the following code:
Point[] vertices = { Point(50, 100), new Point(100, 50), new Point(150, 100) };
GraphicsPath path = new GraphicsPath();
path.AddPolygon(vertices);
region = new Region(path);
Graphics g = CreateGraphics();

region.Translate(10, 0);
int x1 = (int)region.GetBounds(g).X;
//region = region.Clone();
region.Translate(20, 0);
int x2 = (int)region.GetBounds(g).X;

x1 is 60, and I would expect x2 to be 80. However, it's only 80 if I uncomment the call to Clone(). Otherwise it's 60, as if the second call to Translate() has no effect. EDIT: If I comment out the line that assigns x1, then x2 is 80 whether I call Clone() or not. It's as if calling GetBounds() somehow "fixes" the bounds so that you can't modify them anymore? Any idea what's causing this? Thanks in advance. [Edited by - Gage64 on May 3, 2010 1:26:38 PM]

Share this post


Link to post
Share on other sites
Advertisement

Try adding a GetHRGN call followed by a GetRgnBox call. With that you can get the GDI region's equivalent RECT and you may see (as I did) that RECT.left is 61 for your first call and RECT.left is 81 for the second call.

But the docs say that "The rectangle returned by Region::GetBounds is not always the smallest possible rectangle."

So technically, all it has to do is return any rect that contains the region in order to be considered functioning properly. :)

Share this post


Link to post
Share on other sites
Thanks, I'll give it a try.

But I still don't understand why the first call to GetBounds() affects the second call, and why cloning the region changes this behavior.

Share this post


Link to post
Share on other sites
I did a bit more investigating. It's Translate that's buggy, not GetBounds. If you use a Matrix with Region's Transform, it works as expected.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!