コード例 #1
0
TextLayer_Draw( LCUI_Widget *widget, LCUI_TextLayer *layer, int mode )
/* 将文本图层绘制到目标部件的图层上 */
{
	LCUI_Rect area;
	LCUI_Pos pos, mix_pos;
	LCUI_BOOL draw_all = FALSE, redraw_row;
	int i, j, n, rows, size;
	LCUI_RGB color;
	LCUI_Graph slot, *graph;
	LCUI_CharData *p_data;
	Text_RowData *p_row;
	
	//clock_t start;
	//start = clock();
	//_DEBUG_MSG("enter\n");
	
	graph = Widget_GetSelfGraph( widget );
	/* 如果文本缓存区内有数据 */
	if( layer->need_proc_buff ) {
		__TextLayer_Text( layer );
		layer->need_proc_buff = FALSE;
	}
	/* 如果需要滚动图层 */
	if( layer->need_scroll_layer ) {
		layer->need_scroll_layer = FALSE;
		//_DEBUG_MSG("layer->need_scroll_layer\n");
		/* 根据之前记录的偏移坐标,刷新文本图层 */
		__TextLayer_OldArea_Erase( layer, Widget_GetSelfGraph( widget ) );
		draw_all = TRUE;
	}
	
	//_DEBUG_MSG("1, use time: %ld\n", clock() - start );
	//start = clock();
	
	Graph_Init( &slot );
	/* 先处理需要清空的区域 */
	n = Queue_GetTotal( &layer->clear_area ); 
	for(i=0; i<n; ++i) { 
		RectQueue_Get( &area, 0 , &layer->clear_area ); 
		area.x += layer->offset_pos.x;
		area.y += layer->offset_pos.y;
		Queue_Delete( &layer->clear_area, 0 );
		Graph_Quote( &slot, graph, area );
		/* 将该区域的alpha通道填充为0 */
		Graph_FillAlpha( &slot, 0 );
		Widget_InvalidArea( widget, area ); 
		//printf("refresh area: %d,%d,%d,%d\n",
		//area.x, area.y, area.width, area.height);
	}
	//_DEBUG_MSG("2, use time: %ld\n", clock() - start );
	//start = clock();
	/* 开始绘制文本位图至目标图层上 */
	rows = Queue_GetTotal( &layer->rows_data ); 
	for(pos.y=layer->offset_pos.y,i=0; i<rows; ++i) {
		redraw_row = FALSE;
		p_row = Queue_Get( &layer->rows_data, i );
		if( !p_row ) {
			continue;
		}
		n = Queue_GetTotal( &p_row->string );
		/* 如果当前字的位图的Y轴跨距不在有效绘制区域内 */
		if( pos.y + p_row->max_size.h <= 0 ) {
			pos.y += p_row->max_size.h;
			continue;
		}
		for(pos.x=layer->offset_pos.x,j=0; j<n; ++j) {
			/* 如果设置了屏蔽符 */
			p_data = Queue_Get( &p_row->string, j ); 
			if( !p_data ) {
				continue;
			}
			
			if( layer->password_char.char_code > 0 ) {
				layer->password_char.need_update = p_data->need_update;
				p_data = &layer->password_char;
			}
			/* 如果当前字的位图的X轴跨距不在有效绘制区域内 */
			if( pos.x + p_data->bitmap->advance.x <= 0) {
				pos.x += p_data->bitmap->advance.x;
				continue;
			}
			/* 获取该字体位图的大致尺寸 */
			if( p_data->data ) {
				size = p_data->data->pixel_size;
				size += 2;
				color = p_data->data->fore_color;
			} else {
				size = layer->default_data.pixel_size + 2; 
				color = layer->default_data.fore_color;
			}
			/* 如果字体位图已标记更新,则绘制它 */
			if( p_data->need_update || draw_all ) {
				p_data->need_update = FALSE;
				if( !redraw_row ) {
					area.x = pos.x;
					area.height = p_row->max_size.h;
					redraw_row = TRUE;
				}
				mix_pos.x = pos.x + p_data->bitmap->left;
				mix_pos.y = pos.y + p_row->max_size.h-1;
				mix_pos.y -= p_data->bitmap->top;
				/* 贴上字体位图 */
				FontBMP_Mix( graph, mix_pos,
					p_data->bitmap, color, mode );
			}
			pos.x += p_data->bitmap->advance.x;
			if( pos.x > widget->size.w ) {
				break;
			}
		}
		if(redraw_row) {
			area.y = pos.y;
			area.width = pos.x - area.x;
			//_DEBUG_MSG("area:%d,%d,%d,%d\n", 
			//area.x, area.y, area.width, area.height);
			Widget_InvalidArea( widget, area );
		}
		pos.y += p_row->max_size.h;
		if( pos.y > widget->size.h ) {
			break;
		}
	}
	//_DEBUG_MSG("3, use time: %ld\n", clock() - start );
	//_DEBUG_MSG("quit\n");
}
コード例 #2
0
ファイル: picturebox.c プロジェクト: fshunj/LCUI
/* 在PictureBox部件更新时进行附加处理 */
static void 
PictureBox_ExecUpdate(LCUI_Widget *widget)
{
	LCUI_Pos pos;
	LCUI_PictureBox *pic_box;
	LCUI_Graph graph, *widget_graph, *p;
	
	pos = Pos(0,0);
	Graph_Init(&graph);
	pic_box  = (LCUI_PictureBox*)Widget_GetPrivData(widget);
	widget_graph = Widget_GetSelfGraph( widget );
	//print_widget_info(widget);
	//Graph_PrintInfo(widget_graph);
	//Graph_PrintInfo(pic_box->image);
	//printf("PictureBox_ExecUpdate(): 1\n");
	if(! Graph_IsValid(pic_box->image)) {
		return;
	}
	
	//printf("PictureBox_ExecUpdate(): widget size: w: %d, h: %d\n", widget->size.w, widget->size.h);
	//printf("PictureBox_ExecUpdate(): read box: %d,%d,%d,%d\n",
		//pic_box->read_box.x, pic_box->read_box.y, 
		//pic_box->read_box.width, pic_box->read_box.height);
	switch(pic_box->size_mode) {
	case SIZE_MODE_BLOCK_ZOOM:
	case SIZE_MODE_ZOOM:
	/* 裁剪图像 */ 
		if(pic_box->scale == 1.00) p = pic_box->image; 
		else p = &pic_box->buff_graph; 
		if(! Graph_IsValid(p)) {
			//printf("! Graph_IsValid(p)\n");
			return;
		}
		
		pos.x = (widget->size.w - pic_box->read_box.width)/2.0;
		pos.y = (widget->size.h - pic_box->read_box.height)/2.0;
		/* 引用图像中指定区域的图形 */
		Graph_Quote(&graph, p, pic_box->read_box);
		break;
		 
	case SIZE_MODE_NORMAL:/* 正常模式 */
		Graph_Quote(&graph, pic_box->image, pic_box->read_box); 
		break;
		
	case SIZE_MODE_STRETCH:/* 拉伸模式 */ 
		/* 开始缩放图片 */
		Graph_Zoom( pic_box->image, &graph, FALSE, widget->size ); 
		break;
		
	case SIZE_MODE_TILE:/* 平铺模式 */ 
		Graph_Tile( pic_box->image, &graph, TRUE );
		break;
		
	case SIZE_MODE_CENTER:
		/* 判断图像的尺寸是否小于图片盒子的尺寸,并计算坐标位置 */
		if(pic_box->image->w < widget->size.w) {
			pic_box->read_box.x = 0;
			pic_box->read_box.width = pic_box->image->w;
			pos.x = (widget->size.w - pic_box->image->w)/2 + 0.5;
		}
		if(pic_box->image->h < widget->size.h) {
			pos.y = (widget->size.h - pic_box->image->h)/2 + 0.5;
			pic_box->read_box.y = 0;
			pic_box->read_box.height = pic_box->image->h;
		}
		if(pic_box->read_box.y + pic_box->read_box.height >= pic_box->image->h) 
		/* 如果读取区域的尺寸大于图片尺寸 */
			pic_box->read_box.y = pic_box->image->h - pic_box->read_box.height;
		if(pic_box->read_box.x + pic_box->read_box.width >= pic_box->image->w) 
			pic_box->read_box.x = pic_box->image->w - pic_box->read_box.width;
			
		Graph_Quote(&graph, pic_box->image, pic_box->read_box); 
		break;
	default : break;
	}
	// 用于调试
	//printf("PictureBox_ExecUpdate(): read box: %d,%d,%d,%d; %d/%d, %d/%d\n", 
	//pic_box->read_box.x, pic_box->read_box.y, 
	//pic_box->read_box.width, pic_box->read_box.height, 
	//pic_box->read_box.x + pic_box->read_box.width, pic_box->buff_graph.w, 
	//pic_box->read_box.y + pic_box->read_box.height, pic_box->buff_graph.h);
	if(!Graph_IsValid(&widget->background.image)) {
		Graph_Replace( widget_graph, &graph, pos );
	} else {
		Graph_Mix( widget_graph, &graph, pos );
	}
	Graph_Free(&graph);
	//printf("scale: %.4f\n", pic_box->scale);
	//printf("PictureBox_ExecUpdate(): end\n");
	Widget_Refresh(widget); 
}
コード例 #3
0
ファイル: window.c プロジェクト: gateslu/LCUI
static void
Window_ExecUpdate( LCUI_Widget *win_p )
{
	LCUI_Size size;
	LCUI_Graph *graph;
	LCUI_Border border;
	LCUI_Widget *titlebar, *btn, *client_area;
	LCUI_RGB border_color, back_color;
	
	btn = Window_GetCloseButton(win_p);
	titlebar = Window_GetTitleBar(win_p);
	client_area = Window_GetClientArea(win_p);
	graph = Widget_GetSelfGraph( win_p );
	/* 按不同的风格来处理 */ 
	switch( win_p->style_id ) {
	    case WINDOW_STYLE_NONE:  /* 没有边框 */
		/* 先计算坐标和尺寸 */
		Widget_SetDock( client_area, DOCK_TYPE_FILL );
		Widget_Hide( titlebar );/* 隐藏标题栏 */
		Widget_Show( client_area );/* 客户区需要显示 */
		break;
			
	    case WINDOW_STYLE_LINE: /* 线条边框 */
		Widget_SetBorder(win_p,
		 Border(1, BORDER_STYLE_SOLID, RGB(50,50,50)));
		Widget_SetPadding( win_p, Padding(1,1,1,1) );
		Widget_SetDock( client_area, DOCK_TYPE_FILL );
		Widget_Hide( titlebar );
		Widget_Show( client_area );
		break;

	    case WINDOW_STYLE_PURE_BLUE: 
		back_color = RGB(30,160,225); 
		border_color = RGB(0,130,195);
		goto union_draw_method;
	    case WINDOW_STYLE_PURE_GREEN:
		back_color = RGB(140,190,40);
		border_color = RGB(110,160,10);
		goto union_draw_method;
	    case WINDOW_STYLE_PURE_RED: 
		back_color = RGB(230,20,0);
		border_color = RGB(200,0,0);
		goto union_draw_method;
	    case WINDOW_STYLE_PURE_ORANGE: 
		back_color = RGB(240,150,10);
		border_color = RGB(210,120,0); 
		goto union_draw_method;
	    case WINDOW_STYLE_PURE_PURPLE:
		back_color = RGB(110,20,95);
		border_color = RGB(80,0,65); 
union_draw_method:;
		/* 若窗口未获得焦点 */
		if( !Widget_GetFocus( win_p ) ) {
			back_color = RGB(235,235,235);
			border_color = RGB(211,211,211);
		}
		/* 更新窗口标题栏上的关闭按钮 */
		Widget_Update( btn );
		border = Border(1, BORDER_STYLE_SOLID, border_color);
		Widget_SetBorder( client_area, border);
		Widget_SetBorder( win_p, border);
		Widget_SetBackgroundColor( win_p, back_color );
		Graph_FillColor( graph, back_color );
		Widget_SetBackgroundColor( client_area, RGB(255,255,255) );
		Widget_SetBackgroundImage( titlebar, NULL );
		Widget_SetBackgroundLayout( titlebar, 0 );
		Widget_SetBackgroundTransparent( titlebar, TRUE );
		Widget_SetBackgroundTransparent( client_area, FALSE );
		Widget_SetPadding( win_p, Padding(1,4,4,4) );
		Widget_SetPadding( client_area, Padding(1,1,1,1) );
		size = Widget_GetContainerSize( win_p );
		Widget_Resize( titlebar, Size(size.h, 25) );
		Widget_Resize( client_area, Size(size.w, size.h - 25) );
		Widget_SetDock( titlebar, DOCK_TYPE_TOP ); 
		Widget_SetDock( client_area, DOCK_TYPE_BOTTOM );
		Widget_Show( titlebar );
		Widget_Show( client_area ); 
		break;
	    default:
			//
		break;
	}
}