add radiobutton drawing.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@737 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com 2010-05-26 23:58:47 +00:00
parent 94e758a2cd
commit 5b91286805
3 changed files with 94 additions and 3 deletions

View File

@ -484,6 +484,90 @@ static const rt_uint8_t radio_checked_byte[] =
0x40, 0x20, 0x30, 0xc0, 0x0f, 0x00, 0x40, 0x20, 0x30, 0xc0, 0x0f, 0x00,
}; };
void rtgui_theme_draw_radiobutton(struct rtgui_radiobox* radiobox, rt_uint16_t item)
{
struct rtgui_dc* dc;
struct rtgui_rect rect, item_rect;
rt_size_t item_size, bord_size;
/* 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)
{
if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(radiobox)))
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 */
item_rect.x2 = item_rect.x1 + item_size;
item_rect.y2 = item_rect.y1 + bord_size;
/* draw radio */
if (radiobox->item_selection == item)
{
if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(radiobox)))
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);
}
void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox) void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
{ {
struct rtgui_dc* dc; struct rtgui_dc* dc;
@ -590,8 +674,8 @@ void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
/* draw radio */ /* draw radio */
if (radiobox->item_selection == index) if (radiobox->item_selection == index)
{ {
rtgui_dc_draw_focus_rect(dc, &item_rect); if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(radiobox)))
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); rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_checked_byte);
} }
else else

View File

@ -45,6 +45,7 @@ void rtgui_theme_draw_label(rtgui_label_t* label);
void rtgui_theme_draw_textbox(rtgui_textbox_t* box); void rtgui_theme_draw_textbox(rtgui_textbox_t* box);
void rtgui_theme_draw_iconbox(rtgui_iconbox_t* iconbox); void rtgui_theme_draw_iconbox(rtgui_iconbox_t* iconbox);
void rtgui_theme_draw_checkbox(rtgui_checkbox_t* checkbox); void rtgui_theme_draw_checkbox(rtgui_checkbox_t* checkbox);
void rtgui_theme_draw_radiobutton(struct rtgui_radiobox* radiobox, rt_uint16_t item);
void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox); void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox);
void rtgui_theme_draw_slider(struct rtgui_slider* slider); void rtgui_theme_draw_slider(struct rtgui_slider* slider);
void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar); void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar);

View File

@ -224,13 +224,19 @@ void rtgui_radiobox_set_orientation(struct rtgui_radiobox* radiobox, int orienta
void rtgui_radiobox_set_selection(struct rtgui_radiobox* radiobox, int selection) void rtgui_radiobox_set_selection(struct rtgui_radiobox* radiobox, int selection)
{ {
rt_uint16_t old_item;
if (selection == radiobox->item_selection) return;
old_item = radiobox->item_selection;
if (selection >= 0 && selection < radiobox->item_count) if (selection >= 0 && selection < radiobox->item_count)
{ {
radiobox->item_selection = selection; radiobox->item_selection = selection;
} }
/* update radiobox widget */ /* update radiobox widget */
rtgui_theme_draw_radiobox(radiobox); rtgui_theme_draw_radiobutton(radiobox, old_item);
rtgui_theme_draw_radiobutton(radiobox, radiobox->item_selection);
} }
int rtgui_radiobox_get_selection(struct rtgui_radiobox* radiobox) int rtgui_radiobox_get_selection(struct rtgui_radiobox* radiobox)