From 4314d9f0967eb67b64871aad2895d7c70fc7e8ea Mon Sep 17 00:00:00 2001 From: "bernard.xiong@gmail.com" Date: Thu, 27 May 2010 23:03:37 +0000 Subject: [PATCH] update progress bar drawing. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@740 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/rtgui/common/rtgui_theme.c | 42 ++++++++++++-------------- components/rtgui/widgets/progressbar.c | 1 - 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/components/rtgui/common/rtgui_theme.c b/components/rtgui/common/rtgui_theme.c index 646ee9b87..1c5a6f1a9 100644 --- a/components/rtgui/common/rtgui_theme.c +++ b/components/rtgui/common/rtgui_theme.c @@ -541,7 +541,7 @@ void rtgui_theme_draw_radiobutton(struct rtgui_radiobox* radiobox, rt_uint16_t i item_rect.x1 += item * item_size; /* set the first text rect */ - item_rect.x2 = item_rect.x1 + item_size; + item_rect.x2 = item_rect.x1 + item_size - 1; item_rect.y2 = item_rect.y1 + bord_size; /* draw radio */ @@ -689,7 +689,7 @@ void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox) item_rect.x1 -= bord_size + 3; item_rect.x1 += item_size; - item_rect.x2 += item_size; + item_rect.x2 += (item_size - 1); } } @@ -788,7 +788,6 @@ void rtgui_theme_draw_slider(struct rtgui_slider* slider) return; } - void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar) { /* draw progress bar */ @@ -797,40 +796,30 @@ void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar) int max = bar->range; int pos = bar->position; int left; + rtgui_color_t bc; /* begin drawing */ dc = rtgui_dc_begin_drawing(&(bar->parent)); if (dc == RT_NULL) return; + bc = RTGUI_DC_BC(dc); rtgui_widget_get_rect(&(bar->parent), &rect); /* fill button rect with background color */ bar->parent.gc.background = RTGUI_RGB(212, 208, 200); - rtgui_dc_fill_rect(dc, &rect); /* draw border */ - bar->parent.gc.foreground = RTGUI_RGB(128, 128, 128); - rtgui_dc_draw_hline(dc, rect.x1, rect.x2 - 1, rect.y1); - rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2 - 1); - bar->parent.gc.foreground = RTGUI_RGB(64, 64, 64); - rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1 + 1); - rtgui_dc_draw_vline(dc, rect.x1 + 1, rect.y1, rect.y2); - - bar->parent.gc.foreground = RTGUI_RGB(212, 208, 200); - rtgui_dc_draw_hline(dc, rect.x1, rect.x2 + 1, rect.y2); - rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2); - - bar->parent.gc.foreground = RTGUI_RGB(255, 255, 255); - 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); - - /* Nothing to draw */ + rect.x2 --; rect.y2 --; + rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN); + + /* Nothing to draw */ if (max == 0) { rtgui_dc_end_drawing(dc); return; } + rect.x2 ++; rect.y2 ++; left = max - pos; rtgui_rect_inflate(&rect, -2); bar->parent.gc.background = RTGUI_RGB(0, 0, 255); @@ -841,13 +830,22 @@ void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar) int dy = (rtgui_rect_height(rect) * left) / max; rect.y1 += dy; rtgui_dc_fill_rect(dc, &rect); + + RTGUI_DC_BC(dc) = bc; + rect.y1 -= dy; rect.y2 = dy; + rtgui_dc_fill_rect(dc, &rect); } else { /* Horizontal bar grows from left to right */ - rect.x2 -= (rtgui_rect_width(rect) * left) / max; + int dx = (rtgui_rect_width(rect) * left) / max; + rect.x2 -= dx; rtgui_dc_fill_rect(dc, &rect); - } + + RTGUI_DC_BC(dc) = bc; + rect.x1 = rect.x2; rect.x2 += dx; + rtgui_dc_fill_rect(dc, &rect); + } /* end drawing */ rtgui_dc_end_drawing(dc); diff --git a/components/rtgui/widgets/progressbar.c b/components/rtgui/widgets/progressbar.c index 23e844533..4fc1ac4e6 100644 --- a/components/rtgui/widgets/progressbar.c +++ b/components/rtgui/widgets/progressbar.c @@ -77,7 +77,6 @@ void rtgui_progressbar_destroy(struct rtgui_progressbar* bar) rtgui_widget_destroy(RTGUI_WIDGET(bar)); } - void rtgui_progressbar_set_value(struct rtgui_progressbar *bar, int value) { RT_ASSERT(bar != RT_NULL); -- GitLab