Exemplo n.º 1
0
/* 创建用于演示checkbox控件的视图 */
rtgui_view_t* demo_gui_checkbox(rtgui_view_t* parent_view)
{
    rtgui_view_t* view;
    rtgui_checkbox_t* checkbox;
    rtgui_font_t* font;

    /* 先创建一个演示用的视图 */
    view = demo_view_create(parent_view, "CheckBox View");

    /* 创建一个checkbox控件 */
    checkbox = rtgui_checkbox_create(view, "Red", RT_TRUE, 5, 40);
    /* 设置前景色为红色 */
    RTGUI_WIDGET_FOREGROUND(checkbox) = red;

    checkbox = rtgui_checkbox_create(view, "Blue", RT_TRUE, 5, 60);
    RTGUI_WIDGET_FOREGROUND(checkbox) = blue;

    checkbox = rtgui_checkbox_create(view, "12 font", RT_TRUE, 5, 80);
    font = rtgui_font_refer("asc", 12);
    RTGUI_WIDGET_FONT(checkbox) = font;

    checkbox = rtgui_checkbox_create(view, "16 font", RT_TRUE, 5, 100);
    font = rtgui_font_refer("asc", 16);
    RTGUI_WIDGET_FONT(checkbox) = font;

    return view;
}
Exemplo n.º 2
0
/* 创建用于演示button控件的视图 */
rtgui_view_t* demo_gui_button(rtgui_view_t* parent_view)
{
    rtgui_view_t* view;
    rtgui_button_t* button;
    rtgui_font_t* font;

    /* 先创建一个演示用的视图 */
    view = demo_view_create(parent_view, "Button View");

    /* 创建一个button控件 */
    button = rtgui_button_create(view, "Red", 5, 40, 100, 25);
    /* 设置label控件的前景色为红色 */
    RTGUI_WIDGET_FOREGROUND(button) = red;

    button = rtgui_button_create(view, "Blue", 5, 70, 100, 25);
    RTGUI_WIDGET_FOREGROUND(button) = blue;

    button = rtgui_button_create(view, "12 font", 5, 100, 100, 25);
    /* 设置字体为12点阵的asc字体 */
    font = rtgui_font_refer("asc", 12);
    RTGUI_WIDGET_FONT(button) = font;

    button = rtgui_button_create(view, "16 font", 5, 130, 100, 25);
    /* 设置字体为16点阵的asc字体 */
    font = rtgui_font_refer("asc", 16);
    RTGUI_WIDGET_FONT(button) = font;


    return view;
}
Exemplo n.º 3
0
static void rtgui_terminal_calc_width(rtgui_terminal_t *tma)
{
	rt_uint16_t w, h, fw, fh;

	w = rtgui_widget_get_width(tma)-RTGUI_WIDGET_BORDER_SIZE(tma)-RTGUI_MARGIN*2;
	h = rtgui_widget_get_height(tma);
	fw = FONT_W(RTGUI_WIDGET_FONT(tma));
	fh = FONT_H(RTGUI_WIDGET_FONT(tma));

	tma->item_width = w/fw + 1;
	tma->item_per_page = h / (fh);

	/* set minimal value */
	if(tma->item_per_page == 0) tma->item_per_page = 1;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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);
}
Exemplo n.º 8
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;
}
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;
}
Exemplo n.º 10
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;
        }
    }
}
Exemplo n.º 11
0
/* 创建用于演示label控件的视图 */
rtgui_view_t* demo_gui_label(rtgui_view_t* parent_view)
{
	rtgui_view_t* view;
	rtgui_label_t* label;
	rtgui_font_t* font;

	/* 先创建一个演示用的视图 */
	view = demo_view_create(parent_view, "Label View");

	/* 创建一个label控件 */
	label = rtgui_label_create(view, "Red Left", 10, 40, 200, 20);
	/* 设置label控件上的文本对齐方式为:左对齐 */
	RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_LEFT|RTGUI_ALIGN_CENTER_VERTICAL;
	/* 设置label控件的前景色为红色 */
	RTGUI_WIDGET_FOREGROUND(label) = red;
	RTGUI_WIDGET_BACKGROUND(label) = white;


	label = rtgui_label_create(view, "Blue Right", 10, 65, 200, 20);
	RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_RIGHT|RTGUI_ALIGN_CENTER_VERTICAL;
	RTGUI_WIDGET_FOREGROUND(label) = blue;
	RTGUI_WIDGET_BACKGROUND(label) = white;

	label = rtgui_label_create(view, "Green Center", 10, 90, 200, 20);
	RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_CENTER_HORIZONTAL|RTGUI_ALIGN_CENTER_VERTICAL;
	RTGUI_WIDGET_FOREGROUND(label) = green;
	RTGUI_WIDGET_BACKGROUND(label) = white;

	label = rtgui_label_create(view, "12 font",10, 115, 200, 20);
	/* 设置字体为12点阵的asc字体 */
	font = rtgui_font_refer("asc", 12);
	RTGUI_WIDGET_FONT(label) = font;
	RTGUI_WIDGET_BACKGROUND(label) = white;

	label = rtgui_label_create(view, "16 font", 10, 140, 200, 20);
	font = rtgui_font_refer("asc", 16);
	RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
	RTGUI_WIDGET_BACKGROUND(label) = white;

	return view;
}
Exemplo n.º 12
0
/* 创建用于演示文件列表视图的视图 */
rtgui_view_t* demo_fn_view(rtgui_workbench_t* workbench)
{
	rtgui_rect_t rect;
	rtgui_view_t* view;
	rtgui_button_t* open_btn;
	rtgui_font_t* font;

	/* 默认采用12字体的显示 */
	font = rtgui_font_refer("asc", 12);

	/* 创建演示用的视图 */
	view = demo_view(workbench, "FileList View");
	/* 获得演示视图的位置信息 */
	demo_view_get_rect(view, &rect);

	rect.x1 += 5;
	rect.x2 -= 5;
	rect.y1 += 5;
	rect.y2 = rect.y1 + 20;
	/* 创建显示文件路径用的文本标签 */
	label = rtgui_label_create("fn: ");
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
	RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;

	/* 获得演示视图的位置信息 */
	demo_view_get_rect(view, &rect);
	rect.x1 += 5;
	rect.x2 = rect.x1 + 80;
	rect.y1 += 30;
	rect.y2 = rect.y1 + 20;
	/* 创建按钮以触发一个新的文件列表视图 */
	open_btn = rtgui_button_create("Open File");
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn));
	rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
	RTGUI_WIDGET_FONT(RTGUI_WIDGET(open_btn)) = font;
	rtgui_button_set_onbutton(open_btn, open_btn_onbutton);

	return view;
}
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;
}
Exemplo n.º 14
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);
        }
    }
}
Exemplo n.º 15
0
Arquivo: edit.c Projeto: 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
}
Exemplo n.º 16
0
static void gui_win_entry(void* parameter)
{
	const struct rtgui_graphic_driver* gd = rtgui_graphic_driver_get_default();
	struct rt_messagequeue *mq;
	rtgui_win_t *win;
	rtgui_button_t *button;
	rtgui_point_t p;
	rtgui_rect_t rect = {0,0,200,180};
	rtgui_label_t *label;
	rtgui_font_t *font;
	
	/* 创建GUI应用需要的消息队列 */
	mq = rt_mq_create("demo_win", 256, 32, RT_IPC_FLAG_FIFO);
	/* 注册当前线程 */
	rtgui_thread_register(rt_thread_self(), mq);

	/* 窗口居中 */
	rtgui_rect_moveto(&rect, (gd->width - rtgui_rect_width(rect))/2, (gd->height - rtgui_rect_height(rect))/2);
	/* 创建窗口 */
	win = rtgui_win_create(RT_NULL,"demo_win",&rect,RTGUI_WIN_DEFAULT);
	if(win == RT_NULL) return;
 
	/* 取得客户区坐标零点 */
	p = rtgui_win_get_client_zero(win);
	label = rtgui_label_create(win, "hello world!", p.x+5, p.y+5, 100,25);
	font = rtgui_font_refer("asc", 12);	
	RTGUI_WIDGET_FONT(label) = font;

	button = rtgui_button_create(win, "Exit", (rtgui_rect_width(rect)-50)/2,
								rtgui_rect_height(rect)-40,50,25);
	rtgui_button_set_onbutton(button,rtgui_win_close);

	rtgui_widget_set_event_handler(win, demo_gui_win_event_handler);
	
	rtgui_win_show(win,RT_FALSE);
	
	/* 执行工作台事件循环 */
	rtgui_win_event_loop(win);

	demo_win_inited = RT_FALSE;
	
	/* 去注册GUI线程 */
	rtgui_thread_deregister(rt_thread_self());
	rt_mq_delete(mq);
}
Exemplo n.º 17
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;
}
Exemplo n.º 18
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);
}
Exemplo n.º 19
0
static void rtgui_terminal_ondraw(rtgui_terminal_t *tma)
{
	rtgui_dc_t* dc;
	rtgui_rect_t rect;
	char* str;
	rt_ubase_t i, item_height;

	item_height = FONT_H(RTGUI_WIDGET_FONT(tma));

	dc = rtgui_dc_begin_drawing(tma);
	if(dc == RT_NULL) return ;

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

	rtgui_rect_inflate(&rect,-RTGUI_WIDGET_BORDER_SIZE(tma));
	rtgui_dc_fill_rect(dc,&rect);
	rtgui_rect_inflate(&rect,RTGUI_WIDGET_BORDER_SIZE(tma));
	/* draw border */
	rtgui_dc_draw_border(dc,&rect,RTGUI_WIDGET_BORDER_STYLE(tma));

	rect.x1 += RTGUI_MARGIN+RTGUI_WIDGET_BORDER_SIZE(tma);
	rect.x2 -= RTGUI_MARGIN;
	rect.y1 += RTGUI_MARGIN;
	rect.y2 = rect.y1+item_height;

	for(i = tma->now_item;
	        (i < tma->now_item + tma->item_per_page) &&
	        (i < tma->item_count); i++)
	{
		str = (char*)rtgui_terminal_getline(tma, i);
		rtgui_dc_draw_text(dc, str, &rect);

		rect.y1 += item_height;
		rect.y2 = rect.y1+item_height;
	}

	rtgui_dc_end_drawing(dc);
}
Exemplo n.º 20
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;
            }
        }
    }
}
Exemplo n.º 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);
}
Exemplo n.º 22
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);
}
/* 创建用于演示button控件的视图 */
rtgui_container_t *demo_view_button(void)
{
    rtgui_rect_t rect;
    rtgui_container_t *container;
    rtgui_button_t *button;
    rtgui_font_t *font;

    /* 先创建一个演示用的视图 */
    container = demo_view("Button View");

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.x2 = rect.x1 + 100;
    rect.y1 += 5;
    rect.y2 = rect.y1 + 20;
    /* 创建一个button控件 */
    button = rtgui_button_create("Red");
    /* 设置label控件的前景色为红色 */
    RTGUI_WIDGET_FOREGROUND(button) = red;
    /* 设置button的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
    rtgui_container_add_child(container, RTGUI_WIDGET(button));

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.x2 = rect.x1 + 100;
    rect.y1 += 5 + 25;
    rect.y2 = rect.y1 + 20;
    /* 创建一个button控件 */
    button = rtgui_button_create("Blue");
    /* 设置label控件的前景色为蓝色 */
    RTGUI_WIDGET_FOREGROUND(button) = blue;
    /* 设置button的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
    rtgui_container_add_child(container, RTGUI_WIDGET(button));

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.x2 = rect.x1 + 100;
    rect.y1 += 5 + 25 + 25;
    rect.y2 = rect.y1 + 20;
    /* 创建一个button控件 */
    button = rtgui_button_create("12 font");
    /* 设置字体为12点阵的asc字体 */
    font = rtgui_font_refer("asc", 12);
    RTGUI_WIDGET_FONT(button) = font;
    /* 设置button的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
    rtgui_container_add_child(container, RTGUI_WIDGET(button));

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.x2 = rect.x1 + 100;
    rect.y1 += 5 + 25 + 25 + 25;
    rect.y2 = rect.y1 + 20;
    /* 创建一个button控件 */
    button = rtgui_button_create("16 font");
    /* 设置字体为16点阵的asc字体 */
    font = rtgui_font_refer("asc", 16);
    RTGUI_WIDGET_FONT(button) = font;
    /* 设置button的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
    rtgui_container_add_child(container, RTGUI_WIDGET(button));

    return container;
}
Exemplo n.º 24
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);
}
/* 创建用于演示checkbox控件的视图 */
rtgui_container_t *demo_view_checkbox(void)
{
    rtgui_rect_t rect;
    rtgui_container_t *container;
    rtgui_checkbox_t *checkbox;
    rtgui_font_t *font;

    /* 先创建一个演示用的视图 */
    container = demo_view("CheckBox View");

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.x2 = rect.x1 + 100;
    rect.y1 += 5;
    rect.y2 = rect.y1 + 20;
    /* 创建一个checkbox控件 */
    checkbox = rtgui_checkbox_create("Red", RT_TRUE);
    /* 设置前景色为红色 */
    RTGUI_WIDGET_FOREGROUND(checkbox) = red;
    /* 设置checkbox的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
    rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.x2 = rect.x1 + 100;
    rect.y1 += 5 + 25;
    rect.y2 = rect.y1 + 20;
    /* 创建一个checkbox控件 */
    checkbox = rtgui_checkbox_create("Blue", RT_TRUE);
    /* 设置前景色为蓝色 */
    RTGUI_WIDGET_FOREGROUND(checkbox) = blue;
    /* 设置checkbox的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
    rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.x2 = rect.x1 + 100;
    rect.y1 += 5 + 25 + 25;
    rect.y2 = rect.y1 + 20;
    /* 创建一个checkbox控件 */
    checkbox = rtgui_checkbox_create("12 font", RT_TRUE);
    /* 设置字体为12点阵 */
    font = rtgui_font_refer("asc", 12);
    RTGUI_WIDGET_FONT(checkbox) = font;
    /* 设置checkbox的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
    rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.x2 = rect.x1 + 100;
    rect.y1 += 5 + 25 + 25 + 25;
    rect.y2 = rect.y1 + 20;
    /* 创建一个checkbox控件 */
    checkbox = rtgui_checkbox_create("16 font", RT_TRUE);
    /* 设置字体为16点阵 */
    font = rtgui_font_refer("asc", 16);
    RTGUI_WIDGET_FONT(checkbox) = font;
    /* 设置checkbox的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
    rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));

    return container;
}
Exemplo n.º 26
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;
		}

	}
}
/* 创建用于演示checkbox控件的视图 */
rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
{
	rtgui_rect_t rect;
	rtgui_view_t* view;
	rtgui_checkbox_t* checkbox;
	rtgui_font_t* font;

	/* 先创建一个演示用的视图 */
	view = demo_view(workbench, "CheckBox View");

	/* 获得视图的位置信息 */
	demo_view_get_rect(view, &rect);
	rect.x1 += 5;
	rect.x2 = rect.x1 + 100;
	rect.y1 += 5;
	rect.y2 = rect.y1 + 20;
	/* 创建一个checkbox控件 */
	checkbox = rtgui_checkbox_create("Red",RT_TRUE);
	/* 设置前景色为红色 */
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = red;
	/* 设置checkbox的位置 */
	rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
	/* view是一个container控件,调用add_child方法添加这个checkbox控件 */
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));

	/* 获得视图的位置信息 */
	demo_view_get_rect(view, &rect);
	rect.x1 += 5;
	rect.x2 = rect.x1 + 100;
	rect.y1 += 5 + 25;
	rect.y2 = rect.y1 + 20;
	/* 创建一个checkbox控件 */
	checkbox = rtgui_checkbox_create("Blue",RT_TRUE);
	/* 设置前景色为蓝色 */
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = blue;
	/* 设置checkbox的位置 */
	rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
	/* view是一个container控件,调用add_child方法添加这个checkbox控件 */
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));

	/* 获得视图的位置信息 */
	demo_view_get_rect(view, &rect);
	rect.x1 += 5;
	rect.x2 = rect.x1 + 100;
	rect.y1 += 5 + 25 + 25;
	rect.y2 = rect.y1 + 20;
	/* 创建一个checkbox控件 */
	checkbox = rtgui_checkbox_create("12 font",RT_TRUE);
	/* 设置字体为12点阵 */
	font = rtgui_font_refer("asc", 12);
	RTGUI_WIDGET_FONT(RTGUI_WIDGET(checkbox)) = font;
	/* 设置checkbox的位置 */
	rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
	/* view是一个container控件,调用add_child方法添加这个checkbox控件 */
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));

	/* 获得视图的位置信息 */
	demo_view_get_rect(view, &rect);
	rect.x1 += 5;
	rect.x2 = rect.x1 + 100;
	rect.y1 += 5 + 25 + 25 + 25;
	rect.y2 = rect.y1 + 20;
	/* 创建一个checkbox控件 */
	checkbox = rtgui_checkbox_create("16 font",RT_TRUE);
	/* 设置字体为16点阵 */
	font = rtgui_font_refer("asc", 16);
	RTGUI_WIDGET_FONT(RTGUI_WIDGET(checkbox)) = font;
	/* 设置checkbox的位置 */
	rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
	/* view是一个container控件,调用add_child方法添加这个checkbox控件 */
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));

	return view;
}
Exemplo n.º 28
0
/* 创建用于演示label控件的视图 */
rtgui_container_t *demo_view_label(void)
{
    rtgui_rect_t rect;
    rtgui_container_t *container;
    rtgui_label_t *label;
    rtgui_font_t *font;

    /* 先创建一个演示用的视图 */
    container = demo_view("Label View");

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.x2 -= 5;
    rect.y1 += 5;
    rect.y2 = rect.y1 + 20;
    /* 创建一个label控件 */
    label = rtgui_label_create("Red Left");
    /* 设置label控件上的文本对齐方式为:左对齐 */
    RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_LEFT;
    /* 设置label控件的前景色为红色 */
    RTGUI_WIDGET_FOREGROUND(label) = red;
    /* 设置label的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    /* container是一个container控件,调用add_child方法添加这个label控件 */
    rtgui_container_add_child(container, RTGUI_WIDGET(label));

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.x2 -= 5;
    rect.y1 += 5 + 25;
    rect.y2 = rect.y1 + 20;
    /* 创建一个label控件 */
    label = rtgui_label_create("Blue Right");
    /* 设置label控件上的文本对齐方式为:右对齐 */
    RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_RIGHT;
    /* 设置label控件的前景色为蓝色 */
    RTGUI_WIDGET_FOREGROUND(label) = blue;
    /* 设置label的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    /* container是一个container控件,调用add_child方法添加这个label控件 */
    rtgui_container_add_child(container, RTGUI_WIDGET(label));

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.x2 -= 5;
    rect.y1 += 5 + 25 + 25;
    rect.y2 = rect.y1 + 20;
    /* 创建一个label控件 */
    label = rtgui_label_create("Green Center");
    /* 设置label控件的前景色为绿色 */
    RTGUI_WIDGET_FOREGROUND(label) = green;
    /* 设置label控件上的文本对齐方式为:右对齐 */
    RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_CENTER_HORIZONTAL;
    /* 设置label的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    /* container是一个container控件,调用add_child方法添加这个label控件 */
    rtgui_container_add_child(container, RTGUI_WIDGET(label));

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.x2 -= 5;
    rect.y1 += 5 + 25 + 25 + 25;
    rect.y2 = rect.y1 + 20;
    /* 创建一个label控件 */
    label = rtgui_label_create("12 font");
    /* 设置字体为12点阵的asc字体 */
    font = rtgui_font_refer("asc", 12);
    RTGUI_WIDGET_FONT(label) = font;
    /* 设置label的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    /* container是一个container控件,调用add_child方法添加这个label控件 */
    rtgui_container_add_child(container, RTGUI_WIDGET(label));

    /* 获得视图的位置信息 */
    demo_view_get_rect(container, &rect);
    rect.x1 += 5;
    rect.y1 += 5 + 25 + 25 + 25 + 25;
    rect.y2 = rect.y1 + 20;
    /* 创建一个label控件 */
    label = rtgui_label_create("16 font");
    /* 设置字体为16点阵的asc字体 */
    font = rtgui_font_refer("asc", 16);
    RTGUI_WIDGET_FONT(label) = font;
    /* 设置label的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    /* container是一个container控件,调用add_child方法添加这个label控件 */
    rtgui_container_add_child(container, RTGUI_WIDGET(label));

    return container;
}