예제 #1
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 );
}
예제 #2
0
TextLayer_Cursor_GetPixelPos( LCUI_TextLayer *layer )
/* 获取文本图层的光标相对于容器位置,单位为像素 */
{
	LCUI_Pos pos;
	pos = TextLayer_Cursor_GetFixedPixelPos( layer );
	/* 加上偏移坐标 */
	pos = Pos_Add( pos, layer->offset_pos );
	return pos;
}
예제 #3
0
Frames_GetFrameMixPos(LCUI_Frames *stream, LCUI_Frame *frame)
/* 功能:获取指定帧在整个动画容器中的位置 */
{
	LCUI_Pos pos;
	pos = Align_Get_Pos(	stream->size, 
				Graph_GetSize(frame->pic), 
				ALIGN_MIDDLE_CENTER );
	return Pos_Add(pos, frame->offset);
}
예제 #4
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 );
	}
}
예제 #5
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 );
	}
}
예제 #6
0
TextLayer_Cursor_SetPos( LCUI_TextLayer *layer, LCUI_Pos pos )
/* 设定光标在文本框中的位置,并返回该光标的坐标,单位为像素 */
{
	LCUI_Pos pixel_pos;
	Text_RowData *row_ptr;
	LCUI_CharData *char_ptr;
	int rows, cols, total;
	
	pixel_pos.x = pixel_pos.y = 0;
	total = Queue_GetTotal( &layer->rows_data );
	if( pos.y >= total ) {
		pos.y = total-1;
	}
	if( pos.y < 0 ) {
		pos.y = 0;
	}
	/* 累加pos.y行之前几行的高度 */
	for( pixel_pos.y=0,rows=0; rows<pos.y; ++rows ) {
		row_ptr = Queue_Get( &layer->rows_data, rows );
		if( !row_ptr ) {
			continue;
		}
		pixel_pos.y += row_ptr->max_size.h;
	}
	/* 获取当前行的指针 */
	row_ptr = Queue_Get( &layer->rows_data, rows );
	if( !row_ptr ) {
		return pixel_pos;
	}
	/* 获取当前行的文字数 */
	total = Queue_GetTotal( &row_ptr->string ); 
	if( pos.x > total ) {
		pos.x = total;
	}
	if( pos.x < 0 ) {
		pos.x = 0;
	}
	/* 累计宽度 */
	for( pixel_pos.x=0,cols=0; cols<pos.x; ++cols ) {
		char_ptr = Queue_Get( &row_ptr->string, cols );
		if( !char_ptr ) {
			continue;
		}
		pixel_pos.x += char_ptr->bitmap->advance.x;
		//printf("TextLayer_Cursor_SetPos(): pixel pos x: %d, total: %d, cols: %d, pos.x: %d\n", 
		//pixel_pos.x, total, cols, pos.x);
	}
	//printf("layer->current_des_pos: %d,%d,  pos: %d,%d\n",
	//layer->current_des_pos.x, layer->current_des_pos.y, pos.x, pos.y );
	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 );
	}
	layer->current_des_pos = pos;
	/* 加上偏移坐标 */
	pixel_pos = Pos_Add( pixel_pos, layer->offset_pos );
	/* 微调位置 */
	pixel_pos.y += 2;
	return pixel_pos;
}
예제 #7
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;
}