Exemplo n.º 1
0
/* 缩放PictureBox部件的图片浏览区域 */
LCUI_API int
PictureBox_ZoomViewArea( LCUI_Widget *widget, double scale )
{
	LCUI_Graph buff, temp;
	LCUI_PictureBox *pic_box;
	
	pic_box = Widget_GetPrivData(widget);
	if(!Graph_IsValid(pic_box->image)) {
		return -1;
	}
	Graph_Init(&buff);
	Graph_Init(&temp);
	/* 有效范围为2%~2000% */
	if(scale < 0.02) {
		scale = 0.02;
	}
	if(scale > 20) {
		scale = 20;
	}
	if(pic_box->size_mode != SIZE_MODE_ZOOM
	 && pic_box->size_mode != SIZE_MODE_BLOCK_ZOOM) {
		pic_box->size_mode = SIZE_MODE_ZOOM; /* 改为缩放模式 */
	}
	pic_box->scale = scale; 
	Update_BuffGraph(widget); 
	Update_ReadBox(widget);
	Widget_Draw(widget);
	Widget_Refresh(widget);
	return 0;
}
Exemplo n.º 2
0
static void 
ActiveBox_RefreshFrame(LCUI_Graph *frame, void *arg)
/* 功能:刷新动画当前帧的显示 */
{
	LCUI_Widget *widget = (LCUI_Widget*)arg;
	Widget_Draw(widget); 
}
Exemplo n.º 3
0
/* 设定复选框为未选中状态 */
LCUI_API void
CheckBox_SetOff( LCUI_Widget *widget )
{
	LCUI_CheckBox *check_box;
	check_box = Widget_GetPrivData(widget); 
	check_box->on = FALSE;
	Widget_Draw( widget );
}
Exemplo n.º 4
0
/* 设定单选框为未选中状态 */
LCUI_API void
RadioButton_SetOff( LCUI_Widget widget )
{
	LCUI_RadioButton *radio_button;
	radio_button = Widget_GetPrivData(widget); 
	radio_button->on = FALSE;
	Widget_Draw(widget);
}
Exemplo n.º 5
0
static void
_putout_textbox_cursor( LCUI_Widget *widget, LCUI_WidgetEvent *unused )
{
	LCUI_TextBox *tb;
	
	if( widget == active_textbox ) {
		active_textbox = NULL;
	}
	tb = Widget_GetPrivData( widget );
	Widget_Hide( tb->cursor );
	Widget_Draw( widget );
}
Exemplo n.º 6
0
/* 移动PictureBox部件内的图片的显示区域的位置 */
LCUI_API int
PictureBox_MoveViewArea( LCUI_Widget *widget, LCUI_Pos des_pos )
{
	LCUI_Size size;
	LCUI_Graph *p;
	LCUI_PictureBox *pic_box;
	
	pic_box = Widget_GetPrivData(widget);
	
	if(!Graph_IsValid(pic_box->image)) {
		return -1;
	}
	if(pic_box->scale == 1.00 || !Graph_IsValid(&pic_box->buff_graph)) {
		p = pic_box->image;
	} else {
		p = &pic_box->buff_graph;
	}
	size.w = pic_box->read_box.width;
	size.h = pic_box->read_box.height;
	/* 处理区域数据,使之为有效区域 */
	if(des_pos.x < 0) {
		des_pos.x = 0;
	}
	if(des_pos.y < 0) {
		des_pos.y = 0;
	}
	if(des_pos.x + size.w > p->w) {
		des_pos.x = p->w - size.w;
	}
	if(des_pos.y + size.h > p->h) {
		des_pos.y = p->h - size.h;
	}
	if(des_pos.x == pic_box->read_box.x 
	&& des_pos.y == pic_box->read_box.y) {
		return 0; 
	}
	/* 更新图片盒子内的图像 */
	pic_box->read_box.x = des_pos.x;
	pic_box->read_box.y = des_pos.y;
	/* 重新计算中心点的位置 */ 
	pic_box->read_box.center_x = (des_pos.x + size.w/2.0)/p->w;
	pic_box->read_box.center_y = (des_pos.y + size.h/2.0)/p->h;
	
	Widget_Draw(widget);
	//用于调试
	//printf("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->read_box.y + pic_box->read_box.height,
	//pic_box->buff_graph.w, pic_box->buff_graph.h);
	return 0;
}
Exemplo n.º 7
0
/* 设定单选框为选中状态 */
LCUI_API void
RadioButton_SetOn( LCUI_Widget widget )
{
	LCUI_RadioButton *radio_button;
	LCUI_Widget other;
	int i, total;
	
	radio_button = Widget_GetPrivData(widget); 
	/* 如果与其它部件有互斥关系,就将其它单选框部件的状态改为“未选中”状态 */
	if( radio_button->mutex ) {
		total = Queue_GetTotal(radio_button->mutex);
		for(i=0; i<total; ++i) {
			other = (LCUI_Widget*)Queue_Get(radio_button->mutex, i);
			RadioButton_SetOff(other);
		}
	}
	radio_button->on = TRUE;
	Widget_Draw(widget);
}
Exemplo n.º 8
0
/* 设定PictureBox部件的图片显示区域的大小 */
LCUI_API void
PictureBox_ResizeViewArea( LCUI_Widget *widget, int width, int height )
{
	LCUI_Pos start, center_pos;
	LCUI_PictureBox *pic_box;
	
	pic_box = Widget_GetPrivData(widget);
	
	if(width <= 0 || height <= 0) {
		return;
	}
	if(!Graph_IsValid(pic_box->image)) {
		return;
	}
	/* 将中心点位置转换成坐标 */
	center_pos.x = pic_box->read_box.center_x * pic_box->scale * pic_box->image->w;
	center_pos.y = pic_box->read_box.center_y * pic_box->scale * pic_box->image->h;
	/* 处理区域数据,使之为有效区域 */
	start.x = center_pos.x - width/2.0;
	start.y = center_pos.y - height/2.0;
	if(start.x < 0) start.x = 0;
	if(start.y < 0) start.y = 0;
	if(start.x + width > pic_box->image->w)
	start.x = pic_box->image->w - width;
	if(start.y + height > pic_box->image->h)
	start.y = pic_box->image->h - height;
	if(start.x < 0) {
		start.x = 0;
		width = pic_box->image->w;
	}
	if(start.y < 0) {
		start.y = 0;
		height = pic_box->image->h;
	}
	pic_box->read_box.x = start.x;
	pic_box->read_box.y = start.y;
	pic_box->read_box.width = width;
	pic_box->read_box.height = height;
	/* 更新图片盒子内的图像 */
	Widget_Draw(widget);
	Widget_Refresh(widget); 
}
Exemplo n.º 9
0
/* 设定图像显示模式 */
LCUI_API void
PictureBox_SetSizeMode( LCUI_Widget *widget, int mode )
{
	LCUI_Size my_size;
	float scale_x,scale_y;
	LCUI_PictureBox *pic_box;
	
	pic_box = Widget_GetPrivData(widget);
	if(pic_box->size_mode == mode) {
		return;
	}
	
	pic_box->size_mode = mode;
	if( !pic_box->image ) {
		return; 
	}
	my_size = _Widget_GetSize( widget );
	switch(mode) {
	case SIZE_MODE_BLOCK_ZOOM:
	case SIZE_MODE_ZOOM:
		if( my_size.w <= 0 || my_size.h <= 0) {
			pic_box->scale = 1.0; 
		} else {
			scale_x = (float)my_size.w / pic_box->image->w;
			scale_y = (float)my_size.h / pic_box->image->h;
			if(scale_x < scale_y) {
				pic_box->scale = scale_x;
			} else {
				pic_box->scale = scale_y;
			}
		}
		PictureBox_ZoomViewArea(widget, pic_box->scale); 
		break;
	default: pic_box->scale = 1.0; break;
	}
	Widget_Draw(widget);
}
Exemplo n.º 10
0
Arquivo: button.c Projeto: yydaor/LCUI
/* 自定义按钮在各种状态下显示的位图 */
LCUI_API void
Button_CustomStyle(	LCUI_Widget *widget, LCUI_Graph *normal, 
			LCUI_Graph *over, LCUI_Graph *down, 
			LCUI_Graph *focus, LCUI_Graph *disable)
{
	LCUI_Button *btn_data;
	btn_data = Widget_GetPrivData(widget);
	if( Graph_IsValid(normal) ) {
		btn_data->btn_normal = *normal;
	} else {
		Graph_Init( &btn_data->btn_normal );
	}
	if( Graph_IsValid(over) ) {
		btn_data->btn_over = *over;
	} else {
		Graph_Init( &btn_data->btn_over );
	}
	if( Graph_IsValid(down) ) {
		btn_data->btn_down = *down;
	} else {
		Graph_Init( &btn_data->btn_down );
	}
	if( Graph_IsValid(focus) ) {
		btn_data->btn_focus = *focus;
	} else {
		Graph_Init( &btn_data->btn_focus );
	}
	if( Graph_IsValid(disable) ) {
		btn_data->btn_disable = *disable;
	} else {
		Graph_Init( &btn_data->btn_disable );
	}
	/* 设定为自定义风格 */
	Widget_SetStyleID(widget, BUTTON_STYLE_CUSTOM);
	Widget_Draw(widget); /* 重新绘制部件 */
}
Exemplo n.º 11
0
static void
_putin_textbox_cursor( LCUI_Widget *widget, LCUI_WidgetEvent *unused )
{
	active_textbox = widget;
	Widget_Draw( widget );
}
Exemplo n.º 12
0
/* 设定PictureBox部件显示的图像 */
LCUI_API void
PictureBox_SetImage( LCUI_Widget *widget, LCUI_Graph *image )
{ 
	int i;
	float scale_x,scale_y;
	LCUI_Graph *graph; 
	LCUI_PictureBox *pic_box;
	graph_data *data;

	if( widget == NULL ) {
		return;
	}
	graph = image;
	pic_box = Widget_GetPrivData(widget);
	for(i = 0;i < 2; ++i) {
		/* 如果image有效 */ 
		if(Graph_IsValid(graph)) {
			/* 图片更换了,就释放缓存图形 */
			Graph_Free(&pic_box->buff_graph);
			pic_box->image = graph;
			/* 读取的范区域为整个图片区域 */
			pic_box->read_box.x = 0;
			pic_box->read_box.y = 0;
			pic_box->read_box.width = graph->w;
			pic_box->read_box.height = graph->h;
			pic_box->read_box.center_x = 0.5;
			pic_box->read_box.center_y = 0.5;
			pic_box->scale = 1.0; 
			
			//printf("PictureBox_SetImage(): img, w: %d, h: %d\n", graph->w, graph->h);
			//printf("PictureBox_SetImage(): pb: w: %d, h: %d\n", widget->size.w, widget->size.h);
			//printf("PictureBox_SetImage(): size mode: %d\n", pic_box->size_mode);
			switch(pic_box->size_mode) {
			    case SIZE_MODE_BLOCK_ZOOM:
			    case SIZE_MODE_ZOOM: 
			//printf("PictureBox_SetImage(): widget: w: %d, h: %d\n", widget->size.w, widget->size.h);
				if(widget->size.w <= 0 || widget->size.h <= 0) {
					//printf("PictureBox_SetImage(): break\n");
					break;
				}
				scale_x = (float)widget->size.w / pic_box->image->w;
				scale_y = (float)widget->size.h / pic_box->image->h;
				if(scale_x < scale_y) pic_box->scale = scale_x;
				else pic_box->scale = scale_y;
				//printf("PictureBox_SetImage(): scale: %.4f, x: %.4f, y: %.4f\n", 
				//pic_box->scale, scale_x, scale_y);
				PictureBox_ZoomViewArea(widget, pic_box->scale); 
				//printf("PictureBox_SetImage(): 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);
				break;
			/* 正常模式 */
			    case SIZE_MODE_NORMAL: break;
			/* 拉伸模式 */
			    case SIZE_MODE_STRETCH: break;
			/* 平铺模式 */
			    case SIZE_MODE_TILE: break;
			    case SIZE_MODE_CENTER: 
				/* 判断图像的尺寸是否超出图片盒子的尺寸 */
				if(pic_box->image->w >= widget->size.w) {
					pic_box->read_box.x = (pic_box->image->w - widget->size.w)/2.0;
					pic_box->read_box.width = widget->size.w;
				}
				if(pic_box->image->h >= widget->size.h) {
					pic_box->read_box.y = (pic_box->image->h - widget->size.h)/2.0;
					pic_box->read_box.height = widget->size.h;
				}
				break;
				default : break;
			}
			break;
		} else if(pic_box->image_state == IMAGE_STATE_LOADING) {
			/* 使用对应的图片 */ 
			if(Graph_IsValid(&pic_box->initial_image)) { 
				graph = &pic_box->initial_image; 
			} else {
				return;
			}
		}
		else { /* 使用对应的图片 */ 
			if(Graph_IsValid(&pic_box->error_image)) {
				graph = &pic_box->error_image; 
				pic_box->image_state = IMAGE_STATE_FAIL;
			} else {
				return;
			} 
		}
	} 
	/* 如果记录中有该部件,那判断该部件使用的图像是否为同一个,不一样就释放之前的 */
	i = find_widget_data(widget);
	if(i >= 0) {
		data = (graph_data*)Queue_Get(&picbox_graph_mem, i); 
		if(data->image != image) {
			Queue_Delete(&picbox_graph_mem, i);
		}
	}
	Widget_Draw(widget);
}