Win32: client edge exclusions

Started by
6 comments, last by xllx_relient_xllx 18 years, 9 months ago
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.
Advertisement
You're right. The coordinates fall between pixels. I always thought it'd make more sense if they were in the middle of pixels.
Simple reason, try to, say, double the size of your rect:

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

before:left:    0top:     0right:  49bottom: 49after:left:    0top:     0right:  98bottom: 98



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

before:left:    0top:     0right:  50bottom: 50after:left:     0top:      0right:  100bottom: 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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Why are RECTs endpoint-exclusive?
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.
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++)

?


;)
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

just replying to say I got it now[attention] ...

Thanks alot guys,
relient.

This topic is closed to new replies.

Advertisement