Sign in to follow this  
xllx_relient_xllx

Win32: client edge exclusions

Recommended Posts

Hi, I'm trying to figure out something but I need some help. What I'm trying to figure out is: Why does the 7 Windows functions for drawing filled areas with (Rectangle, Ellipse, RoundRect, Chord, Pie, Polygon, PolyPolygon., including; FillRect, ExcludeRect etc..), exclude the right and bottom edges? Example: Horizontal Client Width: 50 Vertical Client Height: 100 GetClientRect(hwnd, &rect); FillRect(hdc, &rect, GetStockObject(WHITE_BRUSH)); rect.right would be 50 and rect.bottom would be 100, but since FillRect does not include the right and bottom edges/sides, they would actually be 49, 99 respectively. Therefore, the client area's right, and bottom edges would not get Erased (by one pixel) with the WHITE_BRUSH. This all makes sense until I actually try it out and it turns out that the right and bottom edges does get erased. This is contrary to what I thought would happen, because of the right and bottom edge exclusions. Why is this so?... One theory that I came up with is that; Client coordinates as we all know, start at 0 (top colum), 0 (top row), like arrays, and, FillRect or any other abovementioned function to actually include the right and bottom edges for filling would go beyond the windows client borders because 50 would become 51 and 100 would become 101 because, 0 through 50 = 51, 0 through 100 = 101 respectively. And so that's why FillRect excludes the right and bottom sides. But I think I'm wrong, of course [embarrass] This might seem like it's unnecessary to know, but, I'm that kinda person that likes to know all the In's and Out's so I would really be greatful if someone could explain to me why this is happening. relient.

Share this post


Link to post
Share on other sites
Deyja    920
You're right. The coordinates fall between pixels. I always thought it'd make more sense if they were in the middle of pixels.

Share this post


Link to post
Share on other sites
Endurion    5412
Simple reason, try to, say, double the size of your rect:

if the GDI function used the exact coordinates (called inclusive/inclusive):


before:

left: 0
top: 0
right: 49
bottom: 49

after:

left: 0
top: 0
right: 98
bottom: 98



GDI functions how they work now (called inclusive/exclusive):


before:

left: 0
top: 0
right: 50
bottom: 50

after:

left: 0
top: 0
right: 100
bottom: 100


Whoopsie, if the coordinates would be exact you suddenly loose a pixel after you recalculated the size. In the second case you don't.

Share this post


Link to post
Share on other sites
Sorry but I still don't get it.

Endurion, I'm confused as to how I would loose 1 pixel in your example.

49 after doubleing (49 + 49) is 98, I don't see what's wrong with that, to me the result looks correct, which number is the lost pixel?

Thanks for that link Invader X. Very good read, I understood some of it; but it only added more confusion.

I'm just not see'ing it guys, sorry.

relient.

Share this post


Link to post
Share on other sites
JY    289
When Microsoft were programming GDI their for loop read:

for (x = left; x < right; x++)

when they should have put

for (x = left; x <= right; x++)

?


;)

Share this post


Link to post
Share on other sites
Endurion    5412
Quote:
Original post by xllx_relient_xllx
Sorry but I still don't get it.

Endurion, I'm confused as to how I would loose 1 pixel in your example.

49 after doubleing (49 + 49) is 98, I don't see what's wrong with that, to me the result looks correct, which number is the lost pixel?

Thanks for that link Invader X. Very good read, I understood some of it; but it only added more confusion.

I'm just not see'ing it guys, sorry.

relient.


Suddenly pixel 99 is gone.
You wanted to double the size of the rect, in GDI the doubled width will be 100. If the right would be 49, the doubled size would amount to 98.

So you got from 49 - 0 + 1 (we started with 50 pixel width) to 98 - 0 + 1, which amounts to 99.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this