コード例 #1
0
rt_bool_t rtgui_listbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	struct rtgui_listbox* box = RT_NULL;

	box = RTGUI_LISTBOX(widget);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		rtgui_listbox_ondraw(box);
		return RT_FALSE;

    case RTGUI_EVENT_RESIZE:
        {
			struct rtgui_event_resize* resize;

			resize = (struct rtgui_event_resize*)event;

            /* recalculate page items */
			box->page_items = resize->h  / (2 + rtgui_theme_get_selected_height());
        }
        break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		{
			rtgui_rect_t rect;
			struct rtgui_event_mouse* emouse;

			emouse = (struct rtgui_event_mouse*)event;

			/* calculate selected item */

			/* get physical extent information */
			rtgui_widget_get_rect(widget, &rect);
			rtgui_widget_rect_to_device(widget, &rect);

			if ((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) && (box->items_count > 0))
			{
				rt_uint16_t index;
				index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

				/* set focus */
				rtgui_widget_focus(widget);
				{
					struct rtgui_rect rect;
					struct rtgui_dc* dc;

					dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
					if (dc != RT_NULL)
					{
						/* get widget rect */
						rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
						/* update focus border */
						rect.x2 -= 1; rect.y2 -= 1;
						/* draw focused border */
						if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(box)))
							rtgui_dc_draw_focus_rect(dc, &rect);
						rtgui_dc_end_drawing(dc);
					}
				}

				if ((index < box->items_count) && (index < box->page_items))
				{
					rt_uint16_t old_item;

					old_item = box->current_item;

					/* set selected item */
					box->current_item = (box->current_item/box->page_items) * box->page_items + index;
					if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
					{
						/* down event */
						rtgui_listbox_update_current(box, old_item);
					}
					else
					{
						/* up event */
						if (box->on_item != RT_NULL)
						{
							box->on_item(RTGUI_WIDGET(box), RT_NULL);
						}
					}
				}
			}

			return RT_TRUE;
		}

    case RTGUI_EVENT_KBD:
        {
            struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
            if ((ekbd->type == RTGUI_KEYDOWN) && (box->items_count > 0))
            {
				rt_uint16_t old_item;

				old_item = box->current_item;
                switch (ekbd->key)
                {
				case RTGUIK_LEFT:
					if (box->current_item - box->page_items >= 0)
						box->current_item -= box->page_items;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

                case RTGUIK_UP:
					if (box->current_item > 0)
						box->current_item --;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

				case RTGUIK_RIGHT:
					if (box->current_item + box->page_items < box->items_count - 1)
						box->current_item += box->page_items;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

                case RTGUIK_DOWN:
					if (box->current_item < box->items_count - 1)
						box->current_item ++;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

				case RTGUIK_RETURN:
                    if (box->on_item != RT_NULL)
					{
						box->on_item(RTGUI_WIDGET(box), RT_NULL);
					}
					return RT_FALSE;

                default:
                    break;
                }
            }
        }
		return RT_FALSE;
	}

    /* use box event handler */
    return rtgui_widget_event_handler(widget, event);
}
コード例 #2
0
void rtgui_theme_draw_radiobutton(struct rtgui_radiobox* radiobox, rt_uint16_t item)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect, item_rect;
	int item_size, bord_size;

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(radiobox));
	if (dc == RT_NULL) return;
	/* get widget rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(radiobox), &rect);

	item_size = radiobox->item_size;
	/* get board size */
	if (radiobox->orient == RTGUI_VERTICAL)
		bord_size = item_size;
	else
	{
		rtgui_font_get_metrics(RTGUI_DC_FONT(dc), "H", &item_rect);
		bord_size = rtgui_rect_height(item_rect);
	}

	item_rect = rect;
	rtgui_rect_inflate(&item_rect, - bord_size);
	if (radiobox->orient == RTGUI_VERTICAL)
	{
		/* set the first text rect */
		item_rect.y1 += item * item_size;
		item_rect.y2 = item_rect.y1 + item_size;

		/* draw radio */
		if (radiobox->item_selection == item)
		{
			if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(radiobox)))
				rtgui_dc_draw_focus_rect(dc, &item_rect);

			rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + (item_size - RADIO_BOX_H) / 2, 
				RADIO_BOX_H, radio_checked_byte);
		}
		else
		{
			item_rect.x2 += 1; item_rect.y2 += 1;
			rtgui_dc_fill_rect(dc, &item_rect);
			item_rect.x2 -= 1; item_rect.y2 -= 1;
			rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + (item_size - RADIO_BOX_H) / 2, 
				RADIO_BOX_H, radio_unchecked_byte);
		}

		/* draw text */
		item_rect.x1 += item_size + 3;
		rtgui_dc_draw_text(dc, radiobox->items[item], &item_rect);
	}
	else
	{
		item_rect.x1 += item * item_size;

		/* set the first text rect */
		item_rect.x2 = item_rect.x1 + item_size - 1;
		item_rect.y2 = item_rect.y1 + bord_size;

		/* draw radio */
		if (radiobox->item_selection == item)
		{
			if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(radiobox)))
				rtgui_dc_draw_focus_rect(dc, &item_rect);
			rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_checked_byte);
		}
		else
		{
			item_rect.x2 += 1; item_rect.y2 += 1;
			rtgui_dc_fill_rect(dc, &item_rect);
			item_rect.x2 -= 1; item_rect.y2 -= 1;
			rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_unchecked_byte);
		}

		/* draw text */
		item_rect.x1 += bord_size + 3;
		rtgui_dc_draw_text(dc, radiobox->items[item], &item_rect);
	}

	/* end drawing */
	rtgui_dc_end_drawing(dc);
}
コード例 #3
0
void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect, item_rect;
	int item_size, bord_size, index;
	rtgui_color_t fc;

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(radiobox));
	if (dc == RT_NULL) return;

	/* get widget rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(radiobox), &rect);
	rtgui_dc_fill_rect(dc, &rect);

	item_size = radiobox->item_size;
	/* get board size */
	if (radiobox->orient == RTGUI_VERTICAL)
		bord_size = item_size;
	else
	{
		rtgui_font_get_metrics(RTGUI_DC_FONT(dc), "H", &item_rect);
		bord_size = rtgui_rect_height(item_rect);
	}

	/* draw box */
	rtgui_rect_inflate(&rect, -bord_size/2);
	fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(radiobox));

	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(radiobox)) = white;
	rect.x1 ++; rect.y1 ++; rect.x2 ++; rect.y2 ++;
	rtgui_dc_draw_rect(dc, &rect);

	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(radiobox)) = RTGUI_RGB(128, 128, 128);
	rect.x1 --; rect.y1 --; rect.x2 --; rect.y2 --;
	rtgui_dc_draw_rect(dc, &rect);

	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(radiobox)) = fc;

	rtgui_rect_inflate(&rect, bord_size/2);
	if (radiobox->text != RT_NULL)
	{
		struct rtgui_rect text_rect;

		/* draw group text */
		rtgui_font_get_metrics(RTGUI_DC_FONT(dc), radiobox->text, &text_rect);
		rtgui_rect_moveto(&text_rect, rect.x1 + bord_size + 5, rect.y1);
		rect.x1 -= 5; rect.x2 += 5;
		rtgui_dc_fill_rect(dc, &text_rect);
		rect.x1 += 5; rect.x2 -= 5;
		rtgui_dc_draw_text(dc, radiobox->text, &text_rect);
	}

	/* set init item rect */
	item_rect = rect;
	rtgui_rect_inflate(&item_rect, - bord_size);

	if (radiobox->orient == RTGUI_VERTICAL)
	{
		rt_uint16_t offset;
		
		/* set the first text rect */
		item_rect.y2 = item_rect.y1 + item_size;

		offset = (item_size - RADIO_BOX_H) / 2;
		/* draw each radio button */
		for (index = 0; index < radiobox->item_count; index ++)
		{
			if (item_rect.y2 > rect.y2 - item_size) break;

			/* draw radio */
			if (radiobox->item_selection == index)
			{
				if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(radiobox)))
					rtgui_dc_draw_focus_rect(dc, &item_rect);

				rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + offset, RADIO_BOX_H, radio_checked_byte);
			}
			else
			{
				rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1 + offset, RADIO_BOX_H, radio_unchecked_byte);
			}

			/* draw text */
			item_rect.x1 += item_size + 3;
			rtgui_dc_draw_text(dc, radiobox->items[index], &item_rect);
			item_rect.x1 -= item_size + 3;

			item_rect.y1 += item_size;
			item_rect.y2 += item_size;
		}
	}
	else
	{
		/* set the first text rect */
		item_rect.x2 = item_rect.x1 + item_size;
		item_rect.y2 = item_rect.y1 + bord_size;

		/* draw each radio button */
		for (index = 0; index < radiobox->item_count; index ++)
		{
			if (item_rect.x2 > rect.x2 - item_size) break;

			/* draw radio */
			if (radiobox->item_selection == index)
			{
				if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(radiobox)))
					rtgui_dc_draw_focus_rect(dc, &item_rect);
				rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_checked_byte);
			}
			else
			{
				rtgui_dc_draw_word(dc, item_rect.x1, item_rect.y1, RADIO_BOX_H, radio_unchecked_byte);
			}

			/* draw text */
			item_rect.x1 += bord_size + 3;
			rtgui_dc_draw_text(dc, radiobox->items[index], &item_rect);
			item_rect.x1 -= bord_size + 3;

			item_rect.x1 += item_size;
			item_rect.x2 += (item_size - 1);
		}
	}

	/* end drawing */
	rtgui_dc_end_drawing(dc);
}
コード例 #4
0
ファイル: listctrl.c プロジェクト: CollinsLiu/rt-thread-pc
rt_bool_t rtgui_listctrl_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	struct rtgui_listctrl* ctrl = RT_NULL;

	ctrl = RTGUI_LISTCTRL(widget);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		_rtgui_listctrl_ondraw(ctrl);
		return RT_FALSE;

    case RTGUI_EVENT_RESIZE:
        {
			struct rtgui_event_resize* resize;

			resize = (struct rtgui_event_resize*)event;

            /* recalculate page items */
			ctrl->page_items = resize->h  / (2 + rtgui_theme_get_selected_height());
        }
        break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		{
			rtgui_rect_t rect;
			struct rtgui_event_mouse* emouse;

			emouse = (struct rtgui_event_mouse*)event;

			/* get scrollbar rect */
			_rtgui_listctrl_get_scrollbar_rect(ctrl, &rect);
			rtgui_widget_rect_to_device(RTGUI_WIDGET(ctrl), &rect);
			if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
			{
				_rtgui_listctrl_scrollbar_onmouse(ctrl, emouse);
				return RT_TRUE;
			}

			/* calculate selected item */

			/* get physical extent information */
			_rtgui_listctrl_get_rect(ctrl, &rect);
			rtgui_widget_rect_to_device(widget, &rect);

			if ((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) &&
					(ctrl->items_count > 0))
			{
				rt_uint16_t index;
				index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

				/* set focus */
				rtgui_widget_focus(widget);
				{
					struct rtgui_rect rect;
					struct rtgui_dc* dc;

					dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl));
					if (dc != RT_NULL)
					{
						/* get widget rect */
						rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), &rect);
						/* update focus border */
						rect.x2 -= 1; rect.y2 -= 1;
						rtgui_dc_end_drawing(dc);
					}
				}

				if ((index < ctrl->page_items) &&
					(ctrl->current_item/ctrl->page_items)* ctrl->page_items + index < ctrl->items_count)
				{
					rt_uint16_t old_item;

					old_item = ctrl->current_item;

					/* set selected item */
					ctrl->current_item = (ctrl->current_item/ctrl->page_items) * ctrl->page_items + index;
					if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
					{
						/* down event */
						rtgui_listctrl_update_current(ctrl, old_item);
					}
					else
					{
						/* up event */
						if (ctrl->on_item != RT_NULL)
						{
							ctrl->on_item(RTGUI_WIDGET(ctrl), RT_NULL);
						}
					}
				}
			}

			return RT_TRUE;
		}

    case RTGUI_EVENT_KBD:
        {
            struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
            if ((ekbd->type == RTGUI_KEYDOWN) && (ctrl->items_count > 0))
            {
				rt_uint16_t old_item;

				old_item = ctrl->current_item;
                switch (ekbd->key)
                {
				case RTGUIK_LEFT:
					if (ctrl->current_item - ctrl->page_items >= 0)
						ctrl->current_item -= ctrl->page_items;
					rtgui_listctrl_update_current(ctrl, old_item);
					return RT_FALSE;

                case RTGUIK_UP:
					if (ctrl->current_item > 0)
						ctrl->current_item --;
					rtgui_listctrl_update_current(ctrl, old_item);
					return RT_FALSE;

				case RTGUIK_RIGHT:
					if (ctrl->current_item + ctrl->page_items < ctrl->items_count - 1)
						ctrl->current_item += ctrl->page_items;
					else
					{
						if ((((ctrl->current_item/ctrl->page_items) + 1) * ctrl->page_items) < ctrl->items_count - 1)
							ctrl->current_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
					}
					rtgui_listctrl_update_current(ctrl, old_item);
					return RT_FALSE;

                case RTGUIK_DOWN:
					if (ctrl->current_item < ctrl->items_count - 1)
						ctrl->current_item ++;
					rtgui_listctrl_update_current(ctrl, old_item);
					return RT_FALSE;

				case RTGUIK_RETURN:
                    if (ctrl->on_item != RT_NULL)
					{
						ctrl->on_item(RTGUI_WIDGET(ctrl), RT_NULL);
					}
					return RT_FALSE;

                default:
                    break;
                }
            }
        }
		return RT_FALSE;
	}

    /* use ctrl event handler */
    return rtgui_widget_event_handler(widget, event);
}
コード例 #5
0
void rtgui_theme_draw_textbox(rtgui_textbox_t* box)
{
	/* draw button */
	struct rtgui_dc* dc;
	struct rtgui_rect rect;
	rtgui_color_t fc;

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
	if (dc == RT_NULL) return;

	/* get widget rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
	fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(box));

	/* fill widget rect with white color */
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(box)) = white;
	rtgui_dc_fill_rect(dc, &rect);

	/* draw border */
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(box)) = RTGUI_RGB(123, 158, 189);
	rtgui_dc_draw_rect(dc, &rect);

	/* draw text */
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(box)) = fc;
	if (box->text != RT_NULL)
	{
		rect.x1 += RTGUI_TEXTBOX_MARGIN;

		if (box->flag & RTGUI_TEXTBOX_MASK)
		{
			/* draw '*' */
			rt_size_t len = rt_strlen(box->text);
			if (len > 0)
			{
				char *text_mask = rtgui_malloc(len + 1);
				rt_memset(text_mask, '*', len + 1);
				text_mask[len] = 0;
				rtgui_dc_draw_text(dc, text_mask, &rect);
				rt_free(text_mask);
			}
		}
		else
		{
			rtgui_dc_draw_text(dc, box->text, &rect);
		}

		/* draw caret */
		if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
		{
			rect.x1 += box->position * box->font_width;
			rect.x2 = rect.x1 + box->font_width;

			rect.y2 -= 2;
			rect.y1 = rect.y2 - 3;

			RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(box)) = black;
			rtgui_dc_fill_rect(dc, &rect);
		}
	}

	/* end drawing */
	rtgui_dc_end_drawing(dc);
}
コード例 #6
0
rtgui_container_t *demo_view_bmp(void)
{
	rtgui_rect_t rect;
	rtgui_container_t *container, *showbox;
	rtgui_button_t *button;
	rtgui_textbox_t *box;
	/* 用bmpdt结构体记录一些参数 */
	rt_memset(&bmpdt, 0, sizeof(struct demo_bmp_dt));
	bmpdt.scale = 1.0;
	bmpdt.angle = 0.0;
	/* 创建用于演示本代码的容器控件 */
	container = demo_view("Bmp File:");

	demo_view_get_rect(container, &rect);
	rect.x1 += 85;
	rect.x2 -= 5;
	rect.y1 -= 42;
	rect.y2 = rect.y1 + 20;
	box = rtgui_textbox_create("", RTGUI_TEXTBOX_SINGLE);
	rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);
	rtgui_container_add_child(container, RTGUI_WIDGET(box));
	bmpdt.box = box;
	/* create a button "open" */
	demo_view_get_rect(container, &rect);
	rect.x1 += 5;
	rect.x2 = rect.x1 + 60;
	rect.y1 -= 10;
	rect.y2 = rect.y1 + 24;
	button = rtgui_button_create("open");
	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
	rtgui_container_add_child(container, RTGUI_WIDGET(button));
	rtgui_button_set_onbutton(button, demo_bitmap_open);

	/* create a button "zoom in" */
	demo_view_get_rect(container, &rect);
	rect.x1 += 85;
	rect.x2 = rect.x1 + 70;
	rect.y1 -= 10;
	rect.y2 = rect.y1 + 24;
	button = rtgui_button_create("zoom in");
	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
	rtgui_container_add_child(container, RTGUI_WIDGET(button));
	rtgui_button_set_onbutton(button, demo_image_zoom_in);

	/* create a button "zoom out" */
	demo_view_get_rect(container, &rect);
	rect.x1 += 165;
	rect.x2 = rect.x1 + 70;
	rect.y1 -= 10;
	rect.y2 = rect.y1 + 24;
	button = rtgui_button_create("zoom out");
	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
	rtgui_container_add_child(container, RTGUI_WIDGET(button));
	rtgui_button_set_onbutton(button, demo_image_zoom_out);

	/* create a button "rotate" */
	demo_view_get_rect(container, &rect);
	rect.x1 += 245;
	rect.x2 = rect.x1 + 70;
	rect.y1 -= 10;
	rect.y2 = rect.y1 + 24;
	button = rtgui_button_create("rotate");
	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
	rtgui_container_add_child(container, RTGUI_WIDGET(button));
	rtgui_button_set_onbutton(button, demo_image_rotate);

	/* create a container "showbox" */
	demo_view_get_rect(container, &rect);
	rect.x1 += 5;
	rect.x2 -= 5;
	rect.y1 += 20;
	rect.y2 -= 0;
	showbox = rtgui_container_create();
	rtgui_widget_set_rect(RTGUI_WIDGET(showbox), &rect);
	rtgui_container_add_child(container, RTGUI_WIDGET(showbox));
	rtgui_widget_set_border(RTGUI_WIDGET(showbox), RTGUI_BORDER_SIMPLE);
	bmpdt.showbox = showbox;
	rtgui_object_set_event_handler(RTGUI_OBJECT(showbox), demo_bitmap_showbox);
	rtgui_widget_get_rect(RTGUI_WIDGET(showbox), &bmpdt.lastrect);
	rtgui_rect_inflate(&bmpdt.lastrect, -RTGUI_WIDGET_BORDER(showbox));
	
	return container;
}
コード例 #7
0
ファイル: scrollbar.c プロジェクト: BernardXiong/realtouch
void rtgui_scrollbar_ondraw(rtgui_scrollbar_t* bar)
{
	/* draw scroll bar */
	rtgui_rect_t rect, btn_rect, thum_rect, arrow_rect;
	struct rtgui_dc* dc;
	rtgui_color_t bc;

	RT_ASSERT(bar != RT_NULL);

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(bar));
	if(dc == RT_NULL)return;

	bc = RTGUI_DC_BC(dc);
	/* begin drawing */
	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
	RTGUI_DC_BC(dc) = white;
	rtgui_dc_fill_rect(dc,&rect);
	RTGUI_DC_BC(dc) = bc;

	if(bar->orient == RTGUI_VERTICAL)
	{
		btn_rect = rect;
		btn_rect.y2 = btn_rect.y1 + (rect.x2 - rect.x1);
		rtgui_dc_fill_rect(dc,&btn_rect);
		/* draw up button */
		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 up 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);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _up_arrow);

		/* draw thumb */
		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);
		/* draw down 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);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _down_arrow);
	}
	else
	{
		btn_rect = rect;
		btn_rect.x2 = btn_rect.x1 + (rect.y2 - rect.y1);
		rtgui_dc_fill_rect(dc,&btn_rect);
		/* draw left button */
		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);
		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(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-rect.y1);
		btn_rect.x2 = rect.x2;
		rtgui_dc_fill_rect(dc,&btn_rect);
		/* draw right button */
		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);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _right_arrow);

	}

	rtgui_dc_end_drawing(dc);
}
コード例 #8
0
ファイル: device_info.c プロジェクト: eyyhappy/network-radio
/*
 * Device Information View
 * Device: Win32 or Cortex-M3 etc
 * Memory:
 * Thread:
 * IP Address:
 * Gateway:
 * DNS:
 */
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		{
			struct rtgui_dc* dc;
			struct rtgui_rect rect;
			char* line;
			rt_uint32_t total, used, max_used;

			line = rtgui_malloc(256);
			if (line == RT_NULL) return RT_FALSE;

			dc = rtgui_dc_begin_drawing(widget);
			if (dc == RT_NULL)
			{
				rtgui_free(line);
				return RT_FALSE;
			}
			rtgui_widget_get_rect(widget, &rect);

			/* fill background */
			rtgui_dc_fill_rect(dc, &rect);

			rect.y2 = rect.y1 + 18;

			{
				rt_uint32_t dev_index, rev_index;
				
				dev_index = DBGMCU_GetDEVID();
				dev_index = (dev_index - 0x410)/2;
				rev_index = DBGMCU_GetREVID();
				switch (rev_index)
				{
				case 0x1000:
				case 0x0000:
					rev_index = 0; 	/* Revision A */
					break;
					
				case 0x1001:
				case 0x2001:
					rev_index = 3;	/* Revision Z */
					break;
				
				case 0x2000:
					rev_index = 1;	/* Revision B */
					break;
				case 0x2002:
					rev_index = 2;	/* Revision Y */
					break;
					
				default:
					rev_index = 4;	/* Unknown */
					break;
				};

				/* check device index */
				if (dev_index > 4) dev_index = 3;

				/* draw each information */
				sprintf(line, "设备: %s %s", 
					stm32_devname[dev_index], 
					stm32_revname[rev_index]);
				rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
			}

			rt_memory_info(&total, &used, &max_used);
			sprintf(line, "内存: 当前使用 %d 字节", used);
			rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
			{
				rt_uint16_t rect_width;
				rtgui_color_t saved;
				
				rtgui_rect_t mem_rect = rect;
				rtgui_rect_inflate(&mem_rect, -2);
				rtgui_dc_draw_rect(dc, &mem_rect);

				rtgui_rect_inflate(&mem_rect, -1);
				rect_width = rtgui_rect_width(mem_rect);

				saved = RTGUI_WIDGET_BACKGROUND(widget);

				RTGUI_WIDGET_BACKGROUND(widget) = light_grey;
				mem_rect.x2 = mem_rect.x1 + (max_used * rect_width / total);
				rtgui_dc_fill_rect(dc, &mem_rect);
				
				RTGUI_WIDGET_BACKGROUND(widget) = blue;
				mem_rect.x2 = mem_rect.x1 + (used * rect_width / total);
				rtgui_dc_fill_rect(dc, &mem_rect);

				/* restore color */
				RTGUI_WIDGET_BACKGROUND(widget) = saved;
			}
			rect.y1 += 18; rect.y2 += 18;

			sprintf(line, "线程数: %d", get_thread_cnt());
			rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;

#ifdef RT_USING_LWIP
			{
				struct ip_addr ip_addr;
				struct _ip_addr
				{
					rt_uint8_t addr0, addr1, addr2, addr3;
				} *addr;
			
				addr = (struct _ip_addr*)&netif_default->ip_addr.addr;

				sprintf(line, "IP地址  : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3);
				rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;

				addr = (struct _ip_addr*)&netif_default->gw.addr;
				sprintf(line, "网关地址: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3);
				rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;

				addr = (struct _ip_addr*)&netif_default->netmask.addr;
				sprintf(line, "网络掩码: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3);
				rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;

#if LWIP_DNS
				ip_addr = dns_getserver(0);
				addr = (struct _ip_addr*)&ip_addr;
				sprintf(line, "DNS地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3);
				rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
#endif
			}
#endif

			rtgui_dc_end_drawing(dc);
			rtgui_free(line);
			return RT_FALSE;
		}

	case RTGUI_EVENT_KBD:
		{
            struct rtgui_event_kbd* ekbd;
			
			ekbd = (struct rtgui_event_kbd*)event;
            if (ekbd->type == RTGUI_KEYDOWN && ekbd->key == RTGUIK_RETURN)
            {
				rtgui_workbench_t* workbench;

				workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(device_view)->parent);
				rtgui_workbench_remove_view(workbench, device_view);

				rtgui_view_destroy(device_view);
				device_view = RT_NULL;
            }
		}
		return RT_FALSE;
	}

	/* use parent event handler */
	return rtgui_view_event_handler(widget, event);
}
コード例 #9
0
rt_bool_t calibration_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
	{
		struct rtgui_dc* dc;
		struct rtgui_rect rect;

		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL) break;

		/* get rect information */
		rtgui_widget_get_rect(widget, &rect);

		/* clear whole window */
		RTGUI_WIDGET_BACKGROUND(widget) = white;
		rtgui_dc_fill_rect(dc, &rect);

		/* reset color */
		RTGUI_WIDGET_BACKGROUND(widget) = green;
		RTGUI_WIDGET_FOREGROUND(widget) = black;

		switch (calibration_ptr->step)
		{
			case CALIBRATION_STEP_LEFTTOP:
				rtgui_dc_draw_hline(dc, 0, 2 * CALIBRATION_WIDTH, CALIBRATION_HEIGHT);
				rtgui_dc_draw_vline(dc, CALIBRATION_WIDTH, 0, 2 * CALIBRATION_HEIGHT);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, CALIBRATION_WIDTH, CALIBRATION_HEIGHT, 4);
				break;

			case CALIBRATION_STEP_RIGHTTOP:
				rtgui_dc_draw_hline(dc, calibration_ptr->width - 2 * CALIBRATION_WIDTH,
					calibration_ptr->width, CALIBRATION_HEIGHT);
				rtgui_dc_draw_vline(dc, calibration_ptr->width - CALIBRATION_WIDTH, 0, 2 * CALIBRATION_HEIGHT);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, calibration_ptr->width - CALIBRATION_WIDTH, CALIBRATION_HEIGHT, 4);
				break;

			case CALIBRATION_STEP_LEFTBOTTOM:
				rtgui_dc_draw_hline(dc, 0, 2 * CALIBRATION_WIDTH, calibration_ptr->height - CALIBRATION_HEIGHT);
				rtgui_dc_draw_vline(dc, CALIBRATION_WIDTH, calibration_ptr->height - 2 * CALIBRATION_HEIGHT, calibration_ptr->height);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, CALIBRATION_WIDTH, calibration_ptr->height - CALIBRATION_HEIGHT, 4);
				break;

			case CALIBRATION_STEP_RIGHTBOTTOM:
				rtgui_dc_draw_hline(dc, calibration_ptr->width - 2 * CALIBRATION_WIDTH,
					calibration_ptr->width, calibration_ptr->height - CALIBRATION_HEIGHT);
				rtgui_dc_draw_vline(dc, calibration_ptr->width - CALIBRATION_WIDTH, calibration_ptr->height - 2 * CALIBRATION_HEIGHT, calibration_ptr->height);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, calibration_ptr->width - CALIBRATION_WIDTH, calibration_ptr->height - CALIBRATION_HEIGHT, 4);
				break;

			case CALIBRATION_STEP_CENTER:
				rtgui_dc_draw_hline(dc, calibration_ptr->width/2 - CALIBRATION_WIDTH, calibration_ptr->width/2 + CALIBRATION_WIDTH, calibration_ptr->height/2);
				rtgui_dc_draw_vline(dc, calibration_ptr->width/2, calibration_ptr->height/2 - CALIBRATION_HEIGHT, calibration_ptr->height/2 + CALIBRATION_HEIGHT);
				RTGUI_WIDGET_FOREGROUND(widget) = red;
				rtgui_dc_fill_circle(dc, calibration_ptr->width/2, calibration_ptr->height/2, 4);
				break;
		}
		rtgui_dc_end_drawing(dc);
	}
		break;

	case RTGUI_EVENT_COMMAND:
		{
			struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;

			switch (ecmd->command_id)
			{
			case TOUCH_WIN_UPDATE:
				rtgui_widget_update(widget);
				break;
			case TOUCH_WIN_CLOSE:
				rtgui_win_close(RTGUI_WIN(widget));
				break;
			}
		}
		return RT_TRUE;

	default:
		rtgui_win_event_handler(widget, event);
	}

	return RT_FALSE;
}
コード例 #10
0
ファイル: filelist_view.c プロジェクト: KodakWang/RTGUI
void rtgui_filelist_view_update_current(struct rtgui_filelist_view *view, rt_uint16_t old_item)
{
    struct rtgui_dc *dc;
    struct rtgui_file_item *item;
    rtgui_rect_t rect, item_rect, image_rect;

    if (old_item / view->page_items != view->current_item / view->page_items)
    {
        /* it's not a same page, update all */
        rtgui_widget_update(RTGUI_WIDGET(view));
        return;
    }

    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
    if (dc == RT_NULL) return;

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

    /* get old item rect */
    item_rect = rect;
    item_rect.y1 += 1;
    item_rect.y1 += (old_item % view->page_items) * (1 + rtgui_theme_get_selected_height());
    item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());

    /* get image rect */
    image_rect.x1 = RTGUI_FILELIST_MARGIN;
    image_rect.y1 = 0;
    image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w;
    image_rect.y2 = file_image->h;
    rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

    /* draw old item */
    rtgui_dc_fill_rect(dc, &item_rect);

    item = &(view->items[old_item]);
    if (item->type == RTGUI_FITEM_FILE) /* draw item image */
        rtgui_image_blit(file_image, dc, &image_rect);
    else
        rtgui_image_blit(folder_image, dc, &image_rect);

    item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
    rtgui_dc_draw_text(dc, item->name, &item_rect);

    /* draw current item */
    item_rect = rect;
    item_rect.y1 += 1;
    item_rect.y1 += (view->current_item % view->page_items) * (1 + rtgui_theme_get_selected_height());
    item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());

    rtgui_theme_draw_selected(dc, &item_rect);

    /* get image base rect */
    image_rect.x1 = RTGUI_FILELIST_MARGIN;
    image_rect.y1 = 0;
    image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w;
    image_rect.y2 = file_image->h;
    rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

    item = &(view->items[view->current_item]);
    if (item->type == RTGUI_FITEM_FILE) /* draw item image */
        rtgui_image_blit(file_image, dc, &image_rect);
    else
        rtgui_image_blit(folder_image, dc, &image_rect);

    item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
    rtgui_dc_draw_text(dc, item->name, &item_rect);
    if(view->on_changed!=RT_NULL)
   {
    view->on_changed(RTGUI_OBJECT(view),RT_NULL);
   }
    rtgui_dc_end_drawing(dc);
}
コード例 #11
0
ファイル: filelist_view.c プロジェクト: KodakWang/RTGUI
rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
    struct rtgui_widget *widget;
    struct rtgui_filelist_view *view = RT_NULL;

    widget = RTGUI_WIDGET(object);
    view = RTGUI_FILELIST_VIEW(widget);
    switch (event->type)
    {
    case RTGUI_EVENT_PAINT:
        rtgui_filelist_view_ondraw(view);
        return RT_FALSE;

    case RTGUI_EVENT_RESIZE:
    {
        struct rtgui_event_resize *resize;

        resize = (struct rtgui_event_resize *)event;

        /* recalculate page items */
        if (file_image != RT_NULL)
            view->page_items = resize->h  / (1 + rtgui_theme_get_selected_height());
        else
            view->page_items = resize->h / (2 + 14);
        if (view->page_items == 0)
            view->page_items = 1;
    }
    break;

    case RTGUI_EVENT_MOUSE_BUTTON:
    {
        rtgui_rect_t rect;
        struct rtgui_event_mouse *emouse;

        emouse = (struct rtgui_event_mouse *)event;

        /* calculate selected item */

        /* get physical extent information */
        rtgui_widget_get_rect(widget, &rect);
        rtgui_widget_rect_to_device(widget, &rect);

        if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
        {
            rt_uint16_t index;
            rt_uint16_t current_page;
            rt_uint16_t old_item;

            index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

            /* get current page */
            current_page = view->current_item / view->page_items;
            old_item = view->current_item;

            if (index + current_page * view->page_items < view->items_count)
            {
                /* set selected item */
                view->current_item = index + current_page * view->page_items;
                if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
                {
                    rtgui_filelist_view_update_current(view, old_item);
                }
                else
                {
                    /* up event */
                    rtgui_filelist_view_onenturn(view);
                }
            }

            return RT_TRUE;
        }
    }
    break;

    case RTGUI_EVENT_KBD:
    {
        struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
        if (ekbd->type == RTGUI_KEYDOWN)
        {
            rt_uint16_t old_item;

            old_item = view->current_item;
            switch (ekbd->key)
            {
            case RTGUIK_UP:
                if (view->current_item > 0)
                    view->current_item --;
                rtgui_filelist_view_update_current(view, old_item);
                return RT_TRUE;

            case RTGUIK_DOWN:
                if (view->current_item < view->items_count - 1)
                    view->current_item ++;
                rtgui_filelist_view_update_current(view, old_item);
                return RT_TRUE;

            case RTGUIK_LEFT:
                if (view->current_item - view->page_items >= 0)
                    view->current_item -= view->page_items;
                rtgui_filelist_view_update_current(view, old_item);
                return RT_TRUE;

            case RTGUIK_RIGHT:
                if (view->current_item + view->page_items < view->items_count - 1)
                    view->current_item += view->page_items;
                rtgui_filelist_view_update_current(view, old_item);
                return RT_TRUE;

            case RTGUIK_RETURN:
                rtgui_filelist_view_onenturn(view);
                return RT_TRUE;

            default:
                break;
            }
        }
    }
    return RT_FALSE;
    }

    /* use view event handler */
    return rtgui_container_event_handler(object, event);
}
コード例 #12
0
ファイル: filelist_view.c プロジェクト: KodakWang/RTGUI
void rtgui_filelist_view_ondraw(struct rtgui_filelist_view *view)
{
    struct rtgui_dc *dc;
    rt_uint16_t page_index, index;
    struct rtgui_file_item *item;
    struct rtgui_rect rect, item_rect, image_rect;

    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
    if (dc == RT_NULL) return;

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
    rtgui_dc_fill_rect(dc, &rect);

    /* get item base rect */
    item_rect = rect;
    item_rect.y1 += 1;
    item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());

    /* get image base rect */
    image_rect.x1 = RTGUI_FILELIST_MARGIN;
    image_rect.y1 = 0;
    image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w;
    image_rect.y2 = file_image->h;
    rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

    /* get current page */
    page_index = (view->current_item / view->page_items) * view->page_items;
    for (index = 0; index < view->page_items; index ++)
    {
        if (page_index + index >= view->items_count) break;

        item = &(view->items[page_index + index]);

        if (page_index + index == view->current_item)
        {
            rtgui_theme_draw_selected(dc, &item_rect);
        }
        else
        {
            /* draw background */
            rtgui_dc_fill_rect(dc, &item_rect);
        }

        /* draw item */
        if (item->type == RTGUI_FITEM_FILE)
            rtgui_image_blit(file_image, dc, &image_rect);
        else
            rtgui_image_blit(folder_image, dc, &image_rect);

        /* draw text */
        item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
        rtgui_dc_draw_text(dc, item->name, &item_rect);
        item_rect.x1 -= RTGUI_FILELIST_MARGIN + file_image->w + 2;

        /* move to next item position */
        item_rect.y1 += (rtgui_theme_get_selected_height() + 1);
        item_rect.y2 += (rtgui_theme_get_selected_height() + 1);

        image_rect.y1 += (rtgui_theme_get_selected_height() + 1);
        image_rect.y2 += (rtgui_theme_get_selected_height() + 1);
    }

    rtgui_dc_end_drawing(dc);
}
コード例 #13
0
rtgui_container_t *demo_view(const char *title)
{
    struct rtgui_container  *container;
    struct rtgui_label      *label;
    struct rtgui_staticline *line;
    struct rtgui_button     *next_btn, *prev_btn;
    struct rtgui_rect       rect;

    container = rtgui_container_create();
    if (container == RT_NULL)
        return RT_NULL;

    rtgui_notebook_add(the_notebook, title, RTGUI_WIDGET(container));

    /* 获得视图的位置信息(在加入到 notebook 中时,notebook 会自动调整 container
     * 的大小) */
    rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
    rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
    rect.x1 += 5;
    rect.y1 += 5;
    rect.x2 = rect.x1 + rt_strlen(title)*8;
    rect.y2 = rect.y1 + 20;

    /* 创建标题用的标签 */
    label = rtgui_label_create(title);
    /* 设置标签位置信息 */
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    /* 添加标签到视图中 */
    rtgui_container_add_child(container, RTGUI_WIDGET(label));
	
	rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
    rect.y1 += 20 + 5;
    rect.y2 = rect.y1 + 2;
    /* 创建一个水平的 staticline 线 */
    line = rtgui_staticline_create(RTGUI_HORIZONTAL);
    /* 设置静态线的位置信息 */
    rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect);
    /* 添加静态线到视图中 */
    rtgui_container_add_child(container, RTGUI_WIDGET(line));

    /* 获得视图的位置信息 */
    rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
    rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
    rect.x2 -= 5;
    rect.y2 -= 5;
    rect.x1 = rect.x2 - 100;
    rect.y1 = rect.y2 - 25;

    /* 创建"下一个"按钮 */
    next_btn = rtgui_button_create("下一个");
    /* 设置onbutton动作到demo_view_next函数 */
    rtgui_button_set_onbutton(next_btn, demo_view_next);
    /* 设置按钮的位置信息 */
    rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect);
    /* 添加按钮到视图中 */
    rtgui_container_add_child(container, RTGUI_WIDGET(next_btn));

    /* 获得视图的位置信息 */
    rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
    rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
    rect.x1 += 5;
    rect.y2 -= 5;
    rect.x2 = rect.x1 + 100;
    rect.y1 = rect.y2 - 25;

    /* 创建"上一个"按钮 */
    prev_btn = rtgui_button_create("上一个");
    /* 设置onbutton动作到demo_view_prev函数 */
    rtgui_button_set_onbutton(prev_btn, demo_view_prev);
    /* 设置按钮的位置信息 */
    rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect);
    /* 添加按钮到视图中 */
    rtgui_container_add_child(container, RTGUI_WIDGET(prev_btn));

    /* 返回创建的视图 */
    return container;
}
コード例 #14
0
ファイル: snake_gui.c プロジェクト: bright-pan/smart-lock
static void snake_draw(struct rtgui_widget *widget)
{
    struct rtgui_dc *dc;
    struct rtgui_rect rect;
    rt_uint32_t i;

    dc = rtgui_dc_begin_drawing(widget);
    if (dc == RT_NULL)
    {
        rt_kprintf("dc == RT_NULL\r\n");
        return;
    }

    /* get room size, run once frist. */
    if ((room_size_x == 0) || (room_size_y == 0))
    {
        rt_size_t tmp;

        rtgui_widget_get_rect(widget, &rect);
        rt_kprintf("rect => x1:%d x2:%d, y1:%d y2:%d\r\n", rect.x1, rect.x2, rect.y1, rect.y2);

        room_size_x = rect.x2 - rect.x1;
        room_size_y = rect.y2 - rect.y1;
        memcpy(&room_rect, &rect, sizeof(struct rtgui_rect));
        rt_kprintf("room_rect => x1:%d x2:%d, y1:%d y2:%d\r\n",
                   room_rect.x1, room_rect.x2,
                   room_rect.y1, room_rect.y2);

        lattice_size_x = (room_rect.x2 - room_rect.x1) / LATTICE_SIZE;
        lattice_size_y = (room_rect.y2 - room_rect.y1) / LATTICE_SIZE;
        lattice_size_x -= 2;
        lattice_size_y -= 2;
        rt_kprintf("lattice_size_x:%d lattice_size_y:%d\r\n",
                   lattice_size_x,
                   lattice_size_y);

        tmp = (room_rect.x2 - room_rect.x1) - (LATTICE_SIZE * lattice_size_x);
        lattice_rect.x1 = room_rect.x1 + (tmp / 2);
        lattice_rect.x2 = lattice_rect.x1 + (LATTICE_SIZE * lattice_size_x);

        tmp = (room_rect.y2 - room_rect.y1) - (LATTICE_SIZE * lattice_size_y);
        lattice_rect.y1 = room_rect.y1 + (tmp / 2);
        lattice_rect.y2 = lattice_rect.y1 + (LATTICE_SIZE * lattice_size_y);
        rt_kprintf("lattice_rect => x1:%d x2:%d, y1:%d y2:%d\r\n",
                   lattice_rect.x1, lattice_rect.x2,
                   lattice_rect.y1, lattice_rect.y2);

        /* create snake. */
        {
            point_t start;
            map = map_init(lattice_size_x, lattice_size_y);
            if (map != RT_NULL)
            {
                start.x = snake_init_pointx;
                start.y = snake_init_pointy;
                run_state = SNAKE_DIR_DOWN;

                if (snake_init(&start, snake_length_init, run_state, map))
                {
                    food_num = 1;
                    food_init(map, food_num);
                }
                else
                {
                    map_deinit(map);
                    map = RT_NULL;
                }
            }
        }
    }

    RTGUI_DC_BC(dc) = BACKGROUND_COLOR;
    rtgui_dc_fill_rect(dc, &room_rect);

    memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
    rect.x2 += 1;
    rect.y2 += 1;
    RTGUI_DC_FC(dc) = WALL_COLOR;
    rtgui_dc_draw_rect(dc, &rect);

    for (i = 1; i < lattice_size_y; i++)
    {
        memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
        rect.x1 += 1;
        rect.x2 -= 1;
        rtgui_dc_draw_horizontal_line(dc, rect.x1, rect.x2,
                                      rect.y1 + (LATTICE_SIZE * i));
    }

    for (i = 1; i < lattice_size_x; i++)
    {
        memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect));
        rect.y1 += 1;
        rect.y2 -= 1;
        rtgui_dc_draw_vertical_line(dc, rect.x1 + (LATTICE_SIZE * i),
                                    rect.y1, rect.y2);
    }

    /* draw snake. */
    {
        rt_int32_t x, y;
        rt_bool_t first_node = RT_TRUE;

        for (y = 0; y < map->height; y++)
        {
            for (x = 0; x < map->width; x++)
            {
                switch (map->range[y * map->width + x])
                {
                case NORMAL:
                    break;
                case FOOD:
                    snake_fill_lattice(dc, x, y, FOOD_COLOR);
                    break;
                case OVER:
                    if (first_node)
                    {
                        first_node = RT_FALSE;
                        second_node.x = x;
                        second_node.y = y;
                        snake_fill_lattice(dc, x, y, SNAKE_HEAD_COLOR);
                    }
                    else
                    {
                        snake_fill_lattice(dc, x, y, SNAKE_COLOR);
                    }
                    break;
                }
            }

        }
    }

    rtgui_dc_end_drawing(dc);

    return;
}
コード例 #15
0
ファイル: list_view.c プロジェクト: idCache/rt-thread
void rtgui_list_view_update_list(struct rtgui_list_view *view, rt_int16_t old_item)
{
    struct rtgui_dc *dc;
    const struct rtgui_list_item *item;
    rtgui_rect_t rect, item_rect;

    if (old_item / view->page_items != view->current_item / view->page_items)
    {
        /* it's not a same page, update all */
        rtgui_widget_update(RTGUI_WIDGET(view));
        return;
    }

    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
    if (dc == RT_NULL) return;

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

    /* get old item's rect and draw old item */
    item_rect.x1 = rect.x1;
    item_rect.x2 = rect.x2;
    item_rect.y1 = rect.y1 + 2;
    item_rect.y1 += (old_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
    item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
    rtgui_dc_fill_rect(dc, &item_rect);

    item_rect.x1 += LIST_MARGIN;

    item = &(view->items[old_item]);
    if (item->image != RT_NULL)
    {
        struct rtgui_rect image_rect;

        /* blit on center */
        image_rect.x1 = 0;
        image_rect.y1 = 0;
        image_rect.x2 = item->image->w;
        image_rect.y2 = item->image->h;

        rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
        rtgui_image_blit(item->image, dc, &image_rect);
        item_rect.x1 += item->image->w + 2;
    }
    rtgui_dc_draw_text(dc, item->name, &item_rect);

    /* draw current item */
    item_rect = rect;
    /* get current item's rect */
    item_rect.y1 += 2;
    item_rect.y1 += (view->current_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
    item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

    /* draw current item */
    rtgui_theme_draw_selected(dc, &item_rect);

    item_rect.x1 += LIST_MARGIN;

    item = &(view->items[view->current_item]);
    if (item->image != RT_NULL)
    {
        struct rtgui_rect image_rect;

        /* blit on center */
        image_rect.x1 = 0;
        image_rect.y1 = 0;
        image_rect.x2 = item->image->w;
        image_rect.y2 = item->image->h;

        rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
        rtgui_image_blit(item->image, dc, &image_rect);
        item_rect.x1 += (item->image->w + 2);
    }
    rtgui_dc_draw_text(dc, item->name, &item_rect);

    rtgui_dc_end_drawing(dc);
}
コード例 #16
0
rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
{
	struct rtgui_workbench* workbench = (struct rtgui_workbench*)widget;

	switch (event->type)
	{
	case RTGUI_EVENT_PANEL_DETACH:
		RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench));
		RTGUI_TOPLEVEL(workbench)->server = RT_NULL;
		return RT_TRUE;

	case RTGUI_EVENT_PANEL_SHOW:
		/* show workbench in server */
		rtgui_workbench_show(workbench);
		break;

	case RTGUI_EVENT_PANEL_HIDE:
		/* hide widget */
		RTGUI_WIDGET_HIDE(widget);
		break;

	case RTGUI_EVENT_MOUSE_MOTION:
		{
			struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(emouse->wid);

			/* check the destination window */
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
			else
			{
				/* let viewer to handle it */
				rtgui_view_t* view = workbench->current_view;
				if (view != RT_NULL &&
					RTGUI_WIDGET(view)->event_handler != RT_NULL)
				{
					RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
				}
			}
		}
		break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		{
			struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(emouse->wid);

			/* check the destination window */
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
			else
			{
				if (RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
				{
					/* let modal widget to handle it */
					if (workbench->modal_widget != RT_NULL &&
							workbench->modal_widget->event_handler != RT_NULL)
					{
						workbench->modal_widget->event_handler(workbench->modal_widget, event);
					}
				}
				else
				{
					/* let viewer to handle it */
					rtgui_view_t* view = workbench->current_view;
					if (view != RT_NULL &&
							RTGUI_WIDGET(view)->event_handler != RT_NULL)
					{
						RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
					}
				}
			}
		}
		break;

	case RTGUI_EVENT_KBD:
		{
			struct rtgui_event_kbd* kbd = (struct rtgui_event_kbd*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(kbd->wid);

			/* check the destination window */
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
			else
			{
				if (RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
				{
					/* let modal widget to handle it */
					if (workbench->modal_widget != RT_NULL &&
							workbench->modal_widget->event_handler != RT_NULL)
					{
						workbench->modal_widget->event_handler(workbench->modal_widget, event);
					}
				}
				else
				{
					if (RTGUI_CONTAINER(widget)->focused == widget)
					{
						/* set focused widget to the current view */
						if (workbench->current_view != RT_NULL)
							rtgui_widget_focus(RTGUI_WIDGET(RTGUI_CONTAINER(workbench->current_view)->focused));
					}

					return rtgui_toplevel_event_handler(widget, event);
				}
			}
		}
		break;

	case RTGUI_EVENT_PAINT:
		{
			struct rtgui_event_paint* epaint = (struct rtgui_event_paint*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(epaint->wid);

			/* check the destination window */
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
			else
			{
				rtgui_view_t* view;

				/* un-hide workbench */
				RTGUI_WIDGET_UNHIDE(widget);

				/* paint a view */
				view = workbench->current_view;
				if (view != RT_NULL)
				{
					/* remake a paint event */
					RTGUI_EVENT_PAINT_INIT(epaint);
					epaint->wid = RT_NULL;

					/* send this event to the view */
					if (RTGUI_WIDGET(view)->event_handler != RT_NULL)
					{
						RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
					}
				}
				else
				{
					struct rtgui_dc* dc;
					struct rtgui_rect rect;

					dc = rtgui_dc_begin_drawing(widget);
					rtgui_widget_get_rect(widget, &rect);
					rtgui_dc_fill_rect(dc, &rect);
					rtgui_dc_end_drawing(dc);
				}
			}
		}
		break;

	case RTGUI_EVENT_CLIP_INFO:
		{
			struct rtgui_event_clip_info* eclip = (struct rtgui_event_clip_info*)event;
			struct rtgui_widget* dest_widget = RTGUI_WIDGET(eclip->wid);

			if (dest_widget != RT_NULL && dest_widget->event_handler != RT_NULL)
			{
				dest_widget->event_handler(dest_widget, event);
			}
			else
			{
				return rtgui_toplevel_event_handler(widget, event);
			}
		}
		break;

	case RTGUI_EVENT_WIN_CLOSE:
	case RTGUI_EVENT_WIN_ACTIVATE:
	case RTGUI_EVENT_WIN_DEACTIVATE:
		{
			struct rtgui_event_win* wevent = (struct rtgui_event_win*)event;
			struct rtgui_widget* dest_widget = RTGUI_WIDGET(wevent->wid);
			if (dest_widget != RT_NULL && dest_widget->event_handler != RT_NULL)
			{
				dest_widget->event_handler(dest_widget, event);
			}
		}
		break;

	case RTGUI_EVENT_WIN_MOVE:
		{
			struct rtgui_event_win_move* wevent = (struct rtgui_event_win_move*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(wevent->wid);
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
		}
		break;

	default:
		return rtgui_toplevel_event_handler(widget, event);
	}

	return RT_TRUE;
}
コード例 #17
0
ファイル: list_view.c プロジェクト: idCache/rt-thread
static rt_bool_t rtgui_list_view_onmouse(struct rtgui_list_view *view, struct rtgui_event_mouse *emouse)
{
    rtgui_rect_t rect;

    /* calculate selected item */

    /* get physical extent information */
    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
    rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);

    if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
    {
        rt_uint16_t index;
        rt_uint16_t old_item;

        /* get old item */
        old_item = view->current_item;

        switch (view->flag)
        {
        case RTGUI_LIST_VIEW_LIST:
            index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

            if ((index < view->items_count) && (index < view->page_items))
            {
                /* set selected item */
                view->current_item = (view->current_item / view->page_items) * view->page_items + index;
                if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
                {
                    /* down event */
                    rtgui_list_view_update_list(view, old_item);
                }
                else
                {
                    /* up event */
                    if (view->items[view->current_item].action != RT_NULL)
                    {
                        view->items[view->current_item].action(RTGUI_WIDGET(view),
                                                               view->items[view->current_item].parameter);
                    }
                }
            }
            break;

        case RTGUI_LIST_VIEW_ICON:
        {
            rt_uint16_t x, y;
            rt_uint16_t item_height, item_width;
            rt_ubase_t current_page;

            item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / view->col_items;
            item_height = (rtgui_rect_height(rect) - 4) / view->row_items;
            x = emouse->x - rect.x1;
            y = emouse->y - rect.y1;

            index = (y / item_height * view->col_items) + x / item_width;
            current_page = view->current_item / view->page_items;

            if ((index + (current_page * view->page_items) < view->items_count))
            {
                if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
                {
                    view->current_item = index + (current_page * view->page_items);

                    /* down event */
                    rtgui_list_view_update_icon(view, old_item);
                }
                else
                {
                    /* up event */
                    if (view->items[view->current_item].action != RT_NULL)
                    {
                        view->items[view->current_item].action(RTGUI_WIDGET(view),
                                                               view->items[view->current_item].parameter);
                    }
                }
            }
        }
        break;

        case RTGUI_LIST_VIEW_REPORT:
            break;
        }

        return RT_TRUE;
    }

    return RT_FALSE;
}
コード例 #18
0
ファイル: demo_view.c プロジェクト: CollinsLiu/rt-thread-pc
/* 创建一个演示视图,需提供父workbench和演示用的标题 */
rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title)
{
	struct rtgui_view* view;

	/* 设置视图的名称 */
	view = rtgui_view_create(title);
	if (view == RT_NULL) return RT_NULL;

	/* 创建成功后,添加到数组中 */
	demo_view_list[demo_view_number] = view;
	demo_view_number ++;

	/* 添加到父workbench中 */
	rtgui_workbench_add_view(workbench, view);

	/* 添加下一个视图和前一个视图按钮 */
	{
		struct rtgui_rect rect;
		struct rtgui_button *next_btn, *prev_btn;
		struct rtgui_label *label;
		struct rtgui_staticline *line;

		/* 获得视图的位置信息(在加入到workbench中时,workbench会自动调整视图的大小) */
		rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
		rect.x1 += 5;
		rect.y1 += 5;
		rect.x2 -= 5;
		rect.y2 = rect.y1 + 20;

		/* 创建标题用的标签 */
		label = rtgui_label_create(title);
		/* 设置标签位置信息 */
		rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
		/* 添加标签到视图中 */
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));

		rect.y1 += 20;
		rect.y2 += 20;
		/* 创建一个水平的staticline线 */
		line = rtgui_staticline_create(RTGUI_HORIZONTAL);
		/* 设置静态线的位置信息 */
		rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect);
		/* 添加静态线到视图中 */
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(line));

		/* 获得视图的位置信息 */
		rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
		rect.x2 -= 5;
		rect.y2 -= 5;
		rect.x1 = rect.x2 - 100;
		rect.y1 = rect.y2 - 25;

		/* 创建"下一个"按钮 */
		next_btn = rtgui_button_create("下一个");
		/* 设置onbutton动作到demo_view_next函数 */
		rtgui_button_set_onbutton(next_btn, demo_view_next);
		/* 设置按钮的位置信息 */
		rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect);
		/* 添加按钮到视图中 */
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(next_btn));

		/* 获得视图的位置信息 */
		rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
		rect.x1 += 5;
		rect.y2 -= 5;
		rect.x2 = rect.x1 + 100;
		rect.y1 = rect.y2 - 25;

		/* 创建"上一个"按钮 */
		prev_btn = rtgui_button_create("上一个");
		/* 设置onbutton动作到demo_view_prev函数 */
		rtgui_button_set_onbutton(prev_btn, demo_view_prev);
		/* 设置按钮的位置信息 */
		rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect);
		/* 添加按钮到视图中 */
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(prev_btn));
	}

	/* 返回创建的视图 */
	return view;
}
コード例 #19
0
rt_bool_t demo_bitmap_showbox(struct rtgui_object* object, struct rtgui_event* event)
{
	rtgui_container_t *container=container;
	rtgui_widget_t *widget;
	
	RT_ASSERT(object != RT_NULL);

	container = RTGUI_CONTAINER(object);
	widget = RTGUI_WIDGET(object);

	if(event->type == RTGUI_EVENT_PAINT)
	{
		int w, h;
		rtgui_rect_t rect;
		struct rtgui_dc *dc;
		struct rtgui_image *image = bmpdt.showimg;
		/* 如果从其他标签切换到当前标签, image应该是RT_NULL, 重置它 */
		if(image == RT_NULL && bmpdt.image != RT_NULL)
		{
			image = bmpdt.image;
			bmpdt.scale = 1.0f;
			bmpdt.angle = 0.0f;
			rtgui_widget_get_rect(RTGUI_WIDGET(bmpdt.showbox), &bmpdt.lastrect);
			rtgui_rect_inflate(&bmpdt.lastrect, -RTGUI_WIDGET_BORDER(bmpdt.showbox));
		}

		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL)
			return RT_FALSE;
		
		rtgui_widget_get_rect(widget, &rect);
		/* 在绘制边框后, 再将rect缩小填充背景, 可以降低闪烁现象 */
		rtgui_dc_draw_border(dc, &rect, RTGUI_WIDGET_BORDER_STYLE(widget));
		rtgui_rect_inflate(&rect, -RTGUI_WIDGET_BORDER(widget));
		w = rtgui_rect_width(bmpdt.lastrect);
		h = rtgui_rect_height(bmpdt.lastrect);
		if(w > rtgui_rect_width(rect)) w = rtgui_rect_width(rect);
		if(h > rtgui_rect_height(rect)) h = rtgui_rect_height(rect);
		
		/* fill container with background */
		/*
		* 参数lastrect会记录上一次绘图所用区域
		* 每次重绘时,只需与lastrect比较,即可得知那些背景区域需要刷新
		* 例如当放大图片时,lastrect比当前绘图区小,所有无需更新背景区,
		* 当缩小图片时, 也仅需要更新绘图区比lastrect大的区域.
		*/
		if(image != RT_NULL)
		{	/* 减少不必要的绘图 */
			rtgui_rect_t rc;
			if(w > image->w)
			{
				rc.x1 = image->w;
				rc.y1 = bmpdt.lastrect.y1;
				rc.x2 = bmpdt.lastrect.x2;
				rc.y2 = (h > image->h) ? image->h : bmpdt.lastrect.y2;
				rtgui_dc_fill_rect(dc, &rc);
			}
			if(h > image->h)
			{
				rc.x1 = bmpdt.lastrect.x1;
				rc.y1 = image->h;
				rc.x2 = bmpdt.lastrect.x2;
				rc.y2 = bmpdt.lastrect.y2;
				rtgui_dc_fill_rect(dc, &rc);
			}
		}
		else
			rtgui_dc_fill_rect(dc, &bmpdt.lastrect);

		/* 将图像数据blit到画布上 */
		if (image != RT_NULL)
		{
			int value;
			rtgui_image_blit(image, dc, &rect);
			bmpdt.lastrect.x1 = bmpdt.lastrect.y1 = RTGUI_WIDGET_BORDER(bmpdt.showbox);

			if(image->w > rtgui_rect_width(rect))
				value = rtgui_rect_width(rect);
			else
				value = image->w;
			bmpdt.lastrect.x2 = bmpdt.lastrect.x1 + value;

			if(image->h > rtgui_rect_height(rect))
				value = rtgui_rect_height(rect);
			else
				value = image->h;
			bmpdt.lastrect.y2 = bmpdt.lastrect.y1 + value;
		}

		rtgui_dc_end_drawing(dc);
		return RT_FALSE;
	}
	return rtgui_container_event_handler(object, event);
}
コード例 #20
0
ファイル: edit.c プロジェクト: amsl/RTGUI
/* local area update */
void rtgui_edit_update(struct rtgui_edit *edit)
{
	rt_uint32_t i,cpy_len=0,prev_len;
	rtgui_rect_t rect, r;
	struct rtgui_dc *dc;
	char *src;
	
	RT_ASSERT(edit != RT_NULL);
	
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(edit));
	if(dc == RT_NULL) return;
	
	rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
	rtgui_rect_inflate(&rect, -(edit->margin + RTGUI_WIDGET_BORDER_SIZE(edit)));

	if(edit->update_buf == RT_NULL) 
	{   /* try again allocate */
		edit->update_buf = rtgui_malloc(edit->col_per_page+1);
	}
	
	prev_len = edit->col_per_page;
	for(i=edit->update.start.y; i<=edit->update.end.y; i++)
	{
		struct edit_line *line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + i);

		if(i > edit->upleft.y+edit->row_per_page) break;
		if(line == RT_NULL) 
		{	/* when use "RTGUIK_BACKSPACE" backspace forward,
			 * the last line is blank, that only fill background. */
			r.x1 = rect.x1;
			r.x2 = rect.x1 + prev_len * edit->font_width;
			r.y1 = rect.y1 + i * edit->font_height;
			r.y2 = r.y1 + edit->font_height;
			if(r.x2 > rect.x2) r.x2 = rect.x2;
			if(r.y2 > rect.y2) r.y2 = rect.y2;
			rtgui_dc_fill_rect(dc, &r);
			break;
		}
		
		if(edit->update.start.y == edit->update.end.y)
		{
			r.x1 = rect.x1 + edit->update.start.x * edit->font_width;
			r.x2 = rect.x1 + edit->update.end.x * edit->font_width;
			r.y1 = rect.y1 + i * edit->font_height;
			r.y2 = r.y1 + edit->font_height;
			cpy_len = edit->update.end.x - edit->update.start.x;
			src = line->text + edit->update.start.x + edit->upleft.x;
		}
		else 
		{
			if(i == edit->update.start.y)
			{
				r.x1 = rect.x1 + edit->update.start.x * edit->font_width;
				r.x2 = rect.x2;
				r.y1 = rect.y1 + i * edit->font_height;
				r.y2 = r.y1 + edit->font_height;
				cpy_len = line->len - edit->update.start.x - edit->upleft.x;
				if(cpy_len > (edit->col_per_page-edit->update.start.x))
					cpy_len = edit->col_per_page-edit->update.start.x;
				src = line->text + edit->update.start.x + edit->upleft.x;
			}
			else if(i == edit->update.end.y)
			{
				r.x1 = rect.x1;
				r.x2 = rect.x1 + edit->update.end.x * edit->font_width;
				cpy_len = edit->update.end.x;
				r.y1 = rect.y1 + i * edit->font_height;
				r.y2 = r.y1 + edit->font_height;
				src = line->text + edit->upleft.x;
			}
			else
			{
				r.x1 = rect.x1;
				r.x2 = rect.x2;
				r.y1 = rect.y1 + i * edit->font_height;
				r.y2 = r.y1 + edit->font_height;
				cpy_len = line->len - edit->upleft.x;
				if(cpy_len > edit->col_per_page)
					cpy_len = edit->col_per_page;
				src = line->text + edit->upleft.x;
			}
		} 
		if(r.y1 > rect.y2) break;
		if(r.x2 > rect.x2) r.x2 = rect.x2;
		if(r.y2 > rect.y2) r.y2 = rect.y2;
		
		rt_memcpy(edit->update_buf, src, cpy_len);
		*(edit->update_buf + cpy_len) = '\0';
		
		rtgui_dc_fill_rect(dc, &r);
		rtgui_dc_draw_text(dc, edit->update_buf, &r);
		prev_len = line->len;
	}
	
	rtgui_dc_end_drawing(dc);
}
コード例 #21
0
ファイル: scrollbar.c プロジェクト: BernardXiong/realtouch
static void _rtgui_scrollbar_on_mouseclick(rtgui_scrollbar_t *bar, rtgui_event_t * event)
{
	rtgui_rect_t btn_rect, bar_rect,rect;
	rt_uint32_t pos;
	struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;

	RT_ASSERT(bar != RT_NULL);

	/* get value */
	pos = get_scrollbar_pos(bar);

	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&rect);

	if(bar->orient == RTGUI_VERTICAL)
	{
		/* arrange vertical */
		/* get up arrow button rect */
		btn_rect.x1 = rect.x1;
		btn_rect.x2 = rect.x2;
		btn_rect.y1 = rect.y1;
		btn_rect.y2 = rect.y1 + rtgui_rect_width(rect);

		if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
		{
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_UPARROW;
				if(bar->value==0)
				{
					rtgui_scrollbar_ondraw(bar);
					return;
				}
				/* line step */
				bar->value -= bar->line_step;
				if(bar->value < 0) bar->value = 0;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				bar->status = 0;
			}
			goto __exit;
		}
		/* click on the thumb chunk, be going to dragging */
		rtgui_scrollbar_get_thumb_rect(bar, &bar_rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&bar_rect);
		if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
		{
			/* on thumb */
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				/* changed status into drag */
				bar->status |= SBS_VERTTHUMB;
				sbar_mouse_move_size.x = mouse->x;
				sbar_mouse_move_size.y = mouse->y;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				bar->status = 0;
			}
			goto __exit;
		}
		else
		{
			/* click on space without thumb */
			/* get bar rect */
			bar_rect.y1 = rect.y1 + rtgui_rect_width(rect);
			bar_rect.y2 = rect.y2 - rtgui_rect_width(rect);
			if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
			{
				if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
				{
					/* page step */
					if(mouse->y < bar_rect.y1 + pos)
					{
						bar->status |= SBS_UPSPACE;
						bar->value -= bar->page_step;
						if(bar->value < 0) bar->value = 0;
					}
					else if(mouse->y > pos + bar->thumb_len)
					{
						bar->status |= SBS_DOWNSPACE;
						bar->value += bar->page_step;
						if(bar->value > bar->count) bar->value = bar->count;
					}
				}
				goto __exit;
			}
		}
		/* likewise foregoing */
		/* get down arrow button rect */
		bar_rect.x1 = rect.x1;
		bar_rect.x2 = rect.x2;
		btn_rect.y1 = rect.y2 - rtgui_rect_width(rect);
		btn_rect.y2 = rect.y2;
		if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
		{
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_DOWNARROW;
				if(bar->value==bar->count)
				{
					rtgui_scrollbar_ondraw(bar);
					return;
				}
				/* line step */
				bar->value += bar->line_step;
				if(bar->value > bar->count) bar->value = bar->count;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
				bar->status = 0;
			goto __exit;
		}
	}
	else
	{
		/* get left arrow button rect */
		btn_rect.x1 = rect.x1;
		btn_rect.x2 = rect.x1 + rtgui_rect_height(rect);
		btn_rect.y1 = rect.y1;
		btn_rect.y2 = rect.y2;
		if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
		{
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_LEFTARROW;
				if(bar->value==0)
				{
					rtgui_scrollbar_ondraw(bar);
					return;
				}
				/* line step */
				bar->value -= bar->line_step;
				if(bar->value < 0) bar->value = 0;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
				bar->status = 0;
			goto __exit;
		}

		rtgui_scrollbar_get_thumb_rect(bar, &bar_rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&bar_rect);
		if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
		{
			/* on the thumb */
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_HORZTHUMB;
				sbar_mouse_move_size.x = mouse->x;
				sbar_mouse_move_size.y = mouse->y;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				bar->status = 0;
			}
			goto __exit;
		}
		else
		{
			/* get bar rect */
			bar_rect.x1 = rect.x1 + rtgui_rect_height(rect);
			bar_rect.x2 = rect.x2 - rtgui_rect_height(rect);
			bar_rect.y1 = rect.y1;
			bar_rect.y2 = rect.y2;
			if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
			{
				if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
				{
					/* page step */
					if(mouse->x <  bar_rect.x1 + pos)
					{
						bar->status |= SBS_LEFTSPACE;
						bar->value -= bar->page_step;
						if(bar->value < 0) bar->value = 0;
					}
					else if(mouse->x > pos + bar->thumb_len)
					{
						bar->status |= SBS_RIGHTSPACE;
						bar->value += bar->page_step;
						if(bar->value > bar->count) bar->value = bar->count;
					}
				}
				else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
				{
					bar->status = 0;
				}
				goto __exit;
			}
		}
		/* get right arrow button rect */
		btn_rect.x1 = rect.x2 - rtgui_rect_height(rect);
		btn_rect.x2 = rect.x2;
		bar_rect.y1 = rect.y1;
		bar_rect.y2 = rect.y2;
		if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
		{
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_RIGHTARROW;
				if(bar->value==bar->count)
				{
					rtgui_scrollbar_ondraw(bar);
					return;
				}
				/* line step */
				bar->value += bar->line_step;
				if(bar->value > bar->count) bar->value = bar->count;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
				bar->status = 0;
			goto __exit;
		}
	}

__exit:
	rtgui_scrollbar_ondraw(bar);
	if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
	{
		if(bar->widget_link != RT_NULL && bar->on_scroll != RT_NULL)
		{
			rtgui_widget_focus(bar->widget_link);
			bar->on_scroll(RTGUI_OBJECT(bar->widget_link), event);
		}
	}
}
コード例 #22
0
ファイル: edit.c プロジェクト: amsl/RTGUI
void rtgui_edit_ondraw(struct rtgui_edit *edit)
{
	rtgui_rect_t rect, r;
	struct rtgui_dc *dc;
#ifdef RTGUI_EDIT_USING_SCROLL
	int hscroll_flag=0;
	int vscroll_flag=0;
#endif
	
	RT_ASSERT(edit != RT_NULL);

	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(edit));
	if(dc == RT_NULL) return;

	/* get widget rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
	rtgui_rect_inflate(&rect, -RTGUI_WIDGET_BORDER_SIZE(edit));

	/* fill widget rect with edit background color */
	RTGUI_DC_BC(dc) = RTGUI_WIDGET_BC(edit);
	rtgui_dc_fill_rect(dc, &rect);

	rtgui_rect_inflate(&rect, RTGUI_WIDGET_BORDER_SIZE(edit));
	/* draw border */
	rtgui_dc_draw_border(dc, &rect, RTGUI_WIDGET_BORDER_STYLE(edit));

	rtgui_rect_inflate(&rect, -(edit->margin + RTGUI_WIDGET_BORDER_SIZE(edit)));

#ifdef RTGUI_EDIT_USING_SCROLL
	if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit->vscroll))
	{
		rect.x2 = rect.x2 - rtgui_rect_width(edit->vscroll->parent.extent);
	}
	if(edit->hscroll && !RTGUI_WIDGET_IS_HIDE(edit->hscroll))
	{
		rect.y2 = rect.y2 - rtgui_rect_height(edit->hscroll->parent.extent);
	}
#endif
	r = rect;
	
	/* draw text */
	if(edit->head != RT_NULL)
	{
		struct edit_line *line = edit->first_line;
		int num=0;
		
		rect.y2 = rect.y1 + edit->item_height;
		while(line)
		{
			rt_uint32_t tmp_pos=0, ofs;
			char *str = line->text+edit->upleft.x;
			
			if(edit->upleft.x < line->len)
			{
				rtgui_point_t p = edit->visual;
				edit->visual.x = 0;
				identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
				ofs = tmp_pos % 2;
				if(ofs == 1)
				{
					char dbl_bmp[3];
					rtgui_point_t pot = {0};
					rtgui_rect_t r = {0};
					
					pot.x = edit->font_width;
					r.x2 = edit->font_width*2;
					r.y2 = edit->font_height;
					dbl_bmp[0] = *(str-1);
					dbl_bmp[1] = *str;
					dbl_bmp[2] = '\0';
					RTGUI_DC_BC(edit->dbl_buf) = RTGUI_WIDGET_BC(edit);
					rtgui_dc_fill_rect(edit->dbl_buf, &r);
					RTGUI_DC_FC(edit->dbl_buf) = RTGUI_WIDGET_FC(edit);
					rtgui_dc_draw_text(edit->dbl_buf, dbl_bmp, &r);
					rtgui_dc_blit(edit->dbl_buf, pot.x, pot.y, dc, rect.x1, rect.y1, 
						edit->font_width, edit->font_height);
				}
				rect.x1 += ofs * edit->font_width;
				rtgui_dc_draw_text(dc, line->text+edit->upleft.x+ofs, &rect);
				rect.x1 -= ofs * edit->font_width;
				edit->visual = p;
			}
			
			line = line->next;
			rect.y1 += edit->item_height;
			if((rect.y1 + edit->item_height) < r.y2)
				rect.y2 = rect.y1 + edit->item_height;
			else
				rect.y2 = r.y2;
			
			if(num++ >= edit->row_per_page)
				break;
		}
	}

#ifdef RTGUI_EDIT_USING_SCROLL
	if(edit->hscroll && !RTGUI_WIDGET_IS_HIDE(edit->hscroll))
	{
		hscroll_flag = 1;
		rtgui_scrollbar_ondraw(edit->hscroll);
	}
	if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit->vscroll))
	{
		vscroll_flag = 1;
		rtgui_scrollbar_ondraw(edit->vscroll);
	}

	if(hscroll_flag && vscroll_flag)
	{
		rtgui_color_t _bc;
		rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
		rect.x1 = rect.x2-RTGUI_WIDGET_BORDER_SIZE(edit);
		rect.y1 = rect.y2-RTGUI_WIDGET_BORDER_SIZE(edit);
		_bc = RTGUI_DC_BC(dc);
		RTGUI_DC_BC(dc) = theme.background;
		rtgui_dc_fill_rect(dc,&rect);
		RTGUI_DC_BC(dc) = _bc;
	}
#endif
	rtgui_dc_end_drawing(dc);
}
コード例 #23
0
/* widget drawing */
void rtgui_theme_draw_button(rtgui_button_t* btn)
{
	/* draw button */
	struct rtgui_dc* dc;
	struct rtgui_rect rect;
	rtgui_color_t bc, 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 foreground color */
	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->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
		{
			/* 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);
		}
	}
	else
	{
		if (btn->unpressed_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->unpressed_image, dc, &image_rect);
		}
		else
		{
			/* 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);
		}
	}

	if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(btn)))
	{
		/* re-set foreground and get default rect */
		rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect);
		rtgui_rect_inflate(&rect, -2);

		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = black;
		rtgui_dc_draw_focus_rect(dc, &rect);
	}

	/* set forecolor */
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(btn)) = bc;
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = fc;

	if (btn->pressed_image == RT_NULL)
	{
		/* re-set foreground and get default rect */
		rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect);

		/* remove border */
		rtgui_rect_inflate(&rect, -2);

		/* draw text */
		rtgui_dc_draw_text(dc, rtgui_label_get_text(RTGUI_LABEL(btn)), &rect);
	}

	/* end drawing */
	rtgui_dc_end_drawing(dc);
}
コード例 #24
0
ファイル: edit.c プロジェクト: amsl/RTGUI
struct rtgui_edit* rtgui_edit_create(pvoid parent, int left, int top, int w, int h)
{
	struct rtgui_container* container;
	struct rtgui_edit* edit;

	RT_ASSERT(parent != RT_NULL);
	container = RTGUI_CONTAINER(parent);

	edit = (struct rtgui_edit*)rtgui_widget_create(RTGUI_EDIT_TYPE);
	if(edit != RT_NULL)
	{
		rtgui_rect_t rect;
		int effe;
		rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(container),&rect);
		rect.x1 += left;
		rect.y1 += top;
		rect.x2 = rect.x1+w;
		rect.y2 = rect.y1+h;
		rtgui_widget_set_rect(RTGUI_WIDGET(edit),&rect);
		rtgui_container_add_child(container, RTGUI_WIDGET(edit));

		/* set character number */
		edit->item_height = edit->font_height; /* the same height */
		effe = h-(edit->margin + RTGUI_WIDGET_BORDER_SIZE(edit))*2;
		edit->row_per_page = effe / edit->item_height;
		if(effe % edit->item_height)
			edit->row_per_page += 1;
		
		effe = w-(edit->margin + RTGUI_WIDGET_BORDER_SIZE(edit))*2;
		edit->col_per_page = effe / edit->font_width;
		if(effe % edit->font_width)
			edit->col_per_page += 1;
		edit->update_buf = rtgui_malloc(edit->col_per_page + 1);

#ifdef RTGUI_EDIT_USING_SCROLL
		if(edit->hscroll == RT_NULL && edit->flag & RTGUI_EDIT_HSCROLL)
		{
			/* create horizontal scrollbar */
			rt_uint32_t _left,_top,_width=RTGUI_DEFAULT_SB_WIDTH,_len;
			_left = RTGUI_WIDGET_BORDER_SIZE(edit);
			_top = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width;
			_len = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2;
			if(edit->max_rows > edit->row_per_page)	_len -= _width;

			edit->hscroll = rtgui_scrollbar_create(edit,_left,_top,_width,_len,RTGUI_HORIZONTAL);

			if(edit->hscroll != RT_NULL)
			{
				edit->hscroll->WIDGET_GROUP = (pvoid)edit;
				edit->hscroll->on_scroll = rtgui_edit_hscroll_handle;
				RTGUI_WIDGET_HIDE(edit->hscroll);
			}
		}
		if(edit->vscroll == RT_NULL && edit->flag & RTGUI_EDIT_VSCROLL)
		{
			/* create vertical scrollbar */
			rt_uint32_t _left,_top,_width=RTGUI_DEFAULT_SB_WIDTH,_len;
			_left = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width;
			_top = RTGUI_WIDGET_BORDER_SIZE(edit);
			_len = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2;
			if(edit->max_cols > edit->col_per_page) _len -= _width;

			edit->vscroll = rtgui_scrollbar_create(edit,_left,_top,_width,_len,RTGUI_VERTICAL);

			if(edit->vscroll != RT_NULL)
			{
				edit->vscroll->WIDGET_GROUP = (pvoid)edit;
				edit->vscroll->on_scroll = rtgui_edit_vscroll_handle;
				RTGUI_WIDGET_HIDE(edit->vscroll);
			}
		}
#endif
	}

	return edit;
}
コード例 #25
0
void rtgui_theme_draw_checkbox(struct rtgui_checkbox* checkbox)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect, box_rect;
	rtgui_color_t bc, fc;

	fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox));
	bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(checkbox));

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(checkbox));
	if (dc == RT_NULL) return;

	/* get rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(checkbox), &rect);

    /* fill rect */
	rtgui_dc_fill_rect(dc, &rect);

	if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(checkbox)))
	{
		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = black;

		/* draw focused border */
		rtgui_rect_inflate(&rect, -1);
		rtgui_dc_draw_focus_rect(dc, &rect);

		rtgui_rect_inflate(&rect, 1);
	}

	/* draw check box */
	box_rect.x1 = 0;
	box_rect.y1 = 0;
	box_rect.x2 = CHECK_BOX_W;
	box_rect.y2 = CHECK_BOX_H;
	rtgui_rect_moveto_align(&rect, &box_rect, RTGUI_ALIGN_CENTER_VERTICAL);
	box_rect.x1 += 2; box_rect.x2 += 2;

	rtgui_dc_draw_border(dc, &box_rect, RTGUI_BORDER_BOX);
	rtgui_rect_inflate(&box_rect, -1);
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(checkbox)) = RTGUI_RGB(247, 247, 246);
	rtgui_dc_fill_rect(dc, &box_rect);
	if (checkbox->status_down == RTGUI_CHECKBOX_STATUS_CHECKED)
	{
		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = RTGUI_RGB(33, 161, 33);
		rtgui_dc_draw_byte(dc, box_rect.x1 + 2, box_rect.y1 + 2, 7, checked_byte);
	}

	/* restore saved color */
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(checkbox)) = bc;
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = fc;

	/* draw text */
	rect.x1 += rtgui_rect_height(rect) - 4 + 5;
	rtgui_dc_draw_text(dc, rtgui_label_get_text(RTGUI_LABEL(checkbox)), &rect);

	/* end drawing */
	rtgui_dc_end_drawing(dc);

	return;
}
コード例 #26
0
ファイル: edit.c プロジェクト: amsl/RTGUI
static void rtgui_edit_onmouse(struct rtgui_edit* edit, struct rtgui_event_mouse* emouse)
{
	rtgui_rect_t rect;

	RT_ASSERT(edit != RT_NULL);
	RT_ASSERT(emouse != RT_NULL);

	rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
	if((rtgui_region_contains_point(&(RTGUI_WIDGET(edit)->clip), emouse->x, emouse->y, &rect) == RT_EOK))
	{
		rt_uint16_t x, y;

		/* multiline text */
		x = (emouse->x - rect.x1) / (edit->font_width);
		y = (emouse->y - rect.y1) / (edit->item_height);
		if((x < edit->col_per_page) && (y < edit->row_per_page))
		{
			if(emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
			{
				struct edit_line *line;
				rt_uint32_t tmp_pos=0;
				
				edit->visual.x = x;
				edit->visual.y = y;
				
				line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->visual.y);
				if(line == RT_NULL)
					return;
				
				if(edit->visual.x > line->len)
					edit->visual.x = line->len;
				if(edit->upleft.x > 0)
				{
					if(edit->upleft.x >= line->len)
						edit->upleft.x = 0;
					else
						edit->visual.x -= edit->upleft.x;
					rtgui_edit_ondraw(edit);
				}
				if(identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
					edit->visual.x -= (2-tmp_pos);
				if(edit->flag & RTGUI_EDIT_CARET)
				{
					if(edit->caret_timer != RT_NULL)
						rtgui_timer_stop(edit->caret_timer);

					edit->flag &= ~RTGUI_EDIT_CARET;
					rtgui_edit_draw_caret(edit);

					if(edit->caret_timer != RT_NULL)
						rtgui_timer_start(edit->caret_timer);
				}

				/* set widget focus */
				rtgui_widget_focus(RTGUI_WIDGET(edit));

				if(RTGUI_WIDGET_IS_FOCUSED(edit))
				{
					rtgui_edit_init_caret(edit, edit->visual);
					edit->flag |= RTGUI_EDIT_CARET;
					rtgui_edit_draw_caret(edit);
				}
			}
			else if(emouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				/* please add codes at here. */
			}
#ifdef RTGUI_EDIT_USING_SCROLL			
			if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit))
			{
				if(!RTGUI_WIDGET_IS_HIDE(edit->vscroll))
					rtgui_scrollbar_set_value(edit->vscroll,edit->upleft.y);
			}
			if(edit->hscroll && !RTGUI_WIDGET_IS_HIDE(edit))
			{
				if(!RTGUI_WIDGET_IS_HIDE(edit->hscroll))
					rtgui_scrollbar_set_value(edit->hscroll,edit->upleft.x);
			}
#endif
		}
	}		
}
コード例 #27
0
/* window drawing */
void rtgui_theme_draw_win(struct rtgui_topwin* win)
{
	struct rtgui_dc* dc;
	rtgui_rect_t rect;

	if (win->title == RT_NULL) return; /* no title and no board */

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(win->title));
	if (dc == RT_NULL) return;

	/* get rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(win->title), &rect);

	/* draw border */
	if (win->flag & WINTITLE_BORDER)
	{
		rect.x2 -= 1; rect.y2 -= 1;
		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(212, 208, 200);
		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(win->title)) = white;
		rtgui_dc_draw_hline(dc, rect.x1 + 1, rect.x2 - 1, rect.y1 + 1);
		rtgui_dc_draw_vline(dc, rect.x1 + 1, rect.y1 + 1, rect.y2 - 1);

		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(128, 128, 128);
		rtgui_dc_draw_hline(dc, rect.x1 + 1, rect.x2 - 1, rect.y2 - 1);
		rtgui_dc_draw_vline(dc, rect.x2 - 1, rect.y1 + 1, rect.y2 - 1);

		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(64, 64, 64);
		rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2);
		rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2);

		/* shrink border */
		rtgui_rect_inflate(&rect, -WINTITLE_BORDER_SIZE);
	}

	/* draw title */
	if (!(win->flag & WINTITLE_NO))
	{
		rt_uint32_t index;
		float r, g, b, delta;

		if (win->flag & WINTITLE_ACTIVATE)
		{
			r = 10; g = 36; b = 106;
			delta = 150 / (float)(rect.x2 - rect.x1);
		}
		else
		{
			r = 128; g = 128; b = 128;
			delta = 64 / (float)(rect.x2 - rect.x1);
		}

		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(r, g, b);
		for (index = rect.x1; index < rect.x2 + 1; index ++)
		{
			rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
			r += delta; g += delta; b += delta;
		}

		if (win->flag & WINTITLE_ACTIVATE)
		{
			RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = white;
		}
		else
		{
			RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(212, 208, 200);
		}

		rect.x1 += 4;
		rect.y1 += 2; rect.y2 = rect.y1 + WINTITLE_CB_HEIGHT;
		rtgui_dc_draw_text(dc, rtgui_wintitle_get_title(win->title), &rect);

		if (win->flag & WINTITLE_CLOSEBOX)
		{
			/* get close button rect */
			rtgui_rect_t box_rect = {0, 0, WINTITLE_CB_WIDTH, WINTITLE_CB_HEIGHT};
			rtgui_rect_moveto_align(&rect, &box_rect, RTGUI_ALIGN_CENTER_VERTICAL | RTGUI_ALIGN_RIGHT);
			box_rect.x1 -= 3; box_rect.x2 -= 3;
			rtgui_dc_fill_rect(dc, &box_rect);

			/* draw close box */
			if (win->flag & WINTITLE_CB_PRESSED)
			{
				rtgui_dc_draw_border(dc, &box_rect, RTGUI_BORDER_SUNKEN);
				RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = red;
				rtgui_dc_draw_word(dc, box_rect.x1, box_rect.y1 + 6, 7, close_byte);
			}
			else
			{
				rtgui_dc_draw_border(dc, &box_rect, RTGUI_BORDER_RAISE);
				RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = black;
				rtgui_dc_draw_word(dc, box_rect.x1 - 1, box_rect.y1 + 5, 7, close_byte);
			}
		}
	}

	rtgui_dc_end_drawing(dc);
}
コード例 #28
0
ファイル: list_view.c プロジェクト: idCache/rt-thread
static void rtgui_list_view_update_icon(struct rtgui_list_view *view, rt_int16_t old_item)
{
    struct rtgui_rect rect, item_rect, drawing_rect;
    rt_ubase_t c, r; /* col and row index */
    rt_ubase_t item_width, item_height;
    rtgui_image_t *image;
    struct rtgui_dc *dc;

    if ((view->items_count == 0) ||
            (old_item == view->current_item))
        return;

    if (old_item / view->page_items != view->current_item / view->page_items)
    {
        /* it's not a same page, update all */
        rtgui_widget_update(RTGUI_WIDGET(view));
        return;
    }

    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
    if (dc == RT_NULL) return;

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

    item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / view->col_items;
    item_height = (rtgui_rect_height(rect) - 4) / view->row_items;
    image = view->items[0].image;

    /* update old item */
    r = (old_item % view->page_items) / view->col_items;
    c = (old_item % view->page_items) % view->col_items;
    item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height;
    item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width;
    item_rect.x2 = item_rect.x1 + item_width;
    item_rect.y2 = item_rect.y1 + item_height;
    rtgui_dc_fill_rect(dc, &item_rect);

    /* draw image */
    drawing_rect.x1 = drawing_rect.y1 = 0;
    drawing_rect.x2 = image->w;
    drawing_rect.y2 = image->h;
    rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
    drawing_rect.y1 += 5;
    drawing_rect.y2 += 5;
    rtgui_image_blit(view->items[old_item].image, dc, &drawing_rect);

    /* draw text */
    item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
    item_rect.x1 += 3;
    item_rect.x2 -= 3;
    rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), view->items[old_item].name,
                           &drawing_rect);
    rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
    rtgui_dc_draw_text(dc, view->items[old_item].name, &drawing_rect);

    /* update new item as selected */
    r = (view->current_item % view->page_items) / view->col_items;
    c = (view->current_item % view->page_items) % view->col_items;
    item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height;
    item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width;
    item_rect.x2 = item_rect.x1 + item_width;
    item_rect.y2 = item_rect.y1 + item_height;
    rtgui_theme_draw_selected(dc, &item_rect);

    /* draw image */
    drawing_rect.x1 = 0;
    drawing_rect.y1 = 3;
    drawing_rect.x2 = image->w;
    drawing_rect.y2 = 3 + image->h;

    rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
    rtgui_image_blit(view->items[view->current_item].image, dc, &drawing_rect);

    /* draw text */
    item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
    item_rect.x1 += 3;
    item_rect.x2 -= 3;
    rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view),
                           view->items[view->current_item].name,
                           &drawing_rect);
    rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
    rtgui_dc_draw_text(dc, view->items[view->current_item].name, &drawing_rect);

    rtgui_dc_end_drawing(dc);
}
コード例 #29
0
void rtgui_theme_draw_slider(struct rtgui_slider* slider)
{
	/* draw button */
	struct rtgui_dc* dc;
	int i, xsize, x0;
	rtgui_rect_t r, focus_rect, slider_rect, slot_rect;

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(slider));
	if (dc == RT_NULL) return;

	/* get widget rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(slider), &focus_rect);
	/* fill widget rect with background color */
	rtgui_dc_fill_rect(dc, &focus_rect);
	r = focus_rect;

	if (slider->orient == RTGUI_VERTICAL)
	{
		rtgui_rect_inflate(&r, -1);
		xsize = r.y2 - r.y1  + 1 - slider->thumb_width;
		x0 = r.y1 + slider->thumb_width / 2;

		/* calculate thumb position */
		slider_rect = r;
		slider_rect.x1 = 5;
		slider_rect.y1 = x0 + xsize * (slider->value - slider->min) / (slider->max - slider->min) - slider->thumb_width/2;
		slider_rect.y2  = slider_rect.y1 + slider->thumb_width;

		/* calculate slot position */
		slot_rect.y1 = x0;
		slot_rect.y2 = x0 + xsize;
		slot_rect.x1 = (slider_rect.x1 + slider_rect.x2) /2 -1;
		slot_rect.x2 = slot_rect.x1 +3;
		/* draw slot */
		rtgui_dc_draw_border(dc, &slot_rect, RTGUI_BORDER_RAISE);

		/* draw the ticks */
		for (i = 0; i <= slider->ticks; i++)
		{
			int x = x0 + xsize * i / slider->ticks;
			rtgui_dc_draw_hline(dc, 1, 3, x);
		}

		/* draw the thumb */
		rtgui_dc_fill_rect(dc, &slider_rect);
		rtgui_dc_draw_border(dc, &slider_rect, RTGUI_BORDER_RAISE);
	}
	else
	{
		rtgui_rect_inflate(&r, -1);
		xsize = r.x2 - r.x1  + 1 - slider->thumb_width;
		x0 = r.x1 + slider->thumb_width / 2;

		/* calculate thumb position */
		slider_rect = r;
		slider_rect.y1 = 5;
		slider_rect.x1 = x0 + xsize * (slider->value - slider->min) / (slider->max - slider->min) - slider->thumb_width/2;
		slider_rect.x2  = slider_rect.x1 + slider->thumb_width;

		/* calculate slot position */
		slot_rect.x1 = x0;
		slot_rect.x2 = x0 + xsize;
		slot_rect.y1 = (slider_rect.y1 + slider_rect.y2) /2 -1;
		slot_rect.y2 = slot_rect.y1 +3;
		/* draw slot */
		rtgui_dc_draw_border(dc, &slot_rect, RTGUI_BORDER_RAISE);

		/* draw the ticks */
		for (i = 0; i <= slider->ticks; i++)
		{
			int x = x0 + xsize * i / slider->ticks;
			rtgui_dc_draw_vline(dc, x, 1, 3);
		}

		/* draw the thumb */
		rtgui_dc_fill_rect(dc, &slider_rect);
		rtgui_dc_draw_border(dc, &slider_rect, RTGUI_BORDER_RAISE);
	}

	/* draw focus */
	if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(slider)))
	{
		rtgui_dc_draw_focus_rect(dc, &focus_rect);
	}

	/* end drawing */
	rtgui_dc_end_drawing(dc);
	return;
}
コード例 #30
0
void rtgui_listbox_update_current(struct rtgui_listbox* box, rt_uint16_t old_item)
{
	struct rtgui_dc* dc;
	const struct rtgui_listbox_item* item;
	rtgui_rect_t rect, item_rect;

	if (old_item/box->page_items != box->current_item/box->page_items)
	{
		/* it's not a same page, update all */
		rtgui_widget_update(RTGUI_WIDGET(box));
		return;
	}

	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
	if (dc == RT_NULL) return;

	rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
	rect.x2 -= 1; rect.y2 -= 1;

	item_rect = rect;
	/* get old item's rect */
	item_rect.x1 += 1; item_rect.x2 -= 1;
	item_rect.y1 += 2;
	item_rect.y1 += (old_item % box->page_items) * (2 + rtgui_theme_get_selected_height());
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

	/* draw old item */
	rtgui_dc_fill_rect(dc, &item_rect);

	item_rect.x1 += LIST_MARGIN;

	item = &(box->items[old_item]);
	if (item->image != RT_NULL)
	{
		rtgui_image_blit(item->image, dc, &item_rect);
		item_rect.x1 += item->image->w + 2;
	}
	rtgui_dc_draw_text(dc, item->name, &item_rect);

	/* draw current item */
	item_rect = rect;
	/* get current item's rect */
	item_rect.x1 += 1; item_rect.x2 -= 1;
	item_rect.y1 += 2;
	item_rect.y1 += (box->current_item % box->page_items) * (2 + rtgui_theme_get_selected_height());
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

	/* draw current item */
	rtgui_theme_draw_selected(dc, &item_rect);

	item_rect.x1 += LIST_MARGIN;

	item = &(box->items[box->current_item]);
	if (item->image != RT_NULL)
	{
		rtgui_image_blit(item->image, dc, &item_rect);
        item_rect.x1 += (item->image->w + 2);
	}
	rtgui_dc_draw_text(dc, item->name, &item_rect);

	rtgui_dc_end_drawing(dc);
}