1. RE: Win32Lib: drawRectangle question

Brendon,

AFAIK, that's the way it's always been.  I remember bringing it to David 
Cuny's attention way back when but I don't remember what he said about 
it.  I think that's just the way Windows does it...

-- Brian


Brendon Sly wrote:
> Hi All,
> 
> While messing with something last night I found an interesting effect 
> with drawRectangle. If I drew a rectangle (filled or not) then plotted 
> the corner points, it wouldn't match up.
> 
> I've attached the smallest piece of code that will show you what I'm on 
> about.
> 
> The top-left dark point is on the yellow rectangle but the other three 
> are outside it. I've tried this on my home machine (Win98) and work 
> (Win2000) and get the same result.
> I can deal with using 'drawRectangle(A, B, x1, y1, x2+1, y2+1)' but I'm 
> just wondering if that's the way it's supposed to be or have I missed 
> something in the win32lib docs.
> 
> Oh yeah, last thing. I'm using win32lib v0.55.1.
> 
> Thanks.
> 
> 
> Brendon   :|
> 
> --
> 
> include Win32Lib.ew
> without warning
> 
> global constant MyWin = create( Window, "MyWin", 0, Default, Default, 
> 300, 300, 0)
> setWindowBackColor( MyWin, White )
> 
> procedure MyWin_onPaint ( int x1, int y1, int x2, int y2 )
>  setPenColor(MyWin, Yellow)
>  drawRectangle(MyWin, True, 10, 10, 100, 100)
>  setPixel(MyWin, 10, 10, Black)
>  setPixel(MyWin, 10, 100, Black) 
>  setPixel(MyWin, 100, 10, Black) 
>  setPixel(MyWin, 100, 100, Black) 
> end procedure
> 
> onPaint[MyWin] = routine_id("MyWin_onPaint")
> 
> WinMain( MyWin, Normal )
> 
> 
>

new topic     » topic index » view message » categorize

2. RE: Win32Lib: drawRectangle question

>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<

> Unfortunately, that's how the Windows GDI call is supposed to work.=20=

There's
> some sort of logic to it, but the end result is still rather
> counter-intuitive.

> AFAIK, that's the way it's always been.  I remember bringing it to Dav=
id
> Cuny's attention way back when but I don't remember what he said about=

> it.  I think that's just the way Windows does it...

Thanks David and Brian,

Now I know it behaves that way, I can deal with it. It sure beats going =

over half a dozen or so lines of code 8 or 9 times trying to figure out =

why the boxes and lines don't match.
smile


Brendon   :|

new topic     » goto parent     » topic index » view message » categorize

3. RE: Win32Lib: drawRectangle question

Hi Brendon,
> -----Original Message-----
> From: Brendon Sly [mailto:bwsly at infoscience.otago.ac.nz]
> Sent: Wednesday, 9 May 2001 7:52 AM
> To: EUforum
> Subject: Win32Lib: drawRectangle question

> If I drew a rectangle (filled or not) then plotted the
> corner points, it wouldn't match up.


Here are the Microsoft docs. Take note of the "Remarks" section.
---------------
Rectangle
The Rectangle function draws a rectangle. The rectangle is outlined by using
the current pen and filled by using the current brush.

BOOL Rectangle(
  HDC hdc,         // handle to DC
  int nLeftRect,   // x-coord of upper-left corner of rectangle
  int nTopRect,    // y-coord of upper-left corner of rectangle
  int nRightRect,  // x-coord of lower-right corner of rectangle
  int nBottomRect  // y-coord of lower-right corner of rectangle
);

-------------
Parameters
-------------
hdc
[in] Handle to the device context.

nLeftRect
[in] Specifies the logical x-coordinate of the upper-left corner of the
rectangle.

nTopRect
[in] Specifies the logical y-coordinate of the upper-left corner of the
rectangle.

nRightRect
[in] Specifies the logical x-coordinate of the lower-right corner of the
rectangle.

nBottomRect
[in] Specifies the logical y-coordinate of the lower-right corner of the
rectangle.

-------------
Return Values
-------------
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

Windows NT/ 2000: To get extended error information, call GetLastError.

-------------
Remarks
-------------
The current position is neither used nor updated by Rectangle.

The rectangle that is drawn excludes the bottom and right edges.

If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less
in height and 1 pixel less in width.

---------------------
As Win32lib uses this GDI function to draw rectangles, it means that the
right and bottom edges are not drawn. This is not intuitive but I'm sure
uncle Bill has a VERY GOOD reason for confusing us all blink My guess is that
it was a bug, but to fix it would break so much code they decided to
document it instead.

-----------
cheers,
Derek Parnell

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu