diff --git a/examples/gui/demo_panel.c b/examples/gui/demo_panel.c index 109565f3db..27536eff46 100644 --- a/examples/gui/demo_panel.c +++ b/examples/gui/demo_panel.c @@ -20,7 +20,7 @@ void panel_init(void) /* register main panel */ rect.x1 = 0; rect.y1 = 25; - rect.x2 = 320; + rect.x2 = 240; rect.y2 = 320; rtgui_panel_register("main", &rect); rtgui_panel_set_default_focused("main"); diff --git a/examples/gui/demo_view_dc_buffer.c b/examples/gui/demo_view_dc_buffer.c new file mode 100644 index 0000000000..314fe88125 --- /dev/null +++ b/examples/gui/demo_view_dc_buffer.c @@ -0,0 +1,77 @@ +/* + * 程序清单:DC Buffer演示 + * + * 这个例子会在创建出的view上进行DC Buffer的演示 + */ + +#include "demo_view.h" +#include +#include +#include +#include + +static rtgui_image_t *background; +static struct rtgui_dc *dc_buffer; + +/* + * view的事件处理函数 + */ +static rt_bool_t dc_buffer_event_handler(rtgui_widget_t* widget, rtgui_event_t *event) +{ + + /* 仅对PAINT事件进行处理 */ + if (event->type == RTGUI_EVENT_PAINT) + { + struct rtgui_dc* dc; + rtgui_rect_t rect; + rtgui_point_t point = {0, 0}; + + /* + * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view + * 先绘图 + */ + rtgui_view_event_handler(widget, event); + + /* 获得控件所属的DC */ + dc = rtgui_dc_begin_drawing(widget); + /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */ + if (dc == RT_NULL) + return RT_FALSE; + + /* 获得demo view允许绘图的区域 */ + demo_view_get_rect(RTGUI_VIEW(widget), &rect); + + rtgui_dc_blit(dc_buffer, &point, dc, &rect); + + /* 绘图完成 */ + rtgui_dc_end_drawing(dc); + } + else + { + /* 其他事件,调用默认的事件处理函数 */ + return rtgui_view_event_handler(widget, event); + } + + return RT_FALSE; +} + +/* 创建用于DC Buffer操作演示用的视图 */ +rtgui_view_t *demo_view_dc_buffer(rtgui_workbench_t* workbench) +{ + rtgui_view_t *view; + + if (dc_buffer == RT_NULL) + { + /* 创建 DC Buffer,长 50,宽 50 */ + dc_buffer = rtgui_dc_buffer_create(50, 50); + rtgui_dc_set_color(dc_buffer, blue); + rtgui_dc_draw_circle(dc_buffer, 25, 25, 10); + } + + view = demo_view(workbench, "缓冲DC演示"); + if (view != RT_NULL) + /* 设置成自己的事件处理函数 */ + rtgui_widget_set_event_handler(RTGUI_WIDGET(view), dc_buffer_event_handler); + + return view; +} diff --git a/examples/gui/demo_workbench.c b/examples/gui/demo_workbench.c index 5b5d01dab0..3efa61ebcb 100644 --- a/examples/gui/demo_workbench.c +++ b/examples/gui/demo_workbench.c @@ -53,6 +53,7 @@ static void workbench_entry(void* parameter) /* 鍒濆鍖栧悇涓緥瀛愮殑瑙嗗浘 */ demo_view_dc(workbench); + demo_view_dc_buffer(workbench); demo_view_animation(workbench); demo_view_window(workbench); demo_view_label(workbench);