rt-thread/examples/rtgui_win/demo_gui_win.c

93 lines
2.2 KiB
C
Raw Normal View History

/*
* <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>win
*/
#include <rtthread.h>
#include <rtgui/rtgui.h>
#include <rtgui/event.h>
#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;
static rt_bool_t demo_gui_win_event_handler(PVOID wdt, rtgui_event_t* event)
{
if(event->type == RTGUI_EVENT_PAINT)
{
}
/* <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>ʹ<EFBFBD><CAB9>winĬ<6E>ϵ<EFBFBD><CFB5>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
return rtgui_win_event_handler(wdt, event);
}
static void gui_win_entry(void* parameter)
{
const struct rtgui_graphic_driver* gd = rtgui_graphic_driver_get_default();
struct rt_messagequeue *mq;
rtgui_win_t *win;
rtgui_button_t *button;
rtgui_point_t p;
rtgui_rect_t rect = {0,0,200,180};
rtgui_label_t *label;
rtgui_font_t *font;
/* <20><><EFBFBD><EFBFBD>GUIӦ<49><D3A6><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD> */
mq = rt_mq_create("demo_win", 256, 32, RT_IPC_FLAG_FIFO);
/* ע<>ᵱǰ<E1B5B1>߳<EFBFBD> */
rtgui_thread_register(rt_thread_self(), mq);
/* <20><><EFBFBD>ھ<EFBFBD><DABE><EFBFBD> */
rtgui_rect_moveto(&rect, (gd->width - rtgui_rect_width(rect))/2, (gd->height - rtgui_rect_height(rect))/2);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
win = rtgui_win_create(RT_NULL,"demo_win",&rect,RTGUI_WIN_DEFAULT);
if(win == RT_NULL) return;
/* ȡ<>ÿͻ<C3BF><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
p = rtgui_win_get_client_zero(win);
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", (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);
rtgui_win_show(win,RT_FALSE);
/* ִ<>й<EFBFBD><D0B9><EFBFBD>̨<EFBFBD>¼<EFBFBD>ѭ<EFBFBD><D1AD> */
rtgui_win_event_loop(win);
demo_win_inited = RT_FALSE;
/* ȥע<C8A5><D7A2>GUI<55>߳<EFBFBD> */
rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq);
}
void demo_gui_win(PVOID wdt, rtgui_event_t *event)
{
if(demo_win_inited == RT_FALSE) /* <20><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD> */
{
struct rt_thread* tid;
tid = rt_thread_create("demo_win", gui_win_entry, RT_NULL, 1024, 5, 10);
if(tid != RT_NULL) rt_thread_startup(tid);
demo_win_inited = RT_TRUE;
}
}