2012-04-18 23:06:12 +08:00
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>嵥<EFBFBD><EFBFBD>DC<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>container<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾͼ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "demo_view.h"
|
|
|
|
|
#include <rtgui/widgets/button.h>
|
|
|
|
|
#include <rtgui/widgets/filelist_view.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
static rtgui_image_t *image = RT_NULL;
|
|
|
|
|
static rtgui_container_t *_container = RT_NULL;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
|
|
|
|
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
|
|
|
|
|
/* <20><EFBFBD>ť<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD> */
|
2012-08-13 16:32:01 +08:00
|
|
|
|
static void open_btn_onbutton(rtgui_widget_t *widget, struct rtgui_event *event)
|
2012-04-18 23:06:12 +08:00
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_filelist_view_t *filelist;
|
|
|
|
|
struct rtgui_rect rect = {0, 100, 240, 280};
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* WIN32ƽ̨<C6BD>Ϻ<EFBFBD><CFBA><EFBFBD>ʵ<EFBFBD>豸<EFBFBD>ϵij<CFB5>ʼ·<CABC><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
2012-04-18 23:06:12 +08:00
|
|
|
|
#ifdef _WIN32
|
2012-08-13 16:32:01 +08:00
|
|
|
|
filelist = rtgui_filelist_view_create("e:\\", "*.*", &rect);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
#else
|
2012-08-13 16:32:01 +08:00
|
|
|
|
filelist = rtgui_filelist_view_create("/", "*.*", &rect);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
#endif
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* ģ̬<C4A3><CCAC>ʾһ<CABE><D2BB><EFBFBD>ļ<EFBFBD><C4BC>б<EFBFBD><D0B1><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>ṩ<EFBFBD><E1B9A9><EFBFBD>û<EFBFBD>ѡ<EFBFBD><D1A1>ͼ<EFBFBD><CDBC><EFBFBD>ļ<EFBFBD> */
|
|
|
|
|
if (rtgui_widget_show(RTGUI_WIDGET(filelist), RT_TRUE) == RTGUI_MODAL_OK)
|
|
|
|
|
{
|
|
|
|
|
char path[32], image_type[8];
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7><EFBFBD>ı<EFBFBD>ǩ */
|
|
|
|
|
rtgui_filelist_view_get_fullpath(filelist, path, sizeof(path));
|
|
|
|
|
if (image != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rtgui_image_destroy(image);
|
|
|
|
|
image = RT_NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rt_memset(image_type, 0, sizeof(image_type));
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
if (rt_strstr(path, ".bmp") != RT_NULL ||
|
|
|
|
|
rt_strstr(path, ".BMP") != RT_NULL)
|
|
|
|
|
strcat(image_type, "bmp");
|
|
|
|
|
if (rt_strstr(path, ".png") != RT_NULL ||
|
|
|
|
|
rt_strstr(path, ".PNG") != RT_NULL)
|
|
|
|
|
strcat(image_type, "png");
|
|
|
|
|
if (rt_strstr(path, ".jpg") != RT_NULL ||
|
|
|
|
|
rt_strstr(path, ".JPG") != RT_NULL)
|
|
|
|
|
strcat(image_type, "jpeg");
|
|
|
|
|
if (rt_strstr(path, ".hdc") != RT_NULL ||
|
|
|
|
|
rt_strstr(path, ".HDC") != RT_NULL)
|
|
|
|
|
strcat(image_type, "hdc");
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>rtgui_image<67><65><EFBFBD><EFBFBD> */
|
|
|
|
|
if (image_type[0] != '\0')
|
|
|
|
|
image = rtgui_image_create_from_file(image_type, path, RT_TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ɾ<><C9BE> <20>ļ<EFBFBD><C4BC>б<EFBFBD> <20><>ͼ */
|
|
|
|
|
rtgui_container_destroy(RTGUI_CONTAINER(filelist));
|
|
|
|
|
rtgui_container_show(_container, RT_FALSE);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><>ʾ<EFBFBD><CABE>ͼ<EFBFBD><CDBC><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
2012-08-13 16:32:01 +08:00
|
|
|
|
static rt_bool_t demo_view_event_handler(rtgui_widget_t *widget, rtgui_event_t *event)
|
2012-04-18 23:06:12 +08:00
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rt_bool_t result;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <20>ȵ<EFBFBD><C8B5><EFBFBD>Ĭ<EFBFBD>ϵ<EFBFBD><CFB5>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>PAINT<4E>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ͼ<EFBFBD><CDBC><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>һЩ<D2BB>ؼ<EFBFBD>) */
|
|
|
|
|
result = rtgui_container_event_handler(widget, event);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
if (event->type == RTGUI_EVENT_PAINT)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_dc *dc;
|
|
|
|
|
rtgui_rect_t rect;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <20><><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC */
|
|
|
|
|
dc = rtgui_dc_begin_drawing(widget);
|
|
|
|
|
if (dc == RT_NULL)
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC>ؼ<F2B8B8BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>DC<44>ǻ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>) */
|
|
|
|
|
return RT_FALSE;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD>demo container<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD> */
|
|
|
|
|
rect.x1 += 5;
|
|
|
|
|
rect.x2 -= 5;
|
|
|
|
|
rect.y1 += 30;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
if (image != RT_NULL)
|
|
|
|
|
rtgui_image_blit(image, dc, &rect);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD> */
|
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
|
}
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
return result;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾͼ<CABE><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ͼ */
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_container_t *demo_view_image(void)
|
2012-04-18 23:06:12 +08:00
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_rect_t rect;
|
|
|
|
|
rtgui_button_t *open_btn;
|
|
|
|
|
|
|
|
|
|
/* <20>ȴ<EFBFBD><C8B4><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ͼ */
|
|
|
|
|
_container = demo_view("ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ");
|
|
|
|
|
if (_container != RT_NULL)
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϵ<EFBFBD><CFB5>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>demo_view_event_handler<65><72><EFBFBD><EFBFBD> */
|
|
|
|
|
rtgui_object_set_event_handler(RTGUI_WIDGET(_container), demo_view_event_handler);
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ť */
|
|
|
|
|
demo_view_get_rect(_container, &rect);
|
|
|
|
|
rect.x1 += 5;
|
|
|
|
|
rect.x2 = rect.x1 + 120;
|
|
|
|
|
rect.y2 = rect.y1 + 20;
|
|
|
|
|
open_btn = rtgui_button_create("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>");
|
|
|
|
|
rtgui_container_add_child(RTGUI_CONTAINER(_container), RTGUI_WIDGET(open_btn));
|
|
|
|
|
rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
|
|
|
|
|
rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
|
|
|
|
|
|
|
|
|
|
return _container;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|
|
|
|
|
#endif
|