mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
224 lines
7.8 KiB
C
224 lines
7.8 KiB
C
/* ***************************************************************************
|
|
* cursor.c -- mouse cursor operation set.
|
|
*
|
|
* Copyright (C) 2012-2017 by Liu Chao <lc-soft@live.cn>
|
|
*
|
|
* This file is part of the LCUI project, and may only be used, modified, and
|
|
* distributed under the terms of the GPLv2.
|
|
*
|
|
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
|
*
|
|
* By continuing to use, modify, or distribute this file you indicate that you
|
|
* have read the license and understand and accept it fully.
|
|
*
|
|
* The LCUI project is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
|
|
*
|
|
* You should have received a copy of the GPLv2 along with this file. It is
|
|
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
|
* ****************************************************************************/
|
|
|
|
/* ****************************************************************************
|
|
* cursor.c -- 鼠标游标的操作集
|
|
*
|
|
* 版权所有 (C) 2012-2017 归属于 刘超 <lc-soft@live.cn>
|
|
*
|
|
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
|
*
|
|
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
|
*
|
|
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
|
*
|
|
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
|
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
|
*
|
|
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
|
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
|
* ****************************************************************************/
|
|
|
|
//#define DEBUG
|
|
#include <LCUI_Build.h>
|
|
#include <LCUI/LCUI.h>
|
|
#include <LCUI/cursor.h>
|
|
#include <LCUI/display.h>
|
|
|
|
static struct LCUICursorModule {
|
|
LCUI_Pos pos; /* 当前帧的坐标 */
|
|
LCUI_Pos new_pos; /* 下一帧将要更新的坐标 */
|
|
LCUI_BOOL visible; /* 是否可见 */
|
|
LCUI_Graph graph; /* 游标的图形 */
|
|
} cursor;
|
|
|
|
static uchar_t cursor_img_rgba[4][12*19] = {
|
|
{3,3,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,0,0,0,0,3,229,3,3,0,0,0,0,0,
|
|
0,0,0,3,255,229,3,3,0,0,0,0,0,0,0,3,255,255,229,3,3,0,0,0,0,0,0,3,255,255,255,229,
|
|
3,3,0,0,0,0,0,3,255,255,255,255,229,3,3,0,0,0,0,3,255,255,255,255,253,226,3,3,0,0,0,3,
|
|
255,255,255,253,251,248,220,3,3,0,0,3,255,255,253,251,248,245,241,214,3,3,0,3,255,253,251,248,245,241,238,234,
|
|
207,3,3,3,253,251,248,245,241,238,234,230,226,201,3,3,251,248,245,217,238,234,3,3,3,3,3,3,248,245,217,3,
|
|
164,230,3,3,0,0,0,3,245,217,3,3,3,226,201,3,0,0,0,3,217,3,3,0,3,176,219,3,3,0,0,3,
|
|
3,3,0,0,3,3,216,192,3,0,0,0,0,0,0,0,0,3,192,211,3,0,0,0,0,0,0,0,0,3,3,3,
|
|
3,0,0},
|
|
{6,6,0,0,0,0,0,0,0,0,0,0,6,6,6,0,0,0,0,0,0,0,0,0,6,230,6,6,0,0,0,0,0,
|
|
0,0,0,6,255,230,6,6,0,0,0,0,0,0,0,6,255,255,230,6,6,0,0,0,0,0,0,6,255,255,255,230,
|
|
6,6,0,0,0,0,0,6,255,255,255,255,230,6,6,0,0,0,0,6,255,255,255,255,253,226,6,6,0,0,0,6,
|
|
255,255,255,253,251,248,221,6,6,0,0,6,255,255,253,251,248,245,241,214,6,6,0,6,255,253,251,248,245,241,238,234,
|
|
207,6,6,6,253,251,248,245,241,238,234,230,226,201,6,6,251,248,245,217,238,234,6,6,6,6,6,6,248,245,217,6,
|
|
165,230,6,6,0,0,0,6,245,217,6,6,6,226,201,6,0,0,0,6,217,6,6,0,6,176,219,6,6,0,0,6,
|
|
6,6,0,0,6,6,216,192,6,0,0,0,0,0,0,0,0,6,192,211,6,0,0,0,0,0,0,0,0,6,6,6,
|
|
6,0,0},
|
|
{26,26,0,0,0,0,0,0,0,0,0,0,26,26,26,0,0,0,0,0,0,0,0,0,26,232,26,26,0,0,0,0,0,
|
|
0,0,0,26,255,232,26,26,0,0,0,0,0,0,0,26,255,255,232,26,26,0,0,0,0,0,0,26,255,255,255,232,
|
|
26,26,0,0,0,0,0,26,255,255,255,255,232,26,26,0,0,0,0,26,255,255,255,255,253,228,26,26,0,0,0,26,
|
|
255,255,255,253,251,248,223,26,26,0,0,26,255,255,253,251,248,245,241,216,26,26,0,26,255,253,251,248,245,241,238,234,
|
|
209,26,26,26,253,251,248,245,241,238,234,230,226,203,26,26,251,248,245,219,238,234,26,26,26,26,26,26,248,245,219,26,
|
|
171,230,26,26,0,0,0,26,245,219,26,26,26,226,203,26,0,0,0,26,219,26,26,0,26,181,219,26,26,0,0,26,
|
|
26,26,0,0,26,26,216,194,26,0,0,0,0,0,0,0,0,26,194,211,26,0,0,0,0,0,0,0,0,26,26,26,
|
|
26,0,0},
|
|
{231,55,0,0,0,0,0,0,0,0,0,0,231,189,55,0,0,0,0,0,0,0,0,0,231,255,189,55,0,0,0,0,0,
|
|
0,0,0,231,255,255,189,55,0,0,0,0,0,0,0,231,255,255,255,189,55,0,0,0,0,0,0,231,255,255,255,255,
|
|
189,55,0,0,0,0,0,231,255,255,255,255,255,189,55,0,0,0,0,231,255,255,255,255,255,255,189,55,0,0,0,231,
|
|
255,255,255,255,255,255,255,189,55,0,0,231,255,255,255,255,255,255,255,255,189,55,0,231,255,255,255,255,255,255,255,255,
|
|
255,189,55,231,255,255,255,255,255,255,255,255,255,255,189,231,255,255,255,255,255,255,189,189,189,189,189,231,255,255,255,244,
|
|
255,255,188,77,0,0,0,231,255,255,244,55,211,255,255,211,0,0,0,231,255,244,55,0,180,255,255,180,77,0,0,189,
|
|
244,55,0,0,55,215,255,255,209,0,0,0,0,0,0,0,0,180,255,255,204,0,0,0,0,0,0,0,0,26,215,158,
|
|
49,0,0}
|
|
};
|
|
|
|
static int LCUICursor_LoadDefualtGraph(LCUI_Graph *buff )
|
|
{
|
|
if( Graph_IsValid(buff) ) {
|
|
Graph_Free( buff );
|
|
}
|
|
Graph_Init( buff );
|
|
buff->color_type = COLOR_TYPE_ARGB;
|
|
if( Graph_Create(buff,12,19) != 0 ) {
|
|
return -1;
|
|
}
|
|
Graph_SetRedBits( buff, cursor_img_rgba[0], 12*19 );
|
|
Graph_SetGreenBits( buff, cursor_img_rgba[1], 12*19 );
|
|
Graph_SetBlueBits( buff, cursor_img_rgba[2], 12*19 );
|
|
Graph_SetAlphaBits( buff, cursor_img_rgba[3], 12*19 );
|
|
return 0;
|
|
}
|
|
|
|
static void OnMouseMoveEvent( LCUI_SysEvent e, void *arg )
|
|
{
|
|
cursor.new_pos.x = e->motion.x;
|
|
cursor.new_pos.y = e->motion.y;
|
|
}
|
|
|
|
/* 初始化游标数据 */
|
|
void LCUI_InitCursor( void )
|
|
{
|
|
LCUI_Graph pic;
|
|
Graph_Init( &pic );
|
|
Graph_Init( &cursor.graph );
|
|
/* 载入自带的游标的图形数据 */
|
|
LCUICursor_LoadDefualtGraph( &pic );
|
|
cursor.new_pos.x = LCUIDisplay_GetWidth() / 2;
|
|
cursor.new_pos.y = LCUIDisplay_GetHeight() / 2;
|
|
LCUI_BindEvent( LCUI_MOUSEMOVE, OnMouseMoveEvent, NULL, NULL );
|
|
LCUICursor_SetGraph( &pic );
|
|
LCUICursor_Show();
|
|
Graph_Free( &pic );
|
|
}
|
|
|
|
void LCUI_ExitCursor( void )
|
|
{
|
|
Graph_Free( &cursor.graph );
|
|
}
|
|
|
|
/* 获取鼠标游标的区域范围 */
|
|
void LCUICursor_GetRect( LCUI_Rect *rect )
|
|
{
|
|
rect->x = cursor.pos.x;
|
|
rect->y = cursor.pos.y;
|
|
rect->width = (int)cursor.graph.width;
|
|
rect->height = (int)cursor.graph.height;
|
|
}
|
|
|
|
/* 刷新鼠标游标在屏幕上显示的图形 */
|
|
void LCUICursor_Refresh( void )
|
|
{
|
|
LCUI_Rect rect;
|
|
if( !cursor.visible ) {
|
|
return;
|
|
}
|
|
LCUICursor_GetRect( &rect );
|
|
LCUIDisplay_InvalidateArea( &rect );
|
|
}
|
|
|
|
/* 检测鼠标游标是否可见 */
|
|
LCUI_BOOL LCUICursor_IsVisible( void )
|
|
{
|
|
return cursor.visible;
|
|
}
|
|
|
|
/* 显示鼠标游标 */
|
|
void LCUICursor_Show( void )
|
|
{
|
|
cursor.visible = TRUE; /* 标识游标为可见 */
|
|
LCUICursor_Refresh();
|
|
}
|
|
|
|
/* 隐藏鼠标游标 */
|
|
void LCUICursor_Hide( void )
|
|
{
|
|
LCUICursor_Refresh();
|
|
cursor.visible = FALSE;
|
|
}
|
|
|
|
/* 更新鼠标指针的位置 */
|
|
void LCUICursor_Update( void )
|
|
{
|
|
if( cursor.pos.x == cursor.new_pos.x
|
|
&& cursor.pos.y == cursor.new_pos.y ) {
|
|
return;
|
|
}
|
|
LCUICursor_Refresh();
|
|
cursor.pos = cursor.new_pos;
|
|
LCUICursor_Refresh();
|
|
}
|
|
|
|
/* 设定游标的位置 */
|
|
void LCUICursor_SetPos( LCUI_Pos pos )
|
|
{
|
|
cursor.new_pos = pos;
|
|
}
|
|
|
|
/** 设置游标的图形 */
|
|
int LCUICursor_SetGraph( LCUI_Graph *graph )
|
|
{
|
|
if( Graph_IsValid (graph) ) {
|
|
LCUICursor_Refresh();
|
|
if( Graph_IsValid(&cursor.graph) ) {
|
|
Graph_Free( &cursor.graph );
|
|
}
|
|
Graph_Copy( &cursor.graph, graph );
|
|
LCUICursor_Refresh();
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
/* 获取鼠标指针当前的坐标 */
|
|
void LCUICursor_GetPos( LCUI_Pos *pos )
|
|
{
|
|
*pos = cursor.new_pos;
|
|
}
|
|
|
|
/* 检测鼠标游标是否覆盖在矩形区域上 */
|
|
LCUI_BOOL LCUICursor_IsCoverRect( LCUI_Rect rect )
|
|
{
|
|
LCUI_Rect cursor_rect;
|
|
LCUICursor_GetRect( &cursor_rect );
|
|
return LCUIRect_IsCoverRect( &rect, &cursor_rect );
|
|
}
|
|
|
|
/* 将当前鼠标游标的图像叠加至目标图像指定位置 */
|
|
int LCUICursor_MixGraph( LCUI_Graph *buff, LCUI_Pos pos )
|
|
{
|
|
return Graph_Mix( buff, &cursor.graph, pos.x, pos.y, FALSE );
|
|
}
|