Mail Archives: djgpp/1992/09/07/13:41:51
I am running into one really annoying problem with the graphics library
concerning Blit()s and subregions. Specifically, if the X starting address
of the destination for the Blit() is negative, instead of clipping the left
part of ths source object and bltting the area on the right that would be
valid, the operation isn't done - nothing is drawn. But if the rightmost
coordinate of the source region is greater than the extent of the destination
region, the right part is clipped and the remaining subregion on the left is
drawn. This is quite an annoying problem, because what it ends up doing is
making clipping inconsistent between left-side and right-side clipping (left
doesn't draw the object at all, right clips and draws). I've looked through
the source for the Blit routine, and to be quite honest, the code is impossible
for me to follow, much less make a non-kludge fix in. The following code
demonstrates the problem - compile with "gcc foo.cc -o foo -lgr":
-----< foo.cc >----------------------------------------------------------------
#include <stdio.h>
#include <graphics.h>
#include <mouse.h>
#include <stdlib.h>
int main(void)
{
short golds[32];
int xbs, ybs;
GrSetMode(GR_width_height_graphics, 800, 600);
for (int bar = 0; bar < 16; bar++)
golds[bar] = GrAllocColor(6 * bar + 120, 6 * bar + 120, bar);
for (bar = 0; bar < 16; bar++)
golds[16 + bar] = GrAllocColor(6 * (16 - bar) + 120, 6 * (16 - bar) + 120, bar);
GrRegion *screen = GrScreenRegion();
for (bar = 0; bar < 32; bar++) {
screen->VLine(bar, bar, 600, golds[bar]);
screen->VLine(704 - bar, bar, 600, golds[bar]);
screen->HLine(bar, 704 - bar, bar, golds[bar]);
}
GrRegion *playfield = screen->SubRegion(32, 32, 640, 480);
GrRegion drawpaddle(50, 10), erasepaddle(50, 10);
erasepaddle.Box(0, 0, 50, 10, GrBlack());
drawpaddle.Rectangle(0, 0, 49, 9, GrAllocColor(150, 150, 150));
drawpaddle.Rectangle(1, 1, 48, 8, GrAllocColor(200, 200, 200));
drawpaddle.Box(2, 2, 47, 7, GrAllocColor(250, 250, 250));
char muf[100];
sprintf(muf, "Res: %d x %d", screen->MaxX() + 1, screen->MaxY() + 1);
screen->Text(100, 100, muf, golds[15]);
MouseEvent baz; int paddlepos = 295;
while(1) {
MouseGetEvent(M_MOTION | M_BUTTON_DOWN, &baz);
if (baz.flags & M_BUTTON_DOWN) {
GrSetMode(GR_default_text);
exit(1);
}
Blit(&erasepaddle, playfield, paddlepos, 469, BlitSrc);
Blit(&drawpaddle, playfield, baz.x, 469, BlitSrc);
paddlepos = baz.x;
}
}
-----------------------------------------------------------------------------
-Craig
- Raw text -