1
0
Эх сурвалжийг харах

rename orientation to orient.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@878 bbd45198-f89e-11dd-88c7-29a3b14d5316
bernard.xiong@gmail.com 14 жил өмнө
parent
commit
4f6e6dab8a

+ 122 - 122
components/rtgui/common/rtgui_theme.c

@@ -791,126 +791,126 @@ void rtgui_theme_draw_slider(struct rtgui_slider* slider)
 	return;
 }
 
-
-const static rt_uint8_t _up_arrow[]    = {0x10, 0x38, 0x7C, 0xFE};
-const static rt_uint8_t _down_arrow[]  = {0xFE,0x7C, 0x38, 0x10};
-const static rt_uint8_t _left_arrow[]  = {0x10, 0x30, 0x70, 0xF0, 0x70, 0x30, 0x10};
-const static rt_uint8_t _right_arrow[] = {0x80, 0xC0, 0xE0, 0xF0, 0xE0, 0xC0, 0x80};
-
-void rtgui_theme_draw_scrollbar(struct rtgui_scrollbar* bar)
-{
-	/* draw scroll bar */
-	struct rtgui_dc* dc;
-	rtgui_rect_t rect, btn_rect, thum_rect, arrow_rect;
-	rtgui_color_t bc, fc;
-
-	/* begin drawing */
-	dc = rtgui_dc_begin_drawing(&(bar->parent));
-	if (dc == RT_NULL) return;
-
-	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
-
-	/* draw background */
-	fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar));
-	if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
-		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(128, 128, 128);
-
-	bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar));
-	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)) = white;
-	rtgui_dc_fill_rect(dc, &rect);
-
-	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)) = bc;
-
-	if (bar->orient == RTGUI_VERTICAL)
-	{
-		btn_rect = rect;
-		btn_rect.y2 = btn_rect.y1 + (rect.x2 - rect.x1);
-
-		/* draw up button */
-		rtgui_dc_fill_rect(dc, &btn_rect);
-		if (bar->status & SBS_UPARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
-		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
-
-		/* draw arrow */
-		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
-		arrow_rect.x2 = 7; arrow_rect.y2 = 4;
-		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
-			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
-		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
-			rtgui_rect_height(arrow_rect), _up_arrow);
-
-		/* draw thumb */
-		if (RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
-		{
-			rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
-			rtgui_dc_fill_rect(dc, &thum_rect);
-			rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
-		}
-
-		/* draw down button */
-		btn_rect.y1 = rect.y2 - (rect.x2 - rect.x1);
-		btn_rect.y2 = rect.y2;
-
-		rtgui_dc_fill_rect(dc, &btn_rect);
-		if (bar->status & SBS_DOWNARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
-		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
-
-		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
-		arrow_rect.x2 = 7; arrow_rect.y2 = 4;
-		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
-			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
-		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
-			rtgui_rect_height(arrow_rect), _down_arrow);
-	}
-	else
-	{
-		btn_rect.x1 = rect.x1;
-		btn_rect.y1 = rect.y1;
-		btn_rect.x2 = rect.y2;
-		btn_rect.y2 = rect.y2;
-
-		/* draw left button */
-		rtgui_dc_fill_rect(dc, &btn_rect);
-		if (bar->status & SBS_LEFTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
-		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
-
-		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
-		arrow_rect.x2 = 4; arrow_rect.y2 = 7;
-		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
-			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
-		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
-			rtgui_rect_height(arrow_rect), _left_arrow);
-
-		/* draw thumb */
-		if (RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
-		{
-			rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
-			rtgui_dc_fill_rect(dc, &thum_rect);
-			rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
-		}
-
-		btn_rect.x1 = rect.x2 - rect.y2;
-		btn_rect.x2 = rect.x2;
-
-		/* draw right button */
-		rtgui_dc_fill_rect(dc, &btn_rect);
-		if (bar->status & SBS_RIGHTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
-		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
-
-		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
-		arrow_rect.x2 = 4; arrow_rect.y2 = 7;
-		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
-			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
-		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
-			rtgui_rect_height(arrow_rect), _right_arrow);
-	}
-
-	/* end drawing */
-	rtgui_dc_end_drawing(dc);
-	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = fc;
-
-	return;
-}
+
+const static rt_uint8_t _up_arrow[]    = {0x10, 0x38, 0x7C, 0xFE};
+const static rt_uint8_t _down_arrow[]  = {0xFE,0x7C, 0x38, 0x10};
+const static rt_uint8_t _left_arrow[]  = {0x10, 0x30, 0x70, 0xF0, 0x70, 0x30, 0x10};
+const static rt_uint8_t _right_arrow[] = {0x80, 0xC0, 0xE0, 0xF0, 0xE0, 0xC0, 0x80};
+
+void rtgui_theme_draw_scrollbar(struct rtgui_scrollbar* bar)
+{
+	/* draw scroll bar */
+	struct rtgui_dc* dc;
+	rtgui_rect_t rect, btn_rect, thum_rect, arrow_rect;
+	rtgui_color_t bc, fc;
+
+	/* begin drawing */
+	dc = rtgui_dc_begin_drawing(&(bar->parent));
+	if (dc == RT_NULL) return;
+
+	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
+
+	/* draw background */
+	fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar));
+	if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
+		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(128, 128, 128);
+
+	bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar));
+	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)) = white;
+	rtgui_dc_fill_rect(dc, &rect);
+
+	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)) = bc;
+
+	if (bar->orient == RTGUI_VERTICAL)
+	{
+		btn_rect = rect;
+		btn_rect.y2 = btn_rect.y1 + (rect.x2 - rect.x1);
+
+		/* draw up button */
+		rtgui_dc_fill_rect(dc, &btn_rect);
+		if (bar->status & SBS_UPARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
+		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
+
+		/* draw arrow */
+		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
+		arrow_rect.x2 = 7; arrow_rect.y2 = 4;
+		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
+			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
+		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
+			rtgui_rect_height(arrow_rect), _up_arrow);
+
+		/* draw thumb */
+		if (RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
+		{
+			rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
+			rtgui_dc_fill_rect(dc, &thum_rect);
+			rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
+		}
+
+		/* draw down button */
+		btn_rect.y1 = rect.y2 - (rect.x2 - rect.x1);
+		btn_rect.y2 = rect.y2;
+
+		rtgui_dc_fill_rect(dc, &btn_rect);
+		if (bar->status & SBS_DOWNARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
+		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
+
+		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
+		arrow_rect.x2 = 7; arrow_rect.y2 = 4;
+		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
+			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
+		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
+			rtgui_rect_height(arrow_rect), _down_arrow);
+	}
+	else
+	{
+		btn_rect.x1 = rect.x1;
+		btn_rect.y1 = rect.y1;
+		btn_rect.x2 = rect.y2;
+		btn_rect.y2 = rect.y2;
+
+		/* draw left button */
+		rtgui_dc_fill_rect(dc, &btn_rect);
+		if (bar->status & SBS_LEFTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
+		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
+
+		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
+		arrow_rect.x2 = 4; arrow_rect.y2 = 7;
+		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
+			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
+		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
+			rtgui_rect_height(arrow_rect), _left_arrow);
+
+		/* draw thumb */
+		if (RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
+		{
+			rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
+			rtgui_dc_fill_rect(dc, &thum_rect);
+			rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
+		}
+
+		btn_rect.x1 = rect.x2 - rect.y2;
+		btn_rect.x2 = rect.x2;
+
+		/* draw right button */
+		rtgui_dc_fill_rect(dc, &btn_rect);
+		if (bar->status & SBS_RIGHTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
+		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
+
+		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
+		arrow_rect.x2 = 4; arrow_rect.y2 = 7;
+		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
+			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
+		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
+			rtgui_rect_height(arrow_rect), _right_arrow);
+	}
+
+	/* end drawing */
+	rtgui_dc_end_drawing(dc);
+	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = fc;
+
+	return;
+}
 
 void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar)
 {
@@ -948,7 +948,7 @@ void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar)
 	rtgui_rect_inflate(&rect, -2);
     bar->parent.gc.background = RTGUI_RGB(0, 0, 255);
 
-    if (bar->orientation == RTGUI_VERTICAL)
+    if (bar->orient == RTGUI_VERTICAL)
     {
         /* Vertical bar grows from bottom to top */
         int dy = (rtgui_rect_height(rect) * left) / max;
@@ -988,7 +988,7 @@ void rtgui_theme_draw_staticline(struct rtgui_staticline* staticline)
 	rtgui_widget_get_rect(RTGUI_WIDGET(staticline), &rect);
 	rtgui_dc_fill_rect(dc, &rect);
 	
-	if (staticline->orientation == RTGUI_HORIZONTAL)
+	if (staticline->orient == RTGUI_HORIZONTAL)
 	{
 		rtgui_dc_draw_horizontal_line(dc, rect.x1, rect.x2, rect.y1);
 	}

+ 1 - 14
components/rtgui/include/rtgui/rtgui.h

@@ -31,6 +31,7 @@ typedef struct rtgui_panel rtgui_panel_t;
 typedef struct rtgui_win rtgui_win_t;
 typedef struct rtgui_workbench rtgui_workbench_t;
 typedef rt_bool_t (*rtgui_event_handler_ptr)(struct rtgui_widget* widget, struct rtgui_event* event);
+typedef void (*rtgui_onbutton_func_t)(struct rtgui_widget* widget, rtgui_event_t *event);
 
 struct rtgui_point
 {
@@ -105,20 +106,6 @@ enum RTGUI_ALIGN
 	RTGUI_ALIGN_STRETCH				= 0x20,
 };
 
-enum RTGUI_TEXTATTR
-{
-	RTGUI_TEXTATTR_NORMAL			= 0x0000,
-	RTGUI_TEXTATTR_
-};
-
-enum RTGUI_ARRAW
-{
-	RTGUI_ARRAW_UP = 0,
-	RTGUI_ARRAW_DOWN,
-	RTGUI_ARRAW_LEFT,
-	RTGUI_ARRAW_RIGHT
-};
-
 enum RTGUI_MODAL_CODE
 {
 	RTGUI_MODAL_OK,

+ 1 - 1
components/rtgui/include/rtgui/widgets/box.h

@@ -33,7 +33,7 @@ struct rtgui_box
 {
 	struct rtgui_container parent;
 
-	rt_uint16_t orientation;
+	rt_uint16_t orient;
 	rt_uint16_t border_size;
 };
 typedef struct rtgui_box rtgui_box_t;

+ 0 - 1
components/rtgui/include/rtgui/widgets/button.h

@@ -58,7 +58,6 @@ struct rtgui_button
 	void (*on_button)(struct rtgui_widget* widget, rtgui_event_t *event);
 };
 typedef struct rtgui_button rtgui_button_t;
-typedef void (*rtgui_onbutton_func_t)(struct rtgui_widget* widget, rtgui_event_t *event);
 
 rtgui_type_t *rtgui_button_type_get(void);
 

+ 5 - 0
components/rtgui/include/rtgui/widgets/checkbox.h

@@ -22,6 +22,9 @@ struct rtgui_checkbox
 
 	/* check box status */
 	rt_uint8_t status_down;
+
+	/* click button event handler */
+	void (*on_button)(struct rtgui_widget* widget, rtgui_event_t *event);
 };
 typedef struct rtgui_checkbox rtgui_checkbox_t;
 
@@ -33,6 +36,8 @@ void rtgui_checkbox_destroy(rtgui_checkbox_t* checkbox);
 void rtgui_checkbox_set_checked(rtgui_checkbox_t* checkbox, rt_bool_t checked);
 rt_bool_t rtgui_checkbox_get_checked(rtgui_checkbox_t* checkbox);
 
+void rtgui_checkbox_set_onbutton(rtgui_checkbox_t* checkbox, rtgui_onbutton_func_t func);
+
 rt_bool_t rtgui_checkbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
 
 #endif

+ 1 - 1
components/rtgui/include/rtgui/widgets/progressbar.h

@@ -18,7 +18,7 @@ struct rtgui_progressbar
 {
 	struct rtgui_widget parent;
 
-	int orientation;
+	int orient;
 
     int range;
     int position;

+ 1 - 1
components/rtgui/include/rtgui/widgets/staticline.h

@@ -20,7 +20,7 @@ struct rtgui_staticline
 	/* inherit from widget */
 	struct rtgui_widget parent;
 
-	int orientation;
+	int orient;
 };
 typedef struct rtgui_staticline rtgui_staticline_t;
 

+ 5 - 5
components/rtgui/widgets/box.c

@@ -24,7 +24,7 @@ static void _rtgui_box_constructor(rtgui_box_t *box)
 	rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_box_event_handler);
 
 	/* set proper of control */
-	box->orientation = RTGUI_HORIZONTAL;
+	box->orient = RTGUI_HORIZONTAL;
 	box->border_size = RTGUI_BORDER_DEFAULT_WIDTH;
 }
 
@@ -70,7 +70,7 @@ struct rtgui_box* rtgui_box_create(int orientation, rtgui_rect_t* rect)
     {
 		/* set proper of control */
 		rtgui_widget_set_rect(RTGUI_WIDGET(box), rect);
-		box->orientation = orientation;
+		box->orient = orientation;
 	}
 
 	return box;
@@ -270,7 +270,7 @@ void rtgui_box_layout(rtgui_box_t* box)
 {
     RT_ASSERT(box != RT_NULL);
 
-	if (box->orientation & RTGUI_VERTICAL)
+	if (box->orient & RTGUI_VERTICAL)
 	{
 		rtgui_box_layout_vertical(box);
 	}
@@ -298,7 +298,7 @@ rt_uint32_t rtgui_box_get_width(rtgui_box_t* box)
 		rt_uint32_t widget_width;
 
 		widget_width = rtgui_rect_width(widget->extent);
-		if (box->orientation & RTGUI_VERTICAL)
+		if (box->orient & RTGUI_VERTICAL)
 		{
 			/* get the max width */
 			if (width < widget_width) width = widget_width;
@@ -325,7 +325,7 @@ rt_uint32_t rtgui_box_get_height(rtgui_box_t* box)
 		rt_uint32_t widget_height;
 
 		widget_height = rtgui_rect_height(widget->extent);
-		if (box->orientation & RTGUI_HORIZONTAL)
+		if (box->orient & RTGUI_HORIZONTAL)
 		{
 			/* get the max height */
 			if (height < widget_height) height = widget_height;

+ 12 - 0
components/rtgui/widgets/checkbox.c

@@ -10,6 +10,7 @@ static void _rtgui_checkbox_constructor(rtgui_checkbox_t *box)
 
 	/* set status */
 	box->status_down = RTGUI_CHECKBOX_STATUS_UNCHECKED;
+	box->on_button = RT_NULL;
 
 	/* set default gc */
 	RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(box)) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
@@ -28,6 +29,13 @@ rtgui_type_t *rtgui_checkbox_type_get(void)
 	return checkbox_type;
 }
 
+void rtgui_checkbox_set_onbutton(rtgui_checkbox_t* checkbox, rtgui_onbutton_func_t func)
+{
+	RT_ASSERT(checkbox != RT_NULL);
+
+	checkbox->on_button = func;
+}
+
 rt_bool_t rtgui_checkbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
 {
 	struct rtgui_checkbox* box = (struct rtgui_checkbox*)widget;
@@ -78,6 +86,10 @@ rt_bool_t rtgui_checkbox_event_handler(struct rtgui_widget* widget, struct rtgui
 					return widget->on_mouseclick(widget, event);
 				}
 #endif
+				if (box->on_button != RT_NULL)
+				{
+					return box->on_button(widget, event);
+				}
 			}
 
 			return RT_TRUE;

+ 2 - 2
components/rtgui/widgets/progressbar.c

@@ -11,7 +11,7 @@ static void _rtgui_progressbar_constructor(rtgui_progressbar_t *bar)
 	rtgui_widget_set_event_handler(RTGUI_WIDGET(bar), rtgui_progressbar_event_handler);
 	rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);
 
-	bar->orientation = RTGUI_HORIZONTAL;
+	bar->orient = RTGUI_HORIZONTAL;
 	bar->range = RTGUI_PROGRESSBAR_DEFAULT_RANGE;
 	bar->position = 0;
 
@@ -65,7 +65,7 @@ struct rtgui_progressbar* rtgui_progressbar_create(int orientation, int range,
 		if (r != RT_NULL)
 			rtgui_widget_set_rect(RTGUI_WIDGET(bar), r);
 
-		bar->orientation = orientation;
+		bar->orient = orientation;
         bar->range = range;
     }
 

+ 2 - 2
components/rtgui/widgets/staticline.c

@@ -8,7 +8,7 @@ static void _rtgui_staticline_constructor(rtgui_staticline_t *staticline)
 	rtgui_rect_t rect = {0, 0, 100, 2};
 
 	rtgui_widget_set_rect(RTGUI_WIDGET(staticline), &rect);
-	staticline->orientation= RTGUI_HORIZONTAL;
+	staticline->orient= RTGUI_HORIZONTAL;
 
 	rtgui_widget_set_event_handler(RTGUI_WIDGET(staticline), rtgui_staticline_event_handler);
 }
@@ -68,7 +68,7 @@ void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orient
 {
 	RT_ASSERT(staticline != RT_NULL);
 
-	staticline->orientation = orientation;
+	staticline->orient = orientation;
 #ifndef RTGUI_USING_SMALL_SIZE
 	if (orientation == RTGUI_HORIZONTAL)
 	{