a8dac7ed473f381b7042cf9d14028488192624c5
As always, full log is in GitHub.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2276 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
dzzxzz@gmail.com
2012-09-07 01:50:13 +00:00
parent fd425e792d
commit 9707b6ce0b
55 changed files with 8795 additions and 351 deletions
+3
View File
@@ -14,6 +14,7 @@ demo_view_module.c
src = Split("""
demo_application.c
demo_view.c
demo_xml.c
demo_view_benchmark.c
demo_view_dc.c
demo_view_ttf.c
@@ -38,6 +39,8 @@ demo_view_notebook.c
demo_view_mywidget.c
demo_view_box.c
demo_view_edit.c
demo_view_bmp.c
demo_plot.c
mywidget.c
""")
+10 -4
View File
@@ -94,19 +94,25 @@ static void application_entry(void *parameter)
demo_view_slider();
demo_view_notebook();
demo_view_mywidget();
demo_view_edit();
demo_plot();
#if defined(RTGUI_USING_DFS_FILERW)
demo_view_edit();
demo_view_bmp();
#endif
#if 0
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
#if defined(RTGUI_USING_DFS_FILERW)
demo_view_image();
#endif
#ifdef RT_USING_MODULE
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
#if defined(RTGUI_USING_DFS_FILERW)
demo_view_module();
#endif
#endif
demo_listview_view();
demo_listview_icon_view();
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
#if defined(RTGUI_USING_DFS_FILERW)
demo_fn_view();
#endif
#endif
+65
View File
@@ -0,0 +1,65 @@
#include <rtgui/widgets/plot.h>
#include "demo_view.h"
/* sin data */
rt_int16_t sin_ydata[] = {
0, 9, 19, 29, 38, 47, 56, 64, 71, 78, 84, 89, 93, 96, 98, 99, 99, 99, 97,
94, 90, 86, 80, 74, 67, 59, 51, 42, 33, 23, 14, 4, -5, -15, -25, -35, -44,
-52, -61, -68, -75, -81, -87, -91, -95, -97, -99, -99, -99, -98, -95, -92,
-88, -83, -77, -70, -63, -55, -46, -37, -27, -18, -8, 1, 11, 21, 31
};
rt_int16_t cos_ydata[] = {
50, 49, 46, 41, 34, 27, 18, 8, -1, -11, -20, -29, -36, -42, -47, -49, -49,
-48, -44, -39, -32, -24, -15, -5, 4, 14, 23, 31, 38, 44, 48, 49, 49, 47,
43, 37, 30, 21, 12, 2, -7, -16, -25, -33, -40, -45, -48, -49, -49, -46,
-41, -35, -28, -19, -9, 0, 10, 19, 28, 36, 42, 46, 49, 49, 48, 45, 40, 33,
25, 16, 6, -3, -12, -22, -30, -37, -43, -47, -49, -49, -47, -44, -38, -31,
-23, -13, -3, 6, 15, 24, 33, 39, 45, 48, 49, 49, 46, 42, 36, 29, 20, 10, 1,
-8, -18, -27, -35, -41, -46, -49, -49, -48, -45, -41, -34, -26, -17, -8, 1,
11, 21, 29, 37, 43, 47, 49, 49, 48, 44, 39, 32, 24, 14, 5, -4, -14, -23,
-32, -39, -44, -48, -49, -49, -47, -43, -37, -30, -21, -12, -2, 7, 17, 26,
34, 40, 45, 48, 49, 49, 46, 41, 35, 27, 18, 9, 0, -10, -20, -28, -36, -42,
-46, -49, -49, -48, -45, -40, -33, -25, -16, -6, 3, 13, 22, 31, 38, 43, 47,
49, 49, 47, 43, 38
};
struct rtgui_container* demo_plot(void)
{
struct rtgui_container *cnt;
struct rtgui_plot_curve *curve1, *curve2, *curve3;
struct rtgui_plot *plot;
struct rtgui_rect rect;
cnt = demo_view("ÇúĎßťćÍź");
curve1 = rtgui_plot_curve_create();
curve1->y_data = sin_ydata;
curve1->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
curve1->color = red;
plot = rtgui_plot_create(curve1);
curve2 = rtgui_plot_curve_create();
curve2->y_data = cos_ydata;
curve2->length = sizeof(cos_ydata)/sizeof(cos_ydata[0]);
curve2->color = blue;
rtgui_plot_append_curve(plot, curve2);
curve3 = rtgui_plot_curve_create();
curve3->x_data = cos_ydata;
curve3->y_data = sin_ydata;
curve3->length = sizeof(sin_ydata)/sizeof(sin_ydata[0]);
curve3->color = black;
rtgui_plot_append_curve(plot, curve3);
rtgui_widget_get_rect(RTGUI_WIDGET(cnt), &rect);
rtgui_widget_set_rect(RTGUI_WIDGET(plot), &rect);
rtgui_plot_set_base_point(plot,
rtgui_rect_width(rect)/3, rtgui_rect_height(rect)/2);
rtgui_container_add_child(cnt, RTGUI_WIDGET(plot));
return cnt;
}
+6 -4
View File
@@ -48,7 +48,7 @@ rtgui_container_t *demo_view(const char *title)
rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
rect.x1 += 5;
rect.y1 += 5;
rect.x2 -= 5;
rect.x2 = rect.x1 + rt_strlen(title)*8;
rect.y2 = rect.y1 + 20;
/* 创建标题用的标签 */
@@ -57,9 +57,11 @@ rtgui_container_t *demo_view(const char *title)
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
/* 添加标签到视图中 */
rtgui_container_add_child(container, RTGUI_WIDGET(label));
rect.y1 += 20;
rect.y2 += 20;
rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
rect.y1 += 20 + 5;
rect.y2 = rect.y1 + 2;
/* 创建一个水平的 staticline 线 */
line = rtgui_staticline_create(RTGUI_HORIZONTAL);
/* 设置静态线的位置信息 */
+26 -19
View File
@@ -61,6 +61,22 @@ void timeout(struct rtgui_timer *timer, void *parameter)
rtgui_dc_end_drawing(dc);
}
static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("animation on show\n");
if (timer != RT_NULL)
rtgui_timer_start(timer);
return RT_TRUE;
}
static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("animation on hide\n");
if (timer != RT_NULL)
rtgui_timer_stop(timer);
return RT_TRUE;
}
rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
struct rtgui_widget *widget = RTGUI_WIDGET(object);
@@ -90,6 +106,16 @@ rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *ev
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
else if (event->type == RTGUI_EVENT_SHOW)
{
rtgui_container_event_handler(object, event);
animation_on_show(object, event);
}
else if (event->type == RTGUI_EVENT_HIDE)
{
rtgui_container_event_handler(object, event);
animation_on_hide(object, event);
}
else
{
/* 调用默认的事件处理函数 */
@@ -99,22 +125,6 @@ rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *ev
return RT_FALSE;
}
static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("animation on show\n");
if (timer != RT_NULL)
rtgui_timer_start(timer);
return RT_TRUE;
}
static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("animation on hide\n");
if (timer != RT_NULL)
rtgui_timer_stop(timer);
return RT_TRUE;
}
rtgui_container_t *demo_view_animation()
{
rtgui_container_t *container;
@@ -127,8 +137,5 @@ rtgui_container_t *demo_view_animation()
rtgui_rect_moveto(&text_rect, 0, 45);
timer = rtgui_timer_create(2, RT_TIMER_FLAG_PERIODIC, timeout, (void *)container);
rtgui_widget_set_onshow(RTGUI_WIDGET(container), animation_on_show);
rtgui_widget_set_onhide(RTGUI_WIDGET(container), animation_on_hide);
return container;
}
+19 -2
View File
@@ -1,3 +1,4 @@
#include <stdlib.h>
#include <rtgui/dc.h>
#include <rtgui/dc_hw.h>
#include <rtgui/rtgui_system.h>
@@ -8,6 +9,8 @@
static struct rtgui_container *container = RT_NULL;
static int running = 0;
static rt_tick_t ticks;
static long long area;
void _onidle(struct rtgui_object *object, rtgui_event_t *event)
{
@@ -26,7 +29,7 @@ void _onidle(struct rtgui_object *object, rtgui_event_t *event)
draw_rect.y1 = RAND(rect.y1, rect.y2);
draw_rect.x2 = RAND(draw_rect.x1, rect.x2);
draw_rect.y2 = RAND(draw_rect.y1, rect.y2);
area += rtgui_rect_width(draw_rect) * rtgui_rect_height(draw_rect);
color = RTGUI_RGB(rand() % 255, rand() % 255, rand() % 255);
RTGUI_WIDGET_BACKGROUND(container) = color;
@@ -34,6 +37,14 @@ void _onidle(struct rtgui_object *object, rtgui_event_t *event)
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
if(rt_tick_get()-ticks >= RT_TICK_PER_SECOND)
{
char buf[16];
sprintf(buf, "%.2f", (double)area/(800*480));
rt_kprintf("frames per second: %s fps\n", buf);
area = 0;
ticks = rt_tick_get();
}
}
void _draw_default(struct rtgui_object *object, rtgui_event_t *event)
@@ -70,6 +81,11 @@ rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *ev
{
_draw_default(object, event);
}
else if (event->type == RTGUI_EVENT_SHOW)
{
rtgui_container_event_handler(object, event);
_benchmark_onshow(object, event);
}
else if (event->type == RTGUI_EVENT_KBD)
{
struct rtgui_event_kbd *kbd = (struct rtgui_event_kbd *)event;
@@ -88,6 +104,8 @@ rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *ev
else
{
/* run */
ticks = rt_tick_get();
area = 0;
rtgui_app_set_onidle(_onidle);
}
@@ -116,7 +134,6 @@ rtgui_container_t *demo_view_benchmark(void)
container = demo_view("绘图测试");
RTGUI_WIDGET(container)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
rtgui_object_set_event_handler(RTGUI_OBJECT(container), benchmark_event_handler);
rtgui_widget_set_onshow(RTGUI_WIDGET(container), _benchmark_onshow);
return container;
}
+304
View File
@@ -0,0 +1,304 @@
/*
* 程序清单:bmp_zoom演示
*/
#include "demo_view.h"
#include <rtgui/dc.h>
#include <rtgui/image.h>
#include <rtgui/image_bmp.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/button.h>
#include <rtgui/widgets/textbox.h>
#include <rtgui/widgets/container.h>
#if defined(RTGUI_USING_DFS_FILERW)
struct demo_bmp_dt
{
float scale, angle;
char *filename;
struct rtgui_image *image;
struct rtgui_image *showimg;
rtgui_container_t *showbox;
rtgui_textbox_t *box;
rtgui_rect_t lastrect;
}bmpdt;
rt_bool_t demo_bitmap_showbox(struct rtgui_object* object, struct rtgui_event* event)
{
rtgui_container_t *container;
rtgui_widget_t *widget;
RT_ASSERT(object != RT_NULL);
container = RTGUI_CONTAINER(object);
widget = RTGUI_WIDGET(object);
if(event->type == RTGUI_EVENT_PAINT)
{
int w, h;
rtgui_rect_t rect;
struct rtgui_dc *dc;
struct rtgui_image *image = bmpdt.showimg;
/* 如果从其他标签切换到当前标签, image应该是RT_NULL, 重置它 */
if(image == RT_NULL && bmpdt.image != RT_NULL)
{
image = bmpdt.image;
bmpdt.scale = 1.0f;
bmpdt.angle = 0.0f;
rtgui_widget_get_rect(RTGUI_WIDGET(bmpdt.showbox), &bmpdt.lastrect);
rtgui_rect_inflate(&bmpdt.lastrect, -RTGUI_WIDGET_BORDER(bmpdt.showbox));
}
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
return RT_FALSE;
rtgui_widget_get_rect(widget, &rect);
/* 在绘制边框后, 再将rect缩小填充背景, 可以降低闪烁现象 */
rtgui_dc_draw_border(dc, &rect, RTGUI_WIDGET_BORDER_STYLE(widget));
rtgui_rect_inflate(&rect, -RTGUI_WIDGET_BORDER(widget));
w = rtgui_rect_width(bmpdt.lastrect);
h = rtgui_rect_height(bmpdt.lastrect);
if(w > rtgui_rect_width(rect)) w = rtgui_rect_width(rect);
if(h > rtgui_rect_height(rect)) h = rtgui_rect_height(rect);
/* fill container with background */
/*
* 参数lastrect会记录上一次绘图所用区域
* 每次重绘时,只需与lastrect比较,即可得知那些背景区域需要刷新
* 例如当放大图片时,lastrect比当前绘图区小,所有无需更新背景区,
* 当缩小图片时, 也仅需要更新绘图区比lastrect大的区域.
*/
if(image != RT_NULL)
{ /* 减少不必要的绘图 */
rtgui_rect_t rc;
if(w > image->w)
{
rc.x1 = image->w;
rc.y1 = bmpdt.lastrect.y1;
rc.x2 = bmpdt.lastrect.x2;
rc.y2 = (h > image->h) ? image->h : bmpdt.lastrect.y2;
rtgui_dc_fill_rect(dc, &rc);
}
if(h > image->h)
{
rc.x1 = bmpdt.lastrect.x1;
rc.y1 = image->h;
rc.x2 = bmpdt.lastrect.x2;
rc.y2 = bmpdt.lastrect.y2;
rtgui_dc_fill_rect(dc, &rc);
}
}
else
rtgui_dc_fill_rect(dc, &bmpdt.lastrect);
/* 将图像数据blit到画布上 */
if (image != RT_NULL)
{
int value;
rtgui_image_blit(image, dc, &rect);
bmpdt.lastrect.x1 = bmpdt.lastrect.y1 = RTGUI_WIDGET_BORDER(bmpdt.showbox);
if(image->w > rtgui_rect_width(rect))
value = rtgui_rect_width(rect);
else
value = image->w;
bmpdt.lastrect.x2 = bmpdt.lastrect.x1 + value;
if(image->h > rtgui_rect_height(rect))
value = rtgui_rect_height(rect);
else
value = image->h;
bmpdt.lastrect.y2 = bmpdt.lastrect.y1 + value;
}
rtgui_dc_end_drawing(dc);
return RT_FALSE;
}
return rtgui_container_event_handler(object, event);
}
void demo_bitmap_open(struct rtgui_object* object, struct rtgui_event* event)
{
char *str;
rtgui_button_t *button = RTGUI_BUTTON(object);
/* 从textbox控件中取得文件名 */
str = (char*)rtgui_textbox_get_value(bmpdt.box);
if(str == RT_NULL) return;
if(*str == '/' && (rt_strstr(str, ".bmp")!=RT_NULL || rt_strstr(str, ".BMP")!=RT_NULL))
{ /* 如果是bmp文件, 且文件名有效, 则读入图像数据 */
if(bmpdt.filename != RT_NULL)
rt_free(bmpdt.filename);
bmpdt.filename = rt_strdup(str);
if(bmpdt.image != RT_NULL)
rtgui_image_destroy(bmpdt.image);
bmpdt.image = rtgui_image_create_from_file("bmp", bmpdt.filename, RT_TRUE);
if(bmpdt.image != RT_NULL)
{
bmpdt.showimg = bmpdt.image;
bmpdt.scale = 1.0;
bmpdt.angle = 0.0;
rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox));
}
}
else
rt_kprintf("Bad filename!");
}
void demo_image_zoom_in(struct rtgui_object* object, struct rtgui_event* event)
{
rtgui_button_t *button = RTGUI_BUTTON(object);
if (bmpdt.image == RT_NULL) return;
if (bmpdt.scale > 0.45)
{ /* 更新缩放倍率 */
if (bmpdt.scale > 1.0) bmpdt.scale -= (float)0.5;
else bmpdt.scale -= (float)0.1;
}
/* 根据缩放倍率, 缩放原始图形, 并得到新图形的指针 */
bmpdt.showimg = rtgui_image_zoom(bmpdt.image, bmpdt.scale, bmpdt.scale, RTGUI_IMG_ZOOM_BILINEAR);
if (bmpdt.showimg != RT_NULL)
rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox));
else
return;
if(bmpdt.showimg != bmpdt.image)
{ /* 释放掉新图形所用的资源 */
rtgui_image_destroy(bmpdt.showimg);
bmpdt.showimg = RT_NULL;
}
}
void demo_image_zoom_out(struct rtgui_object* object, struct rtgui_event* event)
{
rtgui_button_t *button = RTGUI_BUTTON(object);
if (bmpdt.image == RT_NULL) return;
if (bmpdt.scale < 4.95)
{ /* 更新缩放倍率 */
if (bmpdt.scale > 0.95) bmpdt.scale += (float)0.5;
else bmpdt.scale += (float)0.1;
}
bmpdt.showimg = rtgui_image_zoom(bmpdt.image, bmpdt.scale, bmpdt.scale, RTGUI_IMG_ZOOM_BILINEAR);
if (bmpdt.showimg != RT_NULL)
rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox));
else
return;
if(bmpdt.showimg != bmpdt.image)
{
rtgui_image_destroy(bmpdt.showimg);
bmpdt.showimg = RT_NULL;
}
}
void demo_image_rotate(struct rtgui_object* object, struct rtgui_event* event)
{
rtgui_button_t *button = RTGUI_BUTTON(object);
if (bmpdt.image == RT_NULL) return;
/* 更新图像旋转角度 */
if (bmpdt.angle < 360.0)
bmpdt.angle += (float)1.0;
else
bmpdt.angle = 0.0;
/* 调用旋转函数执行旋转, 并取得一个新的图像指针 */
bmpdt.showimg = rtgui_image_rotate(bmpdt.image, bmpdt.angle);
if (bmpdt.showimg != RT_NULL)
rtgui_widget_update(RTGUI_WIDGET(bmpdt.showbox));
else
return;
if(bmpdt.showimg != bmpdt.image)
{
rtgui_image_destroy(bmpdt.showimg);
bmpdt.showimg = RT_NULL;
}
}
rtgui_container_t *demo_view_bmp(void)
{
rtgui_rect_t rect;
rtgui_container_t *container, *showbox;
rtgui_button_t *button;
rtgui_textbox_t *box;
/* 用bmpdt结构体记录一些参数 */
rt_memset(&bmpdt, 0, sizeof(struct demo_bmp_dt));
bmpdt.scale = 1.0;
bmpdt.angle = 0.0;
/* 创建用于演示本代码的容器控件 */
container = demo_view("Bmp File:");
demo_view_get_rect(container, &rect);
rect.x1 += 85;
rect.x2 -= 5;
rect.y1 -= 42;
rect.y2 = rect.y1 + 20;
box = rtgui_textbox_create("", RTGUI_TEXTBOX_SINGLE);
rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(box));
bmpdt.box = box;
/* create a button "open" */
demo_view_get_rect(container, &rect);
rect.x1 += 5;
rect.x2 = rect.x1 + 60;
rect.y1 -= 10;
rect.y2 = rect.y1 + 24;
button = rtgui_button_create("open");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, demo_bitmap_open);
/* create a button "zoom in" */
demo_view_get_rect(container, &rect);
rect.x1 += 85;
rect.x2 = rect.x1 + 70;
rect.y1 -= 10;
rect.y2 = rect.y1 + 24;
button = rtgui_button_create("zoom in");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, demo_image_zoom_in);
/* create a button "zoom out" */
demo_view_get_rect(container, &rect);
rect.x1 += 165;
rect.x2 = rect.x1 + 70;
rect.y1 -= 10;
rect.y2 = rect.y1 + 24;
button = rtgui_button_create("zoom out");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, demo_image_zoom_out);
/* create a button "rotate" */
demo_view_get_rect(container, &rect);
rect.x1 += 245;
rect.x2 = rect.x1 + 70;
rect.y1 -= 10;
rect.y2 = rect.y1 + 24;
button = rtgui_button_create("rotate");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, demo_image_rotate);
/* create a container "showbox" */
demo_view_get_rect(container, &rect);
rect.x1 += 5;
rect.x2 -= 5;
rect.y1 += 20;
rect.y2 -= 0;
showbox = rtgui_container_create();
rtgui_widget_set_rect(RTGUI_WIDGET(showbox), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(showbox));
rtgui_widget_set_border(RTGUI_WIDGET(showbox), RTGUI_BORDER_SIMPLE);
bmpdt.showbox = showbox;
rtgui_object_set_event_handler(RTGUI_OBJECT(showbox), demo_bitmap_showbox);
rtgui_widget_get_rect(RTGUI_WIDGET(showbox), &bmpdt.lastrect);
rtgui_rect_inflate(&bmpdt.lastrect, -RTGUI_WIDGET_BORDER(showbox));
return container;
}
#endif
+26 -19
View File
@@ -59,6 +59,22 @@ static void timeout(struct rtgui_timer *timer, void *parameter)
rtgui_dc_end_drawing(dc);
}
static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("buffer animation on show\n");
rtgui_timer_start(timer);
return RT_TRUE;
}
static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("buffer animation on hide\n");
rtgui_timer_stop(timer);
return RT_TRUE;
}
static rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
struct rtgui_widget *widget = RTGUI_WIDGET(object);
@@ -87,6 +103,16 @@ static rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_even
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
else if (event->type == RTGUI_EVENT_SHOW)
{
rtgui_container_event_handler(object, event);
animation_on_show(object, event);
}
else if (event->type == RTGUI_EVENT_HIDE)
{
rtgui_container_event_handler(object, event);
animation_on_hide(object, event);
}
else
{
/* 调用默认的事件处理函数 */
@@ -96,22 +122,6 @@ static rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_even
return RT_FALSE;
}
static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("buffer animation on show\n");
rtgui_timer_start(timer);
return RT_TRUE;
}
static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event)
{
rt_kprintf("buffer animation on hide\n");
rtgui_timer_stop(timer);
return RT_TRUE;
}
struct rtgui_container *demo_view_buffer_animation(void)
{
struct rtgui_container *container;
@@ -143,8 +153,5 @@ struct rtgui_container *demo_view_buffer_animation(void)
/* 启动定时器以触发动画 */
timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, (void *)container);
rtgui_widget_set_onshow(RTGUI_WIDGET(container), animation_on_show);
rtgui_widget_set_onhide(RTGUI_WIDGET(container), animation_on_hide);
return container;
}
+5 -4
View File
@@ -10,8 +10,6 @@
#include <rtgui/widgets/slider.h>
#include <rtgui/image.h>
static rtgui_image_t *background;
static struct rtgui_dc *dc_buffer;
/*
* view的事件处理函数
@@ -19,6 +17,7 @@ static struct rtgui_dc *dc_buffer;
static rt_bool_t dc_buffer_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
struct rtgui_widget *widget = RTGUI_WIDGET(object);
struct rtgui_dc *dc_buffer;
/* 仅对PAINT事件进行处理 */
if (event->type == RTGUI_EVENT_PAINT)
@@ -31,7 +30,7 @@ static rt_bool_t dc_buffer_event_handler(struct rtgui_object *object, rtgui_even
* 先绘图
*/
rtgui_container_event_handler(object, event);
dc_buffer = (struct rtgui_dc*)widget->user_data;
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(widget);
/* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
@@ -61,6 +60,7 @@ static rt_bool_t dc_buffer_event_handler(struct rtgui_object *object, rtgui_even
rtgui_container_t *demo_view_dc_buffer()
{
rtgui_container_t *view;
struct rtgui_dc *dc_buffer=RT_NULL;
if (dc_buffer == RT_NULL)
{
@@ -68,7 +68,7 @@ rtgui_container_t *demo_view_dc_buffer()
/* 创建 DC Buffer,长 50,宽 50 */
dc_buffer = rtgui_dc_buffer_create(50, 50);
RTGUI_DC_FC(dc_buffer) = blue;
RTGUI_DC_BC(dc_buffer) = blue;
rtgui_dc_fill_rect(dc_buffer, &rect);
RTGUI_DC_FC(dc_buffer) = red;
@@ -79,6 +79,7 @@ rtgui_container_t *demo_view_dc_buffer()
if (view != RT_NULL)
/* 设置成自己的事件处理函数 */
rtgui_object_set_event_handler(RTGUI_OBJECT(view), dc_buffer_event_handler);
RTGUI_WIDGET(view)->user_data = (rt_uint32_t)dc_buffer;
return view;
}
+71 -9
View File
@@ -6,16 +6,19 @@
#include "demo_view.h"
#include <rtgui/dc.h>
#include <rtgui/filerw.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/edit.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/button.h>
#ifdef RTGUI_USING_DFS_FILERW
void demo_edit_readin_file(struct rtgui_object *object, struct rtgui_event *event)
{
rtgui_button_t *button;
struct rtgui_edit *edit;
const char *filename = "/test_readin.txt";
int fd;
struct rtgui_filerw *file;
RT_ASSERT(object != RT_NULL);
button = RTGUI_BUTTON(object);
@@ -23,15 +26,15 @@ void demo_edit_readin_file(struct rtgui_object *object, struct rtgui_event *even
edit = RTGUI_EDIT(RTGUI_WIDGET(button)->user_data);
/* 判断文件是否存在 */
fd = open(filename, O_RDONLY, 0);
if (fd < 0)
file = rtgui_filerw_create_file(filename, "rb");
if (file == RT_NULL)
{
/* 不存在存在,则创建它 */
rt_kprintf("file:\"%s\" does not exist!\n", filename);
return;
}
close(fd);
rtgui_filerw_close(file);
rt_kprintf("read-in file:\"%s\"\n", filename);
rtgui_edit_readin_file(edit, filename);
@@ -42,7 +45,7 @@ void demo_edit_saveas_file(struct rtgui_object *object, struct rtgui_event *even
rtgui_button_t *button;
struct rtgui_edit *edit;
const char* filename = "/test_saveas.txt";
int fd;
struct rtgui_filerw *file;
RT_ASSERT(object != RT_NULL);
button = RTGUI_BUTTON(object);
@@ -50,12 +53,12 @@ void demo_edit_saveas_file(struct rtgui_object *object, struct rtgui_event *even
edit = RTGUI_EDIT(RTGUI_WIDGET(button)->user_data);
/* 判断文件是否存在, 如果存在则删除之 */
fd = open(filename, O_RDONLY, 0);
if (fd > 0)
file = rtgui_filerw_create_file(filename, "rb");
if (file != RT_NULL)
{
close(fd);
rtgui_filerw_close(file);
/* 如果是在win32中调试, 请手工删除该文件吧, NT中文件是只读的,unlink删除不掉 */
if (unlink(filename) == -1)
if (rtgui_filerw_unlink(filename) == -1)
rt_kprintf("Could not delete %s\n", filename);
}
@@ -63,12 +66,42 @@ void demo_edit_saveas_file(struct rtgui_object *object, struct rtgui_event *even
rtgui_edit_saveas_file(edit, filename);
}
void demo_edit_get_mem(struct rtgui_object* object, struct rtgui_event* event)
{
rtgui_button_t *button;
struct rtgui_edit *edit;
RT_ASSERT(object != RT_NULL);
button = RTGUI_BUTTON(object);
edit = RTGUI_EDIT( RTGUI_WIDGET(button)->user_data );
rt_kprintf("edit mem consume: %d\n", rtgui_edit_get_mem_consume(edit));
}
rt_bool_t demo_edit_event_handler(struct rtgui_object* object, struct rtgui_event *event)
{
rt_bool_t result;
char buf[32];
rtgui_point_t p;
struct rtgui_edit *edit = RTGUI_EDIT(object);
struct rtgui_label *label = (struct rtgui_label*)RTGUI_WIDGET(edit)->user_data;
result = rtgui_edit_event_handler(object, event);
p = rtgui_edit_get_current_point(edit);
rt_sprintf(buf, "TRACK: line:%d, col:%d", p.y, p.x);
rtgui_label_set_text(label, buf);
return result;
}
/* 创建用于演示edit控件的视图 */
rtgui_container_t *demo_view_edit(void)
{
rtgui_rect_t rect;
rtgui_container_t *container;
struct rtgui_edit *edit;
struct rtgui_label *label;
struct rtgui_button *button;
/* 先创建一个演示用的视图 */
@@ -84,6 +117,7 @@ rtgui_container_t *demo_view_edit(void)
"rtgui_edit_insert_line\n"
"rtgui_edit_delete_line\n"
"rtgui_edit_connect_line\n"
"双字节测试\n"
"a\n"
"b\n"
"c\n"
@@ -116,5 +150,33 @@ rtgui_container_t *demo_view_edit(void)
/* 使用user_data传递edit指针 */
RTGUI_WIDGET(button)->user_data = (rt_uint32_t)edit;
/* 创建一个标签, 显示EDIT的主要参数 */
demo_view_get_rect(container, &rect);
rect.x1 += 10;
rect.x2 = rect.x1 + 220;
rect.y1 += 225;
rect.y2 = rect.y1 + 18;
label = rtgui_label_create("TRACK:");
RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
RTGUI_WIDGET_FOREGROUND(label) = blue;
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(label));
RTGUI_WIDGET(edit)->user_data = (rt_uint32_t)label;
rtgui_object_set_event_handler(RTGUI_OBJECT(edit), demo_edit_event_handler);
/* 创建一个按钮, 读取EDIT的内存消耗 */
demo_view_get_rect(container, &rect);
rect.x1 += 150;
rect.x2 = rect.x1 + 80;
rect.y1 -= 42;
rect.y2 = rect.y1 + 20;
button = rtgui_button_create("Get Mem");
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
rtgui_container_add_child(container, RTGUI_WIDGET(button));
rtgui_button_set_onbutton(button, demo_edit_get_mem);
RTGUI_WIDGET(button)->user_data = (rt_uint32_t)edit;
return container;
}
#endif
+15 -15
View File
@@ -1,7 +1,7 @@
/*
* 3ìDò??μ¥£oDCé???ê?í????Yê?
* 程序清单:DC上显示图像演示
*
* ?a??ày×ó?á?ú′′?¨3?μ?viewé???ê?í???
* 这个例子会在创建出的view上显示图像
*/
#include "demo_view.h"
@@ -10,63 +10,63 @@
#include <string.h>
#ifdef RT_USING_MODULE
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
#if defined(RTGUI_USING_DFS_FILERW)
static rtgui_container_t *_view = RT_NULL;
/* ′ò?a°′?¥μ???μ÷oˉêy */
/* 打开按钮的回调函数 */
static void open_btn_onbutton(rtgui_widget_t *widget, struct rtgui_event *event)
{
rtgui_filelist_view_t *view;
rtgui_workbench_t *workbench;
rtgui_rect_t rect;
/* ??μ??¥2?μ?workbench */
/* 获得顶层的workbench */
workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
/* WIN32??ì¨é?oí??êμéè±?é?μ?3?ê??·??′|àí */
/* WIN32平台上和真实设备上的初始路径处理 */
#ifdef _WIN32
view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect);
#else
view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
#endif
/* ?£ì???ê?ò??????táD±íêóí?£?ò?ìá1???ó??§????í??????t */
/* 模态显示一个文件列表视图,以提供给用户选择图像文件 */
if (rtgui_container_show(RTGUI_CONTAINER(view), RT_TRUE) == RTGUI_MODAL_OK)
{
char path[32], name[8];
/* éè?????t?·??μ?±ê?? */
/* 设置文件路径的标签 */
rtgui_filelist_view_get_fullpath(view, path, sizeof(path));
rt_memset(name, 0, sizeof(name));
/* ??μ?ó|ó??£?éμ?ààDí */
/* 获得应用模块的类型 */
if (rt_strstr(path, ".mo") != RT_NULL || rt_strstr(path, ".so") != RT_NULL)
{
rt_module_open(path);
}
}
/* é?3y ???táD±í êóí? */
/* 删除 文件列表 视图 */
rtgui_container_destroy(RTGUI_CONTAINER(view));
rtgui_container_show(_view, RT_FALSE);
}
/* ′′?¨ó?óú??ê?ó|ó??£?éμ??Yê?êóí? */
/* 创建用于显示应用模块的演示视图 */
rtgui_container_t *demo_view_module(rtgui_workbench_t *workbench)
{
rtgui_rect_t rect;
rtgui_button_t *open_btn;
/* ?è′′?¨ò????Yê?êóí? */
_view = demo_view(workbench, "ó|ó??£?é?Yê?");
/* 先创建一个演示视图 */
_view = demo_view(workbench, "应用模块演示");
/* ìí?óò???°′?¥ */
/* 添加一个按钮 */
demo_view_get_rect(_view, &rect);
rect.x1 += 5;
rect.x2 = rect.x1 + 120;
rect.y2 = rect.y1 + 20;
open_btn = rtgui_button_create("′ò?aó|ó??£?é");
open_btn = rtgui_button_create("打开应用模块");
rtgui_container_add_child(RTGUI_CONTAINER(_view), RTGUI_WIDGET(open_btn));
rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
+23 -3
View File
@@ -33,6 +33,29 @@ static rt_bool_t stop_timer(struct rtgui_object *object, struct rtgui_event *eve
return RT_TRUE;
}
static rt_bool_t progressbar_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
struct rtgui_widget *widget = RTGUI_WIDGET(object);
if (event->type == RTGUI_EVENT_SHOW)
{
rtgui_container_event_handler(object, event);
start_timer(object, event);
}
else if (event->type == RTGUI_EVENT_HIDE)
{
rtgui_container_event_handler(object, event);
stop_timer(object, event);
}
else
{
/* 调用默认的事件处理函数 */
return rtgui_progressbar_event_handler(object, event);
}
return RT_FALSE;
}
rtgui_container_t *demo_view_progressbar(void)
{
rtgui_container_t *container;
@@ -75,9 +98,6 @@ rtgui_container_t *demo_view_progressbar(void)
bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,
progressbar_timeout, RT_NULL);
rtgui_widget_set_onshow(RTGUI_WIDGET(container), start_timer);
rtgui_widget_set_onhide(RTGUI_WIDGET(container), stop_timer);
return container;
}
+9 -8
View File
@@ -14,7 +14,7 @@
static struct rtgui_timer *timer;
static struct rtgui_label *label;
static struct rtgui_win *msgbox = RT_NULL;
static struct rtgui_win *autowin = RT_NULL;
static char label_text[80];
static rt_uint8_t cnt = 5;
@@ -92,7 +92,7 @@ void diag_close(struct rtgui_timer *timer, void *parameter)
if (cnt == 0)
{
/* 超时,关闭对话框 */
rtgui_win_destroy(msgbox);
rtgui_win_destroy(autowin);
}
}
@@ -107,6 +107,7 @@ rt_bool_t auto_window_close(struct rtgui_object *object, struct rtgui_event *eve
timer = RT_NULL;
}
autowin = RT_NULL;
return RT_TRUE;
}
@@ -120,12 +121,12 @@ static void demo_autowin_onbutton(struct rtgui_object *object, rtgui_event_t *ev
struct rtgui_rect rect = {50, 50, 200, 200};
/* don't create the window twice */
if (msgbox)
if (autowin)
return;
msgbox = rtgui_win_create(main_win, "Information",
autowin = rtgui_win_create(main_win, "Information",
&rect, RTGUI_WIN_STYLE_DEFAULT | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
if (msgbox == RT_NULL)
if (autowin == RT_NULL)
return;
cnt = 5;
@@ -136,13 +137,13 @@ static void demo_autowin_onbutton(struct rtgui_object *object, rtgui_event_t *ev
rect.y1 += 5;
rect.y2 = rect.y1 + 20;
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
rtgui_container_add_child(RTGUI_CONTAINER(msgbox),
rtgui_container_add_child(RTGUI_CONTAINER(autowin),
RTGUI_WIDGET(label));
/* 设置关闭窗口时的动作 */
rtgui_win_set_onclose(msgbox, auto_window_close);
rtgui_win_set_onclose(autowin, auto_window_close);
rtgui_win_show(msgbox, RT_FALSE);
rtgui_win_show(autowin, RT_FALSE);
/* 创建一个定时器 */
timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL);
rtgui_timer_start(timer);