📄 general_draw_api.c
字号:
/*****************************************************************
* 函数库名称:通用绘图API源文件 *
* 版本: v0.01 *
* 作者: I ROBOT *
* 创建日期: Copyright (C) 2008年11月17日 *
*----------------------------------------------------------------*
* [支持库] *
* 支持库名称: *
* 支持库版本:v0.01 *
* 支持库说明:与本文件相应的函数声明 *
*----------------------------------------------------------------*
* [版本更新] *
* 更新: I ROBOT *
* 更新日期: *
* 版本: *
*----------------------------------------------------------------*
* [版本历史] *
* v0.01 创建版本,通用绘图函数 *
*----------------------------------------------------------------*
* [使用说明] *
* 1.直接调用通用绘图函数 *
*****************************************************************/
/********************
* 头 文 件 配 置 区 *
********************/
# include "General_Draw_API.h"
/********************
* 系 统 宏 定 义 *
********************/
/*------------------*
* 常 数 宏 定 义 *
*------------------*/
/*------------------*
* 动 作 宏 定 义 *
*------------------*/
/********************
* 模块结构体定义区 *
********************/
/********************
* 函 数 声 明 区 *
********************/
extern BOOL Dot_Inside(Draw_Info *Draw,
UINT8 chx_Pixel,UINT8 chy_Pixel);
extern void Draw_Dot(Draw_Info *Queue,UINT8 chCur_ID_Draw,
UINT8 chScreen_x,UINT8 chScreen_y);
extern void Clear_Dot(Draw_Info *Queue,UINT8 chCur_ID_Draw,
UINT8 chScreen_x,UINT8 chScreen_y);
/********************
* 模块函数声明区 *
********************/
/********************
* 模块变量声明区 *
********************/
/********************
* 全局变量声明区 *
********************/
/******************************************************************
* 函 数 定 义 区 *
******************************************************************/
/****************************************
* 函数说明: 点在自身图层函数 *
* 输入 :*Queue(图层队列) *
* chCur_ID_Draw(当前图层号) *
* (chScreen_x,chScreen_y) *
* (点的屏幕坐标) *
* 输出 :点在图层内的BOOL *
* 调用函数: Draw_Dot_12864() *
****************************************/
BOOL Dot_Inside(Draw_Info *Draw,
UINT8 chx_Pixel,UINT8 chy_Pixel)
{
if (chx_Pixel < Draw->chx_Pixel
&& chy_Pixel < Draw->chy_Pixel)
{
return TRUE;
}
else
{
return FALSE;
}
}
/****************************************
* 函数说明: 图层画点函数 *
* 输入 :*Queue(图层队列) *
* chCur_ID_Draw(当前图层号) *
* (chScreen_x,chScreen_y) *
* (点的屏幕坐标) *
* 输出 :无 *
* 调用函数: Draw_Dot_12864() *
****************************************/
void Draw_Dot(Draw_Info *Queue,UINT8 chCur_ID_Draw,
UINT8 chScreen_x,UINT8 chScreen_y)
{
UINT8 chCounter = 0;
{
Draw_Info *Draw = &Queue[chCur_ID_Draw-1];
UINT8 chx_Pixel = chScreen_x-Draw->chCur_x;
UINT8 chy_Pixel = Draw->chCur_y-chScreen_y;
if (!(Dot_Inside(Draw,chx_Pixel,chy_Pixel)))
{
return ;
}
}
//筛出越界的错误点
for (chCounter = chCur_ID_Draw-1;chCounter >= ID_MOUSE;chCounter--)
{
Draw_Info *Draw = &Queue[chCounter-1];
//获取当前图层的信息结构体
UINT8 chx_Pixel = chScreen_x-Draw->chCur_x;
UINT8 chy_Pixel = Draw->chCur_y-chScreen_y;
//计算该点在此图层中的位置
if (chx_Pixel < Draw->chx_Pixel &&
chy_Pixel < Draw->chy_Pixel)
{
UINT8 chRow = chy_Pixel >> 3;
UINT8 chCol = chx_Pixel;
UINT8 chBit = BIT(chy_Pixel&7);
UINT8 chPosite = chRow*Draw->chx_Pixel+chCol;
//计算点存放到遮盖缓存中的字节和位的位置
Draw->chMask_Buffer[chPosite] |= chBit;
if (Draw->chAlpha_Buffer != NULL)
{
//存在透明BUFFER
if ((Draw->chAlpha_Buffer[chPosite]&chBit))
{
chCounter = ID_MOUSE-1;
//如果是透明存储并显示出来
}
}
break;
//如果透明度BUFFER为NULL 或者存在Alpha但不需要透明
//并且该点位于当前图层的矩形区域内,
//保存到当前图层的遮盖缓存并退出
}
}
//从当前的下层图层向上层图层扫描该点是否被遮盖。
//如果遮盖将该点存放到第一个遮盖图层的遮盖缓存中
//并跳出,否则直接将该点绘制到屏幕上
if (chCounter == ID_MOUSE-1)
{
Draw_Info *Draw = &Queue[chCur_ID_Draw-1];
UINT8 chx_Pixel = chScreen_x-Draw->chCur_x;
UINT8 chy_Pixel = Draw->chCur_y-chScreen_y;
UINT8 chRow = chy_Pixel >> 3;
UINT8 chCol = chx_Pixel;
UINT8 chBit = BIT(chy_Pixel&7);
//计算点存放到自身图形缓存中的字节和位的位置
Draw->chSelf_Buffer[(chRow*Draw->chx_Pixel+chCol)] |= chBit;
DRAW_DOT(chScreen_x,chScreen_y);
//判断点是否在图层区域内
}
//如果没有图层遮盖该点,直接绘制到屏幕上,
//并将该点信息存储到该点所从属的图层的自身图形缓存中
}
/****************************************
* 函数说明: 图层清点函数 *
* 输入 :*Queue(图层队列) *
* chCur_ID_Draw(当前图层号) *
* (chScreen_x,chScreen_y) *
* (点的屏幕坐标) *
* 输出 :无 *
* 调用函数: Clear_Dot_12864() *
****************************************/
void Clear_Dot(Draw_Info *Queue,UINT8 chCur_ID_Draw,
UINT8 chScreen_x,UINT8 chScreen_y)
{
UINT8 chCounter = 0;
{
Draw_Info *Draw = &Queue[chCur_ID_Draw-1];
UINT8 chx_Pixel = chScreen_x-Draw->chCur_x;
UINT8 chy_Pixel = Draw->chCur_y-chScreen_y;
if (!(Dot_Inside(Draw,chx_Pixel,chy_Pixel)))
{
return ;
}
}
//筛出越界的错误点
for (chCounter = chCur_ID_Draw-1;chCounter >= ID_MOUSE;chCounter--)
{
Draw_Info *Draw = &Queue[chCounter-1];
//获取当前图层的信息结构体
UINT8 chx_Pixel = chScreen_x-Draw->chCur_x;
UINT8 chy_Pixel = Draw->chCur_y-chScreen_y;
//计算该点在此图层中的位置
if (chx_Pixel < Draw->chx_Pixel
&& chy_Pixel < Draw->chy_Pixel)
{
UINT8 chRow = chy_Pixel >> 3;
UINT8 chCol = chx_Pixel;
UINT8 chBit = BIT(chy_Pixel&7);
UINT8 chPosite = chRow*Draw->chx_Pixel+chCol;
//计算点存放到遮盖缓存中的字节和位的位置
Draw->chMask_Buffer[chPosite] &= ~chBit;
if (Draw->chAlpha_Buffer != NULL)
{
//存在透明BUFFER
if ((Draw->chAlpha_Buffer[chPosite]&chBit))
{
chCounter = ID_MOUSE-1;
//如果是透明存储并显示出来
}
}
break;
//如果该点位于当前图层的矩形区域内,
//在当前图层的遮盖缓存清除该点并退出
}
}
//从当前的下层图层向上层图层扫描该点是否被遮盖
//如果遮盖将该点从第一个遮盖图层的遮盖缓存中清除
//并跳出,否则直接将该点绘制到屏幕上
if (chCounter == ID_MOUSE-1)
{
Draw_Info *Draw = &Queue[chCur_ID_Draw-1];
UINT8 chx_Pixel = chScreen_x-Draw->chCur_x;
UINT8 chy_Pixel = Draw->chCur_y-chScreen_y;
UINT8 chRow = chy_Pixel >> 3;
UINT8 chCol = chx_Pixel;
UINT8 chBit = BIT(chy_Pixel&7);
//计算点存放到自身图形缓存中的字节和位的位置
Draw->chSelf_Buffer[(chRow*Draw->chx_Pixel+chCol)] &= ~chBit;
CLEAR_DOT(chScreen_x,chScreen_y);
}
//如果没有图层遮盖该点,直接绘制到屏幕上
//并将该点信息存储到该点所从属的图层的自身图形缓存中
}
/****************************************
* 函数说明: 点被遮盖函数 *
* 输入 :*Queue(图层队列) *
* chCur_ID_Draw(当前图层号) *
* (chScreen_x,chScreen_y) *
* (点的屏幕坐标) *
* 输出 :遮盖层的ID号 *
* 调用函数: *
****************************************/
void Clear_Masked_Dot(Draw_Info *Queue,UINT8 chCur_ID_Draw,
UINT8 chScreen_x,UINT8 chScreen_y)
{
UINT8 chCounter = 0;
UINT8 chx_Pixel = 0,chy_Pixel = 0;
for (chCounter = chCur_ID_Draw-1;chCounter >= ID_MOUSE;chCounter--)
{
Draw_Info *Draw = &Queue[chCounter-1];
chx_Pixel = chScreen_x-Draw->chCur_x;
chy_Pixel = Draw->chCur_y-chScreen_y;
//计算当前屏幕坐标在此图层缓存中的相对位置
if (chx_Pixel < Draw->chx_Pixel &&
chy_Pixel < Draw->chy_Pixel)
{
//如果这个点在图层中
UINT8 chRow = chy_Pixel >> 3;
UINT8 chCol = chx_Pixel;
UINT8 chBit = BIT(chy_Pixel&7);
UINT8 chPosite = chRow*Draw->chx_Pixel+chCol;
//计算在缓存中的字节和位
{
Draw_Info *Cur_Draw = &Queue[chCur_ID_Draw-1];
UINT8 chCur_xPixel = chScreen_x-Cur_Draw->chCur_x;
UINT8 chCur_yPixel = Cur_Draw->chCur_y-chScreen_y;
UINT8 chCur_Posite = 0;
UINT8 chCur_Bit = 0;
chRow = chCur_yPixel >> 3;
chCol = chCur_xPixel;
chCur_Bit = BIT(chCur_yPixel&7);
chCur_Posite = chRow*Cur_Draw->chx_Pixel+chCol;
//计算点在当前自身图层缓存中相对位置
if (Cur_Draw->chMask_Buffer[chCur_Posite]&chCur_Bit)
{
Draw->chMask_Buffer[chPosite] |= chBit;
//如果该点在当前图层中有遮盖,复制遮盖到上层遮盖
}
else
{
Draw->chMask_Buffer[chPosite] &= ~chBit;
//如果该点在当前图层中没有遮盖,清除遮盖到上层遮盖
}
}
if (Draw->chAlpha_Buffer != NULL)
{
if ((Draw->chAlpha_Buffer[chPosite]&chBit))
{
chCounter = ID_MOUSE-1;
//如果是透明也要清点
}
}
//如果遮盖层存在有透明BUFFER并开启了透明效果,清空该点
break;
//如果透明度BUFFER为NULL 或者存在Alpha但不需要透明
//并且该点位于当前图层的矩形区域内,
//保存到当前图层的遮盖缓存并退出
}
}
if (chCounter == ID_MOUSE-1)
{
CLEAR_DOT(chScreen_x,chScreen_y);
}
//如果点没有被遮盖或者是在透明效果
//下显示的就从屏幕上清除点
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -