Example #1
0
static void Exec_Update_PictureBox(LCUI_Widget *widget)
/* 功能:更新PictureBox部件 */
{
    LCUI_Pos pos;
    LCUI_PictureBox *pic_box;
    LCUI_Graph graph, *p;
    //printf("Exec_Update_PictureBox(): start\n");
    pos = Pos(0,0);
    Graph_Init(&graph);
    pic_box  = (LCUI_PictureBox*)Get_Widget_PrivData(widget);

    //print_widget_info(widget);
    //Print_Graph_Info(&widget->graph);
    //Print_Graph_Info(pic_box->image);
    //printf("Exec_Update_PictureBox(): 1\n");
    if(! Graph_Valid(pic_box->image)) return;

    //printf("Exec_Update_PictureBox(): widget size: w: %d, h: %d\n", widget->size.w, widget->size.h);
    //printf("Exec_Update_PictureBox(): 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_Valid(p)) {
            //printf("! Graph_Valid(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;
        /* 引用图像中指定区域的图形 */
        Quote_Graph(&graph, p, pic_box->read_box);
        break;

    case SIZE_MODE_NORMAL:/* 正常模式 */
        Quote_Graph(&graph, pic_box->image, pic_box->read_box);
        break;

    case SIZE_MODE_STRETCH:/* 拉伸模式 */
        /* 开始缩放图片 */
        Graph_Zoom( pic_box->image, &graph, CUSTOM, widget->size );
        break;

    case SIZE_MODE_TILE:/* 平铺模式 */
        Graph_Tile( pic_box->image, &graph, widget->size.w, widget->size.h);
        break;

    case SIZE_MODE_CENTER:
        /* 判断图像的尺寸是否小于图片盒子的尺寸,并计算坐标位置 */
        if(pic_box->image->width < widget->size.w) {
            pic_box->read_box.x = 0;
            pic_box->read_box.width = pic_box->image->width;
            pos.x = (widget->size.w - pic_box->image->width)/2 + 0.5;
        }
        if(pic_box->image->height < widget->size.h) {
            pos.y = (widget->size.h - pic_box->image->height)/2 + 0.5;
            pic_box->read_box.y = 0;
            pic_box->read_box.height = pic_box->image->height;
        }
        if(pic_box->read_box.y + pic_box->read_box.height >= pic_box->image->height)
            /* 如果读取区域的尺寸大于图片尺寸 */
            pic_box->read_box.y = pic_box->image->height - pic_box->read_box.height;
        if(pic_box->read_box.x + pic_box->read_box.width >= pic_box->image->width)
            pic_box->read_box.x = pic_box->image->width - pic_box->read_box.width;

        Quote_Graph(&graph, pic_box->image, pic_box->read_box);
        break;
    default :
        break;
    }
    // 用于调试
    //printf("Exec_Update_PictureBox(): 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.width,
    //pic_box->read_box.y + pic_box->read_box.height, pic_box->buff_graph.height);
    if(!Graph_Valid(&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("Exec_Update_PictureBox(): end\n");
    Refresh_Widget(widget);
}
Example #2
0
void 
TextLayer_Draw( LCUI_Widget *widget, LCUI_TextLayer *layer, int mode )
/* 将文本图层绘制到目标部件的图层上 */
{
	LCUI_Rect area;
	LCUI_Pos pos;
	BOOL draw_all = FALSE;
	int i, j, n, rows, size;
	LCUI_RGB color;
	LCUI_Graph slot;
	LCUI_CharData *p_data;
	Text_RowData *p_row;
	
	//clock_t start;
	//start = clock();
	//printf("TextLayer_Draw(): enter\n");
	/* 如果文本缓存区内有数据 */
	if( layer->need_proc_buff ) {
		__TextLayer_Text( layer );
		layer->need_proc_buff = FALSE;
	}
	/* 如果需要滚动图层 */
	if( layer->need_scroll_layer ) {
		/* 根据之前记录的偏移坐标,刷新文本图层 */
		__TextLayer_OldArea_Erase( widget, layer );
		draw_all = TRUE;
		layer->need_scroll_layer = FALSE;
	}
	
	//nobuff_printf("1, use time: %ld\n", clock() - start );
	//start = clock();
	
	Graph_Init( &slot );
	/* 先处理需要清空的区域 */
	n = Queue_Get_Total( &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 );
		Quote_Graph( &slot, &widget->graph, area );
		/* 将该区域的alpha通道填充为0 */
		Graph_Fill_Alpha( &slot, 0 );
		Add_Widget_Refresh_Area( widget, area ); 
		//printf("refresh area: %d,%d,%d,%d\n",
		//area.x, area.y, area.width, area.height);
	}
	//nobuff_printf("2, use time: %ld\n", clock() - start );
	//start = clock();
	/* 开始绘制文本位图至目标图层上 */
	rows = Queue_Get_Total( &layer->rows_data ); 
	for(pos.y=layer->offset_pos.y,i=0; i<rows; ++i) {
		p_row = Queue_Get( &layer->rows_data, i );
		if( !p_row ) {
			continue;
		}
		n = Queue_Get_Total( &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 ) { 
			//nobuff_printf("get, pos: %d, char_ptr: %p, char: %c, draw\n", 
			//	i, p_data, p_data->char_code ); 
				p_data->need_update = FALSE;
				/* 计算区域范围 */
				area.x = pos.x + p_data->bitmap.left;
				area.y = pos.y + p_row->max_size.h-1;
				area.y -= p_data->bitmap.top;
				area.height = p_data->bitmap.rows;
				area.width = p_data->bitmap.width;
				/* 贴上字体位图 */
				FontBMP_Mix( &widget->graph, Pos(area.x, area.y),
					&p_data->bitmap, color, mode );
				/* 记录该区域,以刷新显示到屏幕上 */
				Add_Widget_Refresh_Area( widget, area );
			}
			pos.x += p_data->bitmap.advance.x;
			if( pos.x > widget->size.w ) {
				break;
			}
		}
		pos.y += p_row->max_size.h;
		if( pos.y > widget->size.h ) {
			break;
		}
	}
	//nobuff_printf("3, use time: %ld\n", clock() - start );
	//printf("TextLayer_Draw(): quit\n");
}
Example #3
0
void 
TextLayer_Draw( LCUI_Widget *widget, LCUI_TextLayer *layer, int mode )
/* 绘制文本图层 */
{
	LCUI_Rect area;
	LCUI_Pos pos;
	int i, j, n, rows, size;
	LCUI_RGB color;
	LCUI_Graph slot;
	LCUI_CharData *p_data;
	Text_RowData *p_row;
	
	Graph_Init( &slot );
	
	n = Queue_Get_Total( &layer->clear_area ); 
	for(i=0; i<n; ++i) { 
		RectQueue_Get( &area, 0 , &layer->clear_area ); 
		Queue_Delete( &layer->clear_area, 0 ); 
		Quote_Graph( &slot, &widget->graph, area );
		/* 将该区域的alpha通道填充为0 */
		Graph_Fill_Alpha( &slot, 0 ); 
		Add_Widget_Refresh_Area( widget, area ); 
	} 
	
	/* 开始粘贴文本位图 */
	rows = Queue_Get_Total( &layer->rows_data ); 
	for(pos.y=0,i=0; i<rows; ++i) {
		p_row = Queue_Get( &layer->rows_data, i );
		n = Queue_Get_Total( &p_row->string ); 
		pos.x = 0;
		//
		//if( p_row->pos.y != pos.y ) { 
		//	RectQueue_Add( &layer->clear_area, Rect(pos.x, pos.y, 
		//		p_row->max_size.w, p_row->max_size.h) );
		//	p_row->pos.y = pos.y;
		//} 
		for(j=0; j<n; ++j) {
			p_data = Queue_Get( &p_row->string, j ); 
			if( p_data->data != NULL ) {
				//if( p_data->data->pixel_size > 0 ) {
					size = p_data->data->pixel_size;
				//} else { 
				//	size = layer->default_data.pixel_size;
				//}
				size += 2;
				
				//if( p_data->data->_fore_color ) {
					color = p_data->data->fore_color;
				//} else {
				//	color = layer->default_data.fore_color;
				//}
			} else {
				size = layer->default_data.pixel_size + 2; 
				color = layer->default_data.fore_color;
			}
			pos.x += p_data->bitmap.left;
			if( p_data->need_update ) {
				p_data->need_update = FALSE; 
				area = Rect(pos.x, pos.y, size, size);
				/* 贴上字体位图 */
				FontBMP_Mix( &widget->graph, Pos( pos.x, 
					pos.y + p_row->max_size.h-1 - p_data->bitmap.top),
					&p_data->bitmap, color, mode );
				Add_Widget_Refresh_Area( widget, area );  
			}
			pos.x += p_data->bitmap.width;
		}
		pos.y += p_row->max_size.h;
	}
}
Example #4
0
static void
__TextLayer_OldArea_Erase( LCUI_Widget *widget, LCUI_TextLayer *layer )
/* 
 * 功能:擦除文本图层的老区域
 * 说明:根据记录的旧偏移坐标,刷新部件区域内的文字所在区域。
 *  */
{
	static int i, j, x, y, rows, len;
	static LCUI_Graph slot;
	static Text_RowData *row_ptr;
	static LCUI_CharData *char_ptr;
	static LCUI_Rect area;
	
	Graph_Init( &slot );
	rows = Queue_Get_Total( &layer->rows_data );
	for(y=layer->old_offset_pos.y,i=0; y<0 && i<rows; ++i) {
		row_ptr = Queue_Get( &layer->rows_data, i );
		if( !row_ptr ) {
			continue;
		}
		if( y + row_ptr->max_size.h >= 0 ) {
			break;
		}
		y += row_ptr->max_size.h;
	}
	for(; i<rows; ++i) {
		row_ptr = Queue_Get( &layer->rows_data, i );
		if( !row_ptr ) {
			continue;
		}
		len = Queue_Get_Total( &row_ptr->string );
		for(x=layer->old_offset_pos.x,j=0; x<0 && j<len; ++j) {
			char_ptr = Queue_Get( &row_ptr->string, j );
			if( !char_ptr ) {
				continue;
			}
			if( x+char_ptr->bitmap.advance.x >= 0 ) {
				break;
			}
			x += char_ptr->bitmap.advance.x;
		}
		
		area.height = layer->default_data.pixel_size+2;
		for( ; j<len; ++j ) {
			char_ptr = Queue_Get( &row_ptr->string, j );
			if( !char_ptr ) {
				continue;
			}
			area.y = row_ptr->max_size.h-1;
			area.y -= char_ptr->bitmap.top;
			if( area.y + char_ptr->bitmap.rows > area.height ) {
				area.height = area.y + char_ptr->bitmap.rows;
			}
			x += char_ptr->bitmap.advance.x;
			if( x > widget->size.w ) {
				break;
			}
		}
		area.x = 0;
		area.y = y;
		area.width = x;
		/* 引用部件图层中的区域 */
		Quote_Graph( &slot, &widget->graph, area );
		/* 将该区域的alpha通道填充为0 */
		Graph_Fill_Alpha( &slot, 0 );
		//printf("area: %d,%d,%d,%d\n", area.x, area.y, area.width, area.height);
		/* 添加刷新区域 */
		Add_Widget_Refresh_Area( widget, area );
		y += row_ptr->max_size.h;
		if( y > widget->size.h ) {
			break;
		}
	}
}