Ejemplo n.º 1
0
int Set_PictureBox_Image_From_File(LCUI_Widget *widget, char *image_file)
/* 功能:添加一个图片文件,并载入至图片盒子 */
{
    int value;
    graph_data data;
    LCUI_PictureBox *pic_box = (LCUI_PictureBox*)
                               Get_Widget_PrivData(widget);
    LCUI_Graph *graph;

    if(init == IS_FALSE) {
        Queue_Init( &picbox_graph_mem,
                    sizeof(graph_data), destroy_graph_data);
        init = IS_TRUE;
    }
    /* 如果在记录中没找到该部件,那么就分配内存,否则,直接使用那块内存 */
    value = find_widget_data(widget);
    if(value == -1) {
        data.image = (LCUI_Graph*) calloc(1, sizeof(LCUI_Graph));
        data.widget = widget;
        Queue_Add(&picbox_graph_mem, &data);
    } else {
        data = *(graph_data*)Queue_Get(&picbox_graph_mem, value);
    }
    graph = data.image;

    pic_box->image_status = IMAGE_STATUS_LOADING; /* 图片状态为正在载入 */
    Set_PictureBox_Image_From_Graph(widget, NULL);
    value = Load_Image(image_file, graph);/* 载入图片文件 */
    if(value != 0) {
        /* 载入失败 */
        pic_box->image_status = IMAGE_STATUS_FAIL;
        Set_PictureBox_Image_From_Graph(widget, NULL);
    } else {
        /* 载入成功 */
        pic_box->image_status = IMAGE_STATUS_SUCCESS;
        Set_PictureBox_Image_From_Graph(widget, graph);
    }

    return value;
}
Ejemplo n.º 2
0
/* 设定图片文件中的图像为PictureBox部件显示的图像 */
LCUI_API int
PictureBox_SetImageFile( LCUI_Widget *widget, char *image_file )
{
	int ret;
	graph_data data;
	LCUI_PictureBox *pic_box;
	LCUI_Graph *graph;
	
	pic_box = Widget_GetPrivData(widget);
	if( !graph_mem_init ) {
		Queue_Init( &picbox_graph_mem, 
			sizeof(graph_data), destroy_graph_data);
		graph_mem_init = TRUE;
	}
	/* 如果在记录中没找到该部件,那么就分配内存,否则,直接使用那块内存 */
	ret = find_widget_data(widget);
	if(ret == -1) {
		data.image = (LCUI_Graph*) calloc(1, sizeof(LCUI_Graph));
		data.widget = widget;
		Queue_Add(&picbox_graph_mem, &data); 
	} else {
		data = *(graph_data*)Queue_Get(&picbox_graph_mem, ret); 
	}
	graph = data.image;
	
	pic_box->image_state = IMAGE_STATE_LOADING; /* 图片状态为正在载入 */
	PictureBox_SetImage(widget, NULL);
	ret = Graph_LoadImage( image_file, graph );/* 载入图片文件 */
	if( ret == 0 ) {
		/* 载入成功 */
		pic_box->image_state = IMAGE_STATE_SUCCESS; 
		PictureBox_SetImage(widget, graph);
	} else {
		/* 载入失败 */
		pic_box->image_state = IMAGE_STATE_FAIL;
		PictureBox_SetImage(widget, NULL);
	}
	return ret;
}
Ejemplo n.º 3
0
void Set_PictureBox_Image_From_Graph(LCUI_Widget *widget, LCUI_Graph *image)
/* 功能:添加一个图片数据至图片盒子 */
{
    int i;
    float scale_x,scale_y;
    LCUI_Graph *graph = image;
    LCUI_PictureBox *pic_box = (LCUI_PictureBox*)
                               Get_Widget_PrivData(widget);
    for(i = 0; i < 2; ++i) {
        /* 如果image有效 */
        if(Graph_Valid(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->width;
            pic_box->read_box.height = graph->height;
            pic_box->read_box.center_x = 0.5;
            pic_box->read_box.center_y = 0.5;
            pic_box->scale = 1.0;

            //printf("Set_PictureBox_Image_From_Graph(): img, w: %d, h: %d\n", graph->width, graph->height);
            //printf("Set_PictureBox_Image_From_Graph(): pb: w: %d, h: %d\n", widget->size.w, widget->size.h);
            //printf("Set_PictureBox_Image_From_Graph(): size mode: %d\n", pic_box->size_mode);
            switch(pic_box->size_mode) {
            case SIZE_MODE_BLOCK_ZOOM:
            case SIZE_MODE_ZOOM:
                //printf("Set_PictureBox_Image_From_Graph(): widget: w: %d, h: %d\n", widget->size.w, widget->size.h);
                if(widget->size.w <= 0 || widget->size.h <= 0) {
                    //printf("Set_PictureBox_Image_From_Graph(): break\n");
                    break;
                }
                scale_x = (float)widget->size.w / pic_box->image->width;
                scale_y = (float)widget->size.h / pic_box->image->height;
                if(scale_x < scale_y) pic_box->scale = scale_x;
                else pic_box->scale = scale_y;
                //printf("Set_PictureBox_Image_From_Graph(): scale: %.4f, x: %.4f, y: %.4f\n",
                //pic_box->scale, scale_x, scale_y);
                Zoom_PictureBox_View_Area(widget, pic_box->scale);
                //printf("Set_PictureBox_Image_From_Graph(): 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->width >= widget->size.w) {
                    pic_box->read_box.x = (pic_box->image->width - widget->size.w)/2.0;
                    pic_box->read_box.width = widget->size.w;
                }
                if(pic_box->image->height >= widget->size.h) {
                    pic_box->read_box.y = (pic_box->image->height - widget->size.h)/2.0;
                    pic_box->read_box.height = widget->size.h;
                }
                break;
            default :
                break;
            }
            break;
        } else if(pic_box->image_status == IMAGE_STATUS_LOADING) {
            /* 使用对应的图片 */
            if(Graph_Valid(&pic_box->initial_image)) {
                graph = &pic_box->initial_image;
            } else {
                return;
            }
        }
        else { /* 使用对应的图片 */
            if(Graph_Valid(&pic_box->error_image)) {
                graph = &pic_box->error_image;
                pic_box->image_status = IMAGE_STATUS_FAIL;
            } else {
                return;
            }
        }
    }
    /* 如果记录中有该部件,那判断该部件使用的图像是否为同一个,不一样就释放之前的 */
    graph_data *data;
    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);
        }
    }
    Draw_Widget(widget);
}