提交 14c2f8c0 编写于 作者: B bernard.xiong@gmail.com

add rtgui_listbox_set_current_item function; fix draw rect issue on the...

add rtgui_listbox_set_current_item function; fix draw rect issue on the border; fix progress bar drawing issue; fix on_item issue in menu if the sub_menu is shown;

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1488 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 e8d72206
......@@ -242,24 +242,24 @@ void rtgui_dc_draw_shaded_rect(struct rtgui_dc* dc, rtgui_rect_t* rect,
rtgui_dc_draw_hline(dc, rect->x1 + 1, rect->x2, rect->y1);
RTGUI_DC_FC(dc) = c2;
rtgui_dc_draw_vline(dc, rect->x2, rect->y1, rect->y2);
rtgui_dc_draw_hline(dc, rect->x1, rect->x2 + 1, rect->y2);
rtgui_dc_draw_vline(dc, rect->x2 - 1, rect->y1, rect->y2);
rtgui_dc_draw_hline(dc, rect->x1, rect->x2, rect->y2 - 1);
}
void rtgui_dc_draw_focus_rect(struct rtgui_dc* dc, rtgui_rect_t* rect)
{
int i;
for (i = rect->x1; i <= rect->x2; i += 2)
for (i = rect->x1; i < rect->x2; i += 2)
{
rtgui_dc_draw_point(dc, i, rect->y1);
rtgui_dc_draw_point(dc, i, rect->y2);
rtgui_dc_draw_point(dc, i, rect->y2 - 1);
}
for (i = rect->y1; i <= rect->y2; i += 2)
for (i = rect->y1; i < rect->y2; i += 2)
{
rtgui_dc_draw_point(dc, rect->x1, i);
rtgui_dc_draw_point(dc, rect->x2, i);
rtgui_dc_draw_point(dc, rect->x2 - 1, i);
}
}
......
......@@ -251,7 +251,6 @@ static void rtgui_dc_client_draw_point(struct rtgui_dc* self, int x, int y)
owner = RTGUI_CONTAINER_OF(self, struct rtgui_widget, dc_type);
if (!RTGUI_WIDGET_IS_DC_VISIBLE(owner)) return;
x = x + owner->extent.x1;
y = y + owner->extent.y1;
......
......@@ -174,36 +174,7 @@ void rtgui_theme_draw_button(rtgui_button_t* btn)
bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(btn));
fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn));
if (btn->flag & RTGUI_BUTTON_TYPE_PUSH && btn->flag & RTGUI_BUTTON_FLAG_PRESS)
{
/* fill button rect with background color */
rtgui_dc_fill_rect(dc, &rect);
/* draw border */
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(64, 64, 64);
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(btn)) = RTGUI_RGB(128, 128, 128);
rtgui_dc_draw_hline(dc, rect.x1, rect.x2 - 1, rect.y1 + 1);
rtgui_dc_draw_vline(dc, rect.x1 + 1, rect.y1 + 1, rect.y2 - 2);
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(255, 255, 255);
rtgui_dc_draw_hline(dc, rect.x1, rect.x2 + 1, rect.y2 - 1);
rtgui_dc_draw_vline(dc, rect.x2 - 1, rect.y1, rect.y2);
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;
rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
rtgui_image_blit(btn->pressed_image, dc, &image_rect);
}
}
else if (btn->flag & RTGUI_BUTTON_FLAG_PRESS)
if (btn->flag & RTGUI_BUTTON_FLAG_PRESS)
{
if (btn->pressed_image != RT_NULL)
{
......@@ -218,16 +189,8 @@ void rtgui_theme_draw_button(rtgui_button_t* btn)
else
{
/* fill button rect with background color */
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(0xff, 0xff, 0xff);
rtgui_dc_fill_rect(dc, &rect);
/* draw border */
RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(0, 0, 0);
rtgui_dc_draw_rect(dc, &rect);
RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(128, 128, 128);
rect.x1 += 1; rect.y1 += 1; rect.x2 -= 1; rect.y2 -= 1;
rtgui_dc_draw_rect(dc, &rect);
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
}
}
else
......@@ -246,19 +209,7 @@ void rtgui_theme_draw_button(rtgui_button_t* btn)
{
/* fill button rect with background color */
rtgui_dc_fill_rect(dc, &rect);
/* draw border */
RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(255, 255, 255);
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1);
rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2);
RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(0, 0, 0);
rtgui_dc_draw_hline(dc, rect.x1, rect.x2 + 1, rect.y2);
rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2);
RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(128, 128, 128);
rtgui_dc_draw_hline(dc, rect.x1 + 1, rect.x2, rect.y2 - 1);
rtgui_dc_draw_vline(dc, rect.x2 - 1, rect.y1 + 1, rect.y2 - 1);
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);
}
}
......@@ -930,10 +881,9 @@ void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar)
rtgui_widget_get_rect(&(bar->parent), &rect);
/* fill button rect with background color */
bar->parent.gc.background = RTGUI_RGB(212, 208, 200);
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(212, 208, 200);
/* draw border */
rect.x2 --; rect.y2 --;
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
/* Nothing to draw */
......@@ -946,7 +896,8 @@ void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar)
rect.x2 ++; rect.y2 ++;
left = max - pos;
rtgui_rect_inflate(&rect, -2);
bar->parent.gc.background = RTGUI_RGB(0, 0, 255);
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(0, 0, 255);
rect.y2 --; rect.x2 --;
if (bar->orient == RTGUI_VERTICAL)
{
......
......@@ -62,6 +62,7 @@ void rtgui_listbox_destroy(rtgui_listbox_t* box);
rt_bool_t rtgui_listbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
void rtgui_listbox_set_onitem(rtgui_listbox_t* box, rtgui_onitem_func_t func);
void rtgui_listbox_set_items(rtgui_listbox_t* box, struct rtgui_listbox_item* items, rt_uint16_t count);
void rtgui_listbox_set_current_item(rtgui_listbox_t* box, int index);
#endif
......@@ -311,9 +311,9 @@ static void rtgui_filelist_view_menu_pop(rtgui_widget_t *parent)
listbox = rtgui_listbox_create(items, sizeof(items)/sizeof(items[0]), &rect);
rtgui_listbox_set_onitem(listbox, rtgui_filelist_view_on_folder_item);
rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(listbox));
rtgui_widget_focus(RTGUI_WIDGET(listbox));
rtgui_win_show(menu, RT_FALSE);
rtgui_widget_focus(RTGUI_WIDGET(listbox));
rtgui_listbox_set_current_item(listbox, 0);
}
}
......
......@@ -359,3 +359,18 @@ void rtgui_listbox_set_items(rtgui_listbox_t* box, struct rtgui_listbox_item* it
rtgui_widget_update(RTGUI_WIDGET(box));
}
void rtgui_listbox_set_current_item(rtgui_listbox_t* box, int index)
{
RT_ASSERT(box != RT_NULL);
if (index != box->current_item)
{
int old_item;
old_item = box->current_item;
box->current_item = index;
rtgui_listbox_update_current(box, old_item);
}
}
......@@ -81,17 +81,14 @@ static void _rtgui_menu_onitem(struct rtgui_widget* widget, struct rtgui_event*
}
else /* other menu item */
{
rt_ubase_t index;
/* invoke action */
if (menu->items[menu->items_list->current_item].on_menuaction != RT_NULL)
menu->items[menu->items_list->current_item].on_menuaction(RTGUI_WIDGET(menu), RT_NULL);
/* hide all of sub-menu */
for (index = 0; index < menu->items_count; index ++)
/* hide sub-menu */
if (menu->sub_menu != RT_NULL)
{
if (menu->items[index].submenu != RT_NULL)
rtgui_menu_hiden(menu->items[index].submenu);
rtgui_menu_hiden(menu->sub_menu);
}
rtgui_menu_hiden(menu);
}
......
......@@ -33,14 +33,7 @@ rt_bool_t rtgui_progressbar_event_handler(struct rtgui_widget* widget,
switch (event->type)
{
case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
else
#endif
{
rtgui_theme_draw_progressbar(bar);
}
rtgui_theme_draw_progressbar(bar);
break;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册