1、每次显示光标时,在绘制光标前先对原来数据备份(包括光标闪烁过程中显示);
2、关闭光标时用已备份的区域还原光标的所占的点阵。
3、显示/关闭过程中加锁。
/*********************************************************
* 功能: 光标背景区域备份
*
* 参数:
* 返回:无
*
*********************************************************/
void cursor_back(void)
{
UINT16 i,j;
UINT32 iLen;
UINT16 *sourceBuf = NULL;
if(((cursor_pos.height+cursor_pos.y_pos)>= PANEL_HEIGHT) || \
((cursor_pos.width+cursor_pos.x_pos)>= PANEL_WIDTH) )
{
PRINT_LOG("Cursor coordinate err !!!\n");
return;
}
if(cursor_backBuf != NULL)
{
free(cursor_backBuf);
cursor_backBuf = NULL;
}
iLen = cursor_pos.height * cursor_pos.width * 2;
cursor_backBuf = (unsigned short *)malloc(iLen);
if(cursor_backBuf == NULL)
{
PRINT_LOG("malloc cursor back buf fail!!!!\n");
}
sourceBuf = (UINT16 *)get_ready_buf();
for( i = 0; i < cursor_pos.height;i++)
{
for(j = 0 ;j < cursor_pos.width ;j++)
{
cursor_backBuf[i*cursor_pos.width + j] = \
sourceBuf[(cursor_pos.y_pos+ i)*PANEL_WIDTH + cursor_pos.x_pos + j];
}
}
}
/*********************************************************
* 功能: row data 缓存初始化
*
* 参数:无
* 返回:无
*
*********************************************************/
void show_cursor(UINT8 flag)
{
int i = 0 ,j = 0 ;
UINT16 *preadyBuf;
preadyBuf = (UINT16 *)get_ready_buf();
if(cursor_backBuf == NULL)
{
return ;
}
for( i = 0; i < cursor_pos.height;i++)
{
for(j = 0 ;j < cursor_pos.width ;j++)
{
preadyBuf[(cursor_pos.y_pos+ i)*PANEL_WIDTH + cursor_pos.x_pos + j] = ((flag ==SHOW_CURSOR)? cursor_color :\
cursor_backBuf[(cursor_pos.width * i) + j]);
}
}
if(cursor_flag == OFF_CURSOR)
{
if(cursor_backBuf != NULL)
{
free(cursor_backBuf);
cursor_backBuf = NULL;
}
}
mutex_lock=0;
}
/*********************************************************
* 功能: 获取光标的当前显示状态
*
* 参数:
* 返回:光标的当前显示状态
*
*********************************************************/
UINT8 get_cursor_state(void)
{
return cursor_flag;
}
/*********************************************************
* 功能: 设置光标参数
*
* 参数: cursor 光标的起始位置及尺寸
* 返回:无
*
*********************************************************/
UINT32 set_cursor_pos(POS cursor)
{
UINT32 ret;
mutex_lock = 1;
if((cursor.x_pos >= PANEL_WIDTH)||(cursor.y_pos >= PANEL_HEIGHT))
{
PRINT_LOG("cusr pos error!!!\n");
ret = ERR_PARA;
goto out;
}
if(((cursor.x_pos + cursor.width) > PANEL_WIDTH)||\
((cursor.y_pos + cursor.height) > PANEL_HEIGHT))
{
PRINT_LOG("cusr size par error!!!\n");
ret = ERR_PARA;
goto out;
}
if(cursor_flag == SHOW_CURSOR)
{
show_cursor(0);
}
memcpy(&cursor_pos,&cursor,sizeof(POS));
ret = ERR_NULL;
out:
return ret;
}
/*********************************************************
* 功能: 设置光标状态
*
* 参数: flag = SHOW_CURSOR or flag = OFF_CURSOR
* 返回:无
*
*********************************************************/
void set_cursor_state(UINT8 flag)
{
mutex_lock = 1;
cursor_flag = flag;
if(cursor_flag == SHOW_CURSOR)
{
cursor_back();
}
}
/*********************************************************
* 功能: 设置光标颜色
*
* 参数:color 光标颜色
* 返回:无
*
*********************************************************/
void set_cursor_color(UINT16 color)
{
cursor_color = color;
}
void gui_show_cursor(POS cursor,UINT16 color,UINT8 enable)
{
if(enable == SHOW_CURSOR)
{
if(set_cursor_pos(cursor) != ERR_NULL )
{
mutex_lock = 0;
return;
}
set_cursor_state(SHOW_CURSOR);
set_cursor_color(color);
// show_cursor(SHOW_CURSOR);
mutex_lock=0;
}
else
{
set_cursor_state(OFF_CURSOR);
show_cursor(OFF_CURSOR);
}
}