rt-thread/examples/rtgui_win/demo_gui_image.c

142 lines
3.8 KiB
C
Raw Normal View History

/*
* <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>view<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾͼ<EFBFBD><EFBFBD>
*/
#include "demo_view.h"
#include <rtgui/widgets/button.h>
#include <rtgui/widgets/filelist_view.h>
#include <string.h>
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
rtgui_filelist_view_t *demo_fview;
static rtgui_view_t *image_view = RT_NULL;
static rtgui_image_t *demo_image = RT_NULL;
/* <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ļ<EFBFBD> */
rt_bool_t demo_image_fview_on_item(PVOID wdt, rtgui_event_t *event)
{
rtgui_filelist_view_t *fview = wdt;
if(fview == RT_NULL) return RT_FALSE;
if(fview->pattern != RT_NULL && fview->items != RT_NULL)
{
char path[32], image_type[8];
/* <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7><EFBFBD>ı<EFBFBD>ǩ */
rtgui_filelist_view_get_fullpath(fview, path, sizeof(path));
if (demo_image != RT_NULL)
{
rtgui_image_destroy(demo_image);
demo_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')
demo_image = rtgui_image_create_from_file(image_type, path, RT_TRUE);
}
rtgui_widget_update(image_view);
return RT_TRUE;
}
/* <20><><EFBFBD>ذ<EFBFBD>ť<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD> */
static void back_btn_onbutton(PVOID wdt, rtgui_event_t* event)
{
if(demo_fview != RT_NULL)
{
rtgui_filelist_view_goto_topfolder(demo_fview);
}
}
/* <20>򿪰<EFBFBD>ť<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD> */
static void open_btn_onbutton(PVOID wdt, rtgui_event_t* event)
{
if(demo_fview != RT_NULL)
{
rtgui_filelist_view_on_enter(demo_fview);
}
}
/* <20><>ʾ<EFBFBD><CABE>ͼ<EFBFBD><CDBC><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
static rt_bool_t demo_gui_image_handler(PVOID wdt, rtgui_event_t *event)
{
rtgui_widget_t* widget = wdt;
if(event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
rtgui_rect_t rect;
/* <20><><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC */
dc = rtgui_dc_begin_drawing(widget);
if(dc == RT_NULL) return RT_FALSE;
/* <20><><EFBFBD><EFBFBD>demo view<65><77><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
rtgui_widget_get_rect(widget, &rect);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
rtgui_dc_fill_rect(dc, &rect);
/* <20><><EFBFBD><EFBFBD>ͼƬ */
if(demo_image != RT_NULL) rtgui_image_blit(demo_image, dc, &rect);
/* <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD> */
rtgui_dc_end_drawing(dc);
}
else
return rtgui_view_event_handler(widget, event);
return RT_TRUE;
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾͼ<CABE><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ͼ */
rtgui_view_t* demo_gui_image(rtgui_view_t* parent_view)
{
rtgui_button_t* button;
rtgui_view_t *view;
/* <20>ȴ<EFBFBD><C8B4><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ͼ */
view = demo_view_create(parent_view, "ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ");
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD> */
#ifdef _WIN32
demo_fview = rtgui_filelist_view_create(view, "d:\\", "*.hdc", 5, 32, 200, 68);
#else
demo_fview = rtgui_filelist_view_create(view, "/", "*.hdc", 5, 32, 200, 68);
#endif
demo_fview->on_item = demo_image_fview_on_item;
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ذ<EFBFBD>ť,<2C><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ʱ,<2C><><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ŀ¼ */
button = rtgui_button_create(view, "back", 5, 102, 40, 24);
rtgui_button_set_onbutton(button, back_btn_onbutton);
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>򿪰<EFBFBD>ť,<2C><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ŀ¼,<2C><><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD><EFBFBD>ļ<EFBFBD> */
button = rtgui_button_create(view, "open", 5, 130, 40, 24);
rtgui_button_set_onbutton(button, open_btn_onbutton);
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ͼ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾͼƬ */
image_view = rtgui_view_create(view, "image_view", 50, 102, 160, 120);
if(image_view == RT_NULL) return RT_NULL;
/* <20><>image_view<65><77><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
rtgui_widget_set_event_handler(image_view, demo_gui_image_handler);
return view;
}
#endif