📄 hal_graphics.c
字号:
/**********************************************************************
; Function: SetPixel()
; Description: This routine writes a pixel.to display memory.
; Parameters:
; x - horizontal coordinate (0 = left of image)
; y - vertical cooridinate (0 = top of image)
; color - color of pixel
; For 1, 2, 4, and 8 bpp, color is an index into LUT.
; For 16 bpp, color is in RGB format.
; Returns: Nothing.
; Modifies: Display memory.
;**********************************************************************/
void SetPixel(long x, long y, unsigned long color)
{
if (gpfnPixel != NULL)
(*gpfnPixel)(x, y, color);
}
/**********************************************************************
; FUNCTION: DrawLine()
; DESCRIPTION: This routine writes a line.to display memory.
; Note that the last point (x2, y2) is written.
; PARAMETERS:
; x1 - horizontal coordinate of top left corner
; y1 - vertical cooridinate of top left corner
; x2 - horizontal coordinate of bottom right corner
; y2 - vertical cooridinate of bottom right corner
; color - color of pixel
; RETURNS: Nothing.
; MODIFIES: Display memory.
;**********************************************************************/
void DrawLine(long x1, long y1, long x2, long y2, unsigned long color)
{
long d, dx, dy;
long Aincr, Bincr, xincr, yincr;
long x, y;
if (gpfnPixel == NULL)
return;
if (x1 > x2)
{
x=x1;x1=x2;x2=x;
y=y1;y1=y2;y2=y;
}
dx = x2 - x1;
if (dx < 0)
dx = -dx;
dy = y2 - y1;
if (dy < 0)
dy = -dy;
if (dx > dy)
{
if (x1 > x2)
{
x=x1;x1=x2;x2=x;
y=y1;y1=y2;y2=y;
}
if (y2 > y1)
yincr = 1;
else
yincr = -1;
dx = x2 - x1;
dy = y2 - y1; /* dy = abs(y2 - y1); */
if (dy < 0)
dy = -dy;
d = 2 * dy - dx;
Aincr = 2 * (dy - dx);
Bincr = 2 * dy;
x = x1;
y = y1;
(*gpfnPixel)(x, y, color);
for (x = x1 + 1; x <= x2; ++x)
{
if (d >= 0)
{
y += yincr;
d += Aincr;
}
else
d += Bincr;
(*gpfnPixel)(x, y, color);
}
}
else
{
if (y1 > y2)
{
x=x1;x1=x2;x2=x;
y=y1;y1=y2;y2=y;
}
if (x2 > x1)
xincr = 1;
else
xincr = -1;
dy = y2 - y1;
dx = x2 - x1; /* dx = abs(x2 - x1); */
if (dx < 0)
dx = -dx;
d = 2 * dx - dy;
Aincr = 2 * (dx - dy);
Bincr = 2 * dx;
x = x1;
y = y1;
(*gpfnPixel)(x, y, color);
for (y = y1 + 1; y <= y2; ++y)
{
if (d >= 0)
{
x += xincr;
d += Aincr;
}
else
d += Bincr;
(*gpfnPixel)(x, y, color);
}
}
}
/**********************************************************************
; FUNCTION: DrawRect()
; DESCRIPTION: This routine writes a line.to display memory.
; PARAMETERS:
; x1 - horizontal coordinate of top left corner
; y1 - vertical cooridinate of top left corner
; width - width in pixels
; height - height in lines
; color - color of pixel
; SolidFill - SOLIDFILL_ON if rectangle is solid color
; SOLIDFILL_OFF if rectangle shows only border
; RETURNS:; Nothing.
; MODIFIES:; Display memory.
;**********************************************************************/
void DrawRect(long x1, long y1, long width, long height, unsigned long color, BOOL SolidFill)
{
long y;
long x2, y2;
if (gpfnLine == NULL)
return;
x2 = x1 + width - 1; // Set x2,y2 to be right/bottom INCLUSIVE coordinates
y2 = y1 + height - 1;
if (SolidFill == SOLIDFILL_ON)
{
for (y = y1; y <= y2; y++)
(*gpfnLine)(x1, y, x2, y, color);
}
else
{
(*gpfnLine)(x1, y1, x2, y1, color);
(*gpfnLine)(x1, y2, x2, y2, color);
(*gpfnLine)(x1, y1, x1, y2, color);
(*gpfnLine)(x2, y1, x2, y2, color);
}
}
/**********************************************************************
; Function: DrawText()
; Description:
; This routine draws colored text to display memory.
; If colorFG==colorBG, then text is drawn transparently.
; Text can be from 0x20 to 0x7F, and '\n' will work.
; Parameters:
; x - horizontal coordinate of top left corner
; y - vertical cooridinate of top left corner
; pszText - Text to draw
; colorFG - Color of font ink
; colorBG - Color of font background
; Returns: Nothing.
; Modifies: Display memory.
;**********************************************************************/
void DrawText(long x, long y, CONST CHAR *pszText, unsigned long colorFG, unsigned long colorBG)
{
long xl, x1, y1;
UCHAR c, b;
CONST UCHAR *pBits;
if (gpfnPixel == NULL)
return;
xl = x;
while (*pszText)
{
c = *pszText++;
if ( c >= ' ' && c <= 0x7F )
{
pBits = &aCharSet8[(c-' ')*8];
for (y1 = y; y1 < y+8; y1++)
{
c = *pBits++;
for (b = 0x80, x1 = x; b; b >>= 1, x1++)
{
if ( (c & b) )
(*gpfnPixel)( x1, y1, colorFG );
else if ( colorBG != colorFG )
(*gpfnPixel)( x1, y1, colorBG );
}
}
x += 8;
}
else if ( c == '\n' )
{
x = xl;
y += 8;
}
}
}
/************************************************************************
; Function: InitGraphics()
; Description: This routine initializes the graphics library.
; Parameters:
; Stride - number of bytes per line
; BitsPerPixel - bits per pixel
; fISVRAM - GRAPHICS_VRAM if the graphics library is to be used on display memory.
; - GRAPHICS_OFFSCREEN if the graphics library is used on offscreen memory.
; Offset - If fISVRAM is GRAPHICS_VRAM, Offset is the offset address from the beginning
; of display memory. (the first byte in display memory is at Offset=0).
; If fISVRAM is GRAPHICS_OFFSCREEN, Offset is a pointer to the start of the image
; in display memory.
; (for example, *((UCHAR *) addr)=0 sets the first byte of the image to 0)
; Returns: Nothing.
; Modifies: Nothing.
; Format: void InitGraphics(unsigned long Stride, int BitsPerPixel, BOOL fISVRAM, unsigned long Offset)
;***********************************************************************/
void InitGraphics(unsigned long Stride, long BitsPerPixel, BOOL fISVRAM, unsigned long Offset)
{
gStride = Stride;
gAddr = Offset;
gOffset = Offset;
gBitsPerPixel = BitsPerPixel;
gUseIndirectMode = (HalInfo.dwFlags & fINDIRECT_INTERFACE) ? TRUE : FALSE;
if (fISVRAM) // Dispatch to appropriate pixel drawing function.
{
switch (gBitsPerPixel)
{
case 8: gpfnPixel = _vramPixel8bpp; gpfnLine = _vramLine8bpp; break;
case 16: gpfnPixel = _vramPixel16bpp; gpfnLine = _vramLine16bpp; break;
case 32: gpfnPixel = _vramPixel32bpp; gpfnLine = _vramLine32bpp; break;
default: gpfnPixel = NULL; gpfnLine = NULL; break;
}
}
else
{
switch (gBitsPerPixel)
{
case 8: gpfnPixel = _Pixel8bpp; gpfnLine = _Line8bpp; break;
case 16: gpfnPixel = _Pixel16bpp; gpfnLine = _Line16bpp; break;
case 32: gpfnPixel = _Pixel32bpp; gpfnLine = _Line32bpp; break;
default: gpfnPixel = NULL; gpfnLine = NULL; break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -