串列埠屏游標移動花屏的問題解決
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);
}
}