Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!snorkelwacker.mit.edu!bloom-beacon!dont-send-mail-to-path-lines From: mouse@lightning.mcrcim.mcgill.EDU Newsgroups: comp.windows.x Subject: Re: XDrawRectangle w/ negative width/height? Message-ID: <9102071335.AA10848@lightning.McRCIM.McGill.EDU> Date: 7 Feb 91 13:35:57 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 48 > So, the question is: can you specify a negative width or height for > a rectangle with no unexpected side effects, and, if that is legal, > are there any known bugs when doing this? At the protocol level, XDrawRectangle turns into a PolyRectangle request. The width and height for the rectangles in a PolyRectangle requests are CARD16, which is an unsigned type. Therefore, you definitely are not going to get what you seem to be expecting. The Xlib document describes the width and height arguments to XDrawRectangle as "unsigned int", which perhaps should tell you something :-) Just what you *will* get depends on your Xlib, your compiler, and your machine: when you pass negative width and/or height values to XDrawRectangle, what does it generate in the transmitted request? I would guess that the most common thing is for it to blindly take the low-order 16 bits, which usually means that negative numbers turn into very large numbers (eg, -100 becomes 65436). As far as I can see, it's your responsibility to make sure that the width and height are always positive by interchanging values when necessary. It doesn't even take much code: MyDrawRectangle(disp,d,gc,x,y,w,h) Display *disp; Drawable d; GC gc; int x; int y; int w; int h; { if (w < 0) { x += w; w = - w; } if (h < 0) { y += h; h = - h; } XDrawRectangle(disp,d,gc,x,y,(unsigned int)w,(unsigned int)h); } der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu