update radiobox handling; add more optimization on small size.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@311 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2010-01-17 23:43:20 +00:00
parent 8d99235dea
commit a1d1aea772
11 changed files with 129 additions and 38 deletions

View File

@ -766,6 +766,10 @@ void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16
rt_uint8_t drawoct;
int startoct, endoct, oct, stopval_start, stopval_end;
double temp;
stopval_start = 0;
stopval_end = 0;
temp = 0;
/* Sanity check radius */
if (r < 0) return ;

View File

@ -47,7 +47,8 @@ void rtgui_font_system_init()
#ifdef RTGUI_USING_FONT12
rtgui_font_set_defaut(&rtgui_font_asc12);
#elif defined(RTGUI_USING_FONT16)
#endif
#ifdef RTGUI_USING_FONT16
rtgui_font_set_defaut(&rtgui_font_asc16);
#endif
}

View File

@ -270,15 +270,19 @@ void rtgui_theme_draw_button(rtgui_button_t* btn)
/* draw button */
struct rtgui_dc* dc;
struct rtgui_rect rect;
rtgui_color_t fc;
/* begin drawing */
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(btn));
if (dc == RT_NULL) return;
/* get widget rect */
rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect);
/* get forecolor */
fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn));
/* fill button rect with background color */
// RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(212, 208, 200);
rtgui_dc_fill_rect(dc, &rect);
if (btn->flag & RTGUI_BUTTON_TYPE_PUSH && btn->flag & RTGUI_BUTTON_FLAG_PRESS)
@ -359,10 +363,12 @@ void rtgui_theme_draw_button(rtgui_button_t* btn)
}
}
/* set forecolor */
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = fc;
if (btn->pressed_image == RT_NULL)
{
/* re-set foreground and get default rect */
RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(0, 0, 0);
rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect);
/* remove border */
@ -511,7 +517,7 @@ void rtgui_theme_draw_checkbox(struct rtgui_checkbox* checkbox)
/* swap fore/back color */
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(checkbox)) = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox));
rtgui_rect_inflate(&box_rect, -2);
rtgui_rect_inflate(&box_rect, -4);
rtgui_dc_fill_rect(dc, &box_rect);
/* restore saved color */
@ -562,7 +568,7 @@ void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
/* draw group text */
rtgui_font_get_metrics(rtgui_dc_get_font(dc), radiobox->text, &text_rect);
rtgui_rect_moveto(&text_rect, rect.x1 + 5, rect.y1);
rtgui_rect_moveto(&text_rect, rect.x1 + bord_size + 5, rect.y1);
rtgui_dc_fill_rect(dc, &text_rect);
rtgui_dc_draw_text(dc, radiobox->text, &text_rect);
}
@ -584,8 +590,10 @@ void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
/* draw radio */
if (radiobox->item_selection == index)
{
rtgui_dc_draw_focus_rect(dc, &item_rect);
rtgui_dc_fill_circle(dc, item_rect.x1 + item_size/2 + 2, item_rect.y1 + item_size/2 + 2, item_size/2 - 2);
if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(radiobox)))
rtgui_dc_draw_focus_rect(dc, &item_rect);
rtgui_dc_draw_circle(dc, item_rect.x1 + item_size/2 + 2, item_rect.y1 + item_size/2 + 2, item_size/2 - 2);
rtgui_dc_fill_circle(dc, item_rect.x1 + item_size/2 + 2, item_rect.y1 + item_size/2 + 2, item_size/2 - 4);
}
else
{
@ -615,17 +623,18 @@ void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
if (radiobox->item_selection == index)
{
rtgui_dc_draw_focus_rect(dc, &item_rect);
rtgui_dc_fill_circle(dc, item_rect.x1 + item_size/2 + 2, item_rect.y1 + item_size/2 + 2, item_size/2 - 2);
rtgui_dc_draw_circle(dc, item_rect.x1 + bord_size/2 + 2, item_rect.y1 + bord_size/2 + 2, bord_size/2 - 2);
rtgui_dc_fill_circle(dc, item_rect.x1 + bord_size/2 + 2, item_rect.y1 + bord_size/2 + 2, bord_size/2 - 4);
}
else
{
rtgui_dc_draw_circle(dc, item_rect.x1 + item_size/2 + 2, item_rect.y1 + item_size/2 + 2, item_size/2 - 2);
rtgui_dc_draw_circle(dc, item_rect.x1 + bord_size/2 + 2, item_rect.y1 + bord_size/2 + 2, bord_size/2 - 2);
}
/* draw text */
item_rect.x1 += item_size + 3;
item_rect.x1 += bord_size + 3;
rtgui_dc_draw_text(dc, radiobox->items[index], &item_rect);
item_rect.x1 -= item_size + 3;
item_rect.x1 -= bord_size + 3;
item_rect.x1 += item_size;
item_rect.x2 += item_size;

View File

@ -344,7 +344,7 @@ struct rtgui_event_kbd
#define RTGUI_KBD_IS_SET_ALT(e) ((e)->mod & (RTGUI_KMOD_LALT | RTGUI_KMOD_RALT))
#define RTGUI_KBD_IS_SET_SHIFT(e) ((e)->mod & (RTGUI_KMOD_LSHIFT| RTGUI_KMOD_RSHIFT))
#define RTGUI_KBD_IS_UP(e) ((e)->type == RTGUI_KEYUP)
#define RTGUI_KBD_IS_DOWN(e) ((e)->flag == RTGUI_KEYDOWN)
#define RTGUI_KBD_IS_DOWN(e) ((e)->type == RTGUI_KEYDOWN)
#define RTGUI_EVENT_MOUSE_MOTION_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_MOTION)
#define RTGUI_EVENT_MOUSE_BUTTON_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_BUTTON)

View File

@ -22,7 +22,7 @@
/* #define RTGUI_USING_MOUSE_CURSOR */
/* #define RTGUI_USING_FONT12 */
#define RTGUI_USING_FONT12
#define RTGUI_USING_FONT16
#define RTGUI_USING_FONTHZ

View File

@ -58,6 +58,7 @@ 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);
@ -68,7 +69,7 @@ void rtgui_button_destroy(rtgui_button_t* btn);
void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image);
void rtgui_button_set_unpressed_image(rtgui_button_t* btn, rtgui_image_t* image);
void rtgui_button_ondraw(rtgui_button_t* btn);
void rtgui_button_set_onbutton(rtgui_button_t* btn, rtgui_onbutton_func_t func);
rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);

View File

@ -31,7 +31,7 @@ typedef struct rtgui_radiobox rtgui_radiobox_t;
rtgui_type_t *rtgui_radiobox_type_get(void);
struct rtgui_radiobox* rtgui_radiobox_create(int orient, char** radio_items, int number);
struct rtgui_radiobox* rtgui_radiobox_create(const char* label, int orient, char** radio_items, int number);
void rtgui_radiobox_destroy(struct rtgui_radiobox* radiobox);
void rtgui_radiobox_set_selection(struct rtgui_radiobox* radiobox, int selection);

View File

@ -975,7 +975,6 @@ void rtgui_topwin_append_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect)
rtgui_mouse_monitor_append(&(win->monitor_list), rect);
}
#ifdef RTGUI_USING_SMALL_SIZE
void rtgui_topwin_remove_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect)
{
struct rtgui_topwin* win;
@ -993,8 +992,8 @@ void rtgui_topwin_remove_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect)
/* remove rect from top window monitor rect list */
rtgui_mouse_monitor_remove(&(win->monitor_list), rect);
}
#endif
#ifdef RTGUI_USING_SMALL_SIZE
/**
* get clip information for topwin
* wid, the self window id. If wid = NULL, get whole topwin clip information.
@ -1025,6 +1024,7 @@ void rtgui_topwin_get_clipinfo(struct rtgui_rect* rect_list, rt_int32_t count)
}
rt_sem_release(&_rtgui_topwin_lock);
}
#endif
#ifdef RT_USING_FINSH
#include <finsh.h>

View File

@ -82,6 +82,33 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_e
rtgui_theme_draw_button(btn);
break;
case RTGUI_EVENT_KBD:
{
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*) event;
if ((ekbd->key == RTGUIK_RETURN) || (ekbd->key == RTGUIK_SPACE))
{
if (RTGUI_KBD_IS_DOWN(ekbd))
{
btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
}
else
{
btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
}
/* draw button */
rtgui_theme_draw_button(btn);
if ((btn->flag & RTGUI_BUTTON_FLAG_PRESS) && (btn->on_button != RT_NULL))
{
/* call on button handler */
btn->on_button(widget, event);
}
}
}
break;
case RTGUI_EVENT_MOUSE_BUTTON:
{
struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
@ -103,6 +130,12 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_e
#endif
rtgui_theme_draw_button(btn);
if (btn->on_button != RT_NULL)
{
/* call on button handler */
btn->on_button(widget, event);
}
#ifndef RTGUI_USING_SMALL_SIZE
/* invokes call back */
if (widget->on_mouseclick != RT_NULL &&
@ -132,6 +165,12 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_e
#endif
rtgui_theme_draw_button(btn);
if (!(btn->flag & RTGUI_BUTTON_FLAG_PRESS) && (btn->on_button != RT_NULL))
{
/* call on button handler */
btn->on_button(widget, event);
}
#ifndef RTGUI_USING_SMALL_SIZE
/* invokes call back */
if (widget->on_mouseclick != RT_NULL &&
@ -198,3 +237,10 @@ void rtgui_button_set_unpressed_image(rtgui_button_t* btn, rtgui_image_t* image)
btn->unpressed_image = image;
}
void rtgui_button_set_onbutton(rtgui_button_t* btn, rtgui_onbutton_func_t func)
{
RT_ASSERT(btn != RT_NULL);
btn->on_button = func;
}

View File

@ -45,6 +45,9 @@ static void rtgui_radiobox_onmouse(struct rtgui_radiobox* radiobox, struct rtgui
int bord_size;
struct rtgui_rect rect;
/* focus widgets */
rtgui_widget_focus(RTGUI_WIDGET(radiobox));
/* get widget rect */
rtgui_widget_get_rect(RTGUI_WIDGET(radiobox), &rect);
@ -59,15 +62,18 @@ static void rtgui_radiobox_onmouse(struct rtgui_radiobox* radiobox, struct rtgui
bord_size = rtgui_rect_height(bord_rect);
}
rtgui_rect_inflate(&rect, - bord_size);
if (rtgui_rect_contains_point(&rect, event->x, event->y) != RT_EOK) return;
if (radiobox->orient == RTGUI_VERTICAL)
{
int delta_y = event->y - rect.y1;
rtgui_radiobox_set_selection(radiobox, delta_y / radiobox->item_size);
}
else
{
int delta_x = event->x - rect.x1;
rtgui_radiobox_set_selection(radiobox, delta_x / radiobox->item_size);
}
rtgui_widget_focus(RTGUI_WIDGET(radiobox));
}
}
@ -100,16 +106,32 @@ rt_bool_t rtgui_radiobox_event_handler(struct rtgui_widget* widget, struct rtgui
rtgui_widget_focus(RTGUI_WIDGET(radiobox));
if (!(RTGUI_KBD_IS_UP(e))) return RT_FALSE;
if (e->key == RTGUIK_UP)
{
if (radiobox->item_selection > 0)
rtgui_radiobox_set_selection(radiobox, radiobox->item_selection - 1);
}
else if (e->key == RTGUIK_DOWN)
{
if (radiobox->item_selection < radiobox->item_count - 1)
rtgui_radiobox_set_selection(radiobox, radiobox->item_selection + 1);
}
if (radiobox->orient == RTGUI_VERTICAL)
{
if (e->key == RTGUIK_UP)
{
if (radiobox->item_selection > 0)
rtgui_radiobox_set_selection(radiobox, radiobox->item_selection - 1);
}
else if (e->key == RTGUIK_DOWN)
{
if (radiobox->item_selection < radiobox->item_count - 1)
rtgui_radiobox_set_selection(radiobox, radiobox->item_selection + 1);
}
}
else
{
if (e->key == RTGUIK_LEFT)
{
if (radiobox->item_selection > 0)
rtgui_radiobox_set_selection(radiobox, radiobox->item_selection - 1);
}
else if (e->key == RTGUIK_RIGHT)
{
if (radiobox->item_selection < radiobox->item_count - 1)
rtgui_radiobox_set_selection(radiobox, radiobox->item_selection + 1);
}
}
}
break;
@ -127,25 +149,29 @@ rt_bool_t rtgui_radiobox_event_handler(struct rtgui_widget* widget, struct rtgui
return RT_FALSE;
}
struct rtgui_radiobox* rtgui_radiobox_create(int orient, char** radio_items, int number)
struct rtgui_radiobox* rtgui_radiobox_create(const char* label, int orient, char** radio_items, int number)
{
struct rtgui_radiobox* radiobox;
radiobox = (struct rtgui_radiobox*) rtgui_widget_create (RTGUI_RADIOBOX_TYPE);
if (radiobox != RT_NULL)
{
rt_uint8_t board_size;
struct rtgui_rect rect;
radiobox->items = radio_items;
radiobox->item_count = number;
radiobox->item_selection = -1;
radiobox->text = rt_strdup(label);
/* set proper of control */
rtgui_radiobox_set_orientation(radiobox, orient);
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(radiobox)), "H", &rect);
board_size = rtgui_rect_height(rect);
if (orient == RTGUI_VERTICAL)
{
struct rtgui_rect rect;
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(radiobox)), "H", &rect);
radiobox->item_size = rtgui_rect_height(rect);
radiobox->item_size = board_size;
}
else
{
@ -161,7 +187,7 @@ struct rtgui_radiobox* rtgui_radiobox_create(int orient, char** radio_items, int
{
rtgui_font_get_metrics(font, radio_items[index], &rect);
if (rtgui_rect_width(rect) > radiobox->item_size)
radiobox->item_size = rtgui_rect_width(rect);
radiobox->item_size = board_size + 3 + rtgui_rect_width(rect);
}
}
}

View File

@ -136,9 +136,13 @@ void rtgui_toplevel_handle_clip(struct rtgui_toplevel* top,
info->num_rect);
top->external_clip_size = info->num_rect;
#ifdef RTGUI_USING_SMALL_SIZE
/* get rect list from topwin list */
rtgui_topwin_get_clipinfo(top->external_clip_rect, top->external_clip_size);
#ifdef RTGUI_USING_SMALL_SIZE
{
extern void rtgui_topwin_get_clipinfo(struct rtgui_rect* list, rt_int32_t count);
/* get rect list from topwin list */
rtgui_topwin_get_clipinfo(top->external_clip_rect, top->external_clip_size);
}
#else
/* copy rect array */
rt_memcpy(top->external_clip_rect, (void*)(info + 1), sizeof(rtgui_rect_t) * info->num_rect);