4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-01-16 14:53:31 +08:00
chaos.proton@gmail.com db06460208 merge new RTGUI in to trunk
The full log is at https://github.com/RTGUI/RTGUI/commits/merge_1 and it's difficult to merge the new tree commit by commit. I also converted all the file into unix eol so there are many fake diff. Big changes are noted in rtgui/doc/road_map.txt and rtgui/doc/attention.txt. Keep an eye on them if you want to migrate your old code.

Note that the work is still in progress and the bsp is not prepared in trunk so far.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2092 bbd45198-f89e-11dd-88c7-29a3b14d5316
2012-04-18 15:06:12 +00:00

105 lines
2.3 KiB
C

#include <rtgui/dc.h>
#include <rtgui/rtgui_theme.h>
#include <rtgui/widgets/progressbar.h>
#define RTGUI_PROGRESSBAR_DEFAULT_RANGE 100
static void _rtgui_progressbar_constructor(rtgui_progressbar_t *bar)
{
rtgui_rect_t rect = {0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT};
rtgui_object_set_event_handler(RTGUI_OBJECT(bar), rtgui_progressbar_event_handler);
rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);
bar->orient = RTGUI_HORIZONTAL;
bar->range = RTGUI_PROGRESSBAR_DEFAULT_RANGE;
bar->position = 0;
/* set gc */
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(bar)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
}
DEFINE_CLASS_TYPE(progressbar, "progressbar",
RTGUI_WIDGET_TYPE,
_rtgui_progressbar_constructor,
RT_NULL,
sizeof(struct rtgui_progressbar));
rt_bool_t rtgui_progressbar_event_handler(struct rtgui_object* object,
struct rtgui_event* event)
{
struct rtgui_progressbar* bar;
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
bar = RTGUI_PROGRESSBAR(object);
switch (event->type)
{
case RTGUI_EVENT_PAINT:
rtgui_theme_draw_progressbar(bar);
break;
}
return RT_FALSE;
}
struct rtgui_progressbar* rtgui_progressbar_create(int orientation, int range,
rtgui_rect_t* r)
{
struct rtgui_progressbar* bar;
bar = (struct rtgui_progressbar*) rtgui_widget_create (RTGUI_PROGRESSBAR_TYPE);
if (bar != RT_NULL)
{
if (r != RT_NULL)
rtgui_widget_set_rect(RTGUI_WIDGET(bar), r);
bar->orient = orientation;
bar->range = range;
}
return bar;
}
void rtgui_progressbar_destroy(struct rtgui_progressbar* bar)
{
rtgui_widget_destroy(RTGUI_WIDGET(bar));
}
void rtgui_progressbar_set_value(struct rtgui_progressbar *bar, int value)
{
RT_ASSERT(bar != RT_NULL);
if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar))) return;
bar->position = value;
rtgui_theme_draw_progressbar(bar);
return;
}
int rtgui_progressbar_get_value(struct rtgui_progressbar *bar)
{
RT_ASSERT(bar != RT_NULL);
return bar->position;
}
void rtgui_progressbar_set_range(struct rtgui_progressbar *bar, int range)
{
RT_ASSERT(bar != RT_NULL);
bar->range = range;
rtgui_theme_draw_progressbar(bar);
return;
}
int rtgui_progressbar_get_range(struct rtgui_progressbar *bar)
{
RT_ASSERT(bar != RT_NULL);
return bar->range;
}