mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-12-28 18:10:21 +00:00
update GUI examples.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@344 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
28
examples/gui/SConscript
Normal file
28
examples/gui/SConscript
Normal file
@@ -0,0 +1,28 @@
|
||||
Import('env')
|
||||
|
||||
src_local = Split("""
|
||||
demo_fnview.c
|
||||
demo_listview.c
|
||||
demo_panel_single.c
|
||||
demo_view.c
|
||||
demo_view_box.c
|
||||
demo_view_button.c
|
||||
demo_view_checkbox.c
|
||||
demo_view_dc.c
|
||||
demo_view_image.c
|
||||
demo_view_label.c
|
||||
demo_view_mywidget.c
|
||||
demo_view_progressbar.c
|
||||
demo_view_radiobox.c
|
||||
demo_view_slider.c
|
||||
demo_view_textbox.c
|
||||
demo_view_window.c
|
||||
demo_workbench.c
|
||||
gui_init.c
|
||||
mywidget.c
|
||||
""")
|
||||
|
||||
# The set of source files associated with this SConscript file.
|
||||
obj = env.Object(src_local)
|
||||
|
||||
Return('obj')
|
||||
@@ -8,10 +8,8 @@ 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)
|
||||
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 ++;
|
||||
@@ -19,10 +17,8 @@ static void demo_view_next(struct rtgui_widget* widget, rtgui_event_t *event)
|
||||
}
|
||||
}
|
||||
|
||||
static void demo_view_prev(struct rtgui_widget* widget, rtgui_event_t *event)
|
||||
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 --;
|
||||
|
||||
@@ -12,11 +12,11 @@ rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
||||
rt_uint32_t vx[] = {20, 50, 60, 45, 60, 20};
|
||||
rt_uint32_t vy[] = {150, 50, 90, 60, 45, 50};
|
||||
|
||||
/* <20><>Ϊ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>demo view<65><77><EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֿؼ<D6BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>ͼʱ<CDBC><CAB1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD>ͼ */
|
||||
/* <20><>Ϊ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>demo view<65><77><EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֿؼ<D6BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>ͼʱ<CDBC><CAB1>Ҫ<EFBFBD><D2AA>demo view<EFBFBD>Ȼ<EFBFBD>ͼ */
|
||||
rtgui_view_event_handler(widget, event);
|
||||
|
||||
/************************************************************************/
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<44>Ĵ<EFBFBD><C4B4><EFBFBD> */
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<44>Ĵ<EFBFBD><C4B4><EFBFBD> */
|
||||
/************************************************************************/
|
||||
|
||||
/* <20><><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC */
|
||||
@@ -35,6 +35,10 @@ rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
||||
rtgui_dc_set_color(dc, green);
|
||||
rtgui_dc_fill_circle(dc, rect.x1 + 30, rect.y1 + 10, 10);
|
||||
|
||||
/* <20><>һ<EFBFBD><D2BB>Բ<EFBFBD><D4B2> */
|
||||
rtgui_dc_set_color(dc, RTGUI_RGB(250, 120, 120));
|
||||
rtgui_dc_draw_arc(dc, rect.x1 + 120, rect.y1 + 60, 30, 0, 120);
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
rtgui_dc_set_color(dc, blue);
|
||||
rtgui_dc_draw_polygon(dc, vx, vy, 6);
|
||||
@@ -56,7 +60,8 @@ rtgui_view_t *demo_view_dc(rtgui_workbench_t* workbench)
|
||||
rtgui_view_t *view;
|
||||
|
||||
view = demo_view(workbench, "DC Demo");
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), dc_event_handler);
|
||||
if (view != RT_NULL)
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), dc_event_handler);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#include "demo_view.h"
|
||||
#include <rtgui/widgets/button.h>
|
||||
#include <rtgui/widgets/filelist_view.h>
|
||||
|
||||
static rtgui_image_t* image = RT_NULL;
|
||||
static rtgui_view_t* _view = RT_NULL;
|
||||
|
||||
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
||||
{
|
||||
/* create a file list view */
|
||||
rtgui_filelist_view_t *view;
|
||||
rtgui_workbench_t *workbench;
|
||||
rtgui_rect_t rect;
|
||||
|
||||
workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
|
||||
|
||||
#ifdef _WIN32
|
||||
view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect);
|
||||
#else
|
||||
view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
|
||||
#endif
|
||||
if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
|
||||
{
|
||||
char path[32], image_type[8];
|
||||
|
||||
/* set label */
|
||||
rtgui_filelist_get_fullpath(view, path, sizeof(path));
|
||||
if (image != RT_NULL) rtgui_image_destroy(image);
|
||||
|
||||
rt_memset(image_type, 0, sizeof(image_type));
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if (rt_strstr(path, ".png") != RT_NULL) strcat(image_type, "png");
|
||||
if (rt_strstr(path, ".jpg") != RT_NULL) strcat(image_type, "jpeg");
|
||||
if (rt_strstr(path, ".hdc") != RT_NULL) strcat(image_type, "hdc");
|
||||
if (image_type[0] != '\0')
|
||||
image = rtgui_image_create_from_file(image_type, path, RT_TRUE);
|
||||
}
|
||||
|
||||
/* ɾ<><C9BE> <20>ļ<EFBFBD><C4BC>б<EFBFBD> <20><>ͼ */
|
||||
rtgui_view_destroy(RTGUI_VIEW(view));
|
||||
rtgui_view_show(_view, RT_FALSE);
|
||||
}
|
||||
|
||||
static rt_bool_t demo_view_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
||||
{
|
||||
rt_bool_t result;
|
||||
|
||||
/* <20><>Ĭ<EFBFBD>ϵ<EFBFBD><CFB5>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
result = rtgui_view_event_handler(widget, event);
|
||||
|
||||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
rtgui_rect_t rect;
|
||||
|
||||
/* <20><><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC */
|
||||
dc = rtgui_dc_begin_drawing(widget);
|
||||
if (dc == RT_NULL) /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<44><43><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC>ؼ<F2B8B8BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>DC<44>ǻ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ɹ<EFBFBD><C9B9>ģ<EFBFBD> */
|
||||
return RT_FALSE;
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>demo view<65><77><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
demo_view_get_rect(RTGUI_VIEW(widget), &rect);
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD> */
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
rect.y1 += 30;
|
||||
|
||||
if (image != RT_NULL)
|
||||
rtgui_image_blit(image, dc, &rect);
|
||||
|
||||
/* <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD> */
|
||||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
rtgui_view_t* demo_view_image(rtgui_workbench_t* workbench)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_button_t* open_btn;
|
||||
|
||||
_view = demo_view(workbench, "ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ");
|
||||
if (_view != RT_NULL)
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(_view), demo_view_event_handler);
|
||||
|
||||
demo_view_get_rect(_view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 120;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
open_btn = rtgui_button_create("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>");
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(_view), RTGUI_WIDGET(open_btn));
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
|
||||
rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
|
||||
|
||||
return _view;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "demo_view.h"
|
||||
#include "mywidget.h"
|
||||
|
||||
rtgui_view_t *demo_view_mywidget(rtgui_workbench_t* workbench)
|
||||
{
|
||||
rtgui_view_t *view;
|
||||
rtgui_rect_t rect;
|
||||
rtgui_mywidget_t *mywidget;
|
||||
|
||||
/* create a demo view */
|
||||
view = demo_view(workbench, "MyWidget View");
|
||||
|
||||
/* get demo view rect */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.y1 + 80;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 80;
|
||||
mywidget = rtgui_mywidget_create(&rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(mywidget));
|
||||
|
||||
/* get demo view rect */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 25; rect.x2 = rect.y1 + 40;
|
||||
rect.y1 += 5 + 100; rect.y2 = rect.y1 + 40;
|
||||
mywidget = rtgui_mywidget_create(&rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(mywidget));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -4,33 +4,30 @@
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/widgets/workbench.h>
|
||||
|
||||
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
static rt_bool_t demo_workbench_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
{
|
||||
/* 我们目前只对绘制事件感兴趣 */
|
||||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
/* 我们目前只对按键事件感兴趣 */
|
||||
if (event->type == RTGUI_EVENT_KBD)
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
struct rtgui_rect rect;
|
||||
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
|
||||
|
||||
/* 获得一个设备上下文 */
|
||||
dc = rtgui_dc_begin_drawing(widget);
|
||||
if (dc == RT_NULL) return RT_FALSE; /* 如果获取失败代表什么?这个控件是隐藏的或... */
|
||||
rtgui_widget_get_rect(widget, &rect); /* 获得控件的可视区域 */
|
||||
|
||||
/* 先对所在可视区域全部填充为背景色 */
|
||||
rtgui_dc_fill_rect(dc, &rect);
|
||||
|
||||
/* 绘制一个hello! */
|
||||
rtgui_dc_draw_text(dc, "hello world", &rect);
|
||||
|
||||
/* 通知RTGUI,绘制结束 */
|
||||
rtgui_dc_end_drawing(dc);
|
||||
|
||||
return RT_FALSE;
|
||||
if (ekbd->type == RTGUI_KEYDOWN)
|
||||
{
|
||||
if (ekbd->key == RTGUIK_RIGHT)
|
||||
{
|
||||
demo_view_next(RT_NULL, RT_NULL);
|
||||
return RT_TRUE;
|
||||
}
|
||||
else if (ekbd->key == RTGUIK_LEFT)
|
||||
{
|
||||
demo_view_prev(RT_NULL, RT_NULL);
|
||||
return RT_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 如果不是绘制事件,使用view原来的事件处理函数处理 */
|
||||
return rtgui_view_event_handler(widget, event);
|
||||
return rtgui_workbench_event_handler(widget, event);
|
||||
}
|
||||
|
||||
static void workbench_entry(void* parameter)
|
||||
@@ -48,13 +45,9 @@ static void workbench_entry(void* parameter)
|
||||
workbench = rtgui_workbench_create("main", "workbench");
|
||||
if (workbench == RT_NULL) return;
|
||||
|
||||
/* 创建一个工作台上的一个视图 */
|
||||
view = rtgui_view_create("view");
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler);
|
||||
|
||||
/* 在工作台上添加一个视图 */
|
||||
rtgui_workbench_add_view(workbench, view);
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(workbench), demo_workbench_event_handler);
|
||||
|
||||
/* 初始化各个例子的视图 */
|
||||
demo_view_dc(workbench);
|
||||
demo_view_window(workbench);
|
||||
demo_view_label(workbench);
|
||||
@@ -64,6 +57,8 @@ static void workbench_entry(void* parameter)
|
||||
demo_view_radiobox(workbench);
|
||||
demo_view_textbox(workbench);
|
||||
demo_view_slider(workbench);
|
||||
demo_view_mywidget(workbench);
|
||||
demo_view_image(workbench);
|
||||
demo_listview_view(workbench);
|
||||
demo_fn_view(workbench);
|
||||
|
||||
|
||||
25
examples/gui/gui_init.c
Normal file
25
examples/gui/gui_init.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
|
||||
extern void rt_hw_lcd_init(void);
|
||||
extern void rt_hw_key_init(void);
|
||||
extern void workbench_init(void);
|
||||
extern void panel_init(void);
|
||||
|
||||
/* GUI<55><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3>н<EFBFBD><D0BD>г<EFBFBD>ʼ<EFBFBD><CABC> */
|
||||
void rtgui_startup()
|
||||
{
|
||||
/* GUIϵͳ<CFB5><CDB3>ʼ<EFBFBD><CABC> */
|
||||
rtgui_system_server_init();
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> */
|
||||
rt_hw_key_init();
|
||||
/* LCD<43><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> */
|
||||
rt_hw_lcd_init();
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> */
|
||||
panel_init();
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>workbench */
|
||||
workbench_init();
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
#include <rtgui/dc.h>
|
||||
#include "mywidget.h"
|
||||
|
||||
/* 控件绘图函数 */
|
||||
static void rtgui_mywidget_ondraw(struct rtgui_mywidget* me)
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
struct rtgui_rect rect;
|
||||
rt_uint16_t x, y;
|
||||
|
||||
/* 获得目标DC,开始绘图 */
|
||||
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(me));
|
||||
if (dc == RT_NULL) return;
|
||||
|
||||
/* 获得窗口的尺寸 */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect);
|
||||
/* 绘制背景色 */
|
||||
rtgui_dc_set_color(dc, white);
|
||||
rtgui_dc_fill_rect(dc, &rect);
|
||||
|
||||
/* 计算中心原点 */
|
||||
x = (rect.x2 + rect.x1)/2; y = (rect.y2 + rect.y1)/2;
|
||||
|
||||
/* 绘制十字架 */
|
||||
rtgui_dc_set_color(dc, black);
|
||||
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, y);
|
||||
rtgui_dc_draw_vline(dc, x, rect.y1, rect.y2);
|
||||
|
||||
/* 根据状态绘制圆圈 */
|
||||
if (me->status == MYWIDGET_STATUS_ON)
|
||||
rtgui_dc_set_color(dc, green);
|
||||
else
|
||||
rtgui_dc_set_color(dc, red);
|
||||
rtgui_dc_fill_circle(dc, x, y, 5);
|
||||
|
||||
/* 结束绘图 */
|
||||
rtgui_dc_end_drawing(dc);
|
||||
return;
|
||||
}
|
||||
|
||||
/* 鼠标事件处理函数 */
|
||||
static void rtgui_mywidget_onmouse(struct rtgui_mywidget* me, struct rtgui_event_mouse* mouse)
|
||||
{
|
||||
struct rtgui_rect rect;
|
||||
rt_uint16_t x, y;
|
||||
|
||||
/* 仅对鼠标抬起动作进行处理 */
|
||||
if (!(mouse->button & RTGUI_MOUSE_BUTTON_UP)) return;
|
||||
|
||||
/* 获得控件的位置 */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect);
|
||||
/* get_rect函数获得是控件的相对位置,而鼠标事件给出的坐标是绝对坐标,需要做一个转换 */
|
||||
rtgui_widget_rect_to_device(RTGUI_WIDGET(me), &rect);
|
||||
|
||||
/* 计算中心原点 */
|
||||
x = (rect.x2 + rect.x1)/2; y = (rect.y2 + rect.y1)/2;
|
||||
|
||||
/* 比较鼠标坐标是否在圈内 */
|
||||
if ((mouse->x < x + 5 && mouse->x > x - 5) &&
|
||||
(mouse->y < y + 5 && mouse->y > y - 5))
|
||||
{
|
||||
/* 更改控件状态 */
|
||||
if (me->status & MYWIDGET_STATUS_ON) me->status = MYWIDGET_STATUS_OFF;
|
||||
else me->status = MYWIDGET_STATUS_ON;
|
||||
|
||||
/* 刷新(重新绘制)控件 */
|
||||
rtgui_mywidget_ondraw(me);
|
||||
}
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_mywidget* me = (struct rtgui_mywidget*)widget;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
/* 绘制事件,调用绘图函数绘制 */
|
||||
rtgui_mywidget_ondraw(me);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
/* 鼠标事件 */
|
||||
rtgui_mywidget_onmouse(RTGUI_MYWIDGET(me), (struct rtgui_event_mouse*) event);
|
||||
break;
|
||||
|
||||
/* 其他事件调用父类的事件处理函数 */
|
||||
default:
|
||||
rtgui_widget_event_handler(widget, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
static void _rtgui_mywidget_constructor(rtgui_mywidget_t *mywidget)
|
||||
{
|
||||
/* 初始化控件并设置事件处理函数 */
|
||||
RTGUI_WIDGET(mywidget)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(mywidget), rtgui_mywidget_event_handler);
|
||||
|
||||
mywidget->status = MYWIDGET_STATUS_OFF;
|
||||
}
|
||||
|
||||
static void _rtgui_mywidget_destructor(rtgui_mywidget_t *mywidget)
|
||||
{
|
||||
}
|
||||
|
||||
rtgui_type_t *rtgui_mywidget_type_get(void)
|
||||
{
|
||||
static rtgui_type_t *mywidget_type = RT_NULL;
|
||||
|
||||
if (!mywidget_type)
|
||||
{
|
||||
mywidget_type = rtgui_type_create("mywidget", RTGUI_WIDGET_TYPE,
|
||||
sizeof(rtgui_mywidget_t),
|
||||
RTGUI_CONSTRUCTOR(_rtgui_mywidget_constructor),
|
||||
RTGUI_DESTRUCTOR(_rtgui_mywidget_destructor));
|
||||
}
|
||||
|
||||
return mywidget_type;
|
||||
}
|
||||
|
||||
struct rtgui_mywidget* rtgui_mywidget_create(rtgui_rect_t* r)
|
||||
{
|
||||
struct rtgui_mywidget* me;
|
||||
|
||||
me = (struct rtgui_mywidget*) rtgui_widget_create (RTGUI_MYWIDGET_TYPE);
|
||||
if (me != RT_NULL)
|
||||
{
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(me), r);
|
||||
}
|
||||
|
||||
return me;
|
||||
}
|
||||
|
||||
void rtgui_mywidget_destroy(struct rtgui_mywidget* me)
|
||||
{
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(me));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef __MY_WIDGET_H__
|
||||
#define __MY_WIDGET_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/widgets/widget.h>
|
||||
|
||||
#define MYWIDGET_STATUS_ON 1
|
||||
#define MYWIDGET_STATUS_OFF 0
|
||||
|
||||
/** Gets the type of a button */
|
||||
#define RTGUI_MYWIDGET_TYPE (rtgui_mywidget_type_get())
|
||||
/** Casts the object to an rtgui_button */
|
||||
#define RTGUI_MYWIDGET(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_MYWIDGET_TYPE, rtgui_mywidget_t))
|
||||
/** Checks if the object is an rtgui_button */
|
||||
#define RTGUI_IS_MYWIDGET(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_MYWIDGET_TYPE))
|
||||
|
||||
/* 个性化控件 */
|
||||
struct rtgui_mywidget
|
||||
{
|
||||
struct rtgui_widget parent;
|
||||
|
||||
/* 状态:ON、OFF */
|
||||
rt_uint8_t status;
|
||||
};
|
||||
typedef struct rtgui_mywidget rtgui_mywidget_t;
|
||||
|
||||
struct rtgui_mywidget* rtgui_mywidget_create(rtgui_rect_t* r);
|
||||
void rtgui_mywidget_destroy(struct rtgui_mywidget* me);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user