Exemplo n.º 1
0
TextLayer_Cursor_GetPixelPos( LCUI_TextLayer *layer )
/* 获取文本图层的光标相对于容器位置,单位为像素 */
{
	LCUI_Pos pos;
	pos = TextLayer_Cursor_GetFixedPixelPos( layer );
	/* 加上偏移坐标 */
	pos = Pos_Add( pos, layer->offset_pos );
	return pos;
}
Exemplo n.º 2
0
TextBox_ViewArea_Update( LCUI_Widget *widget )
/* 更新文本框的文本显示区域 */
{
	static int cursor_h;
	static ScrollBar_Data scrollbar_data;
	static LCUI_Pos cursor_pos, area_pos;
	static LCUI_Size layer_size, area_size;
	static LCUI_Widget *scrollbar[2];
	static LCUI_TextLayer *layer;
	//_DEBUG_MSG("enter\n");
	/* 获取显示区域的尺寸 */
	area_size = Widget_GetContainerSize( widget );
	/* 获取滚动条 */
	scrollbar[0] = TextBox_GetScrollbar( widget, 0 );
	scrollbar[1] = TextBox_GetScrollbar( widget, 1 );
	/* 如果滚动条可见,那么区域尺寸就需要减去滚动条占用的尺寸 */
	if( scrollbar[0]->visible ) {
		area_size.w -= Widget_GetWidth( scrollbar[0] );
	}
	if( scrollbar[1]->visible ) {
		area_size.h -= Widget_GetHeight( scrollbar[1] );
	}
	
	if( area_size.h <= 0 || area_size.w <= 0 ) {
		return -1;
	}
	
	layer = TextBox_GetTextLayer( widget );
	layer_size = TextLayer_GetSize( layer );
	if( layer_size.h <= 0 || layer_size.w <= 0 ) {
		return -2;
	}
	/* 获取显示区域的位置 */
	area_pos = TextBox_ViewArea_GetPos( widget );
	/* 获取光标的坐标 */
	cursor_pos = TextLayer_Cursor_GetFixedPixelPos( layer );
	/* 获取当前行的最大高度作为光标的高度 */
	cursor_h = TextLayer_CurRow_GetMaxHeight( layer );
	
	/* 设定滚动条的数据中的最大值 */
	ScrollBar_SetMaxNum( scrollbar[0], layer_size.h - area_size.h );
	
	//_DEBUG_MSG("cursor_pos: %d,%d\n", cursor_pos.x, cursor_pos.y);
	//_DEBUG_MSG("area_rect: %d,%d,%d,%d\n", 
	//	area_pos.x, area_pos.y,area_size.w, area_size.h );
	//_DEBUG_MSG("layer_size: %d,%d\n", layer_size.w, layer_size.h);
	
	/* 检测光标Y轴坐标是否超出显示区域的范围 */
	if( cursor_pos.y < area_pos.y ) {
		area_pos.y = cursor_pos.y;
	}
	if(cursor_pos.y + cursor_h > area_pos.y + area_size.h ) {
		area_pos.y = cursor_pos.y + cursor_h - area_size.h;
	}
	/* 如果显示区域在Y轴上超过文本图层的范围 */
	if( area_pos.y + area_size.h > layer_size.h ) {
		area_pos.y = layer_size.h - area_size.h;
	}
	if( area_pos.y < 0 ) {
		area_pos.y = 0;
	}
	/* 设定滚动条的数据中的当前值 */
	ScrollBar_SetCurrentValue( scrollbar[0], area_pos.y );
	/* 获取滚动条的数据,供滚动文本层利用 */
	scrollbar_data = ScrollBar_GetData( scrollbar[0] );
	
	//_DEBUG_MSG("scrollbar_data: size: %d / %d, num: %d / %d\n", 
	//scrollbar_data.current_size, scrollbar_data.max_size, 
	//scrollbar_data.current_num, scrollbar_data.max_num);
	/* 根据数据,滚动文本图层至响应的位置,也就是移动文本显示区域 */
	TextBox_TextLayer_VertScroll( scrollbar_data, widget );
	
	/* 设定滚动条的数据中的最大值 */
	ScrollBar_SetMaxNum( scrollbar[1], layer_size.w - area_size.w );
	
	if( cursor_pos.x < area_pos.x ) {
		area_pos.x = cursor_pos.x;
	}
	if(cursor_pos.x +5 > area_pos.x + area_size.w ) {
		area_pos.x = cursor_pos.x+5 - area_size.w;
	}
	if( area_pos.x + area_size.w > layer_size.w ) {
		area_pos.x = layer_size.w - area_size.w;
	}
	if( area_pos.x < 0 ) {
		area_pos.x = 0;
	}
	/* 设定滚动条的数据中的当前值 */
	ScrollBar_SetCurrentValue( scrollbar[1], area_pos.x );
	/* 获取滚动条的数据,供滚动文本层利用 */
	scrollbar_data = ScrollBar_GetData( scrollbar[1] );
	
	//_DEBUG_MSG("scrollbar_data: size: %d / %d, num: %d / %d\n", 
	//scrollbar_data.current_size, scrollbar_data.max_size, 
	//scrollbar_data.current_num, scrollbar_data.max_num);
	TextBox_HoriScroll_TextLayer( scrollbar_data, widget );
	//_DEBUG_MSG("quit\n");
	return 0;
}