add ttf and xml example.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@757 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
3a13964efa
commit
d4150036b8
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* 程序清单:TTF字体显示演示
|
||||
*
|
||||
* 这个例子会在创建出的view上进行TTF字体显示的演示
|
||||
*/
|
||||
|
||||
#include "demo_view.h"
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/font.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
|
||||
#ifdef RTGUI_USING_TTF
|
||||
static rtgui_font_t *font_16, *font_24, *font_36, *font_48;
|
||||
|
||||
/*
|
||||
* view的事件处理函数
|
||||
*/
|
||||
rt_bool_t ttf_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
||||
{
|
||||
/* 仅对PAINT事件进行处理 */
|
||||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
rtgui_rect_t rect;
|
||||
rtgui_font_t* saved;
|
||||
|
||||
/*
|
||||
* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view
|
||||
* 先绘图
|
||||
*/
|
||||
rtgui_view_event_handler(widget, event);
|
||||
|
||||
/************************************************************************/
|
||||
/* 下面的是DC的操作 */
|
||||
/************************************************************************/
|
||||
|
||||
/* 获得控件所属的DC */
|
||||
dc = rtgui_dc_begin_drawing(widget);
|
||||
/* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
|
||||
if (dc == RT_NULL)
|
||||
return RT_FALSE;
|
||||
|
||||
/* 获得demo view允许绘图的区域 */
|
||||
demo_view_get_rect(RTGUI_VIEW(widget), &rect);
|
||||
|
||||
saved = RTGUI_WIDGET_FONT(widget);
|
||||
|
||||
RTGUI_WIDGET_FONT(widget) = font_16;
|
||||
rtgui_dc_draw_text(dc, "ABCD", &rect);
|
||||
rect.y1 += 18;
|
||||
|
||||
RTGUI_WIDGET_FONT(widget) = font_24;
|
||||
rtgui_dc_draw_text(dc, "ABCD", &rect);
|
||||
rect.y1 += 26;
|
||||
|
||||
RTGUI_WIDGET_FONT(widget) = font_36;
|
||||
rtgui_dc_draw_text(dc, "ABCD", &rect);
|
||||
rect.y1 += 38;
|
||||
|
||||
RTGUI_WIDGET_FONT(widget) = font_48;
|
||||
rtgui_dc_draw_text(dc, "ABCD", &rect);
|
||||
|
||||
RTGUI_WIDGET_FONT(widget) = saved;
|
||||
/* 绘图完成 */
|
||||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 其他事件,调用默认的事件处理函数 */
|
||||
return rtgui_view_event_handler(widget, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
extern rtgui_font_t* rtgui_freetype_font_create(const char* filename, int bold, int italic, rt_size_t size);
|
||||
|
||||
/* 创建用于TTF字体显示演示用的视图 */
|
||||
rtgui_view_t *demo_view_ttf(rtgui_workbench_t* workbench)
|
||||
{
|
||||
rtgui_view_t *view;
|
||||
|
||||
font_16 = rtgui_freetype_font_create("d:/arial.ttf", 0, 0, 16);
|
||||
font_24 = rtgui_freetype_font_create("d:/arial.ttf", 0, 0, 24);
|
||||
font_36 = rtgui_freetype_font_create("d:/arial.ttf", 0, 0, 36);
|
||||
font_48 = rtgui_freetype_font_create("d:/HARNGTON.TTF", 0, 0, 72);
|
||||
|
||||
view = demo_view(workbench, "TTF 演示");
|
||||
if (view != RT_NULL)
|
||||
{
|
||||
// RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
|
||||
/* 设置成自己的事件处理函数 */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), ttf_event_handler);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
#endif
|
|
@ -52,6 +52,9 @@ static void workbench_entry(void* parameter)
|
|||
|
||||
/* 初始化各个例子的视图 */
|
||||
demo_view_dc(workbench);
|
||||
#ifdef RTGUI_USING_TTF
|
||||
demo_view_ttf(workbench);
|
||||
#endif
|
||||
demo_view_dc_buffer(workbench);
|
||||
demo_view_animation(workbench);
|
||||
demo_view_buffer_animation(workbench);
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#include <rtthread.h>
|
||||
|
||||
#include <rtgui/rtgui_xml.h>
|
||||
|
||||
static int xml_event_handler(rt_uint8_t event, const char* text, rt_size_t len, void* user)
|
||||
{
|
||||
rt_kprintf("%s: %s\n", rtgui_xml_event_str(event), text);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char xml_str[] = "<?xml version=\"1.0\"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>";
|
||||
void demo_xml()
|
||||
{
|
||||
rtgui_xml_t *xml;
|
||||
|
||||
xml = rtgui_xml_create(512, xml_event_handler, RT_NULL);
|
||||
if (xml != RT_NULL)
|
||||
{
|
||||
rtgui_xml_parse(xml, xml_str, sizeof(xml_str));
|
||||
rtgui_xml_destroy(xml);
|
||||
}
|
||||
}
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
FINSH_FUNCTION_EXPORT(demo_xml, show the demo of xml parser);
|
||||
#endif
|
Loading…
Reference in New Issue