2012-04-18 23:06:12 +08:00
|
|
|
|
#include "demo_view.h"
|
|
|
|
|
#include <rtgui/rtgui_system.h>
|
|
|
|
|
#include <rtgui/widgets/label.h>
|
|
|
|
|
#include <rtgui/widgets/progressbar.h>
|
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
static rtgui_progressbar_t *hbar;
|
|
|
|
|
static rtgui_progressbar_t *vbar;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
static rtgui_timer_t *bar_timer = RT_NULL;
|
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
void progressbar_timeout(struct rtgui_timer *timer, void *parameter)
|
2012-04-18 23:06:12 +08:00
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
static rt_uint32_t value = 0;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
value++;
|
|
|
|
|
if (value == 100)
|
|
|
|
|
value = 0;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_progressbar_set_value(hbar, value);
|
|
|
|
|
rtgui_progressbar_set_value(vbar, value);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static rt_bool_t start_timer(struct rtgui_object *object, struct rtgui_event *event)
|
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
if (bar_timer != RT_NULL)
|
|
|
|
|
rtgui_timer_start(bar_timer);
|
|
|
|
|
return RT_TRUE;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static rt_bool_t stop_timer(struct rtgui_object *object, struct rtgui_event *event)
|
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
if (bar_timer != RT_NULL)
|
|
|
|
|
rtgui_timer_stop(bar_timer);
|
|
|
|
|
return RT_TRUE;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtgui_container_t *demo_view_progressbar(void)
|
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_container_t *container;
|
|
|
|
|
rtgui_rect_t rect;
|
|
|
|
|
rtgui_label_t *label;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* create a demo container */
|
|
|
|
|
container = demo_view("ProgressBar View");
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* get demo container rect */
|
|
|
|
|
demo_view_get_rect(container, &rect);
|
|
|
|
|
label = rtgui_label_create("ˮƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
rtgui_container_add_child(container, RTGUI_WIDGET(label));
|
|
|
|
|
rect.x1 += 5;
|
|
|
|
|
rect.x2 -= 5;
|
|
|
|
|
rect.y1 += 5;
|
|
|
|
|
rect.y2 = rect.y1 + 18;
|
|
|
|
|
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
|
|
|
|
rect.y1 += 20;
|
|
|
|
|
rect.y2 = rect.y1 + 18;
|
|
|
|
|
hbar = rtgui_progressbar_create(RTGUI_HORIZONTAL, 100, &rect);
|
|
|
|
|
rtgui_container_add_child(container, RTGUI_WIDGET(hbar));
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
/* get demo container rect */
|
|
|
|
|
demo_view_get_rect(container, &rect);
|
|
|
|
|
label = rtgui_label_create("<EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
rtgui_container_add_child(container, RTGUI_WIDGET(label));
|
|
|
|
|
rect.x1 += 5;
|
|
|
|
|
rect.x2 -= 5;
|
|
|
|
|
rect.y1 += 45;
|
|
|
|
|
rect.y2 = rect.y1 + 18;
|
|
|
|
|
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
|
|
|
|
rect.x1 += 110;
|
|
|
|
|
rect.x2 = rect.x1 + 20;
|
|
|
|
|
rect.y1 += 18 + 5;
|
|
|
|
|
rect.y2 = rect.y1 + 150;
|
|
|
|
|
vbar = rtgui_progressbar_create(RTGUI_VERTICAL, 100, &rect);
|
|
|
|
|
rtgui_container_add_child(container, RTGUI_WIDGET(vbar));
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,
|
|
|
|
|
progressbar_timeout, RT_NULL);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_widget_set_onshow(RTGUI_WIDGET(container), start_timer);
|
|
|
|
|
rtgui_widget_set_onhide(RTGUI_WIDGET(container), stop_timer);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
return container;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|
|
|
|
|
|