mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-08 14:43:04 +08:00
add font and change theme.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@327 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
1 parent
284727de4a
commit
63dff2e94e
13 files changed
+580
-38
No files matched your search
@@ -48,6 +48,23 @@ rtgui_view_t* demo_view(rtgui_workbench_t* workbench)
|
||||
{
|
||||
struct rtgui_rect rect;
|
||||
struct rtgui_button *next_btn, *prev_btn;
|
||||
struct rtgui_label *label;
|
||||
struct rtgui_staticline *line;
|
||||
|
||||
/* get view's rect */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
rect.x1 += 5; rect.y1 += 5;
|
||||
rect.x2 -= 5; rect.y2 -= 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
|
||||
/* create view label */
|
||||
label = rtgui_label_create("Demo Label");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
rect.y1 += 20; rect.y2 += 20;
|
||||
line = rtgui_staticline_create(RTGUI_HORIZONTAL);
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(line));
|
||||
|
||||
/* get view's rect */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
@@ -93,6 +110,7 @@ rtgui_box_t* demo_view_create_box(rtgui_view_t* view, int orient)
|
||||
|
||||
/* get rect of view */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
rect.y1 += 45;
|
||||
rect.y2 -= 25;
|
||||
|
||||
box = rtgui_box_create(orient, &rect);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
static struct rtgui_timer *timer;
|
||||
static struct rtgui_label* label;
|
||||
static struct rtgui_win* msgbox;
|
||||
static struct rtgui_win* msgbox = RT_NULL;
|
||||
static rt_uint8_t label_text[80];
|
||||
static int cnt = 5;
|
||||
|
||||
@@ -29,20 +29,8 @@ void diag_close(struct rtgui_timer* timer, void* parameter)
|
||||
|
||||
void window_demo()
|
||||
{
|
||||
rt_mq_t mq;
|
||||
rt_thread_t tid;
|
||||
rt_uint32_t user_data;
|
||||
struct rtgui_rect rect = {50, 50, 200, 200};
|
||||
|
||||
tid = rt_thread_self();
|
||||
if (tid == RT_NULL) return; /* can't use in none-scheduler environement */
|
||||
user_data = tid->user_data;
|
||||
|
||||
/* create gui message queue */
|
||||
mq = rt_mq_create("msgbox", 256, 4, RT_IPC_FLAG_FIFO);
|
||||
/* register message queue on current thread */
|
||||
rtgui_thread_register(rt_thread_self(), mq);
|
||||
|
||||
msgbox = rtgui_win_create(RT_NULL, "Information", &rect, RTGUI_WIN_STYLE_DEFAULT);
|
||||
if (msgbox != RT_NULL)
|
||||
{
|
||||
@@ -64,15 +52,6 @@ void window_demo()
|
||||
|
||||
timer = rtgui_timer_create(200, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL);
|
||||
rtgui_timer_start(timer);
|
||||
|
||||
rtgui_win_event_loop(msgbox);
|
||||
|
||||
rtgui_thread_deregister(rt_thread_self());
|
||||
/* remove RTGUI message queue */
|
||||
rt_mq_delete(mq);
|
||||
|
||||
/* recover user data */
|
||||
tid->user_data = user_data;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
@@ -108,7 +87,6 @@ rtgui_view_t* demo_view_window(rtgui_workbench_t* workbench)
|
||||
rtgui_button_t *button;
|
||||
|
||||
view = demo_view(workbench);
|
||||
demo_view_get_rect(view, &rect);
|
||||
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
|
||||
@@ -55,6 +55,7 @@ static void workbench_entry(void* parameter)
|
||||
/* 在工作台上添加一个视图 */
|
||||
rtgui_workbench_add_view(workbench, view);
|
||||
|
||||
demo_view_window(workbench);
|
||||
demo_view_label(workbench);
|
||||
demo_view_button(workbench);
|
||||
demo_view_checkbox(workbench);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -23,9 +23,6 @@ const rtgui_color_t high_light = RTGUI_RGB(0xff, 0xff, 0xff);
|
||||
const rtgui_color_t dark_grey = RTGUI_RGB(0x7f, 0x7f, 0x7f);
|
||||
const rtgui_color_t light_grey = RTGUI_RGB(0xc0, 0xc0, 0xc0);
|
||||
|
||||
const rtgui_color_t default_foreground = RTGUI_RGB(0x00, 0x00, 0x00);
|
||||
const rtgui_color_t default_background = RTGUI_RGB(0xff, 0xff, 0xff);
|
||||
|
||||
#define RTGUI_RGB_R(c) ((c) & 0xff)
|
||||
#define RTGUI_RGB_G(c) (((c) >> 8) & 0xff)
|
||||
#define RTGUI_RGB_B(c) (((c) >> 16) & 0xff)
|
||||
|
||||
+10
-3
@@ -18,7 +18,9 @@ static rtgui_list_t _rtgui_font_list;
|
||||
static struct rtgui_font* rtgui_default_font;
|
||||
|
||||
extern struct rtgui_font rtgui_font_asc16;
|
||||
extern struct rtgui_font rtgui_font_arial16;
|
||||
extern struct rtgui_font rtgui_font_asc12;
|
||||
extern struct rtgui_font rtgui_font_arial12;
|
||||
#ifdef RTGUI_USING_FONTHZ
|
||||
extern struct rtgui_font rtgui_font_hz16;
|
||||
extern struct rtgui_font rtgui_font_hz12;
|
||||
@@ -33,6 +35,7 @@ void rtgui_font_system_init()
|
||||
|
||||
#ifdef RTGUI_USING_FONT16
|
||||
rtgui_font_system_add_font(&rtgui_font_asc16);
|
||||
rtgui_font_system_add_font(&rtgui_font_arial16);
|
||||
#ifdef RTGUI_USING_FONTHZ
|
||||
rtgui_font_system_add_font(&rtgui_font_hz16);
|
||||
#endif
|
||||
@@ -40,16 +43,19 @@ void rtgui_font_system_init()
|
||||
|
||||
#ifdef RTGUI_USING_FONT12
|
||||
rtgui_font_system_add_font(&rtgui_font_asc12);
|
||||
rtgui_font_system_add_font(&rtgui_font_arial12);
|
||||
#ifdef RTGUI_USING_FONTHZ
|
||||
rtgui_font_system_add_font(&rtgui_font_hz12);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef RTGUI_USING_FONT12
|
||||
rtgui_font_set_defaut(&rtgui_font_asc12);
|
||||
if (rtgui_default_font == RT_NULL)
|
||||
rtgui_font_set_defaut(&rtgui_font_asc12);
|
||||
#endif
|
||||
#ifdef RTGUI_USING_FONT16
|
||||
rtgui_font_set_defaut(&rtgui_font_asc16);
|
||||
if (rtgui_default_font == RT_NULL)
|
||||
rtgui_font_set_defaut(&rtgui_font_asc16);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -166,7 +172,7 @@ struct rtgui_font_engine bmp_font_engine =
|
||||
void rtgui_bitmap_font_draw_char(struct rtgui_font_bitmap* font, struct rtgui_dc* dc, const char ch,
|
||||
rtgui_rect_t* rect)
|
||||
{
|
||||
const rt_uint8_t* font_ptr = font->bmp + ch * font->height;
|
||||
const rt_uint8_t* font_ptr;
|
||||
rt_uint16_t x, y, w, h;
|
||||
register rt_base_t i, j;
|
||||
|
||||
@@ -175,6 +181,7 @@ void rtgui_bitmap_font_draw_char(struct rtgui_font_bitmap* font, struct rtgui_dc
|
||||
|
||||
/* check first and last char */
|
||||
if (ch < font->first_char || ch > font->last_char) return;
|
||||
font_ptr = font->bmp + (ch - font->first_char) * font->height;
|
||||
|
||||
w = (font->width + x > rect->x2)? rect->x2 - rect->x1 : font->width;
|
||||
h = (font->height + y > rect->y2)? rect->y2 - rect->y1 : font->height;
|
||||
|
||||
@@ -185,6 +185,14 @@ static const rt_uint8_t *close_pressed_xpm[] = {
|
||||
static rtgui_image_t* close_pressed = RT_NULL;
|
||||
static rtgui_image_t* close_unpressed = RT_NULL;
|
||||
|
||||
const rtgui_color_t default_foreground = RTGUI_RGB(0x00, 0x00, 0x00);
|
||||
const rtgui_color_t default_background = RTGUI_RGB(212, 208, 200);
|
||||
|
||||
extern struct rtgui_font rtgui_font_asc16;
|
||||
extern struct rtgui_font rtgui_font_arial16;
|
||||
extern struct rtgui_font rtgui_font_asc12;
|
||||
extern struct rtgui_font rtgui_font_arial12;
|
||||
|
||||
/* init theme */
|
||||
void rtgui_system_theme_init()
|
||||
{
|
||||
@@ -192,6 +200,8 @@ void rtgui_system_theme_init()
|
||||
(const rt_uint8_t*)close_pressed_xpm, sizeof(close_pressed_xpm), RT_TRUE);
|
||||
close_unpressed = rtgui_image_create_from_mem("xpm",
|
||||
(const rt_uint8_t*)close_unpressed_xpm, sizeof(close_unpressed_xpm), RT_TRUE);
|
||||
|
||||
rtgui_font_set_defaut(&rtgui_font_arial16);
|
||||
}
|
||||
|
||||
/* window drawing */
|
||||
@@ -217,8 +227,21 @@ void rtgui_theme_draw_win(struct rtgui_topwin* win)
|
||||
/* draw border */
|
||||
if (win->flag & WINTITLE_BORDER)
|
||||
{
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(219, 210, 243);
|
||||
rtgui_dc_draw_rect(dc, &rect);
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(212, 208, 200);
|
||||
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1);
|
||||
rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2);
|
||||
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = white;
|
||||
rtgui_dc_draw_hline(dc, rect.x1 + 1, rect.x2 - 1, rect.y1 + 1);
|
||||
rtgui_dc_draw_vline(dc, rect.x1 + 1, rect.y1 + 1, rect.y2 - 1);
|
||||
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(128, 128, 128);
|
||||
rtgui_dc_draw_hline(dc, rect.x1 + 1, rect.x2 - 1, rect.y2 - 1);
|
||||
rtgui_dc_draw_vline(dc, rect.x2 - 1, rect.y1 + 1, rect.y2 - 1);
|
||||
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(64, 64, 64);
|
||||
rtgui_dc_draw_hline(dc, rect.x1, rect.x2 + 1, rect.y2);
|
||||
rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2);
|
||||
|
||||
/* shrink border */
|
||||
rect.x1 += WINTITLE_BORDER_SIZE;
|
||||
@@ -230,17 +253,36 @@ void rtgui_theme_draw_win(struct rtgui_topwin* win)
|
||||
/* draw title */
|
||||
if (!(win->flag & WINTITLE_NO))
|
||||
{
|
||||
rt_uint32_t index;
|
||||
float r, g, b, delta;
|
||||
|
||||
if (win->flag & WINTITLE_ACTIVATE)
|
||||
{
|
||||
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(229, 236, 249);
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB( 51, 102, 204);
|
||||
r = 10; g = 36; b = 106;
|
||||
delta = (float)(rect.x2 - rect.x1) / 160;
|
||||
}
|
||||
else
|
||||
{
|
||||
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(242, 245, 252);
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(153, 178, 229);
|
||||
r = 128; g = 128; b = 128;
|
||||
delta = (float)(rect.x2 - rect.x1) / 64;
|
||||
}
|
||||
rtgui_dc_fill_rect(dc, &rect);
|
||||
|
||||
for (index = rect.x1; index < rect.x2; index ++)
|
||||
{
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(r, g, b);
|
||||
rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
|
||||
r += delta; g += delta; b += delta;
|
||||
}
|
||||
|
||||
if (win->flag & WINTITLE_ACTIVATE)
|
||||
{
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = white;
|
||||
}
|
||||
else
|
||||
{
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(212, 208, 200);
|
||||
}
|
||||
// rtgui_dc_fill_rect(dc, &rect);
|
||||
|
||||
rect.x1 += 4;
|
||||
rect.y1 += 2;
|
||||
@@ -539,6 +581,7 @@ void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
|
||||
struct rtgui_dc* dc;
|
||||
struct rtgui_rect rect, item_rect;
|
||||
rt_size_t item_size, bord_size, index;
|
||||
rtgui_color_t fc;
|
||||
|
||||
/* begin drawing */
|
||||
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(radiobox));
|
||||
@@ -560,7 +603,18 @@ void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
|
||||
|
||||
/* draw box */
|
||||
rtgui_rect_inflate(&rect, -bord_size/2);
|
||||
rtgui_dc_draw_round_rect(dc, &rect);
|
||||
fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(radiobox));
|
||||
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(radiobox)) = white;
|
||||
rect.x1 ++; rect.y1 ++; rect.x2 ++; rect.y2 ++;
|
||||
rtgui_dc_draw_rect(dc, &rect);
|
||||
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(radiobox)) = RTGUI_RGB(128, 128, 128);
|
||||
rect.x1 --; rect.y1 --; rect.x2 --; rect.y2 --;
|
||||
rtgui_dc_draw_rect(dc, &rect);
|
||||
|
||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(radiobox)) = fc;
|
||||
|
||||
rtgui_rect_inflate(&rect, bord_size/2);
|
||||
if (radiobox->text != RT_NULL)
|
||||
{
|
||||
@@ -569,7 +623,9 @@ void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
|
||||
/* draw group text */
|
||||
rtgui_font_get_metrics(rtgui_dc_get_font(dc), radiobox->text, &text_rect);
|
||||
rtgui_rect_moveto(&text_rect, rect.x1 + bord_size + 5, rect.y1);
|
||||
rect.x1 -= 5; rect.x2 += 5;
|
||||
rtgui_dc_fill_rect(dc, &text_rect);
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
rtgui_dc_draw_text(dc, radiobox->text, &text_rect);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#define RTGUI_USING_STDIO_FILERW
|
||||
#define RTGUI_IMAGE_PNG
|
||||
#define RTGUI_IMAGE_JPG
|
||||
|
||||
#define RTGUI_USING_FONT12
|
||||
#else
|
||||
#define RTGUI_USING_DFS_FILERW
|
||||
#define RTGUI_USING_HZ_FILE
|
||||
|
||||
@@ -31,7 +31,7 @@ enum
|
||||
};
|
||||
|
||||
#define WINTITLE_HEIGHT 20
|
||||
#define WINTITLE_BORDER_SIZE 1
|
||||
#define WINTITLE_BORDER_SIZE 2
|
||||
|
||||
struct rtgui_topwin
|
||||
{
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* File : filelist_view.c
|
||||
* This file is part of RTGUI in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2010, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2010-01-06 Bernard first version
|
||||
*/
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* File : list_view.c
|
||||
* This file is part of RTGUI in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2010, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2010-01-06 Bernard first version
|
||||
*/
|
||||
@@ -11,6 +11,7 @@ static void _rtgui_radiobox_constructor(rtgui_radiobox_t *radiobox)
|
||||
|
||||
/* init widget and set event handler */
|
||||
RTGUI_WIDGET(radiobox)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(radiobox)) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(radiobox), rtgui_radiobox_event_handler);
|
||||
|
||||
|
||||
Reference in new issue
Block a user