translation examples to rtgui_win

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1350 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
iamyhw@gmail.com 2011-03-26 16:05:51 +00:00
parent c715ed6d90
commit 967f6f6eef
19 changed files with 1316 additions and 39 deletions

View File

@ -4,6 +4,17 @@ Import('projects')
src = Split("""
gui_init.c
demo_gui_main.c
demo_gui_button.c
demo_gui_dc_buffer.c
demo_gui_label.c
demo_gui_radiobox.c
demo_gui_window.c
demo_gui_checkbox.c
demo_gui_progressbar.c
demo_gui_scrollbar.c
demo_gui_textbox.c
demo_gui_listbox.c
demo_gui_combobox.c
""")
group = {}

View File

@ -0,0 +1,40 @@
/*
* button控件演示
*
* view上添加几个不同类型的button控件
*/
#include "demo_view.h"
#include <rtgui/widgets/button.h>
/* 创建用于演示button控件的视图 */
rtgui_view_t* demo_gui_button(rtgui_view_t* parent_view)
{
rtgui_view_t* view;
rtgui_button_t* button;
rtgui_font_t* font;
/* 先创建一个演示用的视图 */
view = demo_view_create(parent_view, "Button View");
/* 创建一个button控件 */
button = rtgui_button_create(view, "Red", 5, 40, 100, 25);
/* 设置label控件的前景色为红色 */
RTGUI_WIDGET_FOREGROUND(button) = red;
button = rtgui_button_create(view, "Blue", 5, 70, 100, 25);
RTGUI_WIDGET_FOREGROUND(button) = blue;
button = rtgui_button_create(view, "12 font", 5, 100, 100, 25);
/* 设置字体为12点阵的asc字体 */
font = rtgui_font_refer("asc", 12);
RTGUI_WIDGET_FONT(button) = font;
button = rtgui_button_create(view, "16 font", 5, 130, 100, 25);
/* 设置字体为16点阵的asc字体 */
font = rtgui_font_refer("asc", 16);
RTGUI_WIDGET_FONT(button) = font;
return view;
}

View File

@ -0,0 +1,37 @@
/*
* checkbox控件演示
*
* view上添加几个checkbox控件
*/
#include "demo_view.h"
#include <rtgui/widgets/checkbox.h>
/* 创建用于演示checkbox控件的视图 */
rtgui_view_t* demo_gui_checkbox(rtgui_view_t* parent_view)
{
rtgui_view_t* view;
rtgui_checkbox_t* checkbox;
rtgui_font_t* font;
/* 先创建一个演示用的视图 */
view = demo_view_create(parent_view, "CheckBox View");
/* 创建一个checkbox控件 */
checkbox = rtgui_checkbox_create(view, "Red", RT_TRUE, 5, 40);
/* 设置前景色为红色 */
RTGUI_WIDGET_FOREGROUND(checkbox) = red;
checkbox = rtgui_checkbox_create(view, "Blue", RT_TRUE, 5, 60);
RTGUI_WIDGET_FOREGROUND(checkbox) = blue;
checkbox = rtgui_checkbox_create(view, "12 font", RT_TRUE, 5, 80);
font = rtgui_font_refer("asc", 12);
RTGUI_WIDGET_FONT(checkbox) = font;
checkbox = rtgui_checkbox_create(view, "16 font", RT_TRUE, 5, 100);
font = rtgui_font_refer("asc", 16);
RTGUI_WIDGET_FONT(checkbox) = font;
return view;
}

View File

@ -0,0 +1,31 @@
/*
* label控件演示
*
* view上添加几个不同类型的label控件
*/
#include "demo_view.h"
#include <rtgui/widgets/combobox.h>
rtgui_listbox_item_t items[] =
{
{"item 1", RT_NULL},
{"item 2", RT_NULL},
{"item 3", RT_NULL},
};
/* 创建用于演示combobox控件的视图 */
rtgui_view_t* demo_gui_combobox(rtgui_view_t* parent_view)
{
rtgui_view_t* view;
rtgui_combo_t* box;
/* 先创建一个演示用的视图 */
view = demo_view_create(parent_view, "ComboBox View");
box = rtgui_combo_create(view, "demo combo", 5, 40, 120, 20);
rtgui_combo_set_items(box, items, RT_COUNT(items));
box->add_string(box, "add item 1");
box->add_string(box, "add item 2");
return view;
}

View File

@ -0,0 +1,80 @@
/*
* DC Buffer演示
*
* view上进行DC Buffer的演示
*/
#include <rtgui/event.h>
#include <rtgui/widgets/view.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/slider.h>
#include <rtgui/image.h>
#include "demo_view.h"
static struct rtgui_dc *dc_buffer;
/*
* view的事件处理函数
*/
static rt_bool_t dc_buffer_event_handler(PVOID wdt, rtgui_event_t *event)
{
/* 仅对PAINT事件进行处理 */
if (event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
rtgui_rect_t rect;
/*
* demo viewdemo view
*
*/
rtgui_view_event_handler(wdt, event);
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(wdt);
/* 如果不能正常获得DC返回如果控件或父控件是隐藏状态DC是获取不成功的 */
if (dc == RT_NULL)
return RT_FALSE;
rtgui_widget_get_rect(wdt, &rect);
rect.x1 += 10;
rect.y1 += 40;
rtgui_dc_blit(dc_buffer, NULL, dc, &rect);
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
else
{
/* 其他事件,调用默认的事件处理函数 */
return rtgui_view_event_handler(wdt, event);
}
return RT_FALSE;
}
/* 创建用于DC Buffer操作演示用的视图 */
rtgui_view_t *demo_gui_dc_buffer(rtgui_view_t* parent_view)
{
rtgui_view_t *view;
if (dc_buffer == RT_NULL)
{
rtgui_rect_t rect = {0, 0, 50, 50};
/* 创建 DC Buffer长 50宽 50 */
dc_buffer = rtgui_dc_buffer_create(50, 50);
RTGUI_DC_FC(dc_buffer) = blue;
rtgui_dc_fill_rect(dc_buffer, &rect);
RTGUI_DC_FC(dc_buffer) = red;
rtgui_dc_draw_circle(dc_buffer, 25, 25, 10);
}
view = demo_view_create(parent_view, "缓冲DC演示");
if (view == RT_NULL) return RT_NULL;
/* 设置成自己的事件处理函数 */
rtgui_widget_set_event_handler(view, dc_buffer_event_handler);
return view;
}

View File

@ -0,0 +1,70 @@
/*
* DC上显示图像演示
*
* view上显示图像
*/
#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)
/* 打开按钮的回调函数 */
static void open_btn_onbutton(PVOID wdt, rtgui_event_t* event)
{
}
/* 演示视图的事件处理函数 */
static rt_bool_t demo_view_event_handler(PVOID wdt, rtgui_event_t *event)
{
rtgui_widget_t *widget = RTGUI_WIDGET(wdt);
rt_bool_t result;
/* 先调用默认的事件处理函数(这里只关心PAINT事件但演示视图还有本身的一些控件) */
result = rtgui_view_event_handler(widget, event);
if (event->type == RTGUI_EVENT_PAINT)
{
rtgui_dc_t* dc;
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) return RT_FALSE;
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
return result;
}
/* 创建用于显示图像的演示视图 */
rtgui_view_t* demo_gui_image(rtgui_view_t* parent_view)
{
rtgui_button_t* open_btn;
rtgui_view_t *view;
rtgui_filelist_view_t *fview;
/* 先创建一个演示视图 */
view = demo_view_create(parent_view, "图像演示");
#ifdef _WIN32
fview = rtgui_filelist_view_create(view, "d:\\", "*.*", 5, 65, 200, 180);
#else
fview = rtgui_filelist_view_create(view, "/", "*.*", 5, 65, 200, 180);
#endif
if (view != RT_NULL)
/* 设置默认的事件处理函数到demo_view_event_handler函数 */
rtgui_widget_set_event_handler(view, demo_view_event_handler);
/* 添加一个按钮 */
open_btn = rtgui_button_create(view, "打开图像文件", 10, 40, 120, 22);
rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
return view;
}
#endif

View File

@ -0,0 +1,51 @@
/*
* label控件演示
*
* view上添加几个不同类型的label控件
*/
#include "demo_view.h"
#include <rtgui/widgets/label.h>
/* 创建用于演示label控件的视图 */
rtgui_view_t* demo_gui_label(rtgui_view_t* parent_view)
{
rtgui_view_t* view;
rtgui_label_t* label;
rtgui_font_t* font;
/* 先创建一个演示用的视图 */
view = demo_view_create(parent_view, "Label View");
/* 创建一个label控件 */
label = rtgui_label_create(view, "Red Left", 10, 40, 200, 20);
/* 设置label控件上的文本对齐方式为左对齐 */
RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_LEFT|RTGUI_ALIGN_CENTER_VERTICAL;
/* 设置label控件的前景色为红色 */
RTGUI_WIDGET_FOREGROUND(label) = red;
RTGUI_WIDGET_BACKGROUND(label) = white;
label = rtgui_label_create(view, "Blue Right", 10, 65, 200, 20);
RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_RIGHT|RTGUI_ALIGN_CENTER_VERTICAL;
RTGUI_WIDGET_FOREGROUND(label) = blue;
RTGUI_WIDGET_BACKGROUND(label) = white;
label = rtgui_label_create(view, "Green Center", 10, 90, 200, 20);
RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_CENTER_HORIZONTAL|RTGUI_ALIGN_CENTER_VERTICAL;
RTGUI_WIDGET_FOREGROUND(label) = green;
RTGUI_WIDGET_BACKGROUND(label) = white;
label = rtgui_label_create(view, "12 font",10, 115, 200, 20);
/* 设置字体为12点阵的asc字体 */
font = rtgui_font_refer("asc", 12);
RTGUI_WIDGET_FONT(label) = font;
RTGUI_WIDGET_BACKGROUND(label) = white;
label = rtgui_label_create(view, "16 font", 10, 140, 200, 20);
font = rtgui_font_refer("asc", 16);
RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
RTGUI_WIDGET_BACKGROUND(label) = white;
return view;
}

View File

@ -0,0 +1,192 @@
/*
* label控件演示
*
* view上添加几个不同类型的label控件
*/
#include "demo_view.h"
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/button.h>
#include <rtgui/widgets/listbox.h>
/*
static rtgui_image_t* item_icon = RT_NULL;
static const char * image_xpm[] = {
"16 16 106 2",
" c None",
". c #D0C83F",
"+ c #D0C840",
"@ c #D0C030",
"# c #D0B820",
"$ c #D0B020",
"% c #D0B01F",
"& c #5F571F",
"* c #F0F0C0",
"= c #FFF8D0",
"- c #FFF8C0",
"; c #FFF8B0",
"> c #FFF8A0",
", c #F0E870",
"' c #707030",
") c #4F87EF",
"! c #4F78C0",
"~ c #5088E0",
"{ c #5078C0",
"] c #C0D0F0",
"^ c #FFF8E0",
"/ c #FFF090",
"( c #F0E070",
"_ c #6F97D0",
": c #C0D8FE",
"< c #80A8F0",
"[ c #7088D0",
"} c #B0D0FF",
"| c #90B0F0",
"1 c #1040A0",
"2 c #F0F080",
"3 c #707040",
"4 c #7098F0",
"5 c #3068E0",
"6 c #A0B8F0",
"7 c #4070C0",
"8 c #002880",
"9 c #404040",
"0 c #505050",
"a c #F0F090",
"b c #F0E860",
"c c #F0D860",
"d c #807840",
"e c #2F5FC0",
"f c #1050D0",
"g c #1048B0",
"h c #002870",
"i c #C0C080",
"j c #C0C070",
"k c #F0F070",
"l c #F0E060",
"m c #E0D050",
"n c #00277F",
"o c #00287F",
"p c #1F3F6F",
"q c #1048C0",
"r c #0040B0",
"s c #204080",
"t c #FFF890",
"u c #F0D850",
"v c #E0C840",
"w c #807040",
"x c #A0B06F",
"y c #204880",
"z c #2048A0",
"A c #90A8C0",
"B c #FFF080",
"C c #F0D050",
"D c #C0A830",
"E c #6F682F",
"F c #F0F0A0",
"G c #E0D060",
"H c #B0A040",
"I c #D0B840",
"J c #E0C040",
"K c #D0B030",
"L c #706820",
"M c #5F581F",
"N c #CFBF3F",
"O c #FFF0A0",
"P c #A09830",
"Q c #A08820",
"R c #908030",
"S c #807830",
"T c #707020",
"U c #605820",
"V c #6F672F",
"W c #D0C040",
"X c #F0E880",
"Y c #907820",
"Z c #B09820",
"` c #B09010",
" . c #B08820",
".. c #806820",
"+. c #5F5F1F",
"@. c #F0E080",
"#. c #B09020",
"$. c #C0B040",
"%. c #A09030",
"&. c #908020",
"*. c #606020",
"=. c #6F5F1F",
"-. c #9F982F",
";. c #A0872F",
">. c #6F681F",
",. c #706020",
" ",
" . + + + @ @ # # $ % & ",
" + * = = = = - ; > , ' ",
" ) ! ~ { ] ^ = - - > / ( ' ",
"_ : < { [ } | 1 - ; > > / 2 ( 3 ",
"{ 4 5 1 6 7 5 8 9 0 a / , b c d ",
"e f g h 8 8 g h i j / k l c m d ",
" n o p q r s t 2 , l c u v w ",
" x y z A B , l u C v D E ",
" @ F > t k G H I J K L M ",
" N @ O / 2 l P Q R S T U V ",
" W m 2 X l I Y Z ` ...+. ",
" W @.l u I R #.Z Y U M ",
" $.G I $.%.R &.Y *.& =. ",
" -.;.>.,.L L ,.& M ",
" "};
*/
static struct rtgui_listbox_item items[] =
{
{"list #0", RT_NULL},
{"list #1", RT_NULL},
{"list #2", RT_NULL},
{"list #3", RT_NULL},
};
rtgui_listbox_t *__lbox;
/* 给列表添加一个项目 */
void user_add_one_item(PVOID wdt, rtgui_event_t *event)
{
rtgui_listbox_item_t item={"new item", RT_NULL};
if(__lbox != RT_NULL)
{
__lbox->add_item(__lbox, &item);
}
}
static rt_bool_t on_items(PVOID wdt, rtgui_event_t* event)
{
rtgui_listbox_t* box;
/* get listbox */
box = RTGUI_LISTBOX(wdt);
/* 打印当前的项 */
rt_kprintf("current item: %d\n", box->now_aloc);
return RT_TRUE;
}
/* 创建用于演示label控件的视图 */
rtgui_view_t* demo_gui_listbox(rtgui_view_t* parent_view)
{
rtgui_view_t* view;
rtgui_button_t* button;
/* 先创建一个演示用的视图 */
view = demo_view_create(parent_view, "ListBox Demo");
/* if (item_icon == RT_NULL)
item_icon = rtgui_image_create_from_mem("xpm",
(const rt_uint8_t*)image_xpm, sizeof(image_xpm), RT_TRUE);
items[1].image = item_icon; */
rtgui_label_create(view, "listbox: ", 5, 40, 100, 20);
__lbox = rtgui_listbox_create(view, 5, 60, 120, 115, RTGUI_BORDER_SUNKEN);
rtgui_listbox_set_items(__lbox, items, RT_COUNT(items));
rtgui_listbox_set_onitem(__lbox, on_items);
button = rtgui_button_create(view, "Add", 5, 185, 50, 20);
rtgui_button_set_onbutton(button, user_add_one_item);
return view;
}

View File

@ -0,0 +1,237 @@
/*
* label控件演示
*
* view上添加几个不同类型的label控件
*/
#include "demo_view.h"
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/listctrl.h>
/*
static rtgui_image_t* item_icon = RT_NULL;
static const char * image_xpm[] = {
"16 16 106 2",
" c None",
". c #D0C83F",
"+ c #D0C840",
"@ c #D0C030",
"# c #D0B820",
"$ c #D0B020",
"% c #D0B01F",
"& c #5F571F",
"* c #F0F0C0",
"= c #FFF8D0",
"- c #FFF8C0",
"; c #FFF8B0",
"> c #FFF8A0",
", c #F0E870",
"' c #707030",
") c #4F87EF",
"! c #4F78C0",
"~ c #5088E0",
"{ c #5078C0",
"] c #C0D0F0",
"^ c #FFF8E0",
"/ c #FFF090",
"( c #F0E070",
"_ c #6F97D0",
": c #C0D8FE",
"< c #80A8F0",
"[ c #7088D0",
"} c #B0D0FF",
"| c #90B0F0",
"1 c #1040A0",
"2 c #F0F080",
"3 c #707040",
"4 c #7098F0",
"5 c #3068E0",
"6 c #A0B8F0",
"7 c #4070C0",
"8 c #002880",
"9 c #404040",
"0 c #505050",
"a c #F0F090",
"b c #F0E860",
"c c #F0D860",
"d c #807840",
"e c #2F5FC0",
"f c #1050D0",
"g c #1048B0",
"h c #002870",
"i c #C0C080",
"j c #C0C070",
"k c #F0F070",
"l c #F0E060",
"m c #E0D050",
"n c #00277F",
"o c #00287F",
"p c #1F3F6F",
"q c #1048C0",
"r c #0040B0",
"s c #204080",
"t c #FFF890",
"u c #F0D850",
"v c #E0C840",
"w c #807040",
"x c #A0B06F",
"y c #204880",
"z c #2048A0",
"A c #90A8C0",
"B c #FFF080",
"C c #F0D050",
"D c #C0A830",
"E c #6F682F",
"F c #F0F0A0",
"G c #E0D060",
"H c #B0A040",
"I c #D0B840",
"J c #E0C040",
"K c #D0B030",
"L c #706820",
"M c #5F581F",
"N c #CFBF3F",
"O c #FFF0A0",
"P c #A09830",
"Q c #A08820",
"R c #908030",
"S c #807830",
"T c #707020",
"U c #605820",
"V c #6F672F",
"W c #D0C040",
"X c #F0E880",
"Y c #907820",
"Z c #B09820",
"` c #B09010",
" . c #B08820",
".. c #806820",
"+. c #5F5F1F",
"@. c #F0E080",
"#. c #B09020",
"$. c #C0B040",
"%. c #A09030",
"&. c #908020",
"*. c #606020",
"=. c #6F5F1F",
"-. c #9F982F",
";. c #A0872F",
">. c #6F681F",
",. c #706020",
" ",
" . + + + @ @ # # $ % & ",
" + * = = = = - ; > , ' ",
" ) ! ~ { ] ^ = - - > / ( ' ",
"_ : < { [ } | 1 - ; > > / 2 ( 3 ",
"{ 4 5 1 6 7 5 8 9 0 a / , b c d ",
"e f g h 8 8 g h i j / k l c m d ",
" n o p q r s t 2 , l c u v w ",
" x y z A B , l u C v D E ",
" @ F > t k G H I J K L M ",
" N @ O / 2 l P Q R S T U V ",
" W m 2 X l I Y Z ` ...+. ",
" W @.l u I R #.Z Y U M ",
" $.G I $.%.R &.Y *.& =. ",
" -.;.>.,.L L ,.& M ",
" "};
*/
static struct list_item
{
const char* name;
const char* gender;
int age;
rtgui_image_t* image;
} items[] =
{
{"index0", "00", 30, RT_NULL},
{"index1", "m1", 30, RT_NULL},
{"index2", "m2", 30, RT_NULL},
{"index3", "m3", 30, RT_NULL},
{"index4", "m4", 30, RT_NULL},
{"index5", "m5", 30, RT_NULL},
{"index6", "m6", 30, RT_NULL},
{"index7", "m7", 30, RT_NULL},
{"index8", "m8", 30, RT_NULL},
{"index9", "m9", 30, RT_NULL},
{"index10", "m10", 30, RT_NULL},
{"index11", "m11", 30, RT_NULL},
{"index12", "m12", 30, RT_NULL},
{"index13", "m13", 30, RT_NULL},
{"index14", "m14", 30, RT_NULL},
{"index15", "m15", 30, RT_NULL},
{"index16", "m16", 30, RT_NULL},
{"index17", "m17", 30, RT_NULL},
{"index18", "m18", 30, RT_NULL},
{"index19", "m19", 30, RT_NULL},
};
void _rtgui_listctrl_item_draw(struct rtgui_listctrl *list, struct rtgui_dc* dc, rtgui_rect_t* rect, rt_uint16_t index)
{
char age_str[8];
rtgui_rect_t item_rect;
struct list_item *items, *item;
item_rect = *rect;
item_rect.x1 += 5;
items = (struct list_item*)list->items;
item = &items[index];
/* draw text */
rtgui_dc_draw_text(dc, item->name, &item_rect); item_rect.x1 += 60;
rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);
item_rect.x1 += 5;
rtgui_dc_draw_text(dc, item->gender, &item_rect); item_rect.x1 += 60;
rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);
item_rect.x1 += 5;
rt_snprintf(age_str, sizeof(age_str), "%d", item->age);
rtgui_dc_draw_text(dc, age_str, &item_rect); item_rect.x1 += 40;
rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);
item_rect.x1 += 5;
/* draw image */
if (item->image != RT_NULL)
{
rtgui_rect_t image_rect;
image_rect.x1 = 0; image_rect.y1 = 0;
image_rect.x2 = item->image->w; image_rect.y2 = item->image->h;
rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
rtgui_image_blit(item->image, dc, &image_rect);
}
}
static void on_items(rtgui_widget_t* widget, struct rtgui_event* event)
{
rtgui_listctrl_t* ctrl;
/* get listctrl */
ctrl = RTGUI_LISTCTRL(widget);
/* 打印当前的项 */
rt_kprintf("current item: %d\n", ctrl->current_item);
}
/* 创建用于演示label控件的视图 */
rtgui_view_t* demo_gui_listctrl(rtgui_view_t* parent_view)
{
rtgui_rect_t rect;
rtgui_view_t* view;
rtgui_label_t* label;
rtgui_listctrl_t* box;
/* 先创建一个演示用的视图 */
view = demo_view_create(parent_view, "List Control Demo");
/* if (item_icon == RT_NULL)
item_icon = rtgui_image_create_from_mem("xpm",
(const rt_uint8_t*)image_xpm, sizeof(image_xpm), RT_TRUE);
items[1].image = item_icon; */
rtgui_label_create(view, "List Control: ", 5, 40, 120, 20);
box = rtgui_listctrl_create((rt_uint32_t)items, sizeof(items)/sizeof(items[0]), &rect,
_rtgui_listctrl_item_draw);
rtgui_listctrl_set_onitem(box, on_items);
return view;
}

View File

@ -9,31 +9,65 @@
#include <rtgui/event.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/button.h>
#include <rtgui/widgets/textbox.h>
#include <rtgui/widgets/view.h>
#include <rtgui/widgets/listbox.h>
#include <rtgui/rtgui_theme.h>
void demo_gui_win(PVOID wdt, rtgui_event_t *event);
#include "demo_view.h"
rtgui_listbox_t *__lbox;
/* 用于存放演示视图的数组最多可创建32个演示视图 */
static rtgui_view_t* demo_list[32];
/* 当前演示视图索引 */
static rt_uint16_t demo_current = 0;
/* 总共包括的演示视图数目 */
static rt_uint16_t demo_number = 0;
static rtgui_listbox_item_t _demo_list[] =
/* 显示前一个演示视图 */
void demo_gui_prev(PVOID wdt, rtgui_event_t *event)
{
{"item1", RT_NULL},
{"item2", RT_NULL},
};
/* 给列表添加一个项目 */
void user_add_one_item(PVOID wdt, rtgui_event_t *event)
if (demo_current != 0)
{
rtgui_listbox_item_t item={"new item", RT_NULL};
if(__lbox != RT_NULL)
{
__lbox->add_item(__lbox, &item);
RTGUI_WIDGET_HIDE(demo_list[demo_current]);
demo_current --;
RTGUI_WIDGET_UNHIDE(demo_list[demo_current]);
rtgui_widget_update(demo_list[demo_current]);
}
}
/* 显示下一个演示视图 */
void demo_gui_next(PVOID wdt, rtgui_event_t *event)
{
if (demo_current + 1< demo_number)
{
RTGUI_WIDGET_HIDE(demo_list[demo_current]);
demo_current ++;
RTGUI_WIDGET_UNHIDE(demo_list[demo_current]);
rtgui_widget_update(demo_list[demo_current]);
}
}
rtgui_view_t* demo_view_create(rtgui_view_t* parent_view, const char* title)
{
rtgui_view_t* view;
/* 设置视图的名称 */
view = rtgui_view_create(parent_view, title, 0,0,
rtgui_widget_get_width(parent_view),
rtgui_widget_get_height(parent_view));
if (view == RT_NULL) return RT_NULL;
rtgui_widget_set_style(view, RTGUI_BORDER_SIMPLE);
RTGUI_WIDGET_HIDE(view);
/* 创建标题用的标签 */
rtgui_label_create(view, title, 10, 5, 200, 20);
/* 创建一个水平的staticline线 */
rtgui_staticline_create(view, 10, 30, 2, rtgui_widget_get_width(view)-20, RTGUI_HORIZONTAL);
/* 创建成功后,添加到数组中 */
demo_list[demo_number] = view;
demo_number ++;
return view;
}
static void rtgui_panel_entry(void* parameter)
{
const struct rtgui_graphic_driver* gd = rtgui_graphic_driver_get_default();
@ -46,31 +80,70 @@ static void rtgui_panel_entry(void* parameter)
mq = rt_mq_create("Panel", 256, 32, RT_IPC_FLAG_FIFO);
/* 注册当前线程为GUI线程 */
rtgui_thread_register(rt_thread_self(), mq);
panel = rtgui_panel_create(0,0,gd->width,gd->height);
//创建一个标题/信息栏
view = rtgui_view_create(panel,"titlebar",0,0,gd->width,30);
rtgui_widget_set_style(view, RTGUI_BORDER_SIMPLE);
rtgui_label_create(view, "hello world!",5,2,150,24);
//{{{ TODO: START ADD CODE HERE.
//创建一个列表
__lbox = rtgui_listbox_create(panel,10,30,120,100,RTGUI_BORDER_SUNKEN);
rtgui_listbox_set_items(__lbox,_demo_list,RT_COUNT(_demo_list));
button = rtgui_button_create(panel,"add",140,60,50,25);
rtgui_button_set_onbutton(button,user_add_one_item);
view = rtgui_view_create(panel, "demo_view", 5, 5, gd->width-10,gd->height-40);
//创建一个编辑框
rtgui_textbox_create(panel,
"this is a textbox,\n"
"demo multi text.\n",
10,150,180,50,
RTGUI_TEXTBOX_MULTI);
button = rtgui_button_create(panel, "Prev", 5,gd->height-30,50,25);
rtgui_button_set_onbutton(button, demo_gui_prev);
button = rtgui_button_create(panel, "Next", gd->width-55,gd->height-30,50,25);
rtgui_button_set_onbutton(button, demo_gui_next);
button = rtgui_button_create(panel, "win",140,90,50,25);
rtgui_button_set_onbutton(button,demo_gui_win);
///////////////////////////////////////////////////////
/* 初始化各个例子的视图 */
//#if RT_VERSION == 4
// demo_view_benchmark(view);
//#endif
// demo_view_dc(view);
//#if RT_VERSION == 4
//#ifdef RTGUI_USING_TTF
// demo_view_ttf(view);
//#endif
//#endif
#ifndef RTGUI_USING_SMALL_SIZE
demo_gui_dc_buffer(view);
#endif
// demo_gui_animation(view);
//#ifndef RTGUI_USING_SMALL_SIZE
// demo_view_buffer_animation(view);
// // demo_view_instrument_panel(view);
//#endif
demo_gui_window(view);
demo_gui_label(view);
demo_gui_button(view);
demo_gui_checkbox(view);
demo_gui_progressbar(view);
demo_gui_scrollbar(view);
demo_gui_radiobox(view);
demo_gui_textbox(view);
demo_gui_listbox(view);
////// demo_gui_menu(view); /* debugging */
////// demo_gui_listctrl(view); /* debugging */
demo_gui_combobox(view);
demo_gui_slider(view);
//////#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
////// demo_gui_image(view); /* debugging */
//////#endif
//#ifdef RT_USING_MODULE
//#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
// demo_gui_module(view);
//#endif
//#endif
// demo_gui_listview(view);
// demo_gui_listview_icon(view);
//#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
// demo_gui_fn(view);
//#endif
rtgui_view_show(demo_list[demo_current]);
//}}} END ADD CODE.
rtgui_panel_show(panel);
/* 执行工作台事件循环 */

View File

@ -0,0 +1,59 @@
/*
* menu控件演示
*
* view上添加几个不同类型的label控件
*/
#include "demo_view.h"
#include <rtgui/widgets/menu.h>
#include <rtgui/widgets/button.h>
static rt_bool_t _onmenuitem(struct rtgui_widget *widget, struct rtgui_event* event)
{
rt_kprintf("menu action!!\n");
return RT_TRUE;
}
static const rtgui_menu_item_t sub_items[] =
{
{RTGUI_ITEM_NORMAL, "item #1", RT_NULL, RT_NULL, 0, _onmenuitem},
{RTGUI_ITEM_NORMAL, "item #2", RT_NULL, RT_NULL, 0, RT_NULL},
{RTGUI_ITEM_SEPARATOR, RT_NULL, RT_NULL, RT_NULL, 0, RT_NULL},
{RTGUI_ITEM_NORMAL, "item #3", RT_NULL, RT_NULL, 0, RT_NULL},
};
static const rtgui_menu_item_t items[] =
{
{RTGUI_ITEM_NORMAL, "item #1", RT_NULL, RT_NULL, 0, RT_NULL},
{RTGUI_ITEM_NORMAL, "item #2", RT_NULL, RT_NULL, 0, RT_NULL},
{RTGUI_ITEM_SEPARATOR, RT_NULL, RT_NULL, RT_NULL, 0, RT_NULL},
{RTGUI_ITEM_SUBMENU, "item #3", RT_NULL, (struct rtgui_menu_item_t *)sub_items, sizeof(sub_items)/sizeof(sub_items[0]), RT_NULL},
};
static rtgui_menu_t* menu;
static _onmenu(PVOID wdt, rtgui_event_t* event)
{
rtgui_rect_t rect;
rtgui_widget_get_rect(widget, &rect);
rtgui_widget_rect_to_device(widget, &rect);
if (menu != RT_NULL)
rtgui_menu_pop(menu, rect.x1, rect.y2 + 5);
}
/* 创建用于演示menu控件的视图 */
rtgui_view_t* demo_gui_menu(rtgui_view_t* parent_view)
{
rtgui_rect_t rect;
rtgui_view_t* view;
rtgui_button_t* button;
/* 先创建一个演示用的视图 */
view = demo_view_create(parent_view, "MENU View");
button = rtgui_button_create(view, "Pop Menu", 5, 40, 50, 22);
rtgui_button_set_onbutton(button, _onmenu);
menu = rtgui_menu_create("Menu Test", RT_NULL, items, sizeof(items)/sizeof(items[0]));
return view;
}

View File

@ -0,0 +1,51 @@
#include "demo_view.h"
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/progressbar.h>
void hbar_timeout(struct rtgui_timer* timer, void* parameter)
{
static rt_uint32_t value = 0;
rtgui_progressbar_t *bar = (rtgui_progressbar_t*)parameter;
value += 3;
if (value >= 100) value = 0;
rtgui_progressbar_set_value(bar, value);
}
void vbar_timeout(struct rtgui_timer* timer, void* parameter)
{
static rt_uint32_t value = 0;
rtgui_progressbar_t *bar = (rtgui_progressbar_t*)parameter;
value += 5;
if (value >= 100) value = 0;
rtgui_progressbar_set_value(bar, value);
}
rtgui_view_t *demo_gui_progressbar(rtgui_view_t* parent_view)
{
rtgui_view_t *view;
rtgui_progressbar_t *hbar, *vbar;
rtgui_timer_t *timer = RT_NULL;
/* create a demo view */
view = demo_view_create(parent_view, "ProgressBar View");
rtgui_label_create(view, "ˮƽ½ø¶ÈÌõ:", 5, 40, 100, 20);
hbar = rtgui_progressbar_create(view, RTGUI_HORIZONTAL, 100, 10, 70, 150, 15);
rtgui_label_create(view, "´¹Ö±½ø¶ÈÌõ:", 5, 100, 100, 20);
vbar = rtgui_progressbar_create(view, RTGUI_VERTICAL, 100, 10, 130, 15, 60);
timer = rtgui_timer_create(20, RT_TIMER_FLAG_PERIODIC, hbar_timeout, hbar);
rtgui_timer_start(timer);
timer = rtgui_timer_create(20, RT_TIMER_FLAG_PERIODIC, vbar_timeout, vbar);
rtgui_timer_start(timer);
return view;
}

View File

@ -0,0 +1,44 @@
/*
* radiobox控件演示
*
* view上添加两个不同方向的radiobox控件
*/
#include "demo_view.h"
#include <rtgui/widgets/radiobox.h>
static rt_uint32_t bind_var;
/* 创建用于演示radiobox控件的视图 */
rtgui_view_t* demo_gui_radiobox(rtgui_view_t* parent_view)
{
rtgui_view_t* view;
rtgui_radiobox_t *rbox;
rtgui_rb_group_t *group,*_group;
/* 先创建一个演示用的视图 */
view = demo_view_create(parent_view, "RadioBox View");
/* 使用方法一 */
/* 可以先创建一个组对象,再使用 */
group = rtgui_radiobox_create_group();
rtgui_radiobox_create(view, "radio1", 5, 40, 100, 20, group);
rtgui_radiobox_create(view, "radio2", 5, 60, 100, 20, group);
/* 使用方法二 */
rbox = rtgui_radiobox_create(view, "radio-x", 5, 100, 100, 20, RT_NULL);
/* 也可以从radiobox控件中获得一个组对象 */
group = rtgui_radiobox_get_group(rbox);
_group = rtgui_radiobox_create_group();
rtgui_radiobox_create(view, "radio_m", 20,120, 100, 20, _group);
rtgui_radiobox_create(view, "radio_n", 20,140, 100, 20, _group);
/* 设定一个初始值 */
rtgui_rb_group_set_sel(_group, 1);
rtgui_radiobox_create(view, "radio-y", 5, 160, 100, 20, group);
/* 可以为组绑定一个变量,之后可以使用该变量获得group的当前焦点 */
rtgui_rb_group_bind(group, &bind_var);
return view;
}

View File

@ -0,0 +1,28 @@
#include "demo_view.h"
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/scrollbar.h>
rtgui_view_t *demo_gui_scrollbar(rtgui_view_t* parent_view)
{
rtgui_view_t *view;
rtgui_scrollbar_t* hbar;
rtgui_scrollbar_t* vbar;
/* create a demo view */
view = demo_view_create(parent_view, "ScrollBar View");
rtgui_label_create(view, "horizontal bar:", 5, 40, 150, 20);
hbar = rtgui_scrollbar_create(view, 5, 70, 20, 100, RTGUI_HORIZONTAL);
rtgui_scrollbar_set_range(hbar, 10);
rtgui_scrollbar_set_page_step(hbar, 5);
rtgui_scrollbar_set_line_step(hbar, 1);
rtgui_label_create(view, "vertical bar:", 5, 100, 150, 20);
vbar = rtgui_scrollbar_create(view, 10, 140, 20, 80, RTGUI_VERTICAL);
rtgui_scrollbar_set_range(vbar, 5);
rtgui_scrollbar_set_page_step(vbar, 3);
rtgui_scrollbar_set_line_step(vbar, 1);
return view;
}

View File

@ -0,0 +1,20 @@
#include "demo_view.h"
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/slider.h>
rtgui_view_t *demo_gui_slider(rtgui_view_t* parent_view)
{
rtgui_view_t *view;
/* create a demo view */
view = demo_view_create(parent_view, "Slider View");
rtgui_label_create(view, "horizontal slider:", 5, 40, 150, 20);
rtgui_slider_create(view, 0, 100, 5, 60, 100, 16, RTGUI_HORIZONTAL);
rtgui_label_create(view, "vertical slider:", 5, 80, 150, 20);
rtgui_slider_create(view, 0, 100, 10, 100, 16, 80, RTGUI_VERTICAL);
return view;
}

View File

@ -0,0 +1,31 @@
/*
* texbox控件演示
*
* view上添加几个不同类型的textbox控件
*/
#include "demo_view.h"
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/textbox.h>
/* 创建用于演示textbox控件的视图 */
rtgui_view_t* demo_gui_textbox(rtgui_view_t* parent_view)
{
rtgui_view_t* view;
/* 先创建一个演示用的视图 */
view = demo_view_create(parent_view, "TextBox View");
rtgui_label_create(view, "名字: ", 5, 40, 50, 20);
rtgui_textbox_create(view, "bernard",5, 60, 200, 20, RTGUI_TEXTBOX_NONE);
rtgui_label_create(view, "邮件: ", 5, 80, 50, 20);
rtgui_textbox_create(view, "bernard.xiong@gmail.com", 5, 100, 200, 20, RTGUI_TEXTBOX_NONE);
rtgui_label_create(view, "密码: ", 5, 120, 50, 20);
rtgui_textbox_create(view, "rt-thread", 5, 140, 200, 20, RTGUI_TEXTBOX_MASK);
rtgui_label_create(view, "主页: ", 5, 160, 50, 20);
rtgui_textbox_create(view, "http://www.rt-thread.org", 5, 180, 200, 20, RTGUI_TEXTBOX_NONE);
return view;
}

View File

@ -8,6 +8,7 @@
#include <rtgui/driver.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/button.h>
#include <rtgui/widgets/radiobox.h>
#include <rtgui/widgets/window.h>
static rt_bool_t demo_win_inited = RT_FALSE;
@ -32,7 +33,9 @@ static void gui_win_entry(void* parameter)
rtgui_win_t *win;
rtgui_button_t *button;
rtgui_point_t p;
rtgui_rect_t rect = {0,0,150,120};
rtgui_rect_t rect = {0,0,200,180};
rtgui_label_t *label;
rtgui_font_t *font;
/* 创建GUI应用需要的消息队列 */
mq = rt_mq_create("demo_win", 256, 32, RT_IPC_FLAG_FIFO);
@ -47,9 +50,12 @@ static void gui_win_entry(void* parameter)
/* 取得客户区坐标零点 */
p = rtgui_win_get_client_zero(win);
rtgui_label_create(win, "hello world!", p.x+10, p.y+10, 100,25);
label = rtgui_label_create(win, "hello world!", p.x+5, p.y+5, 100,25);
font = rtgui_font_refer("asc", 12);
RTGUI_WIDGET_FONT(label) = font;
button = rtgui_button_create(win, "Exit", 50,80,50,25);
button = rtgui_button_create(win, "Exit", (rtgui_rect_width(rect)-50)/2,
rtgui_rect_height(rect)-40,50,25);
rtgui_button_set_onbutton(button,rtgui_win_close);
rtgui_widget_set_event_handler(win, demo_gui_win_event_handler);

View File

@ -0,0 +1,191 @@
/*
*
*
* view
*/
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/window.h>
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/button.h>
#include "demo_view.h"
#include <string.h>
static rtgui_timer_t *timer;
static char label_text[80];
static rt_uint8_t cnt = 5;
/* 获取一个递增的窗口标题 */
static char* get_win_title(void)
{
static rt_uint8_t win_no = 0;
static char win_title[16];
rt_sprintf(win_title, "win %d", ++win_no);
return win_title;
}
rt_bool_t auto_window_close(PVOID wdt, rtgui_event_t* event)
{
if(timer != RT_NULL)
{
rtgui_timer_stop(timer);
rtgui_timer_destory(timer);
}
return RT_TRUE;
}
/* 关闭对话框时的回调函数 */
void diag_close(struct rtgui_timer* timer, void* parameter)
{
rtgui_label_t *label;
label = (rtgui_label_t*)parameter;
cnt --;
rt_sprintf(label_text, "closed then %d s", cnt);
/* 设置标签文本并更新控件 */
rtgui_label_set_text(label, label_text);
rtgui_widget_update(RTGUI_WIDGET(label));
if (cnt == 0)
{
rtgui_win_t *win;
win = rtgui_win_get_win_by_widget(label);
if(win == RT_NULL) return;
/* 超时,关闭对话框 */
rtgui_win_close(win, RT_NULL);
/* 停止并删除定时器 */
rtgui_timer_stop(timer);
rtgui_timer_destory(timer);
}
}
static rt_uint16_t delta_x = 20;
static rt_uint16_t delta_y = 40;
/* 触发正常窗口显示 */
static void demo_win_onbutton(PVOID wdt, rtgui_event_t* event)
{
rtgui_win_t *win;
PVOID parent;
rtgui_rect_t rect={0, 0, 180, 120};
parent = rtgui_widget_get_toplevel(wdt);
rtgui_rect_moveto(&rect, delta_x, delta_y);
delta_x += 20;
delta_y += 20;
/* 创建一个窗口 */
win = rtgui_win_create(parent, get_win_title(), &rect, RTGUI_WIN_DEFAULT);
/* 添加一个文本标签 */
rtgui_label_create(win, "这是一个普通窗口", 10, 30, 150, 20);
/* 非模态显示窗口 */
rtgui_win_show(win, RT_FALSE);
}
/* 触发自动窗口显示 */
static void demo_autowin_onbutton(PVOID wdt, rtgui_event_t* event)
{
PVOID parent;
rtgui_label_t *label = RT_NULL;
rtgui_win_t *msgbox;
struct rtgui_rect rect ={50, 50, 200, 200};
parent = rtgui_widget_get_toplevel(wdt);
msgbox = rtgui_win_create(parent, "Information", &rect, RTGUI_WIN_DEFAULT);
if (msgbox != RT_NULL)
{
cnt = 5;
rt_sprintf(label_text, "closed then %d s", cnt);
label = rtgui_label_create(msgbox, label_text, 10,30,120,20);
/* 设置关闭窗口时的动作 */
rtgui_win_set_onclose(msgbox, auto_window_close);
rtgui_win_show(msgbox, RT_FALSE);
}
/* 创建一个定时器 */
timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, label);
rtgui_timer_start(timer);
}
/* 触发模态窗口显示 */
static void demo_modalwin_onbutton(PVOID wdt, rtgui_event_t* event)
{
rtgui_win_t *win;
PVOID parent;
rtgui_rect_t rect = {0, 0, 180, 120};
parent = rtgui_widget_get_toplevel(wdt);
rtgui_rect_moveto(&rect, (rtgui_widget_get_width(parent) -180)/2,
(rtgui_widget_get_height(parent)-120)/2);
/* 创建一个窗口 */
win = rtgui_win_create(parent,get_win_title(), &rect, RTGUI_WIN_DEFAULT);
rect.x1 += 20;
rect.x2 -= 5;
rect.y1 += 5;
rect.y2 = rect.y1 + 20;
rtgui_label_create(win, "这是一个模式窗口", 20, 30, 150,20);
/* 模态显示窗口 */
rtgui_win_show(win, RT_TRUE);
}
/* 触发无标题窗口显示 */
static void demo_ntitlewin_onbutton(PVOID wdt, rtgui_event_t* event)
{
rtgui_win_t *win;
rtgui_label_t *label;
rtgui_button_t *button;
PVOID parent;
rtgui_rect_t rect = {0, 0, 180, 120};
parent = rtgui_widget_get_toplevel(wdt);
rtgui_rect_moveto(&rect, delta_x, delta_y);
delta_x += 20;
delta_y += 20;
/* 创建一个窗口,风格为无标题及无边框 */
win = rtgui_win_create(parent,"no title", &rect, RTGUI_WIN_NOBORDER);
RTGUI_WIDGET_BACKGROUND(win) = white;
/* 创建一个文本标签 */
label = rtgui_label_create(win, "无边框窗口", 10, 20, 100, 20);
RTGUI_WIDGET_BACKGROUND(label) = white;
button = rtgui_button_create(win,"关闭", 65, 85, 60, 25);
rtgui_button_set_onbutton(button, rtgui_win_close);
/* 非模态显示窗口 */
rtgui_win_show(win, RT_FALSE);
}
rtgui_view_t* demo_gui_window(rtgui_view_t* parent_view)
{
rtgui_view_t* view;
rtgui_button_t *button;
/* 创建一个演示用的视图 */
view = demo_view_create(parent_view, "Window Demo");
button = rtgui_button_create(view, "Normal Win", 10, 40, 100, 25);
rtgui_button_set_onbutton(button, demo_win_onbutton);
button = rtgui_button_create(view, "Auto Win", 10, 70, 100, 25);
rtgui_button_set_onbutton(button, demo_autowin_onbutton);
button = rtgui_button_create(view, "Modal Win", 10, 100, 100, 25);
rtgui_button_set_onbutton(button, demo_modalwin_onbutton);
button = rtgui_button_create(view, "NoTitle Win", 10, 130, 100, 25);
rtgui_button_set_onbutton(button, demo_ntitlewin_onbutton);
return view;
}

View File

@ -0,0 +1,25 @@
#ifndef __DEMO_VIEW_H__
#define __DEMO_VIEW_H__
#include <rtgui/widgets/view.h>
rtgui_view_t* demo_view_create(rtgui_view_t* parent_view, const char* title);
rtgui_view_t *demo_gui_dc_buffer(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_window(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_label(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_button(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_checkbox(rtgui_view_t* parent_view);
rtgui_view_t *demo_gui_progressbar(rtgui_view_t* parent_view);
rtgui_view_t *demo_gui_scrollbar(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_radiobox(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_textbox(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_listbox(rtgui_view_t* parent_view);
/* rtgui_view_t* demo_gui_menu(rtgui_view_t* parent_view) */ /* debugging */
/* rtgui_view_t* demo_gui_listbox(rtgui_view_t* parent_view) */ /* debugging */
rtgui_view_t* demo_gui_combobox(rtgui_view_t* parent_view);
rtgui_view_t *demo_gui_slider(rtgui_view_t* parent_view);
/* rtgui_view_t* demo_gui_image(rtgui_view_t* parent_view); */ /* debugging */
#endif