📄 draw.cpp
字号:
// 混合结束
POP edi;
}
}
// 在位图上画点(Alpha八级)
void pixel_alpha_8(BMP *bmp, int x, int y, WORD color)
{
return;
}
// 画线函数,包含端点
void line(BMP *bmp, int x1, int y1, int x2, int y2, WORD color)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
int i, sum;
int dx, dy, wcx = 0, wcy = 0, incrementx, incrementy;
dx = x2 - x1;
dy = y2 - y1;
if (dx > 0) incrementx = 1;
else if (dx == 0) incrementx = 0;
else incrementx =- 1, dx =- dx;
if (dy > 0) incrementy = 1;
else if(dy == 0) incrementy = 0;
else incrementy =- 1, dy =- dy;
if(dx > dy) sum = dx;
else sum = dy;
for(i = 0; i <= sum + 1; i++)
{
pixel(bmp, x1, y1, color);
wcx += dx, wcy += dy;
if (wcx > sum) wcx -= sum, x1 += incrementx;
if (wcy > sum) wcy -= sum, y1 += incrementy;
}
}
// 画圆函数
void circle(BMP *bmp, int x0, int y0, int r, WORD color)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
int x, y;
int increment;
int startx, endx, starty, endy, i;
y = r;
increment = 3 - 2 * r;
for (x = 0; x < y;)
{
startx = x, endx = x + 1;
starty = y, endy = y + 1;
for(i = startx; i < endx; i++)
{
pixel(bmp, x0 + i, y0 + y, color);
pixel(bmp, x0 + i, y0 - y, color);
pixel(bmp, x0 - i, y0 - y, color);
pixel(bmp, x0 - i, y0 + y, color);
}
for(i = starty; i < endy; i++)
{
pixel(bmp, x0 + i, y0 + x, color);
pixel(bmp, x0 + i, y0 - x, color);
pixel(bmp, x0 - i, y0 - x, color);
pixel(bmp, x0 - i, y0 + x, color);
}
if (increment < 0) increment += 4 * x + 6;
else increment += 4 * (x - y) + 10, y--;
x++;
}
}
// 实心圆
void circle_fill(BMP *bmp, int x0, int y0, int r, WORD color)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
int x, y;
int increment;
int startx, endx, starty, endy, i;
y = r;
increment = 3 - 2 * r;
for(x = 0; x < y;)
{
startx = x, endx = x + 1;
starty = y, endy = y + 1;
for(i = startx; i < endx; i++)
{
line(bmp, x0 + i, y0 + y, x0 + i, y0 - y, color);
line(bmp, x0 - i, y0 - y, x0 - i, y0 + y, color);
}
for(i = starty; i < endy; i++)
{
line(bmp, x0 + i, y0 + x, x0 + i, y0 - x, color);
line(bmp, x0 - i, y0 - x, x0 - i, y0 + x, color);
}
if (increment < 0) increment += 4 * x + 6;
else increment += 4 * (x - y) + 10, y--;
x++;
}
}
// 矩形
void rect(BMP *bmp, int x1, int y1, int x2, int y2, WORD color)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
line(bmp, x1, y1, x1, y2, color);
line(bmp, x1, y1, x2, y1, color);
line(bmp, x2, y2, x1, y2, color);
line(bmp, x2, y2, x2, y1, color);
}
// 实心矩形
void rect_fill(BMP *bmp, int x1, int y1, int x2, int y2, WORD color)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
int i;
for(i = y1; i <= y2; i++)
line(bmp, x1, i, x2, i, color);
}
// 将16点阵汉字读入内存
BOOL load_hzk16(char *filename)
{
if (hzk_16 != NULL) free(hzk_16);
int fp;
int Length = 0;
// 打开文件
fp = _open(filename, _O_RDONLY);
if (fp == -1)
{
_close(fp);
hzk_16 = NULL;
return FALSE;
}
// 计算文件长度
Length = _filelength(fp);
hzk_16 = (char *)malloc(Length);
if (hzk_16 == NULL)
{
_close(fp);
hzk_16 = NULL;
return FALSE;
}
// 读取
if (_read(fp, hzk_16, Length) <= 0)
{
_close(fp);
hzk_16 = NULL;
return FALSE;
}
return TRUE;
}
// 将24点阵汉字读入内存
BOOL load_hzk24(char *filename)
{
if (hzk_24 != NULL) free(hzk_24);
int fp;
int Length = 0;
// 打开文件
fp = _open(filename, _O_RDONLY);
if (fp == -1)
{
_close(fp);
hzk_24 = NULL;
return FALSE;
}
// 计算文件长度
Length = _filelength(fp);
hzk_24 = (char *)malloc(Length);
if (hzk_24 == NULL)
{
_close(fp);
hzk_24 = NULL;
return FALSE;
}
// 读取
if (_read(fp, hzk_24, Length) <= 0)
{
_close(fp);
hzk_24 = NULL;
return FALSE;
}
return TRUE;
}
// 将8*16ASC点阵字库读入内存
BOOL load_asc16(char *filename)
{
if (asc_16 != NULL) free(asc_16);
int fp;
int Length = 0;
// 打开文件
fp = _open(filename, _O_RDONLY);
if (fp == -1)
{
_close(fp);
asc_16 = NULL;
return FALSE;
}
// 计算文件长度
Length = _filelength(fp);
asc_16 = (char *)malloc(Length);
if (asc_16 == NULL)
{
_close(fp);
asc_16 = NULL;
return FALSE;
}
// 读取
if (_read(fp, asc_16, Length) <= 0)
{
_close(fp);
asc_16 = NULL;
return FALSE;
}
return TRUE;
}
// 显示16点阵汉字
void _paint_C16(BMP *bmp, int x, int y, WORD color,char *text)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
unsigned int i, c1, c2, f = 0;
int rec;
long lseek;
char by[32];
int len = strlen(text);
while((i = *text++) != 0)
{
if (i > 0xa1)
if (f == 0)
{
c1 = (i - 0xa1) & 0x07f;
f = 1;
}
else
{
c2 = (i - 0xa1) & 0x07f;
f = 0;
rec = c1 * 94 + c2;
lseek = rec * 32L;
for (int n = 0; n < 32; n++)
by[n] = hzk_16[lseek + n];
int i1, i2, i3;
for(i1 = 0; i1 < 16; i1++)
for(i2 = 0; i2 < 2; i2++)
for(i3 = 0; i3 < 8; i3++)
if ((by[i1 * 2 + i2] >> (7 - i3)) & 1)
pixel(bmp, x + i2 * 8 + i3, y + i1, color);
x = x + 16;
}
}
}
// 显示16点阵普通汉字
void paint_C16_normal(BMP *bmp, int x, int y, WORD color, char *text)
{
_paint_C16(bmp, x, y, color, text);
}
// 显示16点阵阴影汉字
void paint_C16_shadow(BMP *bmp, int x, int y, WORD color, char *text)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
_paint_C16(bmp, x + font_shadow_x, y + font_shadow_y, font_shadow_color, text);
_paint_C16(bmp, x, y, color, text);
}
// 显示16点阵边框汉字
void paint_C16_hollow(BMP *bmp, int x, int y, WORD color, char *text)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
for (int i = -1; i < 2; i++)
for (int j = -1; j < 2; j++)
_paint_C16(bmp, x+j, y+i, font_hollow_color, text);
_paint_C16(bmp, x, y, color, text);
}
// 24点阵汉字显示
void _paint_C24(BMP *bmp, int x, int y, WORD color, char *text)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
unsigned int i, c1, c2, f = 0;
int i1, i2, i3, rec;
long lseek;
char by[72];
while((i = *text++) != 0)
{
if (i > 0xal)
if (f == 0)
{
c1 = (i - 0xa1) & 0x07f;
f = 1;
}
else
{
c2 = (i - 0xa1) & 0x07f;
f = 0;
rec = (c1 - 15) * 94 + c2;
lseek = rec * 72L;
for(int n = 0; n < 72; n++)
by[n] = hzk_24[lseek + n];
for(i1 = 0; i1 < 24; i1++)
for(i2 = 0; i2 < 3; i2++)
for(i3 = 0; i3 < 8; i3++)
if ((by[i1 * 3 + i2] >> (7 - i3)) & 1)
pixel(bmp, x + i1, y + i2 * 8 + i3, color);
x = x + 24;
}
}
}
// 显示24点阵普通汉字
void paint_C24_normal(BMP *bmp, int x, int y, WORD color, char *text)
{
_paint_C24(bmp, x, y, color, text);
}
// 显示24点阵阴影汉字
void paint_C24_shadow(BMP *bmp, int x, int y, WORD color, char *text)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
_paint_C24(bmp, x + font_shadow_x, y + font_shadow_y, font_shadow_color, text);
_paint_C24(bmp, x, y, color, text);
}
// 显示24点阵边框汉字
void paint_C24_hollow(BMP *bmp, int x, int y, WORD color, char *text)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
for (int i = -1; i < 2; i++)
for (int j = -1; j < 2; j++)
_paint_C24(bmp, x+j, y+i, font_hollow_color, text);
_paint_C24(bmp, x, y, color, text);
}
// 显示8*16ASC字符
void _paint_ASC(BMP *bmp, int x, int y, WORD color,char c)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
char *p = asc_16 + c * 16;
unsigned char mask;
int ex = x, ey = y;
for (int i = 0; i < 16; i++)
{
ex = x;
mask = 0x80; // 1000 0000
for (int ii = 0; ii < 8; ii++)
{
if (mask & *p)
pixel(bmp, ex, ey, color);
mask >>= 1;
ex++;
}
p++;
ey++;
}
}
// 显示8*16ASC普通字符
void paint_ASC_normal(BMP *bmp, int x, int y, WORD color, char text)
{
_paint_ASC(bmp, x, y, color, text);
}
// 显示8*16ASC阴影字符
void paint_ASC_shadow(BMP *bmp, int x, int y, WORD color, char text)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
_paint_ASC(bmp, x + font_shadow_x, y + font_shadow_y, font_shadow_color, text);
_paint_ASC(bmp, x, y, color, text);
}
// 显示8*16ASC边框字符
void paint_ASC_hollow(BMP *bmp, int x, int y, WORD color, char text)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
for (int i = -1; i < 2; i++)
for (int j = -1; j < 2; j++)
_paint_ASC(bmp, x+j, y+i, font_hollow_color, text);
_paint_ASC(bmp, x, y, color, text);
}
// 显示一个16点阵的字符串
void text_out(BMP *bmp, int x, int y, WORD color, char *text)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
char hz[3];
hz[2] = '\0';
int ex = x, ey = y;
for (int i = 0; text[i]; i++)
{
if (text[i] == '\n')
{
ex = x;
ey += 16;
}
else if ((unsigned char)text[i] >= 0xa1)// && text[i + 1] >= 0xal)
{
hz[0] = text[i];
hz[1] = text[i + 1];
paint_C16(bmp, ex, ey, color, hz);
ex += 16, i++;
}
else
{
paint_ASC(bmp, ex, ey, color, text[i]);
ex += 8;
}
}
}
// 用printf的方式显示字符串
void text_printf(BMP *bmp, int x, int y, WORD color, char *format, ...)
{
put_message(bmp == NULL,
"错误,企图对不存在的位图进行操作。");
char temp[256];
va_list list;
va_start(list, format);
vsprintf(temp, format, list);
va_end(list);
text_out(bmp, x, y, color, temp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -