diff options
| author | [email protected] <[email protected]> | 2011-11-28 07:20:14 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2011-11-28 07:20:14 +0000 |
| commit | 0803e79b539ffafcba7049e15dd064ab1e389c31 (patch) | |
| tree | fb77639d19193e3865f95af7af0463acb6c74fd2 /components/rtgui | |
| parent | 09f2dc41377326051e8b9790abde4766f65e2be3 (diff) | |
rtgui/widgets/notebook: move the bar drawing code into one place
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1814 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/rtgui')
| -rw-r--r-- | components/rtgui/widgets/notebook.c | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/components/rtgui/widgets/notebook.c b/components/rtgui/widgets/notebook.c index 60f051390d..5fea83d264 100644 --- a/components/rtgui/widgets/notebook.c +++ b/components/rtgui/widgets/notebook.c @@ -35,11 +35,41 @@ static void _rtgui_notebook_destructor(rtgui_notebook_t *notebook) }
}
+/* Draw tab bars of @param notebook. @param dc should be initialized and
+ * finished outside this function. Don't pass @param notebook or @param dc as
+ * RT_NULL, it should be checked outside.
+ */
+static void _rtgui_notebook_draw_bar(struct rtgui_notebook *notebook,
+ struct rtgui_dc *dc)
+{
+ struct rtgui_rect rect;
+ int index;
+
+ RT_ASSERT((notebook != RT_NULL) && (dc != RT_NULL));
+
+ _rtgui_notebook_get_bar_rect(notebook, &rect);
+ rtgui_dc_fill_rect(dc, &rect);
+
+ rect.x2 = rect.x1 + RTGUI_NOTEBOOK_TAB_WIDTH;
+ /* draw tab bar */
+ for (index = 0; index < notebook->count; index++)
+ {
+ if (notebook->current == index)
+ rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
+ else
+ rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
+
+ rtgui_dc_draw_text(dc, notebook->childs[index].title, &rect);
+ rect.x1 += RTGUI_NOTEBOOK_TAB_WIDTH;
+ rect.x2 += RTGUI_NOTEBOOK_TAB_WIDTH;
+ }
+
+}
+
static void _rtgui_notebook_ondraw(rtgui_notebook_t *notebook)
{
struct rtgui_dc* dc;
rtgui_rect_t rect;
- int index;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
if (dc == RT_NULL) return;
@@ -55,21 +85,7 @@ static void _rtgui_notebook_ondraw(rtgui_notebook_t *notebook) if (notebook->current == RTGUI_NOT_FOUND)
notebook->current = 0;
- _rtgui_notebook_get_bar_rect(notebook, &rect);
- rtgui_dc_fill_rect(dc, &rect);
- rect.x2 = rect.x1 + RTGUI_NOTEBOOK_TAB_WIDTH;
- /* draw tab bar */
- for (index = 0; index < notebook->count; index ++)
- {
- if (notebook->current == index)
- rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
- else
- rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
-
- rtgui_dc_draw_text(dc, notebook->childs[index].title, &rect);
- rect.x1 += RTGUI_NOTEBOOK_TAB_WIDTH;
- rect.x2 += RTGUI_NOTEBOOK_TAB_WIDTH;
- }
+ _rtgui_notebook_draw_bar(notebook, dc);
/* draw current tab */
rtgui_widget_update(notebook->childs[notebook->current].widget);
@@ -80,7 +96,7 @@ static void _rtgui_notebook_ondraw(rtgui_notebook_t *notebook) static void _rtgui_notebook_onmouse(rtgui_notebook_t *notebook, struct rtgui_event_mouse* emouse)
{
rtgui_rect_t rect;
-
+
/* handle notebook bar */
_rtgui_notebook_get_bar_rect(notebook, &rect);
rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
@@ -98,20 +114,7 @@ static void _rtgui_notebook_onmouse(rtgui_notebook_t *notebook, struct rtgui_eve rtgui_notebook_set_current_by_index(notebook, index);
- _rtgui_notebook_get_bar_rect(notebook, &rect);
- rtgui_dc_fill_rect(dc, &rect);
- rect.x2 = rect.x1 + RTGUI_NOTEBOOK_TAB_WIDTH;
- /* draw tab bar */
- for (index = 0; index < notebook->count; index ++)
- {
- if (notebook->current == index)
- rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
- else
- rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
- rtgui_dc_draw_text(dc, notebook->childs[index].title, &rect);
- rect.x1 += RTGUI_NOTEBOOK_TAB_WIDTH;
- rect.x2 += RTGUI_NOTEBOOK_TAB_WIDTH;
- }
+ _rtgui_notebook_draw_bar(notebook, dc);
rtgui_dc_end_drawing(dc);
|
