Пример #1
0
static rt_bool_t picture_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	if (event->type == RTGUI_EVENT_PAINT)
	{
		struct rtgui_dc* dc;
		struct rtgui_rect rect;
		struct rtgui_image* image;
		char fn[32];

		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL) return RT_FALSE;
		rtgui_widget_get_rect(widget, &rect);

		/* open image */
		rt_snprintf(fn, sizeof(fn), "%s/%s", PICTURE_DIR, current_fn);
		image = rtgui_image_create_from_file("hdc",
			fn, RT_FALSE);
		if (image != RT_NULL)
		{
			/* blit image */
			rtgui_image_blit(image, dc, &rect);
			/* destroy image */
			rtgui_image_destroy(image);
		}
		else
		{
			rtgui_dc_fill_rect(dc, &rect);
			rtgui_dc_draw_text(dc, "没有文件被打开", &rect);
		}
		rtgui_dc_end_drawing(dc);

		return RT_FALSE;
	}
	else if (event->type == RTGUI_EVENT_KBD)
	{
		struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
		if (ekbd->type == RTGUI_KEYDOWN)
		{
			switch (ekbd->key)
			{
			case RTGUIK_RIGHT:
				if (view_mode == VIEW_DIR_MODE) picture_show_next();
				else if (view_mode == VIEW_FN_LIST_MODE)
				{
					picture_fn_list_current ++;
					if (picture_fn_list_current == picture_fn_list_size)
					{
						picture_fn_list_current = 0;
					}
					strcpy(current_fn, picture_fn_list[picture_fn_list_current]);
					rtgui_widget_update(RTGUI_WIDGET(picture_view));
				}
				break;
			case RTGUIK_LEFT:
				if (view_mode == VIEW_DIR_MODE) picture_show_prev();
				else if (view_mode == VIEW_FN_LIST_MODE)
				{
					if (picture_fn_list_current == 0)
					{
						picture_fn_list_current = picture_fn_list_size - 1;
					}
					else picture_fn_list_current --;

					strcpy(current_fn, picture_fn_list[picture_fn_list_current]);
					rtgui_widget_update(RTGUI_WIDGET(picture_view));
				}
				break;
			case RTGUIK_RETURN:
			{
				rtgui_view_t* view;

				view = RTGUI_VIEW(widget);

				/* close this view */
				current_fn[0] = '\0';

				/* end of modal */
			    rtgui_view_end_modal(view, RTGUI_MODAL_OK);
			    picture_view = RT_NULL;
			}
				break;
			}
		}
		return RT_FALSE;
	}

	return rtgui_view_event_handler(widget, event);
}
Пример #2
0
/* update fileview */
void rtgui_fileview_update_current(rtgui_fileview_t* fview)
{
	rtgui_fileview_item_t *item;
	rtgui_rect_t rect, item_rect, image_rect;
	rtgui_dc_t *dc;

	RT_ASSERT(fview != RT_NULL);

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

	/* if directory is null, no dispost */
	if(fview->items==RT_NULL)return;

	rtgui_widget_get_rect(fview, &rect);
	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
		rect.x2 -= RC_W(fview->sbar->parent.extent);

	if((fview->old_item >= fview->first_item) &&
	        (fview->old_item < fview->first_item+fview->item_per_page) &&
	        (fview->old_item != fview->now_item))
	{
		/* these condition dispell blinked when drawed */
		/* get old item rect */
		item_rect = rect;
		item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
		item_rect.y1 += ((fview->old_item-fview->first_item) % fview->item_per_page) * (1 + RTGUI_SEL_H);
		item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

		/* get image rect */
		image_rect.x1 = RTGUI_MARGIN;
		image_rect.y1 = 0;
		image_rect.x2 = RTGUI_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 */
		item = &(fview->items[fview->old_item]);
		if(item->type == RTGUI_FITEM_FILE) /* draw item image */
			rtgui_image_paste(file_image, dc, &image_rect, Black);
		else
			rtgui_image_paste(folder_image, dc, &image_rect,Black);

		item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);
		RTGUI_DC_BC(dc) = theme.blankspace;
		RTGUI_DC_FC(dc) = theme.foreground;
		rtgui_dc_fill_rect(dc,&item_rect);
		rtgui_dc_draw_text(dc, item->name, &item_rect);
	}
	/* draw current item */
	item_rect = rect;
	item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y1 += ((fview->now_item-fview->first_item) % fview->item_per_page) * (1 + RTGUI_SEL_H);
	item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

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

	item = &(fview->items[fview->now_item]);
	if(item->type == RTGUI_FITEM_FILE) /* draw item image */
		rtgui_image_paste(file_image, dc, &image_rect, Black);
	else
		rtgui_image_paste(folder_image, dc, &image_rect, Black);

	if(fview->dlg != RT_NULL)
	{
		if(fview->dlg->filename != RT_NULL)
		{
			rt_free(fview->dlg->filename);
			fview->dlg->filename = RT_NULL;
		}
		fview->dlg->filename = rt_strdup(item->name);
	}

	item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
	item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);

	{
		if(RTGUI_WIDGET_IS_FOCUSED(fview))
		{
			RTGUI_DC_BC(dc) = DarkBlue;
			RTGUI_DC_FC(dc) = theme.blankspace;
		}
		else
		{
			RTGUI_DC_BC(dc) = Gray;
			RTGUI_DC_FC(dc) = theme.foreground;
		}
		rtgui_dc_fill_rect(dc, &item_rect);
		rtgui_dc_draw_text(dc, item->name, &item_rect);
	}

	if(fview->dlg != RT_NULL)
	{
		if(item->type == RTGUI_FITEM_FILE)
		{
			if(fview->dlg->tbox_filename != RT_NULL)
			{
				rtgui_textbox_set_value(fview->dlg->tbox_filename,fview->dlg->filename);
				RTGUI_DC_FC(dc) = theme.foreground;
				rtgui_textbox_ondraw(fview->dlg->tbox_filename);
			}
		}
	}

	rtgui_dc_end_drawing(dc);
}
Пример #3
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;
}
void rtgui_theme_draw_scrollbar(struct rtgui_scrollbar* bar)
{
	/* draw scroll bar */
	struct rtgui_dc* dc;
	rtgui_rect_t rect, btn_rect, thum_rect, arrow_rect;
	rtgui_color_t bc, fc;

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(&(bar->parent));
	if (dc == RT_NULL) return;

	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);

	/* draw background */
	fc = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar));
	if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
		RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(128, 128, 128);

	bc = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar));
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)) = white;
	rtgui_dc_fill_rect(dc, &rect);

	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)) = bc;

	if (bar->orient == RTGUI_VERTICAL)
	{
		btn_rect = rect;
		btn_rect.y2 = btn_rect.y1 + (rect.x2 - rect.x1);

		/* draw up button */
		rtgui_dc_fill_rect(dc, &btn_rect);
		if (bar->status & SBS_UPARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);

		/* draw arrow */
		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
		arrow_rect.x2 = 7; arrow_rect.y2 = 4;
		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
			rtgui_rect_height(arrow_rect), _up_arrow);

		/* draw thumb */
		if (RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
		{
			rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
			rtgui_dc_fill_rect(dc, &thum_rect);
			rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
		}

		/* draw down button */
		btn_rect.y1 = rect.y2 - (rect.x2 - rect.x1);
		btn_rect.y2 = rect.y2;

		rtgui_dc_fill_rect(dc, &btn_rect);
		if (bar->status & SBS_DOWNARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);

		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
		arrow_rect.x2 = 7; arrow_rect.y2 = 4;
		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
			rtgui_rect_height(arrow_rect), _down_arrow);
	}
	else
	{
		btn_rect.x1 = rect.x1;
		btn_rect.y1 = rect.y1;
		btn_rect.x2 = rect.y2;
		btn_rect.y2 = rect.y2;

		/* draw left button */
		rtgui_dc_fill_rect(dc, &btn_rect);
		if (bar->status & SBS_LEFTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);

		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
		arrow_rect.x2 = 4; arrow_rect.y2 = 7;
		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
			rtgui_rect_height(arrow_rect), _left_arrow);

		/* draw thumb */
		if (RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
		{
			rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
			rtgui_dc_fill_rect(dc, &thum_rect);
			rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
		}

		btn_rect.x1 = rect.x2 - rect.y2;
		btn_rect.x2 = rect.x2;

		/* draw right button */
		rtgui_dc_fill_rect(dc, &btn_rect);
		if (bar->status & SBS_RIGHTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);

		arrow_rect.x1 = 0; arrow_rect.y1 = 0;
		arrow_rect.x2 = 4; arrow_rect.y2 = 7;
		rtgui_rect_moveto_align(&btn_rect, &arrow_rect, 
			RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, 
			rtgui_rect_height(arrow_rect), _right_arrow);
	}

	/* end drawing */
	rtgui_dc_end_drawing(dc);
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = fc;

	return;
}
Пример #5
0
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);
}
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);
}
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);
}
Пример #8
0
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);
}
Пример #9
0
/*
 * 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);
}
Пример #10
0
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;
}
Пример #11
0
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);
}
Пример #12
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);
}
Пример #13
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);
}
Пример #14
0
rt_bool_t rtgui_digtube_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
	struct rtgui_digtube *digtube;
    struct rtgui_dc *dc;
    rtgui_rect_t rect;
    rtgui_rect_t text_rect;
	rtgui_color_t color = 0;
	char * disbuf;
	char tempbuf[8];
	int i;

	RTGUI_WIDGET_EVENT_HANDLER_PREPARE

	digtube = RTGUI_DIGTUBE(object);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:

	    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(object));
		if (dc == RT_NULL)
			break;
		rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
		rtgui_dc_fill_rect(dc, &rect);

		if (! (digtube->tube_style & RTGUI_DIGTUBE_STYLE_NOBACKFONT))
		{
			color = RTGUI_DC_BC(dc);
			RTGUI_DC_BC(dc) = digtube->digit_bc;
		}
		
		if (digtube->tube_style & RTGUI_DIGTUBE_STYLE_DISCODES)
			disbuf = (char *) (digtube->value);
		else
		{
			const char * format =  
				digtube->tube_style & RTGUI_DIGTUBE_STYLE_DISHEXNUM ? 
				"%7x" : "%7d";

			disbuf = &tempbuf[0];
			rt_snprintf(disbuf, 8, format, digtube->value);
			
			/* */
			for (i=0; i<7; i++)
			{
				if (disbuf[i] == ' ')
					disbuf[i] = 0;
				else
				{
					disbuf[i] = (disbuf[i] >= '0' && disbuf[i] <= '9') ? disbuf[i] - '0':
						disbuf[i] - 'a' + 10;

					disbuf[i] = digtube_code_table[disbuf[i]];
				}
			}

			disbuf = tempbuf + 7 - digtube->tube_count;
		}

		text_rect.x1 = 0;
		text_rect.y1 = 0;
		text_rect.x2 = (digtube->digit_width + digtube->digit_space) * digtube->tube_count
		                -digtube->digit_space;
		text_rect.y2 = digtube->digit_hight;

		rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_DC_TEXTALIGN(dc));
		for (i=0; i<digtube->tube_count; i++)
		{
			rtgui_dc_draw_digitfont_code(dc, &digtube->digitfont, &text_rect, disbuf[i]);
			text_rect.x1 += digtube->digit_width + digtube->digit_space;
		}

		if (! (digtube->tube_style & RTGUI_DIGTUBE_STYLE_NOBACKFONT))
			RTGUI_DC_BC(dc) = color;
		rtgui_dc_end_drawing(dc);
		break;
	default:
		return rtgui_widget_event_handler(object, event);
	}

	return RT_FALSE;
}
Пример #15
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);
}
Пример #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
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;
}
Пример #18
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);
}
Пример #19
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);
}
Пример #20
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);
}
Пример #21
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;
}
Пример #22
0
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);
}
Пример #23
0
void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar)
{
	/* draw progress bar */
	struct rtgui_dc* dc;
	struct rtgui_rect rect;
    int max = bar->range;
    int pos = bar->position;
    int left;
	rtgui_color_t bc;

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(&(bar->parent));
	if (dc == RT_NULL) return;

	bc = RTGUI_DC_BC(dc);
	rtgui_widget_get_rect(&(bar->parent), &rect);

	/* fill button rect with background color */
	bar->parent.gc.background = RTGUI_RGB(212, 208, 200);

    /* draw border */
	rect.x2 --; rect.y2 --;
	rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);

	/* Nothing to draw */
    if (max == 0)
    {
        rtgui_dc_end_drawing(dc);
        return;
    }

	rect.x2 ++; rect.y2 ++;
    left = max - pos;
	rtgui_rect_inflate(&rect, -2);
    bar->parent.gc.background = RTGUI_RGB(0, 0, 255);

    if (bar->orient == RTGUI_VERTICAL)
    {
        /* Vertical bar grows from bottom to top */
        int dy = (rtgui_rect_height(rect) * left) / max;
        rect.y1 += dy;
        rtgui_dc_fill_rect(dc, &rect);

		RTGUI_DC_BC(dc) = bc;
		rect.y1 -= dy; rect.y2 = dy;
		rtgui_dc_fill_rect(dc, &rect);
    }
    else
    {
        /* Horizontal bar grows from left to right */
		int dx = (rtgui_rect_width(rect) * left) / max;
        rect.x2 -= dx;
        rtgui_dc_fill_rect(dc, &rect);

		RTGUI_DC_BC(dc) = bc;
		rect.x1 = rect.x2; rect.x2 += dx;
		rtgui_dc_fill_rect(dc, &rect);
	}

	/* end drawing */
	rtgui_dc_end_drawing(dc);
	return;
}
Пример #24
0
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);
}
Пример #25
0
void rtgui_fileview_ondraw(rtgui_fileview_t* fview)
{
	rt_uint16_t first, i,rx2;
	rtgui_fileview_item_t* item;
	rtgui_rect_t rect, item_rect, image_rect;
	rtgui_dc_t* dc;

	RT_ASSERT(fview != RT_NULL);

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

	rtgui_widget_get_rect(fview, &rect);
	rtgui_dc_draw_border(dc, &rect,RTGUI_WIDGET_BORDER_STYLE(fview));
	rtgui_rect_inflate(&rect,-RTGUI_WIDGET_BORDER_SIZE(fview));
	RTGUI_DC_BC(dc) = theme.blankspace;
	rtgui_dc_fill_rect(dc,&rect);
	rtgui_rect_inflate(&rect,RTGUI_WIDGET_BORDER_SIZE(fview));
	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
		rect.x2 -= RC_W(fview->sbar->parent.extent);

	rect.x2 -=1;
	rect.y2 -= 1;

	/* get item base rect */
	item_rect = rect;
	item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
	rx2 = item_rect.x2;
	item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
	item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);

	/* get image base rect */
	image_rect.x1 = RTGUI_MARGIN;
	image_rect.y1 = 0;
	image_rect.x2 = RTGUI_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 */
	first = fview->first_item;
	for(i = 0; i < fview->item_per_page; i ++)
	{
		char str_size[32];

		if(first + i >= fview->item_count) break;

		item = &(fview->items[first + i]);

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

		/* draw text */
		item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);
		if(first + i == fview->now_item)
		{
			if(RTGUI_WIDGET_IS_FOCUSED(fview))
			{
				RTGUI_DC_BC(dc) = DarkBlue;
				RTGUI_DC_FC(dc) = theme.blankspace;
			}
			else
			{
				RTGUI_DC_BC(dc) = Gray;
				RTGUI_DC_FC(dc) = theme.foreground;
			}
			rtgui_dc_fill_rect(dc, &item_rect);
			rtgui_dc_draw_text(dc, item->name, &item_rect);
		}
		else
		{
			/* draw background */
			RTGUI_DC_BC(dc) = theme.blankspace;
			RTGUI_DC_FC(dc) = theme.foreground;
			rtgui_dc_fill_rect(dc,&item_rect);
			rtgui_dc_draw_text(dc, item->name, &item_rect);
		}

#if (1) /* please turn off it when need. */
		if(item->type == RTGUI_FITEM_FILE)
		{
			rtgui_rect_t rect=item_rect;
			/* print file information */
			rt_snprintf(str_size, 16, "(%dB)",item->size);
			rect.x1 = rect.x2 + RTGUI_MARGIN;
			rect.x2 = rect.x1 + rt_strlen(str_size) * FONT_W(RTGUI_WIDGET_FONT(fview));
			RTGUI_DC_FC(dc) = theme.foreground;
			rtgui_dc_draw_text(dc, str_size, &rect);
		}
#endif
		item_rect.x1 -= RTGUI_MARGIN + file_image->w + 2;
		item_rect.x2 = rx2;
		/* move to next item position */
		item_rect.y1 += (RTGUI_SEL_H + 1);
		item_rect.y2 += (RTGUI_SEL_H + 1);

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

	if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
	{
		rtgui_scrollbar_ondraw(fview->sbar);
	}

	rtgui_dc_end_drawing(dc);
}
/*
 * container的事件处理函数
 */
rt_bool_t instrument_panel_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
    struct rtgui_widget *widget = RTGUI_WIDGET(object);
    char ac[4];
    int i;
    int x0 = 120;
    int y0 = 170;
    int x, y;
    int default_color;

    /* 仅对PAINT事件进行处理 */
    if (event->type == RTGUI_EVENT_PAINT)
    {
        struct rtgui_dc *dc;
        rtgui_rect_t rect;
        const int arrowx[] = {120 + 75, 120 + 75, 120 + 85};
        const int arrowy[] = {170 - 5,  170 + 5,  170};

        /*
         * 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container
         * 先绘图
         */
        rtgui_container_event_handler(RTGUI_OBJECT(widget), event);

        /************************************************************************/
        /* 下面的是DC的操作                                                     */
        /************************************************************************/

        /* 获得控件所属的DC */
        dc = rtgui_dc_begin_drawing(widget);
        /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
        if (dc == RT_NULL)
            return RT_FALSE;

        /* 获得demo container允许绘图的区域 */
        demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);

        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
        /* 显示GUI的版本信息 */
#ifdef RTGUI_USING_SMALL_SIZE
        rtgui_dc_draw_text(dc, "RT-Thread/GUI小型版本", &rect);
#else
        rtgui_dc_draw_text(dc, "RT-Thread/GUI标准版本", &rect);
#endif


        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_CENTER_VERTICAL | RTGUI_ALIGN_CENTER_HORIZONTAL;
        RTGUI_DC_FC(dc) = blue;
        rect.y2 = 270;
        rtgui_dc_draw_text(dc, "rtgui-panel", &rect);

        for (i = 0; i < 6; i++)
        {
            rtgui_dc_draw_arc(dc, x0, y0, 117 - i, 150, 30);
        }

        RTGUI_DC_FC(dc) = black;

        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_LEFT;
        for (i = 0; i <= 23; i++)
        {
            if (i < 12)
            {
                x = x0 + 105 * cos((150 + i * 10) * 3.1415926 / 180);
                y = y0 + 105 * sin((150 + i * 10) * 3.1415926 / 180);
                rect.x1 = x;
                rect.y1 = y;
                rect.x2 = rect.x1 + 12 * 3;
                rect.y2 = rect.y1 + 12;
                rt_sprintf(ac, "%d", 10 * i);
                rtgui_dc_draw_text(dc, ac, &rect);
            }
            else
            {
                RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_RIGHT;

                x = x0 + 105 * cos((160 + i * 10) * 3.1415926 / 180);
                y = y0 + 105 * sin((160 + i * 10) * 3.1415926 / 180);

                rect.x1 = x  - 12 * 3;
                rect.y1 = y;
                rect.x2 = rect.x1 + 12 * 3;
                rect.y2 = rect.y1 + 12;
                rt_sprintf(ac, "%d", 10 * i);
                rtgui_dc_draw_text(dc, ac, &rect);
            }

            x = x0 + 107 * cos((150 + i * 10) * 3.1415926 / 180);
            y = y0 + 107 * sin((150 + i * 10) * 3.1415926 / 180);
            rtgui_dc_fill_circle(dc, x, y, 3);
        }
        RTGUI_DC_FC(dc) = RTGUI_RGB(166, 0, 166);
        rtgui_dc_fill_circle(dc, x0, y0, 3);
        RTGUI_DC_FC(dc) = RTGUI_RGB(120, 141, 30);
        rtgui_dc_draw_circle(dc, x0, y0, 5);

        default_color = RTGUI_DC_BC(dc);
        RTGUI_DC_BC(dc) = red;
        rect.x1 = x0 + 7;
        rect.y1 = y0 - 1;
        rect.x2 = x0 + 75;
        rect.y2 = y0 + 1;
        rtgui_dc_fill_rect(dc, &rect);

        RTGUI_DC_BC(dc) = default_color;

        rtgui_dc_fill_polygon(dc, arrowx, arrowy, 3);

        /* 绘图完成 */
        rtgui_dc_end_drawing(dc);
    }
    else
    {
        /* 其他事件,调用默认的事件处理函数 */
        return rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
    }

    return RT_FALSE;
}
Пример #27
0
rt_bool_t demo_bitmap_showbox(struct rtgui_object* object, struct rtgui_event* event)
{
	rtgui_container_t *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);
}
Пример #28
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);
}
Пример #29
0
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);
}
Пример #30
0
/*
 * view的事件处理函数
 */
rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
{
	/* 仅对PAINT事件进行处理 */
	if (event->type == RTGUI_EVENT_PAINT) {
		struct rtgui_dc* dc;
		rtgui_rect_t rect;
		/*		const int vx[] = {20, 50, 60, 45, 60, 20};
				const int vy[] = {150, 50, 90, 60, 45, 50};
		*/
		/*
		 * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view
		 * 先绘图
		 */
		rtgui_view_event_handler(widget, event);

		/************************************************************************/
		/* 下面的是DC的操作                                                     */
		/************************************************************************/

		/* 获得控件所属的DC */
		dc = rtgui_dc_begin_drawing(widget);
		/* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
		if (dc == RT_NULL)
			return RT_FALSE;

		/* 获得demo view允许绘图的区域 */
		demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect);

		RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
		/* 显示GUI的版本信息 */
#ifdef RTGUI_USING_SMALL_SIZE
		rtgui_dc_draw_text(dc, "RT-Thread/GUI小型版本", &rect);
#else
		rtgui_dc_draw_text(dc, "RT-Thread/GUI标准版本", &rect);
#endif

		{
			rtgui_rect_t rect = {0, 0, 0x1c, 0x16};
			rtgui_rect_moveto(&rect, 80, 80);
			rtgui_image_blit((rtgui_image_t*)&play_image, dc, &rect);

			rect.x1 = 0;
			rect.y1 = 0;
			rect.x2 = 0x1c;
			rect.y2 = 0x16;
			rtgui_rect_moveto(&rect, 130, 80);
			rtgui_image_blit((rtgui_image_t*)&stop_image, dc, &rect);
		}
		/* 绘制一个圆形 */
		RTGUI_DC_FC(dc) = red;
		rtgui_dc_draw_circle(dc, rect.x1 + 10, rect.y1 + 10, 10);

		/* 填充一个圆形 */
		RTGUI_DC_FC(dc) = green;
		rtgui_dc_fill_circle(dc, rect.x1 + 30, rect.y1 + 10, 10);
#if 0
		/* 画一个圆角矩形 */
		rect.x1 = 150;
		rect.y1 = 180;
		rect.x2 = 210;
		rect.y2 = 260;
		RTGUI_DC_FC(dc) = RTGUI_RGB(25, 70, 150);
		rtgui_dc_draw_round_rect(dc, &rect, 10);

		rect.x1 = 160;
		rect.y1 = 190;
		rect.x2 = 200;
		rect.y2 = 250;
		RTGUI_DC_FC(dc) = RTGUI_RGB(170, 7, 80);
		rtgui_dc_fill_round_rect(dc, &rect, 7);

		/* 画一个圆弧 */
		RTGUI_DC_FC(dc) = RTGUI_RGB(250, 120, 120);
		rtgui_dc_draw_arc(dc, rect.x1 + 120, rect.y1 + 60, 30, 0, 120);

		/* 画一个扇形圆环 */
		RTGUI_DC_FC(dc) = RTGUI_RGB(150, 23, 100);
		rtgui_dc_draw_annulus(dc, 180, 170, 30, 50, 210, 330);

		/* 多边形 */
		RTGUI_DC_FC(dc) = blue;
		rtgui_dc_draw_polygon(dc, vx, vy, 6);

#endif
		RTGUI_DC_FC(dc) = blue;

		/* 绘制不同的边框 */
		{
			rtgui_rect_t rect = {0, 0, 16, 16};
			rtgui_rect_moveto(&rect, 30, 120);

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "raise", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SIMPLE);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "simple", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "sunken", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "box", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_STATIC);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "static", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;

			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_EXTRA);
			rect.x1 += 20;
			rect.x2 += 20 + 50;
			rtgui_dc_draw_text(dc, "extera", &rect);
			rect.x1 -= 20;
			rect.x2 -= 20 + 50;
			rect.y1 += 20;
			rect.y2 += 20;
		}

		/* 绘图完成 */
		rtgui_dc_end_drawing(dc);
	} else {
		/* 其他事件,调用默认的事件处理函数 */
		return rtgui_view_event_handler(widget, event);
	}

	return RT_FALSE;
}