PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

DrawRect problem?

It seems that DrawRect() renders a rectangle 1 pixel smaller in both directions than it should.
If you copy and paste the following code in the Minimal application you will see the phenomenon immediately. The red line and the white pixel appear under the rectangle however they should overlap it. I don't know if it is my problem of understanding the RECT structure or it is really a bug. Please advise.

Code:

RECT rect;
::SetRect(&rect, 30,30,100,100);
backbuffer.DrawRect(&rect, RGB(255,0,0), 0,0);
backbuffer.DrawLine(0,100,100,100,RGB(255,255,0),0,0);
backbuffer.SetPixel(100,100,RGB(255,255,255));
OK, probably the previous example sucked so here's another one. One red rectangle and two white pixels in the topleft and the bottomright corner. The latter one is a bit shifted...

Code:
RECT rect;
::SetRect(&rect, 30,30,100,100);

backbuffer.DrawRect(&rect, RGB(255,0,0), 0,0);
backbuffer.SetPixel(rect.left,rect.top,RGB(255,255,255));
backbuffer.SetPixel(rect.right,rect.bottom,RGB(255,255,255));
It works as it should. The doc says that all rectangles used in gapidraw are exlusive, that is the width of the rectangle is (x2 - x1). So if you draw a rectangle from x=0 to x=100, pixels will be set from x=0 to x=99 (100 pixels). This is for DirectDraw compatibility... It's also easier to use in most cases (e.g. RECT(0, 0, GetWidth(), GetHeight()) would not work otherwise)..
Thanks it makes lot of sense. Sorry for this post.