diff --git a/examples/gui/demo_fnview.c b/examples/gui/demo_fnview.c new file mode 100644 index 0000000000..8d69eeaf39 --- /dev/null +++ b/examples/gui/demo_fnview.c @@ -0,0 +1,41 @@ +#include "demo_view.h" +#include +#include +// #include + +static rtgui_label_t* label; +void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event) +{ + /* create a fn view */ +} + +rtgui_view_t* demo_fn_view(rtgui_workbench_t* workbench) +{ + rtgui_rect_t rect; + rtgui_view_t* view; + rtgui_button_t* open_btn; + rtgui_font_t* font; + + view = demo_view(workbench); + rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); + + font = rtgui_font_refer("asc", 12); + + rect.x1 += 5; rect.x2 -= 5; + rect.y1 += 5; rect.y2 = rect.y1 + 20; + label = rtgui_label_create("fn: "); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); + rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); + RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font; + + rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 80; + rect.y1 += 30; rect.y2 = rect.y1 + 20; + open_btn = rtgui_button_create("Open File"); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn)); + rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect); + RTGUI_WIDGET_FONT(RTGUI_WIDGET(open_btn)) = font; + rtgui_button_set_onbutton(open_btn, open_btn_onbutton); + + return view; +} diff --git a/examples/gui/demo_panel.c b/examples/gui/demo_panel.c index 0cc1261351..109565f3db 100644 --- a/examples/gui/demo_panel.c +++ b/examples/gui/demo_panel.c @@ -1,6 +1,11 @@ #include #include +/* + * Panel demo for 240x320 + * info panel: (0, 0) - (240, 25) + * main panel: (0, 25) - (240, 320) + */ void panel_init(void) { rtgui_rect_t rect; diff --git a/examples/gui/demo_panel_single.c b/examples/gui/demo_panel_single.c new file mode 100644 index 0000000000..5b3b217a01 --- /dev/null +++ b/examples/gui/demo_panel_single.c @@ -0,0 +1,18 @@ +#include +#include + +/* + * a single panel for 240x320 + */ +void panel_init(void) +{ + rtgui_rect_t rect; + + /* register main panel */ + rect.x1 = 0; + rect.y1 = 0; + rect.x2 = 240; + rect.y2 = 320; + rtgui_panel_register("main", &rect); + rtgui_panel_set_default_focused("main"); +} diff --git a/examples/gui/demo_view.c b/examples/gui/demo_view.c index 48e78d4aa8..4440d4e129 100644 --- a/examples/gui/demo_view.c +++ b/examples/gui/demo_view.c @@ -1 +1,112 @@ #include +#include +#include +#include + +static rtgui_view_t* demo_view_list[32]; +static rt_uint32_t demo_view_current = 0; +static rt_uint32_t demo_view_number = 0; + +static void demo_view_next(struct rtgui_widget* widget, rtgui_event_t *event) +{ + RT_ASSERT(widget != RT_NULL); + + if (demo_view_current + 1< demo_view_number) + { + demo_view_current ++; + rtgui_view_show(demo_view_list[demo_view_current], RT_FALSE); + } +} + +static void demo_view_prev(struct rtgui_widget* widget, rtgui_event_t *event) +{ + RT_ASSERT(widget != RT_NULL); + + if (demo_view_current != 0) + { + demo_view_current --; + rtgui_view_show(demo_view_list[demo_view_current], RT_FALSE); + } +} + +rtgui_view_t* demo_view(rtgui_workbench_t* workbench) +{ + char view_name[32]; + struct rtgui_view* view; + + rt_sprintf(view_name, "view %d", demo_view_number + 1); + + view = rtgui_view_create(view_name); + + /* add to the list */ + demo_view_list[demo_view_number] = view; + demo_view_number ++; + + rtgui_workbench_add_view(workbench, view); + + /* add next and prev button */ + { + struct rtgui_rect rect; + struct rtgui_button *next_btn, *prev_btn; + + /* get view's rect */ + rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); + rect.x2 -= 5; rect.y2 -= 5; + rect.x1 = rect.x2 - 50; rect.y1 = rect.y2 - 20; + + /* create next button */ + next_btn = rtgui_button_create("Next"); + rtgui_button_set_onbutton(next_btn, demo_view_next); + rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(next_btn)); + + /* get view's rect */ + rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); + rect.x1 += 5; rect.y2 -= 5; + rect.x2 = rect.x1 + 50; rect.y1 = rect.y2 - 20; + + /* create previous button */ + prev_btn = rtgui_button_create("Prev"); + rtgui_button_set_onbutton(prev_btn, demo_view_prev); + rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(prev_btn)); + } + + return view; +} + +void demo_view_get_rect(rtgui_view_t* view, rtgui_rect_t *rect) +{ + RT_ASSERT(view != RT_NULL); + RT_ASSERT(rect != RT_NULL); + + rtgui_widget_get_rect(RTGUI_WIDGET(view), rect); + /* remove the command button rect */ + rect->y2 -= 25; +} + +#ifndef RTGUI_USING_SMALL_SIZE +rtgui_box_t* demo_view_create_box(rtgui_view_t* view, int orient) +{ + rtgui_rect_t rect; + rtgui_box_t* box; + + /* get rect of view */ + rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); + rect.y2 -= 25; + + box = rtgui_box_create(orient, &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box)); + + return box; +} +#endif + +void demo_view_show() +{ + if (demo_view_number != 0) + { + rtgui_view_show(demo_view_list[demo_view_current], RT_FALSE); + } +} + diff --git a/examples/gui/demo_view.h b/examples/gui/demo_view.h new file mode 100644 index 0000000000..4b5b6a173d --- /dev/null +++ b/examples/gui/demo_view.h @@ -0,0 +1,21 @@ +#ifndef __DEMO_VIEW_H__ +#define __DEMO_VIEW_H__ + +#include +#include +#include + +#ifndef RTGUI_USING_SMALL_SIZE +#include +#endif + +rtgui_view_t* demo_view(rtgui_workbench_t* workbench); +void demo_view_get_rect(rtgui_view_t* view, rtgui_rect_t *rect); +void demo_view_show(void); + +#ifndef RTGUI_USING_SMALL_SIZE +rtgui_box_t* demo_view_create_box(rtgui_view_t* view, int orient); +#endif + +#endif + diff --git a/examples/gui/demo_view_box.c b/examples/gui/demo_view_box.c new file mode 100644 index 0000000000..23d136826b --- /dev/null +++ b/examples/gui/demo_view_box.c @@ -0,0 +1,15 @@ +#include "demo_view.h" +#ifndef RTGUI_USING_SMALL_SIZE +#include + +rtgui_view_t* demo_view_box(rtgui_workbench_t* workbench) +{ + rtgui_rect_t rect; + rtgui_view_t* view; + + view = demo_view(workbench); + demo_view_get_rect(view, &rect); + + return view; +} +#endif diff --git a/examples/gui/demo_view_button.c b/examples/gui/demo_view_button.c index e69de29bb2..b3b343175e 100644 --- a/examples/gui/demo_view_button.c +++ b/examples/gui/demo_view_button.c @@ -0,0 +1,50 @@ +#include "demo_view.h" +#include + +rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench) +{ + rtgui_rect_t rect; + rtgui_view_t* view; + rtgui_button_t* button; + rtgui_font_t* font; + + /* create a demo view */ + view = demo_view(workbench); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 100; + rect.y1 += 5; rect.y2 = rect.y1 + 20; + button = rtgui_button_create("Red"); + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = red; + rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 100; + rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20; + button = rtgui_button_create("Blue"); + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = blue; + rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 100; + rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20; + button = rtgui_button_create("12 font"); + font = rtgui_font_refer("asc", 12); + RTGUI_WIDGET_FONT(RTGUI_WIDGET(button)) = font; + rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 100; + rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; + button = rtgui_button_create("16 font"); + font = rtgui_font_refer("asc", 16); + RTGUI_WIDGET_FONT(RTGUI_WIDGET(button)) = font; + rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); + + return view; +} + diff --git a/examples/gui/demo_view_checkbox.c b/examples/gui/demo_view_checkbox.c index e69de29bb2..0e916d0782 100644 --- a/examples/gui/demo_view_checkbox.c +++ b/examples/gui/demo_view_checkbox.c @@ -0,0 +1,51 @@ +#include "demo_view.h" +#include + +rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench) +{ + rtgui_rect_t rect; + rtgui_view_t* view; + rtgui_checkbox_t* checkbox; + rtgui_font_t* font; + + /* create a demo view */ + view = demo_view(workbench); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 100; + rect.y1 += 5; rect.y2 = rect.y1 + 20; + checkbox = rtgui_checkbox_create("Red"); + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = red; + rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox)); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 100; + rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20; + checkbox = rtgui_checkbox_create("Blue"); + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = blue; + rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox)); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 100; + rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20; + checkbox = rtgui_checkbox_create("12 font"); + font = rtgui_font_refer("asc", 12); + RTGUI_WIDGET_FONT(RTGUI_WIDGET(checkbox)) = font; + rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox)); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 100; + rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; + checkbox = rtgui_checkbox_create("16 font"); + font = rtgui_font_refer("asc", 16); + RTGUI_WIDGET_FONT(RTGUI_WIDGET(checkbox)) = font; + rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox)); + + return view; +} + + diff --git a/examples/gui/demo_view_dc.c b/examples/gui/demo_view_dc.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/gui/demo_view_image.c b/examples/gui/demo_view_image.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/gui/demo_view_label.c b/examples/gui/demo_view_label.c new file mode 100644 index 0000000000..aab70f3c4b --- /dev/null +++ b/examples/gui/demo_view_label.c @@ -0,0 +1,61 @@ +#include "demo_view.h" +#include + +rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench) +{ + rtgui_rect_t rect; + rtgui_view_t* view; + rtgui_label_t* label; + rtgui_font_t* font; + + /* create a demo view */ + view = demo_view(workbench); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 -= 5; + rect.y1 += 5; rect.y2 = rect.y1 + 20; + label = rtgui_label_create("Red Left"); + RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_LEFT; + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = red; + rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 -= 5; + rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20; + label = rtgui_label_create("Blue Right"); + RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_RIGHT; + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = blue; + rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 -= 5; + rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20; + label = rtgui_label_create("Green Center"); + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = green; + RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_CENTER_HORIZONTAL; + rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 -= 5; + rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; + label = rtgui_label_create("12 font"); + font = rtgui_font_refer("asc", 12); + RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font; + rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; + rect.y1 += 5 + 25 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; + label = rtgui_label_create("16 font"); + font = rtgui_font_refer("asc", 16); + RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font; + rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); + + return view; +} + diff --git a/examples/gui/demo_view_progressbar.c b/examples/gui/demo_view_progressbar.c index e69de29bb2..b336b5fb57 100644 --- a/examples/gui/demo_view_progressbar.c +++ b/examples/gui/demo_view_progressbar.c @@ -0,0 +1,59 @@ +#include "demo_view.h" +#include +#include +#include + +static rtgui_progressbar_t* hbar; +static rtgui_progressbar_t* vbar; +static rtgui_timer_t *bar_timer = RT_NULL; + +void progressbar_timeout(struct rtgui_timer* timer, void* parameter) +{ + static rt_uint32_t value = 0; + + value ++; + if (value == 100) value = 0; + + rtgui_progressbar_set_value(hbar, value); + rtgui_progressbar_set_value(vbar, value); +} + +rtgui_view_t *demo_view_progressbar(rtgui_workbench_t* workbench) +{ + rtgui_view_t *view; + rtgui_rect_t rect; + rtgui_label_t *label; + + /* create a demo view */ + view = demo_view(workbench); + + /* get demo view rect */ + demo_view_get_rect(view, &rect); + label = rtgui_label_create("horizontal progress bar:"); + rtgui_container_add_child(RTGUI_CONTAINER(view), 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(RTGUI_CONTAINER(view), RTGUI_WIDGET(hbar)); + + /* get demo view rect */ + demo_view_get_rect(view, &rect); + label = rtgui_label_create("vertical progress bar:"); + rtgui_container_add_child(RTGUI_CONTAINER(view), 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(RTGUI_CONTAINER(view), RTGUI_WIDGET(vbar)); + + bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC, + progressbar_timeout, RT_NULL); + rtgui_timer_start(bar_timer); + + return view; +} + diff --git a/examples/gui/demo_view_radiobox.c b/examples/gui/demo_view_radiobox.c index e69de29bb2..ce29962158 100644 --- a/examples/gui/demo_view_radiobox.c +++ b/examples/gui/demo_view_radiobox.c @@ -0,0 +1,48 @@ +#include "demo_view.h" +#include + +static char* radio_item[5] = +{ + "one", + "two", + "three", + "item 1", + "item 2" +}; + +static char* radio_item_h[3] = +{ + "one", "two", "three" +}; + +rtgui_view_t* demo_view_radiobox(rtgui_workbench_t* workbench) +{ + rtgui_rect_t rect; + rtgui_view_t* view; + rtgui_radiobox_t* radiobox; + + view = demo_view(workbench); + demo_view_get_rect(view, &rect); + + rect.x1 += 5; rect.x2 -= 5; + rect.y1 += 5; rect.y2 = rect.y1 + 5 * 25; + + radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item, 5); + rtgui_radiobox_set_selection(radiobox, 0); + + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox)); + rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 -= 5; + rect.y1 = 5 + 5 * 25; rect.y2 = rect.y1 + 60; + + radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3); + rtgui_radiobox_set_selection(radiobox, 0); + + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox)); + rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect); + + return view; +} + diff --git a/examples/gui/demo_view_slider.c b/examples/gui/demo_view_slider.c index e69de29bb2..28f5f0ceaf 100644 --- a/examples/gui/demo_view_slider.c +++ b/examples/gui/demo_view_slider.c @@ -0,0 +1,42 @@ +#include "demo_view.h" +#include +#include +#include + +rtgui_view_t *demo_view_slider(rtgui_workbench_t* workbench) +{ + rtgui_view_t *view; + rtgui_rect_t rect; + rtgui_label_t *label; + rtgui_slider_t *slider; + + /* create a demo view */ + view = demo_view(workbench); + + /* get demo view rect */ + demo_view_get_rect(view, &rect); + label = rtgui_label_create("horizontal slider:"); + rtgui_container_add_child(RTGUI_CONTAINER(view), 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; + slider = rtgui_slider_create(0, 100, RTGUI_HORIZONTAL); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(slider)); + rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect); + + /* get demo view rect */ + demo_view_get_rect(view, &rect); + label = rtgui_label_create("vertical slider:"); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); + rect.x1 += 5; rect.x2 -= 5; + rect.y1 += 50; 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; + slider = rtgui_slider_create(0, 100, RTGUI_VERTICAL); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(slider)); + rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect); + + return view; +} diff --git a/examples/gui/demo_view_window.c b/examples/gui/demo_view_window.c new file mode 100644 index 0000000000..e78385ffe9 --- /dev/null +++ b/examples/gui/demo_view_window.c @@ -0,0 +1,146 @@ +#include +#include +#include +#include +#include +#include "demo_view.h" + +static struct rtgui_timer *timer; +static struct rtgui_label* label; +static struct rtgui_win* msgbox; +static rt_uint8_t label_text[80]; +static int cnt = 5; + +void diag_close(struct rtgui_timer* timer, void* parameter) +{ + sprintf(label_text, "closed then %d second!", cnt); + + rtgui_label_set_text(label, label_text); + rtgui_widget_update(RTGUI_WIDGET(label)); + if (cnt == 0) + { + rtgui_win_destroy(msgbox); + rtgui_timer_stop(timer); + rtgui_timer_destory(timer); + } + + cnt --; +} + +void window_demo() +{ + rt_mq_t mq; + rt_thread_t tid; + rt_uint32_t user_data; + struct rtgui_rect rect = {50, 50, 200, 200}; + + tid = rt_thread_self(); + if (tid == RT_NULL) return; /* can't use in none-scheduler environement */ + user_data = tid->user_data; + + /* create gui message queue */ + mq = rt_mq_create("msgbox", 256, 4, RT_IPC_FLAG_FIFO); + /* register message queue on current thread */ + rtgui_thread_register(rt_thread_self(), mq); + + msgbox = rtgui_win_create(RT_NULL, "Information", &rect, RTGUI_WIN_STYLE_DEFAULT); + if (msgbox != RT_NULL) + { + struct rtgui_box* box = rtgui_box_create(RTGUI_VERTICAL, RT_NULL); + + cnt = 5; + sprintf(label_text, "closed then %d second!", cnt); + label = rtgui_label_create(label_text); + + rtgui_win_set_box(msgbox, box); + RTGUI_WIDGET(label)->align = RTGUI_ALIGN_CENTER_HORIZONTAL | + RTGUI_ALIGN_CENTER_VERTICAL; + rtgui_widget_set_miniwidth(RTGUI_WIDGET(label),130); + rtgui_box_append(box, RTGUI_WIDGET(label)); + rtgui_box_layout(box); + + rtgui_win_show(msgbox, RT_FALSE); + } + + timer = rtgui_timer_create(200, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL); + rtgui_timer_start(timer); + + rtgui_win_event_loop(msgbox); + + rtgui_thread_deregister(rt_thread_self()); + /* remove RTGUI message queue */ + rt_mq_delete(mq); + + /* recover user data */ + tid->user_data = user_data; +} + +#ifdef RT_USING_FINSH +#include +void win_demo() +{ + window_demo(); +} +FINSH_FUNCTION_EXPORT(win_demo, a window demo) +#endif + +static void demo_win_onbutton(struct rtgui_widget* widget, rtgui_event_t* event) +{ + window_demo(); +} + +static void demo_autowin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event) +{ +} + +static void demo_modalwin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event) +{ +} + +static void demo_ntitlewin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event) +{ +} + +rtgui_view_t* demo_view_window(rtgui_workbench_t* workbench) +{ + rtgui_rect_t rect; + rtgui_view_t* view; + rtgui_button_t *button; + + view = demo_view(workbench); + demo_view_get_rect(view, &rect); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 100; + rect.y1 += 5; rect.y2 = rect.y1 + 20; + button = rtgui_button_create("Normal Win"); + rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); + rtgui_button_set_onbutton(button, demo_win_onbutton); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 100; + rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20; + button = rtgui_button_create("Auto Win"); + rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); + rtgui_button_set_onbutton(button, demo_autowin_onbutton); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 100; + rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20; + button = rtgui_button_create("Modal Win"); + rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); + rtgui_button_set_onbutton(button, demo_modalwin_onbutton); + + demo_view_get_rect(view, &rect); + rect.x1 += 5; rect.x2 = rect.x1 + 100; + rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; + button = rtgui_button_create("NoTitle Win"); + rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); + rtgui_button_set_onbutton(button, demo_ntitlewin_onbutton); + + return view; +} diff --git a/examples/gui/demo_window.c b/examples/gui/demo_window.c deleted file mode 100644 index 9d3a5a7773..0000000000 --- a/examples/gui/demo_window.c +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include -#include -#include - -static struct rtgui_timer *timer; -static struct rtgui_label* label; -static struct rtgui_win* msgbox; -static rt_uint8_t label_text[80]; -static int cnt = 5; - -void diag_close(struct rtgui_timer* timer, void* parameter) -{ - sprintf(label_text, "closed then %d second!", cnt); - - rtgui_label_set_text(label, label_text); - rtgui_widget_update(RTGUI_WIDGET(label)); - if (cnt == 0) - { - rtgui_win_destroy(msgbox); - rtgui_timer_stop(timer); - rtgui_timer_destory(timer); - } - - cnt --; -} - -void window_demo() -{ - rt_mq_t mq; - rt_thread_t tid; - rt_uint32_t user_data; - struct rtgui_rect rect = {50, 50, 200, 200}; - - tid = rt_thread_self(); - if (tid == RT_NULL) return; /* can't use in none-scheduler environement */ - user_data = tid->user_data; - - /* create gui message queue */ - mq = rt_mq_create("msgbox", 256, 4, RT_IPC_FLAG_FIFO); - /* register message queue on current thread */ - rtgui_thread_register(rt_thread_self(), mq); - - msgbox = rtgui_win_create(RT_NULL, "Information", &rect, RTGUI_WIN_STYLE_DEFAULT); - if (msgbox != RT_NULL) - { - struct rtgui_box* box = rtgui_box_create(RTGUI_VERTICAL, RT_NULL); - - cnt = 5; - sprintf(label_text, "closed then %d second!", cnt); - label = rtgui_label_create(label_text); - - rtgui_win_set_box(msgbox, box); - RTGUI_WIDGET(label)->align = RTGUI_ALIGN_CENTER_HORIZONTAL | - RTGUI_ALIGN_CENTER_VERTICAL; - rtgui_widget_set_miniwidth(RTGUI_WIDGET(label),130); - rtgui_box_append(box, RTGUI_WIDGET(label)); - rtgui_box_layout(box); - - rtgui_win_show(msgbox, RT_FALSE); - } - - timer = rtgui_timer_create(200, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL); - rtgui_timer_start(timer); - - rtgui_win_event_loop(msgbox); - - rtgui_thread_deregister(rt_thread_self()); - /* remove RTGUI message queue */ - rt_mq_delete(mq); - - /* recover user data */ - tid->user_data = user_data; -} - -void window_demo_init() -{ - rt_thread_t tid; - - tid = rt_thread_create("win", - window_demo, RT_NULL, - 2048, 25, 10); - - if (tid != RT_NULL) rt_thread_startup(tid); -} - -#ifdef RT_USING_FINSH -#include -void win_demo() -{ - window_demo(); -} -FINSH_FUNCTION_EXPORT(win_demo, a window demo) -#endif diff --git a/examples/gui/demo_workbench.c b/examples/gui/demo_workbench.c index f758fb39ea..8a39701331 100644 --- a/examples/gui/demo_workbench.c +++ b/examples/gui/demo_workbench.c @@ -55,8 +55,16 @@ static void workbench_entry(void* parameter) /* 在工作台上添加一个视图 */ rtgui_workbench_add_view(workbench, view); - /* 显示这个视图 */ - rtgui_view_show(view, RT_FALSE); + demo_view_label(workbench); + demo_view_button(workbench); + demo_view_checkbox(workbench); + demo_view_progressbar(workbench); + demo_view_radiobox(workbench); + demo_fn_view(workbench); + demo_view_slider(workbench); + + /* 显示视图 */ + demo_view_show(); /* 执行工作台事件循环 */ rtgui_workbench_event_loop(workbench);