예제 #1
0
static void 
_Start_DragEvent( LCUI_Widget *widget, LCUI_MouseEvent *event )
{
	drag_event.cursor_pos = event->global_pos;
	/* 用全局坐标减去部件的全局坐标,得到偏移坐标 */ 
	__offset_pos = Pos_Sub( event->global_pos, Get_Widget_Global_Pos( widget ) );
	/* 得出部件的新全局坐标 */
	drag_event.new_pos = Pos_Sub( event->global_pos, __offset_pos );
	drag_event.first_click = 1;
	drag_event.end_click = 0;
	/* 处理部件的拖动事件 */
	Handle_Event( &widget->event, EVENT_DRAG );
}
예제 #2
0
파일: window.c 프로젝트: gateslu/LCUI
/* 处理鼠标移动事件 */
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 );
}
예제 #3
0
static void 
_End_DragEvent( LCUI_Widget *widget, LCUI_MouseEvent *event )
{
	drag_event.cursor_pos = event->global_pos;
	drag_event.new_pos = Pos_Sub( event->global_pos, __offset_pos );
	drag_event.first_click = 0;
	drag_event.end_click = 1;
	Handle_Event( &widget->event, EVENT_DRAG );
}
예제 #4
0
파일: LCUI_Window.c 프로젝트: dwdcth/LCUI
static void Move_Window(LCUI_Widget *titlebar, LCUI_DragEvent *event)
/* 功能:处理鼠标移动事件 */
{
    LCUI_Pos pos;
    LCUI_Widget *window;
    if(event->first_click == 0 ) {
        window = titlebar->parent;
        pos = event->new_pos;
        if(window != NULL) {
            /* 减去在窗口中的相对坐标, 得出窗口位置 */
            pos = Pos_Sub(pos, Get_Widget_Pos(titlebar));
            if(window->parent != NULL) {
                pos = Pos_Sub(pos, Get_Widget_Global_Pos(window->parent));
            }
            /* 移动窗口的位置 */
            Move_Widget(window, pos);
        }
    }
}
예제 #5
0
static void 
ScrollBar_Drag( LCUI_Widget *widget, LCUI_DragEvent *event )
{
	static LCUI_Pos pos, offset;
	static LCUI_ScrollBar *scrollbar;
	
	if( !widget->parent ) {
		return;
	}
	
	scrollbar = Get_Widget_PrivData( widget->parent );
	pos = Get_Widget_Global_Pos( widget );
	offset = Pos_Sub( event->new_pos, pos ); 
	pos = Pos_Add( pos, offset ); 
	pos = GlobalPos_ConvTo_RelativePos( widget, pos );
	
	Move_ScrollBar( widget, pos );
	/* 若函数指针有效,则调用回调函数 */
	if( scrollbar->callback_func ) {
		scrollbar->callback_func( scrollbar->data, scrollbar->arg );
	}
}
예제 #6
0
파일: screenlock.c 프로젝트: FrankHB/LCUI
/* 移动滑块 */
void move_pic_btn(LCUI_Widget *widget, LCUI_WidgetEvent *event)
{
	LCUI_Size size;
	LCUI_Rect des, rect;
	LCUI_Pos pos, parent;

	need_move_pic_btn = FALSE;
	parent = Widget_GetGlobalPos(widget->parent);
	pos = Pos_Sub(event->drag.new_pos, parent);
	Widget_Move(widget, pos);
	if(event->drag.end_click) {/* 如果拖动已经结束 */
		rect = Widget_GetRect(widget);
		size = Widget_GetSize(widget->parent);
		des = Rect(size.w-10, 0, 30, 30);/* 目标区域 */
		 /* 如果部件区域与目标区域重叠,则退出程序 */
		if(LCUIRect_Overlay(rect, des)) {
			LCUI_MainLoop_Quit(NULL);
		} else {/* 否则,让部件回到起始位置,这个使用的是匀速移动 */
			need_move_pic_btn = TRUE;
		}
	}
}
예제 #7
0
static void 
ScrollBar_Drag( LCUI_Widget *widget, LCUI_WidgetEvent *event )
{
	static LCUI_Pos pos, offset;
	static LCUI_ScrollBar *scrollbar;
	if( !widget->parent ) {
		return;
	}
	
	scrollbar = Widget_GetPrivData( widget->parent );
	pos = Widget_GetGlobalPos( widget );
	offset = Pos_Sub( event->drag.new_pos, pos ); 
	pos = Pos_Add( pos, offset ); 
	pos = GlobalPos_ConvTo_RelativePos( widget, pos );
	
	Move_ScrollBar( widget, pos );
	/* 若函数指针有效,则调用回调函数 */
	if( scrollbar->callback_func ) {
		//_DEBUG_MSG("current_num: %d, max_num: %d\n", 
		//scrollbar->data.current_num, scrollbar->data.max_num);
		scrollbar->callback_func( scrollbar->data, scrollbar->arg );
	}
}
예제 #8
0
TextLayer_Cursor_SetPixelPos( LCUI_TextLayer *layer, LCUI_Pos pixel_pos )
/* 
 * 功能:根据传入的二维坐标,设定光标在的文本图层中的位置
 * 说明:该位置会根据当前位置中的字体位图来调整,确保光标显示在字体位图边上,而不
 * 会遮挡字体位图;光标在文本图层中的位置改变后,在字符串中的位置也要做相应改变,
 * 因为文本的添加,删减,都需要以光标当前所在位置对应的字符为基础。
 * 返回值:文本图层中对应字体位图的坐标,单位为像素
 *  */
{
	LCUI_Pos new_pos, pos;
	Text_RowData *row_ptr;
	LCUI_CharData *char_ptr;
	int i, n, rows, cols, tmp;
	
	pos.x = pos.y = 0;
	rows = Queue_GetTotal( &layer->rows_data );
	/* 减去偏移坐标 */
	pixel_pos = Pos_Sub( pixel_pos, layer->offset_pos );
	for( new_pos.y=0,i=0; i<rows; ++i ) {
		row_ptr = Queue_Get( &layer->rows_data, i );
		if( pixel_pos.y >= row_ptr->max_size.h ) {
			pixel_pos.y -= row_ptr->max_size.h; 
			if(i < rows-1 ) {
				new_pos.y += row_ptr->max_size.h; 
				continue;
			}
		}
		break;
	}
	pos.y = i;
	row_ptr = Queue_Get( &layer->rows_data, i );
	if( !row_ptr ) {
		cols = 0;
	} else {
		cols = Queue_GetTotal( &row_ptr->string );
	}
	for( new_pos.x=0,n=0; n<cols; ++n ) {
		char_ptr = Queue_Get( &row_ptr->string, n );
		if( !char_ptr ) {
			continue;
		}
		tmp = char_ptr->bitmap->advance.x;
		if( pixel_pos.x >= tmp/2 ) {
			pixel_pos.x -= tmp;
			new_pos.x += tmp;
			if(n < cols-1 || (n == cols-1 && pixel_pos.x >= 0)) {
				continue;
			}
		}
		break;
	}
	pos.x = n;
	/* 判断光标位置变化,以快速确定当前字符在源文本中的位置并更新 */
	if( layer->current_des_pos.y > pos.y 
	 || (layer->current_des_pos.y == pos.y 
	 && layer->current_des_pos.x > pos.x)) {
		layer->current_des_pos = pos;
		 /* 优先向左边遍历 */
		TextLayer_Update_CurSrcPos( layer, 0 );
	} 
	else if( layer->current_des_pos.y == pos.y 
		&& layer->current_des_pos.x == pos.x );
	else { 
		layer->current_des_pos = pos;
		/* 优先向右边遍历 */
		TextLayer_Update_CurSrcPos( layer, 1 );
	}
	/* 加上偏移坐标 */
	new_pos = Pos_Add( new_pos, layer->offset_pos );
	return new_pos;
}