114 lines
1.8 KiB
C
114 lines
1.8 KiB
C
|
#include "wintype.h"
|
||
|
#include "fbinit.h"
|
||
|
|
||
|
inline static PUINT16 loc_from_coords(INT32 x, INT32 y)
|
||
|
{
|
||
|
return Fb_Ptr + (y * Fb_Info->width) + x;
|
||
|
}
|
||
|
|
||
|
UINT16 Fb_setpixel(INT32 x, INT32 y, UINT16 color, BOOL xor)
|
||
|
{
|
||
|
UINT16 rc;
|
||
|
PUINT16 loc = loc_from_coords(x, y);
|
||
|
|
||
|
rc = *loc;
|
||
|
if (xor)
|
||
|
*loc ^= color;
|
||
|
else
|
||
|
*loc = color;
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
|
void Fb_line(INT32 x1, INT32 y1, INT32 x2, INT32 y2, UINT16 color, BOOL xor)
|
||
|
{
|
||
|
INT32 tmp;
|
||
|
INT32 dx = x2 - x1;
|
||
|
INT32 dy = y2 - y1;
|
||
|
|
||
|
if (ABS(dx) < ABS(dy))
|
||
|
{
|
||
|
if (y1 > y2)
|
||
|
{
|
||
|
tmp = x1;
|
||
|
x1 = x2;
|
||
|
x2 = tmp;
|
||
|
tmp = y1;
|
||
|
y1 = y2;
|
||
|
y2 = tmp;
|
||
|
dx = -dx;
|
||
|
dy = -dy;
|
||
|
}
|
||
|
x1 <<= 16;
|
||
|
dx = (dx << 16) / dy;
|
||
|
while (y1 <= y2)
|
||
|
{
|
||
|
Fb_setpixel(x1 >> 16, y1, color, xor);
|
||
|
x1 += dx;
|
||
|
y1++;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (x1 > x2)
|
||
|
{
|
||
|
tmp = x1;
|
||
|
x1 = x2;
|
||
|
x2 = tmp;
|
||
|
tmp = y1;
|
||
|
y1 = y2;
|
||
|
y2 = tmp;
|
||
|
dx = -dx;
|
||
|
dy = -dy;
|
||
|
}
|
||
|
y1 <<= 16;
|
||
|
dy = dx ? (dy << 16) / dx : 0;
|
||
|
while (x1 <= x2)
|
||
|
{
|
||
|
Fb_setpixel(x1, y1 >> 16, color, xor);
|
||
|
y1 += dy;
|
||
|
x1++;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Fb_rectangle(INT32 x1, INT32 y1, INT32 x2, INT32 y2, UINT16 color, BOOL xor)
|
||
|
{
|
||
|
FB_line(x1, y1, x2, y1, color, xor);
|
||
|
FB_line(x2, y1 + 1, x2, y2 - 1, color, xor);
|
||
|
FB_line(x1, y2, x2, y2, color, xor);
|
||
|
FB_line(x1, y1 + 1, x1, y2 - 1, color, xor);
|
||
|
}
|
||
|
|
||
|
void Fb_filled_rectangle(INT32 x1, INT32 y1, INT32 x2, INT32 y2, UINT16 color, BOOL xor)
|
||
|
{
|
||
|
INT32 tmp;
|
||
|
PUINT16 ps, p;
|
||
|
|
||
|
if (x1 > x2)
|
||
|
{
|
||
|
tmp = x1;
|
||
|
x1 = x2;
|
||
|
x2 = tmp;
|
||
|
}
|
||
|
if (y1 > y2)
|
||
|
{
|
||
|
tmp = y1;
|
||
|
y1 = y2;
|
||
|
y2 = tmp;
|
||
|
}
|
||
|
|
||
|
ps = loc_from_coords(x1, y1);
|
||
|
for (; y1 <= y2; y1++)
|
||
|
{
|
||
|
p = ps;
|
||
|
for (tmp = x1; tmp <= x2; tmp++)
|
||
|
{
|
||
|
if (xor)
|
||
|
*p++ ^= color;
|
||
|
else
|
||
|
*p++ = color;
|
||
|
}
|
||
|
ps += Fb_Info->width;
|
||
|
}
|
||
|
}
|