rtt-f030/examples/rtgui_win/demo_gui_main.c

100 lines
2.5 KiB
C
Raw Normal View History

/*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>RTGUI<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>RTGUI<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>rtgui_win<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>У<EFBFBD>û<EFBFBD><EFBFBD>toplevel<EFBFBD>ؼ<EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><EFBFBD>panel
* <EFBFBD><EFBFBD>Ϊtoplevel<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 <rtthread.h>
#include <rtgui/rtgui.h>
#include <panel.h>
#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);
rtgui_listbox_t *__lbox;
static rtgui_listbox_item_t _demo_list[] =
{
{"item1", RT_NULL},
{"item2", RT_NULL},
};
/* <20><><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ŀ */
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 void rtgui_panel_entry(void* parameter)
{
const struct rtgui_graphic_driver* gd = rtgui_graphic_driver_get_default();
struct rt_messagequeue* mq;
rtgui_panel_t *panel;
rtgui_view_t *view;
rtgui_button_t *button;
/* <20><><EFBFBD><EFBFBD>GUIӦ<49><D3A6><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD> */
mq = rt_mq_create("Panel", 256, 32, RT_IPC_FLAG_FIFO);
/* ע<>ᵱǰ<E1B5B1>߳<EFBFBD>ΪGUI<55>߳<EFBFBD> */
rtgui_thread_register(rt_thread_self(), mq);
panel = rtgui_panel_create(0,0,gd->width,gd->height);
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><>Ϣ<EFBFBD><CFA2>
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);
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>б<EFBFBD>
__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);
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><E0BCAD>
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, "win",140,90,50,25);
rtgui_button_set_onbutton(button,demo_gui_win);
///////////////////////////////////////////////////////
rtgui_panel_show(panel);
/* ִ<>й<EFBFBD><D0B9><EFBFBD>̨<EFBFBD>¼<EFBFBD>ѭ<EFBFBD><D1AD> */
rtgui_panel_event_loop(panel);
/* ȥע<C8A5><D7A2>GUI<55>߳<EFBFBD> */
rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq);
}
void rtgui_panel_init(void)
{
static rt_bool_t main_inited = RT_FALSE;
if(main_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("Panel", rtgui_panel_entry, RT_NULL, 4096, 4, 5);
if(tid != RT_NULL) rt_thread_startup(tid);
main_inited = RT_TRUE;
}
}