Beispiel #1
0
/* 处理鼠标移动事件 */
static void 
Window_ExecMove(LCUI_Widget *titlebar, LCUI_WidgetEvent *event)
{
	LCUI_Pos pos, offset;
	LCUI_Widget *window;
	
	window = titlebar->parent;
	if( !window ) {
		return;
	}
	//_DEBUG_MSG( "new:%d,%d, cursor:%d,%d\n", 
	//event->drag.new_pos.x, event->drag.new_pos.y, 
	//event->drag.cursor_pos.x, event->drag.cursor_pos.y );
	/* 将新全局坐标减去标题栏的全局坐标,得到偏移坐标 */
	pos = Widget_GetGlobalPos( titlebar );
	offset = Pos_Sub( event->drag.new_pos, pos );
	pos = Widget_GetGlobalPos( window );
	/* 将偏移坐标加在窗口全局坐标上,得出窗口的新全局坐标 */
	pos = Pos_Add( pos, offset );
	/* 转换成在容器区域内的相对坐标 */
	pos = Widget_ToRelPos( window->parent, pos );
	/* 解除之前设定的align */
	Widget_SetAlign( window, ALIGN_NONE, Pos(0,0) );
	/* 移动窗口的位置 */
	Widget_Move( window, pos );
}
Beispiel #2
0
/* 处理鼠标移动事件 */
static void Window_ExecMove( LCUI_Widget *window, LCUI_WidgetEvent *event )
{
	LCUI_Pos pos;
	/* 解除之前设定的align */
	Widget_SetAlign( window, ALIGN_NONE, Pos(0,0) );
	pos = Widget_ToRelPos( window->parent, event->drag.new_pos );
	/* 移动窗口的位置 */
	Widget_Move( window, pos );
}
Beispiel #3
0
static void LCUI_HandleMouseMotion( LCUI_Event *event, void *unused )
{
	LCUI_Pos pos;
	LCUI_Widget *tmp_widget, *widget;
	LCUI_WidgetEvent wdg_event;

	pos.x = event->motion.x;
	pos.y = event->motion.y;
	/* 获取当前鼠标游标覆盖到的部件的指针 */
	widget = Widget_At( NULL, pos );
	if( widget ) {
		tmp_widget = GetWidgetOfResponseEvent( widget, EVENT_MOUSEMOTION );
		if( tmp_widget ) {
			wdg_event.type = EVENT_MOUSEMOTION;
			pos = Widget_ToRelPos( tmp_widget, pos );
			wdg_event.mouse_motion.rel_pos = pos;
			Widget_DispatchEvent( tmp_widget, &wdg_event );
		}
	}
	
	/* 如果没有部件处于按住状态 */
	if( !click_widget ) {
		/* 如果允许响应状态,就设置为OVERLAY状态,否则重置为NORMAL状态 */
		if( Widget_IsAllowResponseEvent(widget) ) {
			WidgetRecord_SetWidgetState( widget, WIDGET_STATE_OVERLAY );
		} else {
			WidgetRecord_SetWidgetState( widget, WIDGET_STATE_NORMAL );
		}
	}
	/* 如果之前点击过部件,并且现在鼠标左键还处于按下状态,那就处理部件拖动 */
	tmp_widget = GetWidgetOfResponseEvent( click_widget, EVENT_DRAG );
	if( tmp_widget != click_widget ) {
		return;
	}
	if( tmp_widget && event->motion.state == LCUIKEYSTATE_PRESSED ) {
		DEBUG_MSG("doing drag\n");
		_DragEvent_Do( tmp_widget, &event->motion );
	}
}
Beispiel #4
0
/** 响应鼠标按键释放事件 */
static void LCUI_HandleMouseButtonUp( LCUI_MouseButtonEvent *event )
{
	LCUI_Widget *tmp_widget, *widget;
	LCUI_WidgetEvent tmp_event;
	LCUI_Pos pos;
	LCUI_BOOL can_click=TRUE;

	if( !event || event->state != LCUIKEYSTATE_RELEASE ) {
		return;
	}
	pos.x = event->x;
	pos.y = event->y;
	widget = Widget_At( NULL, pos );

	if( !Widget_IsAllowResponseEvent(widget) ) {
		return;
	}
	if( widget ) {
		pos = Widget_ToRelPos( widget, pos );
		tmp_event.type = EVENT_MOUSEBUTTON;
		tmp_event.mouse_button.x = pos.x;
		tmp_event.mouse_button.y = pos.y;
		tmp_event.mouse_button.button = event->button;
		tmp_event.mouse_button.state = event->state;
		Widget_DispatchEvent( widget, &tmp_event );
	}

	if( event->button != LCUIKEY_LEFTBUTTON ) {
		return;
	}
	DEBUG_MSG("mouse left button free, click_widget: %p\n", click_widget );
	if( !click_widget ) {
		/* 如果是点击屏幕空白处,则复位焦点 */
		Widget_ResetFocus( NULL );
		return;
	}
	/* 如果能拖动部件 */
	if( can_drag_widget ) {
		tmp_widget = GetWidgetOfResponseEvent( click_widget, EVENT_DRAG );
		if( tmp_widget && tmp_widget == click_widget ) {
			DEBUG_MSG("end drag\n");
			/* 结束部件的拖动 */
			can_click =  _DragEvent_End( tmp_widget, event );
		}
		/* 标记为不能拖动部件 */
		can_drag_widget = FALSE;
	}
	/* 如果不能处理点击,则跳转至后面的退出点 */
	if( !can_click ) {
		goto exit_point;
	}
	tmp_widget = GetWidgetOfResponseEvent( widget, EVENT_CLICKED );
	/* 如果之前点击的部件和当前点击的部件一样 */
	if( click_widget == tmp_widget ) {
		/* 如果部件有效且已经启用 */
		if( tmp_widget && tmp_widget->enabled ) {
			tmp_event.type = EVENT_CLICKED;
			pos.x = event->x;
			pos.y = event->y;
			tmp_event.clicked.rel_pos = Widget_ToRelPos( tmp_widget, pos );
			Widget_DispatchEvent( tmp_widget, &tmp_event );
		}
		WidgetRecord_SetWidgetState( widget, WIDGET_STATE_ACTIVE );
	}
exit_point:;
	WidgetRecord_SetWidgetState( widget, WIDGET_STATE_OVERLAY );
	click_widget = NULL;
}
Beispiel #5
0
/** 响应鼠标按键按下事件 */
static void LCUI_HandleMouseButtonDown( LCUI_MouseButtonEvent *event )
{
	LCUI_Widget *widget, *tmp_widget;
	LCUI_Pos pos;
	LCUI_WidgetEvent wdg_event;
	
	if( !event || event->state != LCUIKEYSTATE_PRESSED ) {
		return;
	}
	pos.x = event->x;
	pos.y = event->y;
	old_cursor_pos.x = pos.x;
	old_cursor_pos.y = pos.y;
	widget = Widget_At( NULL, pos );
	if( !Widget_IsAllowResponseEvent(widget) ) {
		return;
	}
	/* 获取能够响应此事件的部件 */
	tmp_widget = GetWidgetOfResponseEvent( widget, EVENT_MOUSEBUTTON );
	if( widget && tmp_widget ) {
		/* 开始准备事件数据 */
		pos = Widget_ToRelPos( tmp_widget, pos );
		wdg_event.type = EVENT_MOUSEBUTTON;
		wdg_event.mouse_button.x = pos.x;
		wdg_event.mouse_button.y = pos.y;
		wdg_event.mouse_button.button = event->button;
		wdg_event.mouse_button.state = event->state;
		/* 派发事件 */
		Widget_DispatchEvent( tmp_widget, &wdg_event );
	}
	if( event->button != LCUIKEY_LEFTBUTTON ) {
		return;
	}
	tmp_widget = GetWidgetOfResponseEvent( widget, EVENT_CLICKED );
	if( tmp_widget ) {
		click_widget = tmp_widget;
		tmp_widget = GetWidgetOfResponseEvent( widget, EVENT_DRAG );
		if( click_widget == tmp_widget ) {
			DEBUG_MSG("start drag\n");
			/* 开始处理部件的拖动 */
			_DragEvent_Start( tmp_widget, event );
			/* 设置标记,表示可以进行部件拖动 */
			can_drag_widget = TRUE;
		} else {
			/* 设置标记,表示不能进行部件拖动 */
			can_drag_widget = FALSE;
		}
	} else {
		click_widget = widget;
		tmp_widget = GetWidgetOfResponseEvent( widget, EVENT_DRAG );
		if( widget && tmp_widget ) {
			DEBUG_MSG("start drag\n");
			/* 开始处理部件的拖动 */
			_DragEvent_Start( tmp_widget, event );
			can_drag_widget = TRUE;
		}
	}
	/* 焦点转移给该部件 */
	Widget_SetFocus( click_widget );
	WidgetRecord_SetWidgetState( widget, WIDGET_STATE_ACTIVE );
}