summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
author[email protected] <[email protected]>2011-06-11 06:18:46 +0000
committer[email protected] <[email protected]>2011-06-11 06:18:46 +0000
commit14c2f8c0399d2041d75fac43c42d87bf6a2e3b93 (patch)
treea7a5de9eb33296b476eeb813be8df28baf4384ef /components
parente8d7220682b061846844f98eb0f8d891c89c0e37 (diff)
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
Diffstat (limited to 'components')
-rw-r--r--components/rtgui/common/dc.c12
-rw-r--r--components/rtgui/common/dc_client.c1
-rw-r--r--components/rtgui/common/rtgui_theme.c61
-rw-r--r--components/rtgui/include/rtgui/widgets/listbox.h1
-rw-r--r--components/rtgui/widgets/filelist_view.c4
-rw-r--r--components/rtgui/widgets/listbox.c15
-rw-r--r--components/rtgui/widgets/menu.c9
-rw-r--r--components/rtgui/widgets/progressbar.c9
8 files changed, 34 insertions, 78 deletions
diff --git a/components/rtgui/common/dc.c b/components/rtgui/common/dc.c
index a0d170de8f..5c7d130037 100644
--- a/components/rtgui/common/dc.c
+++ b/components/rtgui/common/dc.c
@@ -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);
}
}
diff --git a/components/rtgui/common/dc_client.c b/components/rtgui/common/dc_client.c
index a3559a8842..2b43d189e6 100644
--- a/components/rtgui/common/dc_client.c
+++ b/components/rtgui/common/dc_client.c
@@ -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;
diff --git a/components/rtgui/common/rtgui_theme.c b/components/rtgui/common/rtgui_theme.c
index 5e337482a7..b9e52b3a99 100644
--- a/components/rtgui/common/rtgui_theme.c
+++ b/components/rtgui/common/rtgui_theme.c
@@ -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)
{
diff --git a/components/rtgui/include/rtgui/widgets/listbox.h b/components/rtgui/include/rtgui/widgets/listbox.h
index d53ed84540..8eb10206c7 100644
--- a/components/rtgui/include/rtgui/widgets/listbox.h
+++ b/components/rtgui/include/rtgui/widgets/listbox.h
@@ -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
diff --git a/components/rtgui/widgets/filelist_view.c b/components/rtgui/widgets/filelist_view.c
index 9d8b89dee1..3e38cb193f 100644
--- a/components/rtgui/widgets/filelist_view.c
+++ b/components/rtgui/widgets/filelist_view.c
@@ -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);
}
}
diff --git a/components/rtgui/widgets/listbox.c b/components/rtgui/widgets/listbox.c
index cf2532771d..f68ec02efe 100644
--- a/components/rtgui/widgets/listbox.c
+++ b/components/rtgui/widgets/listbox.c
@@ -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);
+ }
+}
+
diff --git a/components/rtgui/widgets/menu.c b/components/rtgui/widgets/menu.c
index a68ca9e39f..7d8b02dd3b 100644
--- a/components/rtgui/widgets/menu.c
+++ b/components/rtgui/widgets/menu.c
@@ -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);
}
diff --git a/components/rtgui/widgets/progressbar.c b/components/rtgui/widgets/progressbar.c
index 2d7ddc0ed2..84e2adea1d 100644
--- a/components/rtgui/widgets/progressbar.c
+++ b/components/rtgui/widgets/progressbar.c
@@ -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;
}