提交 790fff9d 编写于 作者: I iamyhw@gmail.com

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1378 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 73656d53
#include <rtgui/dc.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/view.h>
#include "demo_view.h"
/*
* 直接在DC上绘图以实现动画效果
*
* 动画是依赖于定时器驱动的,会上下翻滚显示文字
* "飞线乱飞"
*/
static rt_int8_t dx = 1, dy = 1;
static rtgui_rect_t text_rect;
static rtgui_timer_t *timer;
void timeout(struct rtgui_timer* timer, void* parameter)
{
struct rtgui_dc* dc;
rtgui_rect_t rect;
rtgui_widget_t *widget;
/* 控件(view)通过parameter参数传递给定时器 */
widget = (rtgui_widget_t*)parameter;
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
return ;
/* 获得demo view允许绘图的区域,主要用于判断边界 */
rtgui_widget_get_rect(widget, &rect);
rtgui_rect_inflate(&rect, -5);
rect.y1 += 35;
/* 判断是否是第一次绘图 */
if ((text_rect.x1 == 0) && (text_rect.y1 == 0))
{
rtgui_rect_moveto(&text_rect, rect.x1, rect.y1);
}
else
{
/* 擦除老的文字 */
rtgui_dc_fill_rect(dc, &text_rect);
}
/* 设置dx和dy */
if (text_rect.x2 >= rect.x2) dx = -1;
if (text_rect.x1 < rect.x1) dx = 1;
if (text_rect.y2 >= rect.y2) dy = -1;
if (text_rect.y1 < rect.y1) dy = 1;
/* 移动文本框的位置 */
text_rect.x1 += dx; text_rect.x2 += dx;
text_rect.y1 += dy; text_rect.y2 += dy;
/* 绘图 */
rtgui_dc_draw_text(dc, "飞线乱飞", &text_rect);
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
rt_bool_t animation_event_handler(PVOID wdt, rtgui_event_t *event)
{
rtgui_widget_t *widget = (rtgui_widget_t*)wdt;
if (event->type == RTGUI_EVENT_PAINT)
{
rtgui_dc_t* dc;
rtgui_rect_t rect;
/* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view先绘图 */
rtgui_view_event_handler(widget, event);
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
return RT_FALSE;
/* 获得demo view允许绘图的区域 */
rtgui_widget_get_rect(widget, &rect);
rtgui_rect_inflate(&rect, -5);
rect.y1 += 35;
/* 擦除所有 */
rtgui_dc_fill_rect(dc, &rect);
/* 绘图 */
rtgui_dc_draw_text(dc, "飞线乱飞", &text_rect);
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
else
{
/* 调用默认的事件处理函数 */
return rtgui_view_event_handler(widget, event);
}
return RT_FALSE;
}
rtgui_view_t *demo_gui_animation(rtgui_view_t* parent_view)
{
rtgui_view_t *view;
view = demo_view_create(parent_view, "DC 动画");
if (view != RT_NULL)
rtgui_widget_set_event_handler(view, animation_event_handler);
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), "飞线乱飞", &text_rect);
rtgui_rect_moveto(&text_rect, 5, 40);
/* 启动定时器以触发动画 */
timer = rtgui_timer_create(2, RT_TIMER_FLAG_PERIODIC, timeout, view);
rtgui_timer_start(timer);
return view;
}
#include <rtgui/dc.h>
#include <rtgui/dc_hw.h>
#include <rtgui/kbddef.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h>
#include <stdlib.h>
#include "demo_view.h"
#if RT_VERSION == 4
#define RAND(x1, x2) ((rand() % (x2 - x1)) + x1)
static rtgui_view_t* view = RT_NULL;
static int running = 0;
void _onidle(PVOID wdt, rtgui_event_t *event)
{
rtgui_color_t color;
rtgui_rect_t rect, draw_rect;
struct rtgui_dc *dc;
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(view);
if (dc == RT_NULL) return ;
rtgui_widget_get_rect(view, &rect);
rtgui_rect_inflate(&rect, -5);
rect.y1 += 35;
draw_rect.x1 = RAND(rect.x1, rect.x2);
draw_rect.y1 = RAND(rect.y1, rect.y2);
draw_rect.x2 = RAND(draw_rect.x1, rect.x2);
draw_rect.y2 = RAND(draw_rect.y1, rect.y2);
color = RTGUI_RGB(rand() % 255, rand() % 255, rand() % 255);
RTGUI_WIDGET_BACKGROUND(view) = color;
rtgui_dc_fill_rect(dc, &draw_rect);
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
void _draw_default(PVOID wdt, rtgui_event_t* event)
{
struct rtgui_dc* dc;
rtgui_widget_t* widget = (rtgui_widget_t*)wdt;
rtgui_rect_t rect;
/* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view先绘图 */
rtgui_view_event_handler(widget, event);
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
return ;
/* 获得demo view允许绘图的区域 */
rtgui_widget_get_rect(widget, &rect);
rtgui_rect_inflate(&rect, -5);
rect.y1 += 35;
/* 擦除所有 */
RTGUI_WIDGET_BACKGROUND(widget) = default_background;
rtgui_dc_fill_rect(dc, &rect);
/* 显示提示 */
rtgui_dc_draw_text(dc, "按鼠标键开始/停止测试...", &rect);
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
rt_bool_t benchmark_event_handler(PVOID wdt, rtgui_event_t *event)
{
rtgui_widget_t *widget = (rtgui_widget_t*)wdt;
if (event->type == RTGUI_EVENT_PAINT)
{
_draw_default(widget, event);
}
else if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
{
rtgui_event_mouse_t *emouse = (rtgui_event_mouse_t*)event;
if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
{
if (running)
{
/* stop */
rtgui_thread_set_onidle(RT_NULL);
_draw_default(widget, event);
}
else
{
/* run */
rtgui_thread_set_onidle(_onidle);
}
running = !running;
}
return RT_TRUE;
}
else
{
/* 调用默认的事件处理函数 */
return rtgui_view_event_handler(widget, event);
}
return RT_FALSE;
}
rtgui_view_t *demo_gui_benchmark(rtgui_view_t* parent_view)
{
srand(100);
view = demo_view_create(parent_view, "绘图测试");
rtgui_widget_set_event_handler(view, benchmark_event_handler);
return view;
}
#endif
#include <rtgui/dc.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h>
#include "demo_view.h"
/*
* 直接在DC上绘图以实现动画效果
*
* 动画是依赖于定时器驱动的,会上下翻滚显示文字
* "飞线乱飞"
*/
static rt_int8_t dx = 1, dy = 1;
static rtgui_rect_t text_rect;
static rtgui_timer_t *timer;
static rtgui_dc_t *dc_buffer;
static void timeout(struct rtgui_timer* timer, void* parameter)
{
rtgui_dc_t* dc;
rtgui_rect_t rect;
rtgui_view_t *view;
/* 控件(view)通过parameter参数传递给定时器 */
view = (rtgui_view_t*)parameter;
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(view);
if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
return ;
/* 获得demo view允许绘图的区域,主要用于判断边界 */
rtgui_widget_get_rect(view, &rect);
rtgui_rect_inflate(&rect, -5);
rect.y1 += 35;
/* 判断是否是第一次绘图 */
if ((text_rect.x1 == 0) && (text_rect.y1 == 0))
{
rtgui_rect_moveto(&text_rect, rect.x1, rect.y1);
}
/* 设置dx和dy */
if (text_rect.x2 >= rect.x2) dx = -1;
if (text_rect.x1 < rect.x1) dx = 1;
if (text_rect.y2 >= rect.y2) dy = -1;
if (text_rect.y1 < rect.y1) dy = 1;
/* 移动文本框的位置 */
text_rect.x1 += dx; text_rect.x2 += dx;
text_rect.y1 += dy; text_rect.y2 += dy;
/* 绘图 */
rect = text_rect;
rect.x2 += 2; rect.y2 += 2;
rtgui_dc_blit(dc_buffer, NULL, dc, &rect);
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
static rt_bool_t animation_event_handler(PVOID wdt, rtgui_event_t *event)
{
rtgui_widget_t* widget = (rtgui_widget_t*)wdt;
if (event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
rtgui_rect_t rect;
/* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view先绘图 */
rtgui_view_event_handler(widget, event);
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
return RT_FALSE;
/* 绘图 */
rect = text_rect;
rtgui_dc_blit(dc_buffer, NULL, dc, &rect);
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
else
{
/* 调用默认的事件处理函数 */
return rtgui_view_event_handler(widget, event);
}
return RT_FALSE;
}
rtgui_view_t *demo_gui_buffer_animation(rtgui_view_t* parent_view)
{
rtgui_view_t *view;
view = demo_view_create(parent_view, "DC 缓冲区动画");
if (view != RT_NULL)
rtgui_widget_set_event_handler(view, animation_event_handler);
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), "缓冲动画", &text_rect);
if (dc_buffer == RT_NULL)
{
rtgui_rect_t rect;
rect.x1 = 0; rect.x2 = rtgui_rect_width(text_rect) + 2;
rect.y1 = 0; rect.y2 = rtgui_rect_height(text_rect) + 2;
/* 创建 DC Buffer,长 50,宽 50 */
dc_buffer = rtgui_dc_buffer_create(rtgui_rect_width(rect), rtgui_rect_height(rect));
RTGUI_DC_FC(dc_buffer) = RTGUI_WIDGET_BACKGROUND(view);
rtgui_dc_fill_rect(dc_buffer, &rect);
RTGUI_DC_FC(dc_buffer) = black;
rect.x1 = 1; rect.y1 = 1;
rtgui_dc_draw_text(dc_buffer, "缓冲动画", &rect);
}
/* 启动定时器以触发动画 */
timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, view);
rtgui_timer_start(timer);
return view;
}
/*
* 程序清单:文件列表视图演示
*
* 这个例子会先创建出一个演示用的view,当点击上面的按钮时会按照模式显示的形式显示
* 新的文件列表视图。
*/
#include "demo_view.h"
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/button.h>
#include <rtgui/widgets/filelist_view.h>
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
/* 文件处理函数 */
rt_bool_t demo_fview_on_item(PVOID wdt, struct rtgui_event *event)
{
rt_kprintf("fview file on item.\n");
return RT_TRUE;
}
/* 创建用于演示文件列表视图的视图 */
/* 方向键: 移动
* 回车键: 进入下一级目录,或调用文件处理函数
* 退格键: 返回上一级目录
*/
rtgui_view_t* demo_gui_fnview(rtgui_view_t* parent_view)
{
rtgui_view_t *view;
rtgui_filelist_view_t *fview;
/* 创建演示用的视图 */
view = demo_view_create(parent_view, "FileList View");
#ifdef _WIN32
fview = rtgui_filelist_view_create(view, "d:\\", "*.*", 5, 40, 200, 150);
#else
fview = rtgui_filelist_view_create(view, "/", "*.*", 5, 40, 200, 150);
#endif
fview->on_item = demo_fview_on_item;
return view;
}
#endif
......@@ -10,60 +10,131 @@
#include <string.h>
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
rtgui_filelist_view_t *demo_fview;
static rtgui_view_t *image_view = RT_NULL;
static rtgui_image_t *demo_image = RT_NULL;
/* 打开文件处理函数,这里只处理图像文件 */
rt_bool_t demo_image_fview_on_item(PVOID wdt, rtgui_event_t *event)
{
rtgui_filelist_view_t *fview = wdt;
if(fview == RT_NULL) return RT_FALSE;
if(fview->pattern != RT_NULL && fview->items != RT_NULL)
{
char path[32], image_type[8];
/* 设置文件路径的标签 */
rtgui_filelist_view_get_fullpath(fview, path, sizeof(path));
if (demo_image != RT_NULL)
{
rtgui_image_destroy(demo_image);
demo_image = RT_NULL;
}
rt_memset(image_type, 0, sizeof(image_type));
/* 获得图像的类型 */
if (rt_strstr(path, ".bmp") != RT_NULL ||
rt_strstr(path, ".BMP") != RT_NULL)
strcat(image_type, "bmp");
if (rt_strstr(path, ".png") != RT_NULL ||
rt_strstr(path, ".PNG") != RT_NULL)
strcat(image_type, "png");
if (rt_strstr(path, ".jpg") != RT_NULL ||
rt_strstr(path, ".JPG") != RT_NULL)
strcat(image_type, "jpeg");
if (rt_strstr(path, ".hdc") != RT_NULL ||
rt_strstr(path, ".HDC") != RT_NULL)
strcat(image_type, "hdc");
/* 如果图像文件有效,创建相应的rtgui_image对象 */
if (image_type[0] != '\0')
demo_image = rtgui_image_create_from_file(image_type, path, RT_TRUE);
}
rtgui_widget_update(image_view);
return RT_TRUE;
}
/* 返回按钮的回调函数 */
static void back_btn_onbutton(PVOID wdt, rtgui_event_t* event)
{
if(demo_fview != RT_NULL)
{
rtgui_filelist_view_goto_topfolder(demo_fview);
}
}
/* 打开按钮的回调函数 */
static void open_btn_onbutton(PVOID wdt, rtgui_event_t* event)
{
if(demo_fview != RT_NULL)
{
rtgui_filelist_view_on_enter(demo_fview);
}
}
/* 演示视图的事件处理函数 */
static rt_bool_t demo_view_event_handler(PVOID wdt, rtgui_event_t *event)
static rt_bool_t demo_gui_image_handler(PVOID wdt, rtgui_event_t *event)
{
rtgui_widget_t *widget = RTGUI_WIDGET(wdt);
rt_bool_t result;
/* 先调用默认的事件处理函数(这里只关心PAINT事件,但演示视图还有本身的一些控件) */
result = rtgui_view_event_handler(widget, event);
rtgui_widget_t* widget = wdt;
if (event->type == RTGUI_EVENT_PAINT)
if(event->type == RTGUI_EVENT_PAINT)
{
rtgui_dc_t* dc;
struct rtgui_dc* dc;
rtgui_rect_t rect;
/* 获得控件所属的DC */
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) return RT_FALSE;
if(dc == RT_NULL) return RT_FALSE;
/* 获得demo view允许绘图的区域 */
rtgui_widget_get_rect(widget, &rect);
/* 清除背景 */
rtgui_dc_fill_rect(dc, &rect);
/* 绘制图片 */
if(demo_image != RT_NULL) rtgui_image_blit(demo_image, dc, &rect);
/* 绘图完成 */
rtgui_dc_end_drawing(dc);
}
return result;
else
return rtgui_view_event_handler(widget, event);
return RT_TRUE;
}
/* 创建用于显示图像的演示视图 */
rtgui_view_t* demo_gui_image(rtgui_view_t* parent_view)
{
rtgui_button_t* open_btn;
rtgui_button_t* button;
rtgui_view_t *view;
rtgui_filelist_view_t *fview;
/* 先创建一个演示视图 */
view = demo_view_create(parent_view, "图像演示");
/* 创建一个文件浏览列表 */
#ifdef _WIN32
fview = rtgui_filelist_view_create(view, "d:\\", "*.*", 5, 65, 200, 180);
demo_fview = rtgui_filelist_view_create(view, "d:\\", "*.hdc", 5, 32, 200, 68);
#else
fview = rtgui_filelist_view_create(view, "/", "*.*", 5, 65, 200, 180);
demo_fview = rtgui_filelist_view_create(view, "/", "*.hdc", 5, 32, 200, 68);
#endif
demo_fview->on_item = demo_image_fview_on_item;
if (view != RT_NULL)
/* 设置默认的事件处理函数到demo_view_event_handler函数 */
rtgui_widget_set_event_handler(view, demo_view_event_handler);
/* 添加一个按钮 */
open_btn = rtgui_button_create(view, "打开图像文件", 10, 40, 120, 22);
rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
/* 添加一个返回按钮,浏览文件夹时,用于返回上一级目录 */
button = rtgui_button_create(view, "back", 5, 102, 40, 24);
rtgui_button_set_onbutton(button, back_btn_onbutton);
/* 添加一个打开按钮,浏览文件夹是,用于进入下一级目录,或者打开文件 */
button = rtgui_button_create(view, "open", 5, 130, 40, 24);
rtgui_button_set_onbutton(button, open_btn_onbutton);
/* 创建一个视图,用于显示图片 */
image_view = rtgui_view_create(view, "image_view", 50, 102, 160, 120);
if(image_view == RT_NULL) return RT_NULL;
/* 给image_view设置一个事件处理句柄 */
rtgui_widget_set_event_handler(image_view, demo_gui_image_handler);
return view;
}
......
......@@ -154,6 +154,14 @@ void user_add_one_item(PVOID wdt, rtgui_event_t *event)
}
}
void user_set_one_item(PVOID wdt, rtgui_event_t *event)
{
if(__lbox != RT_NULL)
{
rtgui_listbox_update_aloc(__lbox, __lbox->item_count-1);
}
}
static rt_bool_t on_items(PVOID wdt, rtgui_event_t* event)
{
rtgui_listbox_t* box;
......@@ -180,13 +188,16 @@ rtgui_view_t* demo_gui_listbox(rtgui_view_t* parent_view)
(const rt_uint8_t*)image_xpm, sizeof(image_xpm), RT_TRUE);
items[1].image = item_icon; */
rtgui_label_create(view, "listbox: ", 5, 40, 100, 20);
__lbox = rtgui_listbox_create(view, 5, 60, 120, 115, RTGUI_BORDER_SUNKEN);
rtgui_label_create(view, "listbox: ", 5, 35, 100, 20);
__lbox = rtgui_listbox_create(view, 5, 55, 120, 115, RTGUI_BORDER_SUNKEN);
rtgui_listbox_set_items(__lbox, items, RT_COUNT(items));
rtgui_listbox_set_onitem(__lbox, on_items);
button = rtgui_button_create(view, "Add", 5, 185, 50, 20);
button = rtgui_button_create(view, "Add", 5, 175, 50, 20);
rtgui_button_set_onbutton(button, user_add_one_item);
button = rtgui_button_create(view, "last", 65, 175, 50, 20);
rtgui_button_set_onbutton(button, user_set_one_item);
return view;
}
......@@ -6,7 +6,7 @@
#include "demo_view.h"
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/listctrl.h>
/*
static rtgui_image_t* item_icon = RT_NULL;
static const char * image_xpm[] = {
"16 16 106 2",
......@@ -132,7 +132,7 @@ static const char * image_xpm[] = {
" $.G I $.%.R &.Y *.& =. ",
" -.;.>.,.L L ,.& M ",
" "};
*/
static struct list_item
{
const char* name;
......@@ -163,7 +163,7 @@ static struct list_item
{"index19", "m19", 30, RT_NULL},
};
void _rtgui_listctrl_item_draw(struct rtgui_listctrl *list, struct rtgui_dc* dc, rtgui_rect_t* rect, rt_uint16_t index)
void _rtgui_listctrl_item_draw(rtgui_listctrl_t *list, struct rtgui_dc* dc, rtgui_rect_t* rect, rt_uint16_t index)
{
char age_str[8];
rtgui_rect_t item_rect;
......@@ -214,23 +214,21 @@ static void on_items(rtgui_widget_t* widget, struct rtgui_event* event)
/* 创建用于演示label控件的视图 */
rtgui_view_t* demo_gui_listctrl(rtgui_view_t* parent_view)
{
rtgui_rect_t rect;
rtgui_view_t* view;
rtgui_label_t* label;
rtgui_listctrl_t* box;
/* 先创建一个演示用的视图 */
view = demo_view_create(parent_view, "List Control Demo");
/* if (item_icon == RT_NULL)
if (item_icon == RT_NULL)
item_icon = rtgui_image_create_from_mem("xpm",
(const rt_uint8_t*)image_xpm, sizeof(image_xpm), RT_TRUE);
items[1].image = item_icon; */
items[1].image = item_icon;
rtgui_label_create(view, "List Control: ", 5, 40, 120, 20);
box = rtgui_listctrl_create((rt_uint32_t)items, sizeof(items)/sizeof(items[0]), &rect,
_rtgui_listctrl_item_draw);
box = rtgui_listctrl_create(view, (rt_uint32_t)items, sizeof(items)/sizeof(items[0]),
5, 60, 210, 100, _rtgui_listctrl_item_draw);
rtgui_listctrl_set_onitem(box, on_items);
return view;
......
......@@ -24,24 +24,30 @@ static rt_uint16_t demo_number = 0;
/* 显示前一个演示视图 */
void demo_gui_prev(PVOID wdt, rtgui_event_t *event)
{
rtgui_panel_t *panel = rtgui_panel_get();
if (demo_current != 0)
{
RTGUI_WIDGET_HIDE(demo_list[demo_current]);
demo_current --;
RTGUI_WIDGET_UNHIDE(demo_list[demo_current]);
rtgui_widget_update(demo_list[demo_current]);
rtgui_panel_update_clip(panel);
rtgui_panel_redraw(&RTGUI_WIDGET_EXTENT(demo_list[demo_current]));
}
}
/* 显示下一个演示视图 */
void demo_gui_next(PVOID wdt, rtgui_event_t *event)
{
rtgui_panel_t *panel = rtgui_panel_get();
if (demo_current + 1< demo_number)
{
RTGUI_WIDGET_HIDE(demo_list[demo_current]);
demo_current ++;
RTGUI_WIDGET_UNHIDE(demo_list[demo_current]);
rtgui_widget_update(demo_list[demo_current]);
rtgui_panel_update_clip(panel);
rtgui_panel_redraw(&RTGUI_WIDGET_EXTENT(demo_list[demo_current]));
}
}
......@@ -93,25 +99,24 @@ static void rtgui_panel_entry(void* parameter)
/* 初始化各个例子的视图 */
//#if RT_VERSION == 4
// demo_view_benchmark(view);
//#endif
#if RT_VERSION == 4
demo_gui_benchmark(view);
#endif
// demo_view_dc(view);
//#if RT_VERSION == 4
//#ifdef RTGUI_USING_TTF
// demo_view_ttf(view);
//#endif
//#endif
/* demo_view_dc(view);
#if RT_VERSION == 4
#ifdef RTGUI_USING_TTF
demo_view_ttf(view);
#endif
#endif */
#ifndef RTGUI_USING_SMALL_SIZE
demo_gui_dc_buffer(view);
#endif
// demo_gui_animation(view);
//#ifndef RTGUI_USING_SMALL_SIZE
// demo_view_buffer_animation(view);
// // demo_view_instrument_panel(view);
//#endif
demo_gui_animation(view);
#ifndef RTGUI_USING_SMALL_SIZE
demo_gui_buffer_animation(view);
#endif
demo_gui_window(view);
demo_gui_label(view);
demo_gui_button(view);
......@@ -121,24 +126,24 @@ static void rtgui_panel_entry(void* parameter)
demo_gui_radiobox(view);
demo_gui_textbox(view);
demo_gui_listbox(view);
////// demo_gui_menu(view); /* debugging */
////// demo_gui_listctrl(view); /* debugging */
demo_gui_menu(view);
demo_gui_listctrl(view);
demo_gui_combobox(view);
demo_gui_slider(view);
//////#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
////// demo_gui_image(view); /* debugging */
//////#endif
//#ifdef RT_USING_MODULE
//#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
// demo_gui_module(view);
//#endif
//#endif
// demo_gui_listview(view);
// demo_gui_listview_icon(view);
//#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
// demo_gui_fn(view);
//#endif
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
demo_gui_image(view);
#endif
#ifdef RT_USING_MODULE
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
demo_gui_module(view);
#endif
#endif
/* demo_gui_listview(view); */
/* demo_gui_listview_icon(view); */
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
demo_gui_fnview(view);
#endif
rtgui_view_show(demo_list[demo_current]);
......
......@@ -7,53 +7,45 @@
#include <rtgui/widgets/menu.h>
#include <rtgui/widgets/button.h>
static rt_bool_t _onmenuitem(struct rtgui_widget *widget, struct rtgui_event* event)
{
rt_kprintf("menu action!!\n");
return RT_TRUE;
}
static const rtgui_menu_item_t sub_items[] =
{
{RTGUI_ITEM_NORMAL, "item #1", RT_NULL, RT_NULL, 0, _onmenuitem},
{RTGUI_ITEM_NORMAL, "item #2", RT_NULL, RT_NULL, 0, RT_NULL},
{RTGUI_ITEM_SEPARATOR, RT_NULL, RT_NULL, RT_NULL, 0, RT_NULL},
{RTGUI_ITEM_NORMAL, "item #3", RT_NULL, RT_NULL, 0, RT_NULL},
};
static const rtgui_menu_item_t items[] =
{
{RTGUI_ITEM_NORMAL, "item #1", RT_NULL, RT_NULL, 0, RT_NULL},
{RTGUI_ITEM_NORMAL, "item #2", RT_NULL, RT_NULL, 0, RT_NULL},
{RTGUI_ITEM_SEPARATOR, RT_NULL, RT_NULL, RT_NULL, 0, RT_NULL},
{RTGUI_ITEM_SUBMENU, "item #3", RT_NULL, (struct rtgui_menu_item_t *)sub_items, sizeof(sub_items)/sizeof(sub_items[0]), RT_NULL},
};
static rtgui_menu_t* menu;
static _onmenu(PVOID wdt, rtgui_event_t* event)
{
rtgui_rect_t rect;
rtgui_widget_get_rect(widget, &rect);
rtgui_widget_rect_to_device(widget, &rect);
if (menu != RT_NULL)
rtgui_menu_pop(menu, rect.x1, rect.y2 + 5);
}
/* 创建用于演示menu控件的视图 */
rtgui_view_t* demo_gui_menu(rtgui_view_t* parent_view)
{
rtgui_rect_t rect;
rtgui_view_t* view;
rtgui_button_t* button;
rtgui_view_t *view;
rtgui_menu_t *main_menu, *sub_menu, *toolmenu;
/* 先创建一个演示用的视图 */
view = demo_view_create(parent_view, "MENU View");
button = rtgui_button_create(view, "Pop Menu", 5, 40, 50, 22);
rtgui_button_set_onbutton(button, _onmenu);
menu = rtgui_menu_create("Menu Test", RT_NULL, items, sizeof(items)/sizeof(items[0]));
/* 1.使用动态方式创建菜单 */
main_menu = rtgui_menu_create(view, "menu", 5, 40, RTGUI_MENU_NORMAL);
sub_menu = rtgui_menu_create(view, "File", 0, 0, RTGUI_MENU_POPUP);
rtgui_menu_append(sub_menu, 0, 0x20001, "New", RT_NULL);
rtgui_menu_append(sub_menu, 0, 0x20002, "Open", RT_NULL);
rtgui_menu_append(sub_menu, 0, 0x20003, "Save", RT_NULL);
rtgui_menu_append(sub_menu, 0, 0x20004, "Print", RT_NULL);
rtgui_menu_append(sub_menu, 0, 0x20005, "Exit", RT_NULL);
rtgui_menu_append(main_menu, RTGUI_MENU_POPUP, (rt_uint32_t)sub_menu, sub_menu->name, RT_NULL);
sub_menu = rtgui_menu_create(view, "EditDocument", 0, 0, RTGUI_MENU_POPUP);
rtgui_menu_append(sub_menu, 0, 0x30001, "Cut", RT_NULL);
rtgui_menu_append(sub_menu, 0, 0x30002, "Copy", RT_NULL);
rtgui_menu_append(sub_menu, 0, 0x30002, "Paste", RT_NULL);
rtgui_menu_append(sub_menu, 0, 0x30003, "Find...", RT_NULL);
toolmenu = rtgui_menu_create(view, "Toolbars", 0, 0, RTGUI_MENU_POPUP);
rtgui_menu_append(toolmenu, 0, 0x50001, "File Tools", RT_NULL);
rtgui_menu_append(toolmenu, 0, 0x50002, "build Tools", RT_NULL);
rtgui_menu_append(sub_menu, RTGUI_MENU_POPUP, (rt_uint32_t)toolmenu, toolmenu->name, RT_NULL);
rtgui_menu_append(main_menu, RTGUI_MENU_POPUP, (rt_uint32_t)sub_menu, sub_menu->name, RT_NULL);
sub_menu = rtgui_menu_create(view, "View", 0, 0, RTGUI_MENU_POPUP);
rtgui_menu_append(sub_menu, 0, 0x40001, "Status bar", RT_NULL);
rtgui_menu_append(sub_menu, 0, 0x40001, "Tool bar", RT_NULL);
rtgui_menu_append(sub_menu, 0, 0x40001, "Project window", RT_NULL);
rtgui_menu_append(sub_menu, 0, 0x40001, "Books window", RT_NULL);
rtgui_menu_append(sub_menu, 0, 0x40001, "Functions window", RT_NULL);
rtgui_menu_append(sub_menu, 0, 0x40001, "Full screen", RT_NULL);
rtgui_menu_append(main_menu, RTGUI_MENU_POPUP, (rt_uint32_t)sub_menu, sub_menu->name, RT_NULL);
rtgui_menu_append(main_menu, 0, 0x10004, "Help", RT_NULL);
/* 2.使用静态方式创建菜单 */
/* 菜单的一些功能还在调试中... */
return view;
}
......@@ -37,8 +37,8 @@ rtgui_view_t *demo_gui_progressbar(rtgui_view_t* parent_view)
rtgui_label_create(view, "ˮƽ:", 5, 40, 100, 20);
hbar = rtgui_progressbar_create(view, RTGUI_HORIZONTAL, 100, 10, 70, 150, 15);
rtgui_label_create(view, "ֱ:", 5, 100, 100, 20);
vbar = rtgui_progressbar_create(view, RTGUI_VERTICAL, 100, 10, 130, 15, 60);
rtgui_label_create(view, "ֱ:", 5, 90, 100, 20);
vbar = rtgui_progressbar_create(view, RTGUI_VERTICAL, 100, 10, 110, 15, 60);
timer = rtgui_timer_create(20, RT_TIMER_FLAG_PERIODIC, hbar_timeout, hbar);
rtgui_timer_start(timer);
......
......@@ -26,16 +26,16 @@ rtgui_view_t* demo_gui_radiobox(rtgui_view_t* parent_view)
rtgui_radiobox_create(view, "radio2", 5, 60, 100, 20, group);
/* 使用方法二 */
rbox = rtgui_radiobox_create(view, "radio-x", 5, 100, 100, 20, RT_NULL);
rbox = rtgui_radiobox_create(view, "radio-x", 5, 90, 100, 20, RT_NULL);
/* 也可以从radiobox控件中获得一个组对象 */
group = rtgui_radiobox_get_group(rbox);
_group = rtgui_radiobox_create_group();
rtgui_radiobox_create(view, "radio_m", 20,120, 100, 20, _group);
rtgui_radiobox_create(view, "radio_n", 20,140, 100, 20, _group);
rtgui_radiobox_create(view, "radio_m", 20,110, 100, 20, _group);
rtgui_radiobox_create(view, "radio_n", 20,130, 100, 20, _group);
/* 设定一个初始值 */
rtgui_rb_group_set_sel(_group, 1);
rtgui_radiobox_create(view, "radio-y", 5, 160, 100, 20, group);
rtgui_radiobox_create(view, "radio-y", 5, 150, 100, 20, group);
/* 可以为组绑定一个变量,之后可以使用该变量获得group的当前焦点 */
rtgui_rb_group_bind(group, &bind_var);
......
......@@ -13,13 +13,13 @@ rtgui_view_t *demo_gui_scrollbar(rtgui_view_t* parent_view)
view = demo_view_create(parent_view, "ScrollBar View");
rtgui_label_create(view, "horizontal bar:", 5, 40, 150, 20);
hbar = rtgui_scrollbar_create(view, 5, 70, 20, 100, RTGUI_HORIZONTAL);
hbar = rtgui_scrollbar_create(view, 5, 65, 20, 100, RTGUI_HORIZONTAL);
rtgui_scrollbar_set_range(hbar, 10);
rtgui_scrollbar_set_page_step(hbar, 5);
rtgui_scrollbar_set_line_step(hbar, 1);
rtgui_label_create(view, "vertical bar:", 5, 100, 150, 20);
vbar = rtgui_scrollbar_create(view, 10, 140, 20, 80, RTGUI_VERTICAL);
rtgui_label_create(view, "vertical bar:", 5, 90, 150, 20);
vbar = rtgui_scrollbar_create(view, 10, 115, 20, 80, RTGUI_VERTICAL);
rtgui_scrollbar_set_range(vbar, 5);
rtgui_scrollbar_set_page_step(vbar, 3);
rtgui_scrollbar_set_line_step(vbar, 1);
......
......@@ -153,10 +153,11 @@ static void demo_ntitlewin_onbutton(PVOID wdt, rtgui_event_t* event)
delta_x += 20;
delta_y += 20;
/* 创建一个窗口,风格为无标题及无边框 */
win = rtgui_win_create(parent,"no title", &rect, RTGUI_WIN_NOBORDER);
win = rtgui_win_create(parent,"no title", &rect, RTGUI_WIN_DEFAULT);
RTGUI_WIDGET_BACKGROUND(win) = white;
win->level = RTGUI_WIN_LEVEL_EXPERT;
/* 创建一个文本标签 */
label = rtgui_label_create(win, "无边框窗口", 10, 20, 100, 20);
label = rtgui_label_create(win, "无标题栏窗口", 10, 30, 100, 20);
RTGUI_WIDGET_BACKGROUND(label) = white;
button = rtgui_button_create(win,"关闭", 65, 85, 60, 25);
......
......@@ -5,21 +5,26 @@
rtgui_view_t* demo_view_create(rtgui_view_t* parent_view, const char* title);
rtgui_view_t *demo_gui_dc_buffer(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_benchmark(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_dc_buffer(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_animation(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_buffer_animation(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_window(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_label(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_button(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_checkbox(rtgui_view_t* parent_view);
rtgui_view_t *demo_gui_progressbar(rtgui_view_t* parent_view);
rtgui_view_t *demo_gui_scrollbar(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_progressbar(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_scrollbar(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_radiobox(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_textbox(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_listbox(rtgui_view_t* parent_view);
/* rtgui_view_t* demo_gui_menu(rtgui_view_t* parent_view) */ /* debugging */
/* rtgui_view_t* demo_gui_listbox(rtgui_view_t* parent_view) */ /* debugging */
rtgui_view_t* demo_gui_menu(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_listctrl(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_listbox(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_combobox(rtgui_view_t* parent_view);
rtgui_view_t *demo_gui_slider(rtgui_view_t* parent_view);
/* rtgui_view_t* demo_gui_image(rtgui_view_t* parent_view); */ /* debugging */
rtgui_view_t* demo_gui_slider(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_image(rtgui_view_t* parent_view);
rtgui_view_t* demo_gui_fnview(rtgui_view_t* parent_view);
#endif
......@@ -4,7 +4,7 @@
#include "touch.h"
void rt_hw_lcd_init(void);
void rt_key_init(void);
void rt_hw_key_init(void);
void rtgui_panel_init(void);
......@@ -15,7 +15,7 @@ void rtgui_startup()
rtgui_system_server_init();
/* 按键初始化 */
//rt_key_hw_init();
rt_hw_key_init();
/* LCD驱动初始化 */
rt_hw_lcd_init();
rtgui_touch_hw_init();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册