Example #1
0
struct rtgui_radiobox *rtgui_radiobox_create(const char *label, int orient, char **radio_items, int number)
{
    struct rtgui_radiobox *radiobox;

    radiobox = (struct rtgui_radiobox *) rtgui_widget_create(RTGUI_RADIOBOX_TYPE);
    if (radiobox != RT_NULL)
    {
        rt_uint8_t board_size;
        struct rtgui_rect rect;

        radiobox->items = radio_items;
        radiobox->item_count = number;
        radiobox->item_selection = -1;
        radiobox->text = rt_strdup(label);

        /* set proper of control */
        rtgui_radiobox_set_orientation(radiobox, orient);
        rtgui_font_get_metrics(RTGUI_WIDGET_FONT(radiobox), "H", &rect);
        board_size = rtgui_rect_height(rect);

        if (orient == RTGUI_VERTICAL)
        {
            radiobox->item_size = board_size;
        }
        else
        {
            int index;
            struct rtgui_font *font;
            struct rtgui_rect rect;

            /* set init item size */
            radiobox->item_size = 0;

            font = RTGUI_WIDGET_FONT(radiobox);
            for (index = 0; index < number; index ++)
            {
                rtgui_font_get_metrics(font, radio_items[index], &rect);
                if ((board_size + 3 + rtgui_rect_width(rect)) > radiobox->item_size)
                    radiobox->item_size = board_size + 3 + rtgui_rect_width(rect);
            }
        }

        if (radiobox->item_size < RADIO_BOX_H + 2)
            radiobox->item_size = RADIO_BOX_H + 2;
    }

    return radiobox;
}
Example #2
0
struct rtgui_checkbox* rtgui_checkbox_create(const char* text, rt_bool_t checked)
{
    struct rtgui_checkbox* box;

    box = (struct rtgui_checkbox*) rtgui_widget_create (RTGUI_CHECKBOX_TYPE);
    if (box != RT_NULL)
    {
		rtgui_rect_t rect;

		/* set default rect */
		rtgui_font_get_metrics(rtgui_font_default(), text, &rect);
		rect.x2 += RTGUI_BORDER_DEFAULT_WIDTH + 5 + (RTGUI_BORDER_DEFAULT_WIDTH << 1);
		rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1);

		rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);
		rtgui_label_set_text(RTGUI_LABEL(box), text);
		
		if (checked == RT_TRUE)
			box->status_down = RTGUI_CHECKBOX_STATUS_CHECKED;
		else
			box->status_down = RTGUI_CHECKBOX_STATUS_UNCHECKED;
	}

	return box;
}
Example #3
0
static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
{
	rtgui_rect_t rect;

	RTGUI_WIDGET_FLAG(RTGUI_WIDGET(box)) |= RTGUI_WIDGET_FLAG_FOCUSABLE;

	rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_textbox_event_handler);
	rtgui_widget_set_onfocus(RTGUI_WIDGET(box), rtgui_textbox_onfocus);
	rtgui_widget_set_onunfocus(RTGUI_WIDGET(box), rtgui_textbox_onunfocus);
#ifndef RTGUI_USING_SMALL_SIZE
	rtgui_widget_set_onkey(RTGUI_WIDGET(box), rtgui_textbox_onkey);
#endif

	RTGUI_WIDGET_FOREGROUND(box) = black;
	RTGUI_WIDGET_BACKGROUND(box) = white;
	/* set default text align */
	RTGUI_WIDGET_TEXTALIGN(box) = RTGUI_ALIGN_CENTER_VERTICAL;
	/* set proper of control */
	box->caret_timer = RT_NULL;
	box->caret = RT_NULL;

	box->line = box->line_begin = box->position = 0;
	box->flag = RTGUI_TEXTBOX_SINGLE;
	/* allocate default line buffer */
	box->text = RT_NULL;
	rtgui_textbox_set_mask_char(box, '*');

	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(box), "H", &rect);
	box->font_width = rtgui_rect_width(rect);
	box->on_enter = RT_NULL;
	box->dis_length = 0;
	box->first_pos = 0;
}
Example #4
0
static void rtgui_list_view_calc(struct rtgui_list_view* view)
{
	/* get image of first item*/
	rtgui_image_t *image;
	rtgui_rect_t rect;
	rt_ubase_t text_width, text_height;
	rt_ubase_t item_width, item_height;

	if (view->items_count == 0) return;

	image = view->items[0].image;
	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), "HHHHHH", &rect);

	text_height = rtgui_rect_height(rect);
	text_width = rtgui_rect_width(rect);

	rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

	item_width = (image->w + LIST_MARGIN);
	if (item_width < (text_width + LIST_MARGIN)) item_width = text_width + LIST_MARGIN;
	item_height = image->h + 3 + text_height + LIST_MARGIN; 

	view->row_items = (rtgui_rect_height(rect) - 2 * LIST_MARGIN) / item_height;
	view->col_items = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / item_width;
	view->page_items = view->row_items * view->col_items;
}
Example #5
0
static void rtgui_list_view_calc(struct rtgui_list_view* view)
{
    rtgui_rect_t rect;
    rt_uint32_t image_width, image_height;
    rt_ubase_t text_width, text_height;
    rt_ubase_t item_width, item_height;

    if (view->items_count == 0) return;

    /* get image width and height */
    if (view->items[0].image != RT_NULL) {
        image_width  = view->items[0].image->w;
        image_height = view->items[0].image->h;
    } else {
        image_width  = 0;
        image_height = 0;
    }

    rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), "HHHHHH", &rect);

    text_height = rtgui_rect_height(rect);
    text_width = rtgui_rect_width(rect);

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

    item_width = (image_width + LIST_MARGIN);
    if (item_width < (text_width + LIST_MARGIN)) item_width = text_width + LIST_MARGIN;
    item_height = image_height + 8 + text_height + LIST_MARGIN;
    if (item_width > item_height) item_height = item_width;
    else item_width = item_height;

    view->row_items = (rtgui_rect_height(rect) - 2 * LIST_MARGIN) / item_height;
    view->col_items = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / item_width;
    view->page_items = view->row_items * view->col_items;
}
static void _draw_textview(rtgui_textview_t *textview)
{
	struct rtgui_dc* dc;
	struct rtgui_rect rect, font_rect;
	char* line;
	rt_ubase_t line_index, item_height;

	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(textview)), "W", &font_rect);
	item_height = rtgui_rect_height(font_rect) + 3;

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

	/* fill rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(textview), &rect);
	rtgui_dc_fill_rect(dc, &rect);

	rect.x1 += 3;
	rect.x2 -= 3;

	for (line_index = textview->line_current; 
		(line_index < textview->line_current + textview->line_page_count) &&
		(line_index < textview->line_count); 
		line_index ++)
	{
		line = (char* )_get_line_text(textview, line_index);
		rtgui_dc_draw_text(dc, line, &rect);

		rect.y1 += item_height;
	}

	rtgui_dc_end_drawing(dc);
}
Example #7
0
static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
{
	rtgui_rect_t rect = {0, 0, RTGUI_TEXTBOX_DEFAULT_WIDTH, RTGUI_TEXTBOX_DEFAULT_HEIGHT};
	rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);

	RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
	rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_textbox_event_handler);
	rtgui_widget_set_onfocus(RTGUI_WIDGET(box), rtgui_textbox_onfocus);
	rtgui_widget_set_onunfocus(RTGUI_WIDGET(box), rtgui_textbox_onunfocus);

	/* set default text align */
	RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(box)) = RTGUI_ALIGN_CENTER_VERTICAL;

	/* set proper of control */
	box->caret_timer = rtgui_timer_create(RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC, 
		_rtgui_textbox_caret_timeout, box);

	box->line = box->line_begin = box->position = 0;
	box->flag = RTGUI_TEXTBOX_SINGLE;

	/* allocate default line buffer */
	box->text = RT_NULL;

	rtgui_font_get_metrics(RTGUI_WIDGET(box)->gc.font, "h", &rect);
	box->font_width = rtgui_rect_width(rect);
}
rtgui_view_t *demo_view_buffer_animation(rtgui_workbench_t* workbench)
{
	rtgui_view_t *view;

	view = demo_view(workbench, "DC 缓冲区动画");
	if (view != RT_NULL)
		rtgui_widget_set_event_handler(RTGUI_WIDGET(view), animation_event_handler);

	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), "缓冲动画", &text_rect);
	if (dc_buffer == RT_NULL)
	{
		rtgui_rect_t rect;

		rect.x1 = 0; rect.x2 = rtgui_rect_width(text_rect) + 2;
		rect.y1 = 0; rect.y2 = rtgui_rect_height(text_rect) + 2;

		/* 创建 DC Buffer,长 50,宽 50 */
		dc_buffer = rtgui_dc_buffer_create(rtgui_rect_width(rect), rtgui_rect_height(rect));
		RTGUI_DC_FC(dc_buffer) = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view));
		rtgui_dc_fill_rect(dc_buffer, &rect);
		RTGUI_DC_FC(dc_buffer) = black;
		rect.x1 = 1; rect.y1 = 1;
		rtgui_dc_draw_text(dc_buffer, "缓冲动画", &rect);
	}

	/* 启动定时器以触发动画 */
	timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, (void*)view);
	rtgui_timer_start(timer);

	return view;
}
Example #9
0
static void rtgui_list_view_onicondraw(struct rtgui_list_view *view, struct rtgui_dc *dc)
{
    struct rtgui_rect rect, item_rect, drawing_rect;
    rt_ubase_t c, r, item_index; /* col and row index */
    rt_ubase_t item_width, item_height;
    rtgui_image_t *image;

    if (view->items_count == 0) return;

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
    item_index = (view->current_item / view->page_items) * view->page_items;

    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;

    for (r = 0; r < view->row_items; r ++)
    {
        for (c = 0; c < view->col_items; c ++)
        {
            if (item_index < view->items_count)
            {
                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;

                if (item_index == view->current_item)
                {
                    rtgui_theme_draw_selected(dc, &item_rect);
                }

                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[item_index].image, dc, &drawing_rect);

                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[item_index].name,
                                       &drawing_rect);
                rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
                rtgui_dc_draw_text(dc, view->items[item_index].name, &drawing_rect);

                item_index ++;
            }
            else break;
        }
    }
}
static void _calc_width(rtgui_textview_t *textview)
{
	rtgui_rect_t rect;
	rt_uint16_t width, height;

	width = rtgui_rect_width(RTGUI_WIDGET(textview)->extent) - 6;
	height = rtgui_rect_height(RTGUI_WIDGET(textview)->extent);

	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(textview)), "W", &rect);
	textview->line_width = width / rtgui_rect_width(rect) + 1;
	textview->line_page_count = height / (rtgui_rect_height(rect) + 3);

	/* set minimal value */
	if (textview->line_page_count == 0) textview->line_page_count = 1;
}
Example #11
0
static void rtgui_radiobox_onmouse(struct rtgui_radiobox *radiobox, struct rtgui_event_mouse *event)
{
    RT_ASSERT(radiobox != RT_NULL);
    RT_ASSERT(event  != RT_NULL);

    /* widget is hide, return */
    if (RTGUI_WIDGET_IS_HIDE(radiobox) ||
            !RTGUI_WIDGET_IS_ENABLE(radiobox)) return;

    if (event->button & RTGUI_MOUSE_BUTTON_DOWN &&
            event->button & RTGUI_MOUSE_BUTTON_LEFT)
    {
        int bord_size;
        struct rtgui_rect rect;

        /* focus widgets */
        rtgui_widget_focus(RTGUI_WIDGET(radiobox));

        /* get widget physical rect */
        rtgui_widget_get_rect(RTGUI_WIDGET(radiobox), &rect);
        rtgui_widget_rect_to_device(RTGUI_WIDGET(radiobox), &rect);

        /* get board size */
        if (radiobox->orient == RTGUI_VERTICAL)
            bord_size = radiobox->item_size;
        else
        {
            struct rtgui_rect bord_rect;

            rtgui_font_get_metrics(RTGUI_WIDGET_FONT(radiobox), "H", &bord_rect);
            bord_size = rtgui_rect_height(bord_rect);
        }
        rtgui_rect_inflate(&rect, - bord_size);
        if (rtgui_rect_contains_point(&rect, event->x, event->y) != RT_EOK) return;

        if (radiobox->orient == RTGUI_VERTICAL)
        {
            int delta_y = event->y - rect.y1;
            rtgui_radiobox_set_selection(radiobox, delta_y / radiobox->item_size);
        }
        else
        {
            int delta_x = event->x - rect.x1;
            rtgui_radiobox_set_selection(radiobox, delta_x / radiobox->item_size);
        }
    }
}
Example #12
0
File: edit.c Project: amsl/RTGUI
void _rtgui_edit_constructor(struct rtgui_edit *edit)
{
	rtgui_rect_t font_rect;
	RTGUI_WIDGET_FLAG(edit) |= RTGUI_WIDGET_FLAG_FOCUSABLE;

	rtgui_widget_set_event_handler(edit, rtgui_edit_event_handler);
	rtgui_widget_set_onfocus(edit, rtgui_edit_onfocus);
	rtgui_widget_set_onunfocus(edit, rtgui_edit_onunfocus);
	
	RTGUI_WIDGET_FC(edit) = theme.foreground;
	RTGUI_WIDGET_BC(edit) = theme.blankspace;
	/* set default text align */
	RTGUI_WIDGET_TEXTALIGN(edit) = RTGUI_ALIGN_CENTER_VERTICAL;
	/* set proper of control */
	edit->caret_timer = RT_NULL;
	edit->caret = RT_NULL;

	edit->tabsize = 4;
	edit->margin  = 1;
	edit->max_rows = edit->max_cols = 0;
	edit->visual.x = edit->visual.y = 0;
	edit->upleft.x = edit->upleft.y = 0;
	edit->row_per_page = edit->col_per_page = 0;

	edit->update_buf = RT_NULL;
	edit->flag = RTGUI_EDIT_NONE;
#ifdef RTGUI_EDIT_USING_SCROLL
	edit->flag |= RTGUI_EDIT_VSCROLL;
	edit->flag |= RTGUI_EDIT_HSCROLL;
#endif
	/* allocate default line buffer */
	edit->bzsize = 16;
	
	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(edit), "H", &font_rect);
	edit->font_width = rtgui_rect_width(font_rect);
	edit->font_height = rtgui_rect_height(font_rect);

	edit->dbl_buf = rtgui_dc_buffer_create(edit->font_width*2+1, edit->font_height+1);
	
	edit->head = RT_NULL;
	edit->tail = RT_NULL;
	edit->first_line = RT_NULL;
#ifdef RTGUI_EDIT_USING_SCROLL	
	edit->hscroll = RT_NULL;
	edit->vscroll = RT_NULL;
#endif
}
struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image,
	const char* text,
	int position)
{
    struct rtgui_iconbox* iconbox;

	iconbox = (struct rtgui_iconbox*)rtgui_widget_create(RTGUI_ICONBOX_TYPE);
    if (iconbox != RT_NULL)
    {
		rtgui_rect_t rect = {0, 0, 0, 0}, text_rect;

		rect.x2 = image->w;
		rect.y2 = image->h;

		/* get text rect */
		rtgui_font_get_metrics(rtgui_font_default(), text, &text_rect);
		if (position == RTGUI_ICONBOX_TEXT_BELOW)
		{
			rect.y2 += RTGUI_WIDGET_DEFAULT_MARGIN;
			if (text_rect.x2 > rect.x2)
			{
				rect.x2 = text_rect.x2;
			}
			rect.y2 += text_rect.y2;
		}
		else if (position == RTGUI_ICONBOX_TEXT_RIGHT)
		{
			rect.x2 += RTGUI_WIDGET_DEFAULT_MARGIN;
			if (text_rect.y2 > rect.y2)
			{
				rect.y2 = text_rect.y2;
			}
			rect.x2 += text_rect.x2;
		}

		/* set widget rect */
		rtgui_widget_set_rect(RTGUI_WIDGET(iconbox), &rect);

		/* set image and text position */
		iconbox->image = image;
		iconbox->text = (char*)rt_strdup((const char*)text);
		iconbox->text_position = position;
	}

	return iconbox;
}
Example #14
0
struct rtgui_textbox* rtgui_textbox_create(const char* text, rt_uint8_t flag)
{
    struct rtgui_textbox* box;

    box = (struct rtgui_textbox*) rtgui_widget_create (RTGUI_TEXTBOX_TYPE);
    if (box != RT_NULL)
    {
		rtgui_rect_t rect = {0, 0, RTGUI_TEXTBOX_DEFAULT_WIDTH, RTGUI_TEXTBOX_DEFAULT_HEIGHT};

		/* allocate default line buffer */
		rtgui_textbox_set_value(box, text);
		box->flag = flag;

		rtgui_font_get_metrics(RTGUI_WIDGET(box)->gc.font, "h", &rect);
	}

	return box;
}
Example #15
0
static void rtgui_textbox_get_caret_rect(rtgui_textbox_t *box, rtgui_rect_t *rect, rt_uint16_t position)
{
	int font_h, box_h;
	rtgui_rect_t item_rect;

	RT_ASSERT(box != RT_NULL);

	rtgui_widget_get_rect(RTGUI_WIDGET(box), rect);

	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(box), "H", &item_rect);
	font_h = rtgui_rect_height(item_rect);
	box_h = rtgui_rect_height(*rect);

	rect->x1 += position * box->font_width + 2;
	rect->x2 = rect->x1 + 2;
	rect->y1 += (box_h - font_h) / 2;
	rect->y2 = rect->y1 + font_h;
}
Example #16
0
/* 触发无标题窗口显示 */
static void demo_ntitlewin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
{
	rtgui_win_t *win;
	rtgui_label_t *label;
	rtgui_button_t *button;
	rtgui_toplevel_t *parent;
	rtgui_rect_t widget_rect, rect = {0, 0, 150, 80};

	parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget));
	rtgui_rect_moveto(&rect, delta_x, delta_y);
	delta_x += 20;
	delta_y += 20;

	/* 创建一个窗口,风格为无标题及无边框 */
	win = rtgui_win_create(parent,
		"no title", &rect, RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER);
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win)) = white;

	/* 创建一个文本标签 */
	label = rtgui_label_create("无边框窗口");
	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)), "无边框窗口", &widget_rect);
	rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
	widget_rect.y1 += 20;
	widget_rect.y2 += 20;
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &widget_rect);
	rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(label)) = white;

	/* 创建一个关闭按钮 */
	widget_rect.x1 = 0;
	widget_rect.y1 = 0;
	widget_rect.x2 = 40;
	widget_rect.y2 = 20;
	rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
	widget_rect.y1 += 40;
	widget_rect.y2 += 40;
	button = rtgui_button_create("关闭");
	rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);
	rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(button));
	rtgui_button_set_onbutton(button, window_demo_close);

	/* 非模态显示窗口 */
	rtgui_win_show(win, RT_FALSE);
}
Example #17
0
rtgui_button_t* rtgui_button_create(const char* text)
{
    struct rtgui_button* btn;

    btn = (struct rtgui_button*) rtgui_widget_create (RTGUI_BUTTON_TYPE);
    if (btn != RT_NULL)
    {
		rtgui_rect_t rect;

		/* set default rect */
		rtgui_font_get_metrics(rtgui_font_default(), text, &rect);
		rect.x2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1);
		rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1);
		rtgui_widget_set_rect(RTGUI_WIDGET(btn), &rect);
		rtgui_label_set_text(RTGUI_LABEL(btn), text);
    }

    return btn;
}
void rtgui_iconbox_set_text_position(struct rtgui_iconbox* iconbox, int position)
{
	rtgui_rect_t rect = {0, 0, 0, 0}, text_rect;

	RT_ASSERT(iconbox != RT_NULL);

	iconbox->text_position = position;

	/* set mini width and height */
	rect.x2 = iconbox->image->w;
	rect.y2 = iconbox->image->h;

	/* get text rect */
	if (iconbox->text != RT_NULL)
	{
		rtgui_font_get_metrics(rtgui_font_default(),
			iconbox->text, &text_rect);
		if (position == RTGUI_ICONBOX_TEXT_BELOW)
		{
			rect.y2 += RTGUI_WIDGET_DEFAULT_MARGIN;
			if (text_rect.x2 > rect.x2)
			{
				rect.x2 = text_rect.x2;
			}
			rect.y2 += text_rect.y2;
		}
		else if (position == RTGUI_ICONBOX_TEXT_RIGHT)
		{
			rect.x2 += RTGUI_WIDGET_DEFAULT_MARGIN;
			if (text_rect.y2 > rect.y2)
			{
				rect.y2 = text_rect.y2;
			}
			rect.x2 += text_rect.x2;
		}
	}

#ifndef RTGUI_USING_SMALL_SIZE
	rtgui_widget_set_miniwidth(RTGUI_WIDGET(iconbox), rect.x2);
	rtgui_widget_set_miniheight(RTGUI_WIDGET(iconbox), rect.y2);
#endif
}
Example #19
0
rtgui_label_t* rtgui_label_create(const char* text)
{
    struct rtgui_label* label;

    label = (struct rtgui_label*) rtgui_widget_create(RTGUI_LABEL_TYPE);
    if (label != RT_NULL)
    {
        rtgui_rect_t rect;

        /* set default rect */
        rtgui_font_get_metrics(rtgui_font_default(), text, &rect);
        rect.x2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1);
        rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1);
        rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);

        /* set text */
        label->text = (char*)rt_strdup((const char*)text);
    }

    return label;
}
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);
}
Example #21
0
static void rtgui_list_view_update_icon(struct rtgui_list_view* view, rt_uint16_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 += 3; drawing_rect.y2 += 3;
	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(RTGUI_WIDGET(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(RTGUI_WIDGET(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);
}
Example #22
0
static void app_list_draw(struct app_list_view *view)
{
    struct rtgui_rect item_rect, drawing_rect;
    rt_ubase_t p, c, r, item_index; /* col and row index */
    rt_ubase_t item_width, item_height;
    rtgui_image_t *image;
    rt_uint16_t width, height;

    if (view->items_count == 0)
        return;

    width = rtgui_rect_width(view->view_rect);
    height = rtgui_rect_height(view->view_rect);
    item_index = (view->current_item / view->page_items) * view->page_items;
    item_width = (width - 2 * LIST_MARGIN) / view->col_items;
    item_height = (height - 4) / view->row_items;
    image = view->items[0].icon;
    for (p = 0; p < view->page_count; p++)
    {
        for (r = 0; r < view->row_items; r++)
        {
            for (c = 0; c < view->col_items; c++)
            {
                if (item_index < view->items_count)
                {
                    item_rect.y1 =  r * item_height;
                    item_rect.x1 =  p * width + LIST_MARGIN + c * item_width;
                    item_rect.x2 = item_rect.x1 + item_width;
                    item_rect.y2 = item_rect.y1 + item_height;
                    if (item_index == view->current_item)
                    {
                        //TO DO
                    }
                    if (view->items[item_index].icon)
                    {
                        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[item_index].icon,
                                         view->view_buffer,
                                         &drawing_rect);
                    }
                    if (view->items[item_index].text)
                    {
                        item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
                        item_rect.x1 += 3;
                        item_rect.x2 -= 3;
                        rtgui_font_get_metrics(RTGUI_WIDGET_FONT(win),
                                               view->items[item_index].text,
                                               &drawing_rect);
                        rtgui_rect_moveto_align(&item_rect, &drawing_rect,
                                                RTGUI_ALIGN_CENTER_HORIZONTAL);
                        rtgui_dc_draw_text(view->view_buffer,
                                           view->items[item_index].text,
                                           &drawing_rect);
                    }
                    item_index++;
                }
                else
                    break;
            }
        }
    }
}
Example #23
0
void app_mgr_win_init(void)
{
	struct rtgui_win* win;
	rtgui_rect_t rect;
	struct rtgui_notebook *notebook;
	rtgui_listbox_t* box;
	struct rtgui_image* pressed_image;
	struct rtgui_image* unpressed_image;
	int font_size;
	struct block_panel* block;
	int angle_y;
	
	/* create main window of Application Manager */
	win = rtgui_mainwin_create(RT_NULL, "AppMgr", RTGUI_WIN_STYLE_MAINWIN);
	RTGUI_WIDGET_BACKGROUND(win) = RTGUI_RGB(241, 241, 241);

	/* create icon image */
	pressed_image = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)home_xpm, sizeof(home_xpm), RT_FALSE);
	unpressed_image = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)home_gray_xpm, sizeof(home_gray_xpm), RT_FALSE);
	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(win), "AppMgr", &rect);
	font_size = rtgui_rect_height(rect);

	/* create notebook */
	rtgui_widget_get_extent(RTGUI_WIDGET(win), &rect);
	notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_LEFT);
	RTGUI_WIDGET_BACKGROUND(notebook) = RTGUI_RGB(241, 241, 241);
	rtgui_notebook_set_tab_height(notebook, pressed_image->h + font_size + 3 * RTGUI_WIDGET_DEFAULT_MARGIN);
	rtgui_notebook_set_tab_width(notebook, 65);
	angle_y = rect.x1;

	/* create navigation */
	rtgui_notebook_get_client_rect(notebook, &rect);
	block = block_panel_create(angle_y + notebook->tab_h/2, &rect);
	RTGUI_WIDGET_BACKGROUND(block) = RTGUI_RGB(241, 241, 241);
	rtgui_notebook_add_image(notebook, "AppTask", RTGUI_WIDGET(block),
		pressed_image, unpressed_image);
	apps_list_create(RTGUI_PANEL(block));
	angle_y += notebook->tab_h;

	block = block_panel_create(angle_y + notebook->tab_h/2, &rect);
	RTGUI_WIDGET_BACKGROUND(block) = RTGUI_RGB(241, 241, 241);
	rtgui_notebook_add_image(notebook, "Tab 1", RTGUI_WIDGET(block),
		pressed_image, unpressed_image);
	{
		struct rtgui_rect box_rect;
		block_panel_get_client_extent(block, &box_rect);
		// rtgui_widget_get_extent(RTGUI_WIDGET(block), &box_rect);
		// rtgui_rect_inflate(&box_rect, -15);
		box = rtgui_listbox_create(items, sizeof(items)/sizeof(struct rtgui_listbox_item), &box_rect);
		rtgui_container_add_child(RTGUI_CONTAINER(block), RTGUI_WIDGET(box));
	}
	angle_y += notebook->tab_h;

	block = block_panel_create(angle_y + notebook->tab_h/2, &rect);
	RTGUI_WIDGET_BACKGROUND(block) = RTGUI_RGB(241, 241, 241);
	rtgui_notebook_add_image(notebook, "Tab 2", RTGUI_WIDGET(block), 
		pressed_image, unpressed_image);
	angle_y += notebook->tab_h;

	rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(notebook));

	rtgui_win_show(win, RT_FALSE);

	/* set as main window */
	rtgui_app_set_main_win(win);
}
Example #24
0
/* Draw tab bars of @param notebook. @param dc should be initialized and
 * finished outside this function. Don't pass @param notebook or @param dc as
 * RT_NULL, it should be checked outside.
 */
static void _rtgui_notebook_draw_bar(struct rtgui_notebook *notebook,
		struct rtgui_dc *dc)
{
	int index;
	struct rtgui_rect rect;
	struct rtgui_rect text_rect;
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
	struct rtgui_image* image = RT_NULL;
	struct rtgui_rect image_rect;
#endif

	RT_ASSERT((notebook != RT_NULL) && (dc != RT_NULL));

	if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
		return;

	_rtgui_notebook_get_bar_rect(notebook, &rect);
	rtgui_dc_fill_rect(dc, &rect);

	if (notebook->flag == RTGUI_NOTEBOOK_TOP ||
		notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
	{
		rect.x2 = rect.x1 + notebook->tab_w;
		/* draw tab bar */
		for (index = 0; index < notebook->count; index++)
		{
			if (notebook->current == index)
			{
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
				if (notebook->childs[index].pressed_image != RT_NULL)
					image = notebook->childs[index].pressed_image;
				else
#endif
				rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
			}
			else
			{
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
				if (notebook->childs[index].unpressed_image != RT_NULL)
					image = notebook->childs[index].unpressed_image;
				else
#endif
					rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
			}

			rtgui_font_get_metrics(RTGUI_WIDGET_FONT(notebook), 
				notebook->childs[index].title, &text_rect);
			rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_ALIGN_CENTER);

#ifdef RTGUI_USING_NOTEBOOK_IMAGE
			if (image != RT_NULL)
			{
				image_rect.x1 = 0;
				image_rect.y1 = RTGUI_WIDGET_DEFAULT_MARGIN;
				image_rect.x2 = image_rect.x1 + image->w;
				image_rect.y2 = image_rect.y1 + image->h;
				rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
				
				rtgui_image_blit(image, dc, &image_rect);
			}
			if (image != RT_NULL)
			{
				int text_height = text_rect.y2 - text_rect.y1;
				
				text_rect.y1 = image_rect.y2 +  RTGUI_WIDGET_DEFAULT_MARGIN;
				text_rect.y2 = text_rect.y1 + text_height;
			}
			image = RT_NULL;
#endif

			rtgui_dc_draw_text(dc, notebook->childs[index].title, &text_rect);

			/* move to next tab */
			rect.x1 = rect.x2;
			rect.x2 = rect.x1 + notebook->tab_w;
		}
	}
	else
	{
		rect.y2 = rect.y1 + notebook->tab_h;
		/* draw tab bar */
		for (index = 0; index < notebook->count; index++)
		{
			if (notebook->current == index)
			{
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
				if (notebook->childs[index].pressed_image != RT_NULL)
					image = notebook->childs[index].pressed_image;
				else
#endif
					rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
			}
			else
			{
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
				if (notebook->childs[index].unpressed_image != RT_NULL)
					image = notebook->childs[index].unpressed_image;
				else
#endif
					rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
			}

			rtgui_font_get_metrics(RTGUI_WIDGET_FONT(notebook), 
				notebook->childs[index].title, &text_rect);
			rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_ALIGN_CENTER);
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
			if (image != RT_NULL)
			{
				image_rect.x1 = 0;
				image_rect.y1 = RTGUI_WIDGET_DEFAULT_MARGIN;
				image_rect.x2 = image->w;
				image_rect.y2 = image_rect.y1 + image->h;
				rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
				
				rtgui_image_blit(image, dc, &image_rect);
			}

			if (image != RT_NULL)
			{
				int text_height = text_rect.y2 - text_rect.y1;
				
				text_rect.y1 = image_rect.y2 +  RTGUI_WIDGET_DEFAULT_MARGIN;
				text_rect.y2 = text_rect.y1 + text_height;
			}
			image = RT_NULL;
#endif
			rtgui_dc_draw_text(dc, notebook->childs[index].title, &text_rect);

			/* move to next tab */
			rect.y1 = rect.y2;
			rect.y2 = rect.y1 + notebook->tab_h;
		}

	}
}
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);
}