static LCUI_BOOL MouseProc( void ) { POINT new_pos; LCUI_SystemEvent e; static LCUI_Pos old_pos = {0, 0}; /* 如果是无缝模式则获取系统鼠标游标的坐标 */ if( LCUIDisplay_GetMode() == LDM_SEAMLESS ) { GetCursorPos( &new_pos ); } else { new_pos.x = mouse.x; new_pos.y = mouse.y; } e.type = LCUI_MOUSEMOVE; e.type_name = NULL; e.data = e.destroy_data = NULL; e.rel_x = new_pos.x - old_pos.x; e.rel_y = new_pos.y - old_pos.y; if( e.rel_x == 0 && e.rel_y == 0 ) { return FALSE; } old_pos.x = new_pos.x; old_pos.y = new_pos.y; _DEBUG_MSG("x: %d, y: %d, rel_x: %d, rel_y: %d\n", new_pos.x, new_pos.y, e.rel_x, e.rel_y); _DEBUG_MSG("post result: %d\n", LCUI_PostEvent( &e )); return TRUE; }
/* 添加键盘的按键释放事件 */ void LCUI_PostKeyUpEvent( int key_code ) { LCUI_SystemEvent event; event.type = LCUI_KEYUP; event.which = key_code; LCUIKeyBoard_ReleaseKey( key_code ); LCUI_PostEvent( "keyup", &event ); }
static LCUI_BOOL LCUIKeyboard_Proc(void) { LCUI_SystemEvent e; /* 如果没有按键输入 */ if ( !LCUIKeyboard_IsHit() ) { return FALSE; } e.type = LCUI_KEYDOWN; e.which = LCUIKeyboard_GetKey(); LCUI_PostEvent( &e ); return TRUE; }
static void OnEvent( LCUI_Surface surface, LCUI_SystemEvent *e ) { #ifdef LCUI_BUILD_IN_WIN32 if( display.mode == LDM_SEAMLESS ) { return; } _DEBUG_MSG("surface: %p, event: %d, rel_x: %d, rel_y: %d\n", surface, e->type, e->rel_x, e->rel_y); if( e->type == LCUI_MOUSEMOVE ) { LCUIMouse_SetPos( e->rel_x, e->rel_y ); return; } LCUI_PostEvent( e ); #endif }
/** 投递鼠标移动事件 */ void LCUI_PostMouseMoveEvent( LCUI_Pos new_pos ) { LCUI_SystemEvent event; static LCUI_Pos old_pos = {0,0}; if( new_pos.x == old_pos.x && new_pos.y == old_pos.y ) { return; } event.type = LCUI_MOUSEMOVE; event.type_name = NULL; event.x = new_pos.x; event.y = new_pos.y; LCUI_PostEvent( &event ); old_pos = new_pos; }
/* 添加键盘的按键按下事件 */ void LCUI_PostKeyDownEvent( int key_code ) { key_state *data_ptr; LCUI_SystemEvent event; LCUIMutex_Lock( &record_mutex ); data_ptr = KeyStateRecord_FindData( key_code ); LCUIMutex_Unlock( &record_mutex ); /* 已经按下过的按键就不用再触发KEYDOWN事件了 */ if( data_ptr && data_ptr->state == LCUIKEYSTATE_PRESSED ) { return; } event.type = LCUI_KEYDOWN; event.which = key_code; LCUIKeyBoard_HitKey( key_code ); LCUI_PostEvent( "keydown", &event ); }
/** 投递鼠标按键释放事件 */ int LCUI_PostMouseUpEvent( int key_code ) { LCUI_Pos pos; LCUI_SystemEvent event; if( mouse.button_state[key_code] == LCUIKEYSTATE_RELEASE ) { return -1; } mouse.button_state[key_code] = LCUIKEYSTATE_RELEASE; LCUICursor_GetPos( &pos ); event.type = LCUI_MOUSEUP; event.type_name = NULL; event.x = pos.x; event.y = pos.y; event.which = key_code; LCUI_PostEvent( &event ); return 0; }