2009-11-24 07:34:58 +08:00
|
|
|
/*
|
|
|
|
* File : rtgui_theme.c
|
|
|
|
* This file is part of RTGUI in RT-Thread RTOS
|
|
|
|
* COPYRIGHT (C) 2006 - 2009, 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
|
|
|
|
* 2009-10-04 Bernard first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtgui/rtgui.h>
|
|
|
|
#include <rtgui/dc.h>
|
|
|
|
#include <rtgui/widgets/widget.h>
|
|
|
|
#include <rtgui/widgets/button.h>
|
|
|
|
#include <rtgui/widgets/label.h>
|
|
|
|
#include <rtgui/widgets/textbox.h>
|
|
|
|
#include <rtgui/widgets/iconbox.h>
|
|
|
|
#include <rtgui/widgets/title.h>
|
|
|
|
#include <rtgui/rtgui_theme.h>
|
|
|
|
#include <rtgui/rtgui_server.h>
|
2010-01-27 09:26:12 +08:00
|
|
|
#include <rtgui/rtgui_system.h>
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
#define SELECTED_HEIGHT 25
|
|
|
|
|
2010-01-21 18:05:06 +08:00
|
|
|
const rtgui_color_t default_foreground = RTGUI_RGB(0x00, 0x00, 0x00);
|
|
|
|
const rtgui_color_t default_background = RTGUI_RGB(212, 208, 200);
|
2010-02-01 17:45:33 +08:00
|
|
|
const rtgui_color_t selected_color = RTGUI_RGB(0xc0, 0xc0, 0xc0);
|
2010-08-09 07:18:02 +08:00
|
|
|
const rtgui_color_t disable_foreground = RTGUI_RGB(0x80, 0x80, 0x80);
|
2010-01-21 18:05:06 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-11-24 07:34:58 +08:00
|
|
|
/* init theme */
|
|
|
|
void rtgui_system_theme_init()
|
2010-02-13 00:02:00 +08:00
|
|
|
{
|
|
|
|
#if RTGUI_DEFAULT_FONT_SIZE == 16
|
|
|
|
rtgui_font_set_defaut(&rtgui_font_asc16);
|
2010-02-08 22:15:11 +08:00
|
|
|
#elif RTGUI_DEFAULT_FONT_SIZE == 12
|
2010-02-13 00:02:00 +08:00
|
|
|
rtgui_font_set_defaut(&rtgui_font_asc12);
|
|
|
|
#else
|
|
|
|
rtgui_font_set_defaut(&rtgui_font_asc12);
|
2010-02-08 22:15:11 +08:00
|
|
|
#endif
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
|
2010-02-13 00:02:00 +08:00
|
|
|
static const rt_uint8_t close_byte[14] = {0x06, 0x18, 0x03, 0x30, 0x01, 0xE0, 0x00,
|
|
|
|
0xC0, 0x01, 0xE0, 0x03, 0x30, 0x06, 0x18
|
|
|
|
};
|
2010-02-01 17:45:33 +08:00
|
|
|
|
2009-11-24 07:34:58 +08:00
|
|
|
/* window drawing */
|
|
|
|
void rtgui_theme_draw_win(struct rtgui_topwin* win)
|
|
|
|
{
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
rtgui_rect_t rect;
|
|
|
|
|
2010-08-22 22:53:32 +08:00
|
|
|
if (win->title == RT_NULL) return; /* no title and no board */
|
|
|
|
|
2009-11-24 07:34:58 +08:00
|
|
|
/* begin drawing */
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(win->title));
|
2010-02-05 08:05:30 +08:00
|
|
|
if (dc == RT_NULL) return;
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
/* get rect */
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(win->title), &rect);
|
|
|
|
|
|
|
|
/* draw border */
|
|
|
|
if (win->flag & WINTITLE_BORDER)
|
|
|
|
{
|
2010-02-01 17:45:33 +08:00
|
|
|
rect.x2 -= 1; rect.y2 -= 1;
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(win->title) = RTGUI_RGB(212, 208, 200);
|
2010-01-21 18:05:06 +08:00
|
|
|
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1);
|
|
|
|
rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2);
|
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(win->title) = white;
|
2010-01-21 18:05:06 +08:00
|
|
|
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);
|
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(win->title) = RTGUI_RGB(128, 128, 128);
|
2010-01-21 18:05:06 +08:00
|
|
|
rtgui_dc_draw_hline(dc, rect.x1 + 1, rect.x2 - 1, rect.y2 - 1);
|
2011-01-25 08:05:52 +08:00
|
|
|
rtgui_dc_draw_vline(dc, rect.x2 - 1, rect.y1 + 1, rect.y2);
|
2010-01-21 18:05:06 +08:00
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(win->title) = RTGUI_RGB(64, 64, 64);
|
2010-02-01 17:45:33 +08:00
|
|
|
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2);
|
2011-01-25 08:05:52 +08:00
|
|
|
rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2 + 1);
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
/* shrink border */
|
2010-02-01 17:45:33 +08:00
|
|
|
rtgui_rect_inflate(&rect, -WINTITLE_BORDER_SIZE);
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* draw title */
|
|
|
|
if (!(win->flag & WINTITLE_NO))
|
|
|
|
{
|
2010-01-21 18:05:06 +08:00
|
|
|
rt_uint32_t index;
|
|
|
|
float r, g, b, delta;
|
|
|
|
|
|
|
|
if (win->flag & WINTITLE_ACTIVATE)
|
|
|
|
{
|
|
|
|
r = 10; g = 36; b = 106;
|
2010-01-25 08:01:18 +08:00
|
|
|
delta = 150 / (float)(rect.x2 - rect.x1);
|
2010-01-21 18:05:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = 128; g = 128; b = 128;
|
2010-01-25 08:01:18 +08:00
|
|
|
delta = 64 / (float)(rect.x2 - rect.x1);
|
2010-01-21 18:05:06 +08:00
|
|
|
}
|
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(win->title) = RTGUI_RGB(r, g, b);
|
2010-07-03 23:24:40 +08:00
|
|
|
for (index = rect.x1; index < rect.x2 + 1; index ++)
|
2010-01-21 18:05:06 +08:00
|
|
|
{
|
|
|
|
rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
|
|
|
|
r += delta; g += delta; b += delta;
|
|
|
|
}
|
|
|
|
|
2009-11-24 07:34:58 +08:00
|
|
|
if (win->flag & WINTITLE_ACTIVATE)
|
|
|
|
{
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(win->title) = white;
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(win->title) = RTGUI_RGB(212, 208, 200);
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rect.x1 += 4;
|
2010-01-26 07:38:47 +08:00
|
|
|
rect.y1 += 2; rect.y2 = rect.y1 + WINTITLE_CB_HEIGHT;
|
2009-11-24 07:34:58 +08:00
|
|
|
rtgui_dc_draw_text(dc, rtgui_wintitle_get_title(win->title), &rect);
|
|
|
|
|
|
|
|
if (win->flag & WINTITLE_CLOSEBOX)
|
|
|
|
{
|
|
|
|
/* get close button rect */
|
2010-02-01 17:45:33 +08:00
|
|
|
rtgui_rect_t box_rect = {0, 0, WINTITLE_CB_WIDTH, WINTITLE_CB_HEIGHT};
|
|
|
|
rtgui_rect_moveto_align(&rect, &box_rect, RTGUI_ALIGN_CENTER_VERTICAL | RTGUI_ALIGN_RIGHT);
|
|
|
|
box_rect.x1 -= 3; box_rect.x2 -= 3;
|
|
|
|
rtgui_dc_fill_rect(dc, &box_rect);
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
/* draw close box */
|
2010-02-01 17:45:33 +08:00
|
|
|
if (win->flag & WINTITLE_CB_PRESSED)
|
|
|
|
{
|
|
|
|
rtgui_dc_draw_border(dc, &box_rect, RTGUI_BORDER_SUNKEN);
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(win->title) = red;
|
2010-02-01 17:45:33 +08:00
|
|
|
rtgui_dc_draw_word(dc, box_rect.x1, box_rect.y1 + 6, 7, close_byte);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rtgui_dc_draw_border(dc, &box_rect, RTGUI_BORDER_RAISE);
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(win->title) = black;
|
2010-02-01 17:45:33 +08:00
|
|
|
rtgui_dc_draw_word(dc, box_rect.x1 - 1, box_rect.y1 + 5, 7, close_byte);
|
|
|
|
}
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* widget drawing */
|
|
|
|
void rtgui_theme_draw_button(rtgui_button_t* btn)
|
|
|
|
{
|
|
|
|
/* draw button */
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
struct rtgui_rect rect;
|
2010-01-29 18:08:27 +08:00
|
|
|
rtgui_color_t bc, fc;
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
/* begin drawing */
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(btn));
|
|
|
|
if (dc == RT_NULL) return;
|
|
|
|
|
2010-01-18 07:43:20 +08:00
|
|
|
/* get widget rect */
|
2009-11-24 07:34:58 +08:00
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect);
|
|
|
|
|
2010-01-26 07:38:47 +08:00
|
|
|
/* get foreground color */
|
2012-08-13 14:30:05 +08:00
|
|
|
bc = RTGUI_WIDGET_BACKGROUND(btn);
|
|
|
|
fc = RTGUI_WIDGET_FOREGROUND(btn);
|
2010-01-18 07:43:20 +08:00
|
|
|
|
2011-06-11 14:18:46 +08:00
|
|
|
if (btn->flag & RTGUI_BUTTON_FLAG_PRESS)
|
2009-11-24 07:34:58 +08:00
|
|
|
{
|
2012-08-13 14:30:05 +08:00
|
|
|
/* fill button rect with background color */
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
2009-11-24 07:34:58 +08:00
|
|
|
if (btn->pressed_image != RT_NULL)
|
|
|
|
{
|
|
|
|
rtgui_rect_t image_rect;
|
|
|
|
image_rect.x1 = 0; image_rect.y1 = 0;
|
|
|
|
image_rect.x2 = btn->unpressed_image->w;
|
|
|
|
image_rect.y2 = btn->unpressed_image->h;
|
2012-08-13 14:30:05 +08:00
|
|
|
rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER);
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
rtgui_image_blit(btn->pressed_image, dc, &image_rect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-11 14:18:46 +08:00
|
|
|
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-13 14:30:05 +08:00
|
|
|
/* fill button rect with background color */
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
2009-11-24 07:34:58 +08:00
|
|
|
if (btn->unpressed_image != RT_NULL)
|
|
|
|
{
|
|
|
|
rtgui_rect_t image_rect;
|
|
|
|
image_rect.x1 = 0; image_rect.y1 = 0;
|
|
|
|
image_rect.x2 = btn->unpressed_image->w;
|
|
|
|
image_rect.y2 = btn->unpressed_image->h;
|
2012-08-13 14:30:05 +08:00
|
|
|
rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER);
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
rtgui_image_blit(btn->unpressed_image, dc, &image_rect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-11 14:18:46 +08:00
|
|
|
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
if (RTGUI_WIDGET_IS_FOCUSED(btn))
|
2010-02-03 18:28:11 +08:00
|
|
|
{
|
|
|
|
/* re-set foreground and get default rect */
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect);
|
|
|
|
rtgui_rect_inflate(&rect, -2);
|
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(btn) = black;
|
2010-02-03 18:28:11 +08:00
|
|
|
rtgui_dc_draw_focus_rect(dc, &rect);
|
|
|
|
}
|
|
|
|
|
2010-01-18 07:43:20 +08:00
|
|
|
/* set forecolor */
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_BACKGROUND(btn) = bc;
|
|
|
|
RTGUI_WIDGET_FOREGROUND(btn) = fc;
|
2010-01-18 07:43:20 +08:00
|
|
|
|
2009-11-24 07:34:58 +08:00
|
|
|
if (btn->pressed_image == RT_NULL)
|
|
|
|
{
|
|
|
|
/* re-set foreground and get default rect */
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect);
|
|
|
|
|
|
|
|
/* remove border */
|
|
|
|
rtgui_rect_inflate(&rect, -2);
|
|
|
|
|
|
|
|
/* draw text */
|
|
|
|
rtgui_dc_draw_text(dc, rtgui_label_get_text(RTGUI_LABEL(btn)), &rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* end drawing */
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtgui_theme_draw_label(rtgui_label_t* label)
|
|
|
|
{
|
|
|
|
/* draw label */
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
struct rtgui_rect rect;
|
|
|
|
|
|
|
|
/* begin drawing */
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(label));
|
|
|
|
if (dc == RT_NULL) return;
|
|
|
|
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(label), &rect);
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
|
|
|
/* default left and center draw */
|
|
|
|
rtgui_dc_draw_text(dc, rtgui_label_get_text(label), &rect);
|
|
|
|
|
|
|
|
/* end drawing */
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RTGUI_TEXTBOX_MARGIN 3
|
|
|
|
void rtgui_theme_draw_textbox(rtgui_textbox_t* box)
|
|
|
|
{
|
|
|
|
/* draw button */
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
struct rtgui_rect rect;
|
2010-01-25 08:01:18 +08:00
|
|
|
rtgui_color_t fc;
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
/* begin drawing */
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
|
|
|
|
if (dc == RT_NULL) return;
|
|
|
|
|
|
|
|
/* get widget rect */
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
|
2012-08-13 14:30:05 +08:00
|
|
|
fc = RTGUI_WIDGET_FOREGROUND(box);
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2010-01-25 08:01:18 +08:00
|
|
|
/* fill widget rect with white color */
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_BACKGROUND(box) = white;
|
2009-11-24 07:34:58 +08:00
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
|
|
|
/* draw border */
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(box) = RTGUI_RGB(123, 158, 189);
|
2010-01-25 08:01:18 +08:00
|
|
|
rtgui_dc_draw_rect(dc, &rect);
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
/* draw text */
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(box) = fc;
|
2009-11-24 07:34:58 +08:00
|
|
|
if (box->text != RT_NULL)
|
|
|
|
{
|
|
|
|
rect.x1 += RTGUI_TEXTBOX_MARGIN;
|
|
|
|
|
2010-01-25 08:01:18 +08:00
|
|
|
if (box->flag & RTGUI_TEXTBOX_MASK)
|
|
|
|
{
|
|
|
|
/* draw '*' */
|
|
|
|
rt_size_t len = rt_strlen(box->text);
|
|
|
|
if (len > 0)
|
|
|
|
{
|
2010-01-27 08:06:09 +08:00
|
|
|
char *text_mask = rtgui_malloc(len + 1);
|
|
|
|
rt_memset(text_mask, '*', len + 1);
|
2010-01-25 08:01:18 +08:00
|
|
|
text_mask[len] = 0;
|
|
|
|
rtgui_dc_draw_text(dc, text_mask, &rect);
|
2012-08-13 14:30:05 +08:00
|
|
|
rtgui_free(text_mask);
|
2010-01-25 08:01:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rtgui_dc_draw_text(dc, box->text, &rect);
|
|
|
|
}
|
2010-01-08 08:02:24 +08:00
|
|
|
|
|
|
|
/* draw caret */
|
|
|
|
if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
|
|
|
|
{
|
|
|
|
rect.x1 += box->position * box->font_width;
|
|
|
|
rect.x2 = rect.x1 + box->font_width;
|
|
|
|
|
2010-01-25 08:01:18 +08:00
|
|
|
rect.y2 -= 2;
|
2010-01-08 08:02:24 +08:00
|
|
|
rect.y1 = rect.y2 - 3;
|
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_BACKGROUND(box) = black;
|
2010-01-08 08:02:24 +08:00
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
}
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* end drawing */
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtgui_theme_draw_iconbox(rtgui_iconbox_t* iconbox)
|
|
|
|
{
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
struct rtgui_rect rect;
|
2012-08-13 14:30:05 +08:00
|
|
|
struct rtgui_rect text_rect;
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
/* begin drawing */
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(iconbox));
|
|
|
|
if (dc == RT_NULL) return;
|
|
|
|
|
|
|
|
/* get widget rect */
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(iconbox), &rect);
|
|
|
|
|
|
|
|
/* draw icon */
|
|
|
|
rtgui_image_blit(iconbox->image, dc, &rect);
|
|
|
|
|
|
|
|
/* draw text */
|
|
|
|
if (iconbox->text_position == RTGUI_ICONBOX_TEXT_BELOW && iconbox->text != RT_NULL)
|
|
|
|
{
|
|
|
|
rect.y1 = iconbox->image->h + RTGUI_WIDGET_DEFAULT_MARGIN;
|
2012-08-13 14:30:05 +08:00
|
|
|
rtgui_font_get_metrics(rtgui_dc_get_gc(dc)->font, iconbox->text, &text_rect);
|
|
|
|
rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_ALIGN_CENTER);
|
|
|
|
rtgui_dc_draw_text(dc, iconbox->text, &text_rect);
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
else if (iconbox->text_position == RTGUI_ICONBOX_TEXT_RIGHT && iconbox->text != RT_NULL)
|
|
|
|
{
|
|
|
|
rect.x1 = iconbox->image->w + RTGUI_WIDGET_DEFAULT_MARGIN;
|
2012-08-13 14:30:05 +08:00
|
|
|
rtgui_font_get_metrics(rtgui_dc_get_gc(dc)->font, iconbox->text, &text_rect);
|
|
|
|
rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_ALIGN_CENTER);
|
|
|
|
rtgui_dc_draw_text(dc, iconbox->text, &text_rect);
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* end drawing */
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
}
|
|
|
|
|
2010-02-13 00:02:00 +08:00
|
|
|
static const rt_uint8_t checked_byte[7] = {0x02, 0x06, 0x8E, 0xDC, 0xF8, 0x70, 0x20};
|
2010-01-14 07:41:15 +08:00
|
|
|
void rtgui_theme_draw_checkbox(struct rtgui_checkbox* checkbox)
|
2010-01-08 08:02:24 +08:00
|
|
|
{
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
struct rtgui_rect rect, box_rect;
|
2010-02-01 17:45:33 +08:00
|
|
|
rtgui_color_t bc, fc;
|
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
fc = RTGUI_WIDGET_FOREGROUND(checkbox);
|
|
|
|
bc = RTGUI_WIDGET_BACKGROUND(checkbox);
|
2010-01-08 08:02:24 +08:00
|
|
|
|
|
|
|
/* begin drawing */
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(checkbox));
|
|
|
|
if (dc == RT_NULL) return;
|
|
|
|
|
|
|
|
/* get rect */
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(checkbox), &rect);
|
|
|
|
|
|
|
|
/* fill rect */
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
if (RTGUI_WIDGET_IS_FOCUSED(checkbox))
|
2010-01-08 08:02:24 +08:00
|
|
|
{
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(checkbox) = black;
|
2010-02-03 18:28:11 +08:00
|
|
|
|
2010-01-08 08:02:24 +08:00
|
|
|
/* draw focused border */
|
|
|
|
rtgui_rect_inflate(&rect, -1);
|
|
|
|
rtgui_dc_draw_focus_rect(dc, &rect);
|
|
|
|
|
|
|
|
rtgui_rect_inflate(&rect, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw check box */
|
2010-02-01 17:45:33 +08:00
|
|
|
box_rect.x1 = 0;
|
|
|
|
box_rect.y1 = 0;
|
|
|
|
box_rect.x2 = CHECK_BOX_W;
|
|
|
|
box_rect.y2 = CHECK_BOX_H;
|
|
|
|
rtgui_rect_moveto_align(&rect, &box_rect, RTGUI_ALIGN_CENTER_VERTICAL);
|
2010-02-03 18:28:11 +08:00
|
|
|
box_rect.x1 += 2; box_rect.x2 += 2;
|
2010-02-01 17:45:33 +08:00
|
|
|
|
|
|
|
rtgui_dc_draw_border(dc, &box_rect, RTGUI_BORDER_BOX);
|
|
|
|
rtgui_rect_inflate(&box_rect, -1);
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_BACKGROUND(checkbox) = RTGUI_RGB(247, 247, 246);
|
2010-02-01 17:45:33 +08:00
|
|
|
rtgui_dc_fill_rect(dc, &box_rect);
|
2010-01-08 08:02:24 +08:00
|
|
|
if (checkbox->status_down == RTGUI_CHECKBOX_STATUS_CHECKED)
|
|
|
|
{
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(checkbox) = RTGUI_RGB(33, 161, 33);
|
2010-02-01 17:45:33 +08:00
|
|
|
rtgui_dc_draw_byte(dc, box_rect.x1 + 2, box_rect.y1 + 2, 7, checked_byte);
|
2010-01-08 08:02:24 +08:00
|
|
|
}
|
|
|
|
|
2010-02-01 17:45:33 +08:00
|
|
|
/* restore saved color */
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_BACKGROUND(checkbox) = bc;
|
|
|
|
RTGUI_WIDGET_FOREGROUND(checkbox) = fc;
|
2010-02-01 17:45:33 +08:00
|
|
|
|
2010-01-08 08:02:24 +08:00
|
|
|
/* draw text */
|
|
|
|
rect.x1 += rtgui_rect_height(rect) - 4 + 5;
|
|
|
|
rtgui_dc_draw_text(dc, rtgui_label_get_text(RTGUI_LABEL(checkbox)), &rect);
|
|
|
|
|
|
|
|
/* end drawing */
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-13 00:02:00 +08:00
|
|
|
static const rt_uint8_t radio_unchecked_byte[] =
|
|
|
|
{
|
|
|
|
0x0f, 0x00, 0x30, 0xc0, 0x40, 0x20,
|
|
|
|
0x40, 0x20, 0x80, 0x10, 0x80, 0x10,
|
|
|
|
0x80, 0x10, 0x80, 0x10, 0x40, 0x20,
|
|
|
|
0x40, 0x20, 0x30, 0xc0, 0x0f, 0x00,
|
|
|
|
};
|
|
|
|
static const rt_uint8_t radio_checked_byte[] =
|
|
|
|
{
|
|
|
|
0x0f, 0x00, 0x30, 0xc0, 0x40, 0x20,
|
|
|
|
0x40, 0x20, 0x86, 0x10, 0x8f, 0x10,
|
|
|
|
0x8f, 0x10, 0x86, 0x10, 0x40, 0x20,
|
|
|
|
0x40, 0x20, 0x30, 0xc0, 0x0f, 0x00,
|
|
|
|
};
|
|
|
|
|
2010-05-27 07:58:47 +08:00
|
|
|
void rtgui_theme_draw_radiobutton(struct rtgui_radiobox* radiobox, rt_uint16_t item)
|
|
|
|
{
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
struct rtgui_rect rect, item_rect;
|
2010-05-31 06:44:21 +08:00
|
|
|
int item_size, bord_size;
|
2010-05-27 07:58:47 +08:00
|
|
|
|
|
|
|
/* begin drawing */
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(radiobox));
|
|
|
|
if (dc == RT_NULL) return;
|
|
|
|
/* get widget rect */
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(radiobox), &rect);
|
|
|
|
|
|
|
|
item_size = radiobox->item_size;
|
|
|
|
/* get board size */
|
|
|
|
if (radiobox->orient == RTGUI_VERTICAL)
|
|
|
|
bord_size = item_size;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rtgui_font_get_metrics(RTGUI_DC_FONT(dc), "H", &item_rect);
|
|
|
|
bord_size = rtgui_rect_height(item_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
item_rect = rect;
|
|
|
|
rtgui_rect_inflate(&item_rect, - bord_size);
|
|
|
|
if (radiobox->orient == RTGUI_VERTICAL)
|
|
|
|
{
|
|
|
|
/* set the first text rect */
|
|
|
|
item_rect.y1 += item * item_size;
|
|
|
|
item_rect.y2 = item_rect.y1 + item_size;
|
|
|
|
|
|
|
|
/* draw radio */
|
|
|
|
if (radiobox->item_selection == item)
|
|
|
|
{
|
2012-08-13 14:30:05 +08:00
|
|
|
if (RTGUI_WIDGET_IS_FOCUSED(radiobox))
|
2010-05-27 07:58:47 +08:00
|
|
|
rtgui_dc_draw_focus_rect(dc, &item_rect);
|
|
|
|
|
|
|
|
rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + (item_size - RADIO_BOX_H) / 2,
|
|
|
|
RADIO_BOX_H, radio_checked_byte);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item_rect.x2 += 1; item_rect.y2 += 1;
|
|
|
|
rtgui_dc_fill_rect(dc, &item_rect);
|
|
|
|
item_rect.x2 -= 1; item_rect.y2 -= 1;
|
|
|
|
rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + (item_size - RADIO_BOX_H) / 2,
|
|
|
|
RADIO_BOX_H, radio_unchecked_byte);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw text */
|
|
|
|
item_rect.x1 += item_size + 3;
|
|
|
|
rtgui_dc_draw_text(dc, radiobox->items[item], &item_rect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item_rect.x1 += item * item_size;
|
|
|
|
|
|
|
|
/* set the first text rect */
|
2010-05-28 07:03:37 +08:00
|
|
|
item_rect.x2 = item_rect.x1 + item_size - 1;
|
2010-05-27 07:58:47 +08:00
|
|
|
item_rect.y2 = item_rect.y1 + bord_size;
|
|
|
|
|
|
|
|
/* draw radio */
|
|
|
|
if (radiobox->item_selection == item)
|
|
|
|
{
|
2012-08-13 14:30:05 +08:00
|
|
|
if (RTGUI_WIDGET_IS_FOCUSED(radiobox))
|
2010-05-27 07:58:47 +08:00
|
|
|
rtgui_dc_draw_focus_rect(dc, &item_rect);
|
|
|
|
rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_checked_byte);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item_rect.x2 += 1; item_rect.y2 += 1;
|
|
|
|
rtgui_dc_fill_rect(dc, &item_rect);
|
|
|
|
item_rect.x2 -= 1; item_rect.y2 -= 1;
|
|
|
|
rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_unchecked_byte);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw text */
|
|
|
|
item_rect.x1 += bord_size + 3;
|
|
|
|
rtgui_dc_draw_text(dc, radiobox->items[item], &item_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* end drawing */
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
}
|
|
|
|
|
2010-01-14 07:41:15 +08:00
|
|
|
void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
|
|
|
|
{
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
struct rtgui_rect rect, item_rect;
|
2010-05-31 06:44:21 +08:00
|
|
|
int item_size, bord_size, index;
|
2010-01-21 18:05:06 +08:00
|
|
|
rtgui_color_t fc;
|
2010-01-14 07:41:15 +08:00
|
|
|
|
|
|
|
/* begin drawing */
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(radiobox));
|
|
|
|
if (dc == RT_NULL) return;
|
|
|
|
|
|
|
|
/* get widget rect */
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(radiobox), &rect);
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
|
|
|
item_size = radiobox->item_size;
|
|
|
|
/* get board size */
|
|
|
|
if (radiobox->orient == RTGUI_VERTICAL)
|
|
|
|
bord_size = item_size;
|
|
|
|
else
|
|
|
|
{
|
2010-04-12 07:57:21 +08:00
|
|
|
rtgui_font_get_metrics(RTGUI_DC_FONT(dc), "H", &item_rect);
|
2010-01-14 07:41:15 +08:00
|
|
|
bord_size = rtgui_rect_height(item_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw box */
|
|
|
|
rtgui_rect_inflate(&rect, -bord_size/2);
|
2012-08-13 14:30:05 +08:00
|
|
|
fc = RTGUI_WIDGET_FOREGROUND(radiobox);
|
2010-01-21 18:05:06 +08:00
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(radiobox) = white;
|
2010-01-21 18:05:06 +08:00
|
|
|
rect.x1 ++; rect.y1 ++; rect.x2 ++; rect.y2 ++;
|
|
|
|
rtgui_dc_draw_rect(dc, &rect);
|
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(radiobox) = RTGUI_RGB(128, 128, 128);
|
2010-01-21 18:05:06 +08:00
|
|
|
rect.x1 --; rect.y1 --; rect.x2 --; rect.y2 --;
|
|
|
|
rtgui_dc_draw_rect(dc, &rect);
|
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(radiobox) = fc;
|
2010-01-21 18:05:06 +08:00
|
|
|
|
2010-01-14 07:41:15 +08:00
|
|
|
rtgui_rect_inflate(&rect, bord_size/2);
|
|
|
|
if (radiobox->text != RT_NULL)
|
|
|
|
{
|
|
|
|
struct rtgui_rect text_rect;
|
|
|
|
|
|
|
|
/* draw group text */
|
2010-04-12 07:57:21 +08:00
|
|
|
rtgui_font_get_metrics(RTGUI_DC_FONT(dc), radiobox->text, &text_rect);
|
2010-01-18 07:43:20 +08:00
|
|
|
rtgui_rect_moveto(&text_rect, rect.x1 + bord_size + 5, rect.y1);
|
2010-01-21 18:05:06 +08:00
|
|
|
rect.x1 -= 5; rect.x2 += 5;
|
2010-01-14 07:41:15 +08:00
|
|
|
rtgui_dc_fill_rect(dc, &text_rect);
|
2010-01-21 18:05:06 +08:00
|
|
|
rect.x1 += 5; rect.x2 -= 5;
|
2010-01-14 07:41:15 +08:00
|
|
|
rtgui_dc_draw_text(dc, radiobox->text, &text_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set init item rect */
|
|
|
|
item_rect = rect;
|
|
|
|
rtgui_rect_inflate(&item_rect, - bord_size);
|
|
|
|
|
|
|
|
if (radiobox->orient == RTGUI_VERTICAL)
|
|
|
|
{
|
2010-02-13 00:02:00 +08:00
|
|
|
rt_uint16_t offset;
|
|
|
|
|
2010-01-14 07:41:15 +08:00
|
|
|
/* set the first text rect */
|
|
|
|
item_rect.y2 = item_rect.y1 + item_size;
|
|
|
|
|
2010-02-13 00:02:00 +08:00
|
|
|
offset = (item_size - RADIO_BOX_H) / 2;
|
2010-01-14 07:41:15 +08:00
|
|
|
/* draw each radio button */
|
|
|
|
for (index = 0; index < radiobox->item_count; index ++)
|
|
|
|
{
|
|
|
|
if (item_rect.y2 > rect.y2 - item_size) break;
|
|
|
|
|
|
|
|
/* draw radio */
|
|
|
|
if (radiobox->item_selection == index)
|
|
|
|
{
|
2012-08-13 14:30:05 +08:00
|
|
|
if (RTGUI_WIDGET_IS_FOCUSED(radiobox))
|
2010-01-18 07:43:20 +08:00
|
|
|
rtgui_dc_draw_focus_rect(dc, &item_rect);
|
2010-02-13 00:02:00 +08:00
|
|
|
|
|
|
|
rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + offset, RADIO_BOX_H, radio_checked_byte);
|
2010-01-14 07:41:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-13 00:02:00 +08:00
|
|
|
rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + offset, RADIO_BOX_H, radio_unchecked_byte);
|
2010-01-14 07:41:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* draw text */
|
|
|
|
item_rect.x1 += item_size + 3;
|
2010-01-14 18:03:50 +08:00
|
|
|
rtgui_dc_draw_text(dc, radiobox->items[index], &item_rect);
|
2010-01-14 07:41:15 +08:00
|
|
|
item_rect.x1 -= item_size + 3;
|
|
|
|
|
|
|
|
item_rect.y1 += item_size;
|
|
|
|
item_rect.y2 += item_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* set the first text rect */
|
|
|
|
item_rect.x2 = item_rect.x1 + item_size;
|
2010-01-25 08:01:18 +08:00
|
|
|
item_rect.y2 = item_rect.y1 + bord_size;
|
2010-01-14 07:41:15 +08:00
|
|
|
|
|
|
|
/* draw each radio button */
|
|
|
|
for (index = 0; index < radiobox->item_count; index ++)
|
|
|
|
{
|
|
|
|
if (item_rect.x2 > rect.x2 - item_size) break;
|
|
|
|
|
|
|
|
/* draw radio */
|
|
|
|
if (radiobox->item_selection == index)
|
|
|
|
{
|
2012-08-13 14:30:05 +08:00
|
|
|
if (RTGUI_WIDGET_IS_FOCUSED(radiobox))
|
2010-05-27 07:58:47 +08:00
|
|
|
rtgui_dc_draw_focus_rect(dc, &item_rect);
|
2010-02-13 00:02:00 +08:00
|
|
|
rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_checked_byte);
|
2010-01-14 07:41:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-13 00:02:00 +08:00
|
|
|
rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_unchecked_byte);
|
2010-01-14 07:41:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* draw text */
|
2010-01-18 07:43:20 +08:00
|
|
|
item_rect.x1 += bord_size + 3;
|
2010-01-14 18:03:50 +08:00
|
|
|
rtgui_dc_draw_text(dc, radiobox->items[index], &item_rect);
|
2010-01-18 07:43:20 +08:00
|
|
|
item_rect.x1 -= bord_size + 3;
|
2010-01-14 07:41:15 +08:00
|
|
|
|
|
|
|
item_rect.x1 += item_size;
|
2010-05-28 07:03:37 +08:00
|
|
|
item_rect.x2 += (item_size - 1);
|
2010-01-14 07:41:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* end drawing */
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
}
|
|
|
|
|
2010-01-08 08:02:24 +08:00
|
|
|
void rtgui_theme_draw_slider(struct rtgui_slider* slider)
|
|
|
|
{
|
|
|
|
/* draw button */
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
int i, xsize, x0;
|
|
|
|
rtgui_rect_t r, focus_rect, slider_rect, slot_rect;
|
|
|
|
|
|
|
|
/* begin drawing */
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(slider));
|
|
|
|
if (dc == RT_NULL) return;
|
|
|
|
|
|
|
|
/* get widget rect */
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(slider), &focus_rect);
|
|
|
|
/* fill widget rect with background color */
|
|
|
|
rtgui_dc_fill_rect(dc, &focus_rect);
|
|
|
|
r = focus_rect;
|
|
|
|
|
|
|
|
if (slider->orient == RTGUI_VERTICAL)
|
|
|
|
{
|
|
|
|
rtgui_rect_inflate(&r, -1);
|
|
|
|
xsize = r.y2 - r.y1 + 1 - slider->thumb_width;
|
|
|
|
x0 = r.y1 + slider->thumb_width / 2;
|
|
|
|
|
|
|
|
/* calculate thumb position */
|
|
|
|
slider_rect = r;
|
|
|
|
slider_rect.x1 = 5;
|
|
|
|
slider_rect.y1 = x0 + xsize * (slider->value - slider->min) / (slider->max - slider->min) - slider->thumb_width/2;
|
|
|
|
slider_rect.y2 = slider_rect.y1 + slider->thumb_width;
|
|
|
|
|
|
|
|
/* calculate slot position */
|
|
|
|
slot_rect.y1 = x0;
|
|
|
|
slot_rect.y2 = x0 + xsize;
|
|
|
|
slot_rect.x1 = (slider_rect.x1 + slider_rect.x2) /2 -1;
|
|
|
|
slot_rect.x2 = slot_rect.x1 +3;
|
|
|
|
/* draw slot */
|
|
|
|
rtgui_dc_draw_border(dc, &slot_rect, RTGUI_BORDER_RAISE);
|
|
|
|
|
|
|
|
/* draw the ticks */
|
|
|
|
for (i = 0; i <= slider->ticks; i++)
|
|
|
|
{
|
|
|
|
int x = x0 + xsize * i / slider->ticks;
|
|
|
|
rtgui_dc_draw_hline(dc, 1, 3, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw the thumb */
|
|
|
|
rtgui_dc_fill_rect(dc, &slider_rect);
|
|
|
|
rtgui_dc_draw_border(dc, &slider_rect, RTGUI_BORDER_RAISE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rtgui_rect_inflate(&r, -1);
|
|
|
|
xsize = r.x2 - r.x1 + 1 - slider->thumb_width;
|
|
|
|
x0 = r.x1 + slider->thumb_width / 2;
|
|
|
|
|
|
|
|
/* calculate thumb position */
|
|
|
|
slider_rect = r;
|
|
|
|
slider_rect.y1 = 5;
|
|
|
|
slider_rect.x1 = x0 + xsize * (slider->value - slider->min) / (slider->max - slider->min) - slider->thumb_width/2;
|
|
|
|
slider_rect.x2 = slider_rect.x1 + slider->thumb_width;
|
|
|
|
|
|
|
|
/* calculate slot position */
|
|
|
|
slot_rect.x1 = x0;
|
|
|
|
slot_rect.x2 = x0 + xsize;
|
|
|
|
slot_rect.y1 = (slider_rect.y1 + slider_rect.y2) /2 -1;
|
|
|
|
slot_rect.y2 = slot_rect.y1 +3;
|
|
|
|
/* draw slot */
|
|
|
|
rtgui_dc_draw_border(dc, &slot_rect, RTGUI_BORDER_RAISE);
|
|
|
|
|
|
|
|
/* draw the ticks */
|
|
|
|
for (i = 0; i <= slider->ticks; i++)
|
|
|
|
{
|
|
|
|
int x = x0 + xsize * i / slider->ticks;
|
|
|
|
rtgui_dc_draw_vline(dc, x, 1, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw the thumb */
|
|
|
|
rtgui_dc_fill_rect(dc, &slider_rect);
|
|
|
|
rtgui_dc_draw_border(dc, &slider_rect, RTGUI_BORDER_RAISE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw focus */
|
2012-08-13 14:30:05 +08:00
|
|
|
if (RTGUI_WIDGET_IS_FOCUSED(slider))
|
2010-01-08 08:02:24 +08:00
|
|
|
{
|
|
|
|
rtgui_dc_draw_focus_rect(dc, &focus_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* end drawing */
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-24 07:33:17 +08:00
|
|
|
|
|
|
|
const static rt_uint8_t _up_arrow[] = {0x10, 0x38, 0x7C, 0xFE};
|
|
|
|
const static rt_uint8_t _down_arrow[] = {0xFE,0x7C, 0x38, 0x10};
|
|
|
|
const static rt_uint8_t _left_arrow[] = {0x10, 0x30, 0x70, 0xF0, 0x70, 0x30, 0x10};
|
|
|
|
const static rt_uint8_t _right_arrow[] = {0x80, 0xC0, 0xE0, 0xF0, 0xE0, 0xC0, 0x80};
|
|
|
|
|
|
|
|
void rtgui_theme_draw_scrollbar(struct rtgui_scrollbar* bar)
|
|
|
|
{
|
|
|
|
/* draw scroll bar */
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
rtgui_rect_t rect, btn_rect, thum_rect, arrow_rect;
|
|
|
|
rtgui_color_t bc, fc;
|
|
|
|
|
|
|
|
/* begin drawing */
|
|
|
|
dc = rtgui_dc_begin_drawing(&(bar->parent));
|
|
|
|
if (dc == RT_NULL) return;
|
|
|
|
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
|
|
|
|
|
|
|
|
/* draw background */
|
2012-08-13 14:30:05 +08:00
|
|
|
fc = RTGUI_WIDGET_FOREGROUND(bar);
|
|
|
|
if (!RTGUI_WIDGET_IS_ENABLE(bar))
|
|
|
|
RTGUI_WIDGET_FOREGROUND(bar) = RTGUI_RGB(128, 128, 128);
|
2010-08-24 07:33:17 +08:00
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
bc = RTGUI_WIDGET_BACKGROUND(bar);
|
|
|
|
RTGUI_WIDGET_BACKGROUND(bar) = white;
|
2010-08-24 07:33:17 +08:00
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_BACKGROUND(bar) = bc;
|
2010-08-24 07:33:17 +08:00
|
|
|
|
|
|
|
if (bar->orient == RTGUI_VERTICAL)
|
|
|
|
{
|
|
|
|
btn_rect = rect;
|
|
|
|
btn_rect.y2 = btn_rect.y1 + (rect.x2 - rect.x1);
|
|
|
|
|
|
|
|
/* draw up button */
|
|
|
|
rtgui_dc_fill_rect(dc, &btn_rect);
|
|
|
|
if (bar->status & SBS_UPARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
|
|
|
|
else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
|
|
|
|
|
|
|
|
/* draw arrow */
|
|
|
|
arrow_rect.x1 = 0; arrow_rect.y1 = 0;
|
|
|
|
arrow_rect.x2 = 7; arrow_rect.y2 = 4;
|
|
|
|
rtgui_rect_moveto_align(&btn_rect, &arrow_rect,
|
|
|
|
RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
|
|
|
|
rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1,
|
|
|
|
rtgui_rect_height(arrow_rect), _up_arrow);
|
|
|
|
|
|
|
|
/* draw thumb */
|
2012-08-13 14:30:05 +08:00
|
|
|
if (RTGUI_WIDGET_IS_ENABLE(bar))
|
2010-08-24 07:33:17 +08:00
|
|
|
{
|
|
|
|
rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
|
|
|
|
rtgui_dc_fill_rect(dc, &thum_rect);
|
|
|
|
rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw down button */
|
|
|
|
btn_rect.y1 = rect.y2 - (rect.x2 - rect.x1);
|
|
|
|
btn_rect.y2 = rect.y2;
|
|
|
|
|
|
|
|
rtgui_dc_fill_rect(dc, &btn_rect);
|
|
|
|
if (bar->status & SBS_DOWNARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
|
|
|
|
else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
|
|
|
|
|
|
|
|
arrow_rect.x1 = 0; arrow_rect.y1 = 0;
|
|
|
|
arrow_rect.x2 = 7; arrow_rect.y2 = 4;
|
|
|
|
rtgui_rect_moveto_align(&btn_rect, &arrow_rect,
|
|
|
|
RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
|
|
|
|
rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1,
|
|
|
|
rtgui_rect_height(arrow_rect), _down_arrow);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
btn_rect.x1 = rect.x1;
|
|
|
|
btn_rect.y1 = rect.y1;
|
|
|
|
btn_rect.x2 = rect.y2;
|
|
|
|
btn_rect.y2 = rect.y2;
|
|
|
|
|
|
|
|
/* draw left button */
|
|
|
|
rtgui_dc_fill_rect(dc, &btn_rect);
|
|
|
|
if (bar->status & SBS_LEFTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
|
|
|
|
else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
|
|
|
|
|
|
|
|
arrow_rect.x1 = 0; arrow_rect.y1 = 0;
|
|
|
|
arrow_rect.x2 = 4; arrow_rect.y2 = 7;
|
|
|
|
rtgui_rect_moveto_align(&btn_rect, &arrow_rect,
|
|
|
|
RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
|
|
|
|
rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1,
|
|
|
|
rtgui_rect_height(arrow_rect), _left_arrow);
|
|
|
|
|
|
|
|
/* draw thumb */
|
2012-08-13 14:30:05 +08:00
|
|
|
if (RTGUI_WIDGET_IS_ENABLE(bar))
|
2010-08-24 07:33:17 +08:00
|
|
|
{
|
|
|
|
rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
|
|
|
|
rtgui_dc_fill_rect(dc, &thum_rect);
|
|
|
|
rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
|
|
|
|
}
|
|
|
|
|
|
|
|
btn_rect.x1 = rect.x2 - rect.y2;
|
|
|
|
btn_rect.x2 = rect.x2;
|
|
|
|
|
|
|
|
/* draw right button */
|
|
|
|
rtgui_dc_fill_rect(dc, &btn_rect);
|
|
|
|
if (bar->status & SBS_RIGHTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
|
|
|
|
else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
|
|
|
|
|
|
|
|
arrow_rect.x1 = 0; arrow_rect.y1 = 0;
|
|
|
|
arrow_rect.x2 = 4; arrow_rect.y2 = 7;
|
|
|
|
rtgui_rect_moveto_align(&btn_rect, &arrow_rect,
|
|
|
|
RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
|
|
|
|
rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1,
|
|
|
|
rtgui_rect_height(arrow_rect), _right_arrow);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* end drawing */
|
|
|
|
rtgui_dc_end_drawing(dc);
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_FOREGROUND(bar) = fc;
|
2010-08-24 07:33:17 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2010-08-09 07:18:02 +08:00
|
|
|
|
2010-01-08 08:02:24 +08:00
|
|
|
void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar)
|
|
|
|
{
|
|
|
|
/* draw progress bar */
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
struct rtgui_rect rect;
|
|
|
|
int max = bar->range;
|
|
|
|
int pos = bar->position;
|
|
|
|
int left;
|
2010-05-28 07:03:37 +08:00
|
|
|
rtgui_color_t bc;
|
2010-01-08 08:02:24 +08:00
|
|
|
|
|
|
|
/* begin drawing */
|
|
|
|
dc = rtgui_dc_begin_drawing(&(bar->parent));
|
|
|
|
if (dc == RT_NULL) return;
|
|
|
|
|
2010-05-28 07:03:37 +08:00
|
|
|
bc = RTGUI_DC_BC(dc);
|
2010-01-08 08:02:24 +08:00
|
|
|
rtgui_widget_get_rect(&(bar->parent), &rect);
|
|
|
|
|
|
|
|
/* fill button rect with background color */
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_BACKGROUND(bar) = RTGUI_RGB(212, 208, 200);
|
2010-01-08 08:02:24 +08:00
|
|
|
|
|
|
|
/* draw border */
|
2010-05-28 07:03:37 +08:00
|
|
|
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
|
|
|
|
|
|
|
|
/* Nothing to draw */
|
2010-01-08 08:02:24 +08:00
|
|
|
if (max == 0)
|
|
|
|
{
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-28 07:03:37 +08:00
|
|
|
rect.x2 ++; rect.y2 ++;
|
2010-01-08 08:02:24 +08:00
|
|
|
left = max - pos;
|
|
|
|
rtgui_rect_inflate(&rect, -2);
|
2012-08-13 14:30:05 +08:00
|
|
|
RTGUI_WIDGET_BACKGROUND(bar) = RTGUI_RGB(0, 0, 255);
|
2011-06-11 14:18:46 +08:00
|
|
|
rect.y2 --; rect.x2 --;
|
2010-01-08 08:02:24 +08:00
|
|
|
|
2010-08-24 07:33:17 +08:00
|
|
|
if (bar->orient == RTGUI_VERTICAL)
|
2010-01-08 08:02:24 +08:00
|
|
|
{
|
|
|
|
/* Vertical bar grows from bottom to top */
|
|
|
|
int dy = (rtgui_rect_height(rect) * left) / max;
|
|
|
|
rect.y1 += dy;
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
2010-05-28 07:03:37 +08:00
|
|
|
|
|
|
|
RTGUI_DC_BC(dc) = bc;
|
|
|
|
rect.y1 -= dy; rect.y2 = dy;
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
2010-01-08 08:02:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Horizontal bar grows from left to right */
|
2010-05-28 07:03:37 +08:00
|
|
|
int dx = (rtgui_rect_width(rect) * left) / max;
|
|
|
|
rect.x2 -= dx;
|
2010-01-08 08:02:24 +08:00
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
2010-05-28 07:03:37 +08:00
|
|
|
|
|
|
|
RTGUI_DC_BC(dc) = bc;
|
|
|
|
rect.x1 = rect.x2; rect.x2 += dx;
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
}
|
2010-01-08 08:02:24 +08:00
|
|
|
|
|
|
|
/* end drawing */
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtgui_theme_draw_staticline(struct rtgui_staticline* staticline)
|
|
|
|
{
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
struct rtgui_rect rect;
|
|
|
|
|
|
|
|
/* begin drawing */
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(staticline));
|
|
|
|
if (dc == RT_NULL) return ;
|
2010-01-25 08:01:18 +08:00
|
|
|
|
2010-01-08 08:02:24 +08:00
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(staticline), &rect);
|
2010-01-25 08:01:18 +08:00
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
2010-01-08 08:02:24 +08:00
|
|
|
|
2010-08-24 07:33:17 +08:00
|
|
|
if (staticline->orient == RTGUI_HORIZONTAL)
|
2010-01-08 08:02:24 +08:00
|
|
|
{
|
|
|
|
rtgui_dc_draw_horizontal_line(dc, rect.x1, rect.x2, rect.y1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rtgui_dc_draw_vertical_line(dc, rect.x1, rect.y1, rect.y2);
|
|
|
|
}
|
|
|
|
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
}
|
|
|
|
|
2009-11-24 07:34:58 +08:00
|
|
|
rt_uint16_t rtgui_theme_get_selected_height()
|
|
|
|
{
|
|
|
|
return SELECTED_HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtgui_theme_draw_selected(struct rtgui_dc* dc, rtgui_rect_t *rect)
|
|
|
|
{
|
2010-02-01 17:45:33 +08:00
|
|
|
rtgui_color_t bc;
|
|
|
|
rt_uint16_t index;
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2010-04-12 07:57:21 +08:00
|
|
|
bc = RTGUI_DC_FC(dc);
|
|
|
|
RTGUI_DC_FC(dc) = selected_color;
|
2010-02-01 17:45:33 +08:00
|
|
|
|
|
|
|
rtgui_dc_draw_hline(dc, rect->x1 + 3, rect->x2 - 2, rect->y1 + 1);
|
|
|
|
rtgui_dc_draw_hline(dc, rect->x1 + 3, rect->x2 - 2, rect->y2 - 2);
|
|
|
|
|
|
|
|
rtgui_dc_draw_vline(dc, rect->x1 + 2, rect->y1 + 2, rect->y2 - 2);
|
|
|
|
rtgui_dc_draw_vline(dc, rect->x2 - 2, rect->y1 + 2, rect->y2 - 2);
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2010-02-01 17:45:33 +08:00
|
|
|
for (index = rect->y1 + 1; index < rect->y2 - 2; index ++)
|
|
|
|
rtgui_dc_draw_hline(dc, rect->x1 + 3, rect->x2 - 2, index);
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2010-04-12 07:57:21 +08:00
|
|
|
RTGUI_DC_FC(dc) = bc;
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get default background color */
|
|
|
|
rtgui_color_t rtgui_theme_default_bc()
|
|
|
|
{
|
|
|
|
return default_background;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get default foreground color */
|
|
|
|
rtgui_color_t rtgui_theme_default_fc()
|
|
|
|
{
|
|
|
|
return default_foreground;
|
|
|
|
}
|
|
|
|
|