2011-03-27 00:05:51 +08:00
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>嵥<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD><EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>õ<EFBFBD>view<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>ťʱ<EFBFBD>ͬ<EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
|
|
/* <20><>ȡһ<C8A1><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4>ڱ<EFBFBD><DAB1><EFBFBD> */
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20>رնԻ<D5B6><D4BB><EFBFBD>ʱ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD>ñ<EFBFBD>ǩ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¿ؼ<C2BF> */
|
|
|
|
|
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;
|
|
|
|
|
/* <20><>ʱ<EFBFBD><CAB1><EFBFBD>رնԻ<D5B6><D4BB><EFBFBD> */
|
|
|
|
|
rtgui_win_close(win, RT_NULL);
|
|
|
|
|
|
|
|
|
|
/* ֹͣ<CDA3><D6B9>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
|
|
|
|
|
rtgui_timer_stop(timer);
|
|
|
|
|
rtgui_timer_destory(timer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static rt_uint16_t delta_x = 20;
|
|
|
|
|
static rt_uint16_t delta_y = 40;
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ */
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
win = rtgui_win_create(parent, get_win_title(), &rect, RTGUI_WIN_DEFAULT);
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ǩ */
|
|
|
|
|
rtgui_label_create(win, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 10, 30, 150, 20);
|
|
|
|
|
|
|
|
|
|
/* <20><>ģ̬<C4A3><CCAC>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD> */
|
|
|
|
|
rtgui_win_show(win, RT_FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ */
|
|
|
|
|
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);
|
|
|
|
|
/* <20><><EFBFBD>ùرմ<D8B1><D5B4><EFBFBD>ʱ<EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD> */
|
|
|
|
|
rtgui_win_set_onclose(msgbox, auto_window_close);
|
|
|
|
|
|
|
|
|
|
rtgui_win_show(msgbox, RT_FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
|
|
|
|
|
timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, label);
|
|
|
|
|
rtgui_timer_start(timer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>ģ̬<C4A3><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ */
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
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, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 20, 30, 150,20);
|
|
|
|
|
|
|
|
|
|
/* ģ̬<C4A3><CCAC>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD> */
|
|
|
|
|
rtgui_win_show(win, RT_TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>ޱ<EFBFBD><DEB1>ⴰ<EFBFBD><E2B4B0><EFBFBD><EFBFBD>ʾ */
|
|
|
|
|
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;
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ޱ<EFBFBD><DEB1>⼰<EFBFBD>ޱ߿<DEB1> */
|
2011-04-16 18:20:24 +08:00
|
|
|
|
win = rtgui_win_create(parent,"no title", &rect, RTGUI_WIN_DEFAULT);
|
2011-03-27 00:05:51 +08:00
|
|
|
|
RTGUI_WIDGET_BACKGROUND(win) = white;
|
2011-04-16 18:20:24 +08:00
|
|
|
|
win->level = RTGUI_WIN_LEVEL_EXPERT;
|
2011-03-27 00:05:51 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ǩ */
|
2011-04-16 18:20:24 +08:00
|
|
|
|
label = rtgui_label_create(win, "<EFBFBD>ޱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 10, 30, 100, 20);
|
2011-03-27 00:05:51 +08:00
|
|
|
|
RTGUI_WIDGET_BACKGROUND(label) = white;
|
|
|
|
|
|
|
|
|
|
button = rtgui_button_create(win,"<EFBFBD>ر<EFBFBD>", 65, 85, 60, 25);
|
|
|
|
|
rtgui_button_set_onbutton(button, rtgui_win_close);
|
|
|
|
|
|
|
|
|
|
/* <20><>ģ̬<C4A3><CCAC>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD> */
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʾ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ͼ */
|
|
|
|
|
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;
|
|
|
|
|
}
|