rtt-f030/examples/gui/demo_view_ttf.c

99 lines
2.6 KiB
C
Raw Normal View History

/*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TTF<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ʾ
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>view<EFBFBD>Ͻ<EFBFBD><EFBFBD><EFBFBD>TTF<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
*/
#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<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
rt_bool_t ttf_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
{
/* <20><><EFBFBD><EFBFBD>PAINT<4E>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD> */
if (event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
rtgui_rect_t rect;
rtgui_font_t* saved;
/*
* <EFBFBD><EFBFBD>Ϊ<EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>demo view<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>demo view
* <EFBFBD>Ȼ<EFBFBD>ͼ
*/
rtgui_view_event_handler(widget, event);
/************************************************************************/
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<44>IJ<EFBFBD><C4B2><EFBFBD> */
/************************************************************************/
/* <20><><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC */
dc = rtgui_dc_begin_drawing(widget);
/* <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> */
if (dc == RT_NULL)
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);
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;
/* <20><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD> */
rtgui_dc_end_drawing(dc);
}
else
{
/* <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϵ<EFBFBD><CFB5>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
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);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TTF<54><46><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ʾ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ͼ */
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 <20><>ʾ");
if (view != RT_NULL)
{
// RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
/* <20><><EFBFBD>ó<EFBFBD><C3B3>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), ttf_event_handler);
}
return view;
}
#endif