/* 创建用于演示自定义控件的视图 */
rtgui_container_t *demo_view_mywidget(void)
{
	rtgui_container_t *container;
	rtgui_rect_t rect;
	rtgui_mywidget_t *mywidget;

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

	/* 获得视图的位置信息 */
	demo_view_get_rect(container, &rect);
	rect.x1 += 5;
	rect.x2 = rect.y1 + 80;
	rect.y1 += 5;
	rect.y2 = rect.y1 + 80;
	/* 创建一个自定义控件 */
	mywidget = rtgui_mywidget_create(&rect);
	/* container是一个container控件,调用add_child方法添加这个自控件 */
	rtgui_container_add_child(container, RTGUI_WIDGET(mywidget));

	/* 获得视图的位置信息 */
	demo_view_get_rect(container, &rect);
	rect.x1 += 25;
	rect.x2 = rect.y1 + 40;
	rect.y1 += 5 + 100;
	rect.y2 = rect.y1 + 40;
	/* 创建一个自定义控件 */
	mywidget = rtgui_mywidget_create(&rect);
	/* container是一个container控件,调用add_child方法添加这个自控件 */
	rtgui_container_add_child(container, RTGUI_WIDGET(mywidget));

	return container;
}
Example #2
0
rtgui_view_t* demo_view_window(rtgui_workbench_t* workbench)
{
	rtgui_rect_t  rect;
	rtgui_view_t* view;
	rtgui_button_t *button;

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

	demo_view_get_rect(view, &rect);
	rect.x1 += 5;
	rect.x2 = rect.x1 + 100;
	rect.y1 += 5;
	rect.y2 = rect.y1 + 20;
	/* 创建按钮用于显示正常窗口 */
	button = rtgui_button_create("Normal Win");
	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
	/* 设置onbutton为demo_win_onbutton函数 */
	rtgui_button_set_onbutton(button, demo_win_onbutton);

	demo_view_get_rect(view, &rect);
	rect.x1 += 5;
	rect.x2 = rect.x1 + 100;
	rect.y1 += 5 + 25;
	rect.y2 = rect.y1 + 20;
	/* 创建按钮用于显示一个自动关闭的窗口 */
	button = rtgui_button_create("Auto Win");
	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
	/* 设置onbutton为demo_autowin_onbutton函数 */
	rtgui_button_set_onbutton(button, demo_autowin_onbutton);

	demo_view_get_rect(view, &rect);
	rect.x1 += 5;
	rect.x2 = rect.x1 + 100;
	rect.y1 += 5 + 25 + 25;
	rect.y2 = rect.y1 + 20;
	/* 创建按钮用于触发一个模式窗口 */
	button = rtgui_button_create("Modal Win");
	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
	/* 设置onbutton为demo_modalwin_onbutton函数 */
	rtgui_button_set_onbutton(button, demo_modalwin_onbutton);

	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;
	/* 创建按钮用于触发一个不包含标题的窗口 */
	button = rtgui_button_create("NoTitle Win");
	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
	/* 设置onbutton为demo_ntitlewin_onbutton函数 */
	rtgui_button_set_onbutton(button, demo_ntitlewin_onbutton);

	return view;
}
Example #3
0
static void app_lcd(void *parameter)
{
    /* create application */
	struct rtgui_app *app;
    struct rtgui_rect rect1 = {0, 0, 240, 320};
    struct rtgui_button* btn;
    struct rtgui_label *lb;

	app = rtgui_app_create("lcd_app");

    if (!app)
    {
        rt_kprintf("Create application \"lcd_app\" failed!\n");
        return;
    }

    /* create main window */
    win_main = rtgui_win_create(RT_NULL, "main",
                    &rect1,
                    RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE);
    if (win_main == RT_NULL)
    {
        rt_kprintf("Create window \"main\" failed!\n");
        rtgui_app_destroy(app);
        return;
    }
    RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win_main)) = green;

    rect1.x1 = rect1.y1 = 50;
    rect1.x2 -= 50;
    rect1.y2 -= 50;
    lb = rtgui_label_create("I am a transparent label!!!!!!!!!");
    rtgui_widget_set_rect(RTGUI_WIDGET(lb), &rect1);
    RTGUI_WIDGET_FLAG(RTGUI_WIDGET(lb)) |= RTGUI_WIDGET_FLAG_TRANSPARENT;

    rect1.x1 += 20;
    rect1.y1 += 20;
	notebook = rtgui_notebook_create(&rect1, 0);
    /* create lable in main container */
    btn = rtgui_button_create("Here I am.");
    rtgui_notebook_add(notebook, "btn A", RTGUI_WIDGET(btn));
    rtgui_button_set_onbutton(btn, remove_myself);
    btn = rtgui_button_create("There I am.");
    rtgui_notebook_add(notebook, "btn B", RTGUI_WIDGET(btn));

    rtgui_container_add_child(RTGUI_CONTAINER(win_main), RTGUI_WIDGET(lb));
	rtgui_container_add_child(RTGUI_CONTAINER(win_main), RTGUI_WIDGET(notebook));

    rtgui_win_show(win_main, RT_FALSE);

    rtgui_app_run(app);
    rtgui_app_destroy(app);
}
Example #4
0
/* 触发模态窗口显示 */
static void demo_modalwin_onbutton(struct rtgui_object *object, rtgui_event_t *event)
{
    rtgui_win_t *win;
    rtgui_label_t *label;
    rtgui_rect_t rect = {0, 0, 150, 80};

    rtgui_rect_moveto(&rect, delta_x, delta_y);
    delta_x += 20;
    delta_y += 20;

    /* 创建一个窗口 */
    win = rtgui_win_create(main_win,
                           get_win_title(), &rect, RTGUI_WIN_STYLE_DEFAULT);

    rect.x1 += 20;
    rect.x2 -= 5;
    rect.y1 += 5;
    rect.y2 = rect.y1 + 20;

    label = rtgui_label_create("这是一个模式窗口");
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));

    /* 模态显示窗口 */
    rtgui_win_show(win, RT_TRUE);

    /* 删除非自动删除窗口 */
    rtgui_win_destroy(win);
}
/* 创建用于演示notebook控件的视图 */
rtgui_view_t* demo_view_notebook(rtgui_workbench_t* workbench)
{
	rtgui_rect_t rect;
	rtgui_view_t* view;
	rtgui_notebook_t* notebook;
	rtgui_listbox_t* box;

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

	/* 获得视图的位置信息 */
	demo_view_get_rect(view, &rect);

	notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_BOTTOM);
	/* view是一个container控件,调用add_child方法添加这个notebook控件 */
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(notebook));

	box = rtgui_listbox_create(items, sizeof(items)/sizeof(struct rtgui_listbox_item), &rect);
	rtgui_notebook_add(notebook, "Tab 1", RTGUI_WIDGET(box));

	box = rtgui_listbox_create(items2, sizeof(items2)/sizeof(struct rtgui_listbox_item), &rect);
	rtgui_notebook_add(notebook, "Tab 2", RTGUI_WIDGET(box));

	return view;
}
Example #6
0
static void rtgui_filelist_view_menu_pop(rtgui_widget_t *parent)
{
	rtgui_win_t *menu;
	rtgui_listbox_t *listbox;
	rtgui_rect_t screen, rect = {0, 0, 140, 85};

	rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &screen);
	rtgui_rect_moveto_align(&screen, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);

	menu = rtgui_win_create(RTGUI_WIN(rtgui_widget_get_toplevel(parent)),
							"Folder Menu", &rect, RTGUI_WIN_STYLE_DEFAULT);
	if (menu != RT_NULL)
	{
		/* set user data on menu window */
		menu->user_data = (rt_uint32_t)parent;

		rtgui_win_set_ondeactivate(menu, rtgui_filelist_view_on_menu_deactivate);

		listbox = rtgui_listbox_create(items, sizeof(items)/sizeof(items[0]), &rect);
		rtgui_listbox_set_onitem(listbox, rtgui_filelist_view_on_folder_item);
		rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(listbox));
		rtgui_win_show(menu, RT_FALSE);
		rtgui_widget_focus(RTGUI_WIDGET(listbox));
		rtgui_listbox_set_current_item(listbox, 0);
	}
}
Example #7
0
/* 触发自动窗口显示 */
static void demo_autowin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
{
	rtgui_toplevel_t *parent;
	struct rtgui_rect rect ={50, 50, 200, 200};

	parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget));
	msgbox = rtgui_win_create(parent, "Information", &rect, RTGUI_WIN_STYLE_DEFAULT);
	if (msgbox != RT_NULL)
	{
		cnt = 5;
		rt_sprintf(label_text, "closed then %d second!", cnt);
		label = rtgui_label_create(label_text);
		rect.x1 += 5;
		rect.x2 -= 5;
		rect.y1 += 5;
		rect.y2 = rect.y1 + 20;
		rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
		rtgui_container_add_child(RTGUI_CONTAINER(msgbox), RTGUI_WIDGET(label));

		rtgui_win_show(msgbox, RT_FALSE);
	}

	/* 创建一个定时器 */
	timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL);
	rtgui_timer_start(timer);
}
Example #8
0
/* 触发正常窗口显示 */
static void demo_win_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
{
	rtgui_win_t *win;
	rtgui_label_t *label;
	rtgui_toplevel_t *parent;
	rtgui_rect_t 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,
		get_win_title(), &rect, RTGUI_WIN_STYLE_DEFAULT);

	rect.x1 += 20;
	rect.x2 -= 5;
	rect.y1 += 5;
	rect.y2 = rect.y1 + 20;

	/* 添加一个文本标签 */
	label = rtgui_label_create("这是一个普通窗口");
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
	rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));

	/* 非模态显示窗口 */
	rtgui_win_show(win, RT_FALSE);
}
Example #9
0
/* 列表项的动作函数 */
static void listitem_action(rtgui_widget_t *widget, void *parameter)
{
    char label_text[32];
    rtgui_win_t *win;
    rtgui_label_t *label;
    rtgui_rect_t rect = {0, 0, 150, 80};
    int no = (int)parameter;

    rtgui_rect_moveto(&rect, 20, 50);

    /* 显示消息窗口 */
    win = rtgui_win_create(main_win,
                           "窗口", &rect, RTGUI_WIN_STYLE_DEFAULT);

    rect.x1 += 20;
    rect.x2 -= 5;
    rect.y1 += 5;
    rect.y2 = rect.y1 + 20;

    /* 添加相应的标签 */
    rt_sprintf(label_text, "动作 %d", no);
    label = rtgui_label_create(label_text);

    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    rtgui_container_add_child(win, RTGUI_WIDGET(label));

    /* 非模态显示窗口 */
    rtgui_win_show(win, RT_FALSE);
}
Example #10
0
rt_bool_t show_modal_info(struct rtgui_widget *object, struct rtgui_event *event)
{
	rtgui_label_t *label;
	struct rtgui_win *win;
	rtgui_rect_t rect = {0, 60, 150, 100};
	win = rtgui_win_create(main_win,
						   "Info",
						   &rect,
						   RTGUI_WIN_STYLE_DEFAULT);

	rect.x1 += 20;
	rect.x2 -= 5;
	rect.y1 += 5;
	rect.y2 = rect.y1 + 20;

	label = rtgui_label_create("modal mode info");
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
	rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));

	rtgui_win_show(win, RT_TRUE);

	rtgui_win_destroy(win);

	return RT_TRUE;
}
Example #11
0
void rtgui_win_set_box(rtgui_win_t* win, rtgui_box_t* box)
{
    if (win == RT_NULL || box == RT_NULL) return;

    rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(box));
    rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(win)->extent));
}
Example #12
0
static void rtgui_filelist_view_menu_pop(rtgui_widget_t *parent)
{
    struct rtgui_win *menu;
    rtgui_rect_t screen, rect = {0, 0, 140, 85};

    rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &screen);
    rtgui_rect_moveto_align(&screen, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);

    menu = rtgui_win_create(RTGUI_WIN(rtgui_widget_get_toplevel(parent)),
                            "Folder Menu", &rect, RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
    if (menu != RT_NULL)
    {
        rtgui_listbox_t *listbox;
        /* Pass the pointer to filelist_view via user_data. */
        menu->user_data = (rt_uint32_t)parent;

        rtgui_win_set_ondeactivate(menu, rtgui_filelist_view_on_menu_deactivate);

        listbox = rtgui_listbox_create(_folder_actions,
                                       sizeof(_folder_actions) / sizeof(_folder_actions[0]),
                                       &rect);
        /* Set the item index *before* setup the callback. `set_current_item`
         * will invoke the "onitem". So just keep it clean when setting the
         * current item. */
        rtgui_listbox_set_current_item(listbox, 0);
        rtgui_listbox_set_onitem(listbox, rtgui_filelist_view_on_folder_item);

        rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(listbox));

        rtgui_win_show(menu, RT_TRUE);
    }
}
Example #13
0
/* 触发自动窗口显示 */
static void demo_autowin_onbutton(struct rtgui_object *object, rtgui_event_t *event)
{
    struct rtgui_rect rect = {50, 50, 200, 200};

    /* don't create the window twice */
    if (autowin)
        return;

    autowin = rtgui_win_create(main_win, "Information",
                              &rect, RTGUI_WIN_STYLE_DEFAULT | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
    if (autowin == RT_NULL)
        return;

    cnt = 5;
    rt_sprintf(label_text, "closed then %d second!", cnt);
    label = rtgui_label_create(label_text);
    rect.x1 += 5;
    rect.x2 -= 5;
    rect.y1 += 5;
    rect.y2 = rect.y1 + 20;
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    rtgui_container_add_child(RTGUI_CONTAINER(autowin),
                              RTGUI_WIDGET(label));

    /* 设置关闭窗口时的动作 */
    rtgui_win_set_onclose(autowin, auto_window_close);

    rtgui_win_show(autowin, RT_FALSE);
    /* 创建一个定时器 */
    timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL);
    rtgui_timer_start(timer);
}
/* 创建用于演示列表视图的视图 */
rtgui_view_t* demo_listview_icon_view(rtgui_workbench_t* workbench)
{
	rtgui_rect_t rect;
	rtgui_view_t *view;
	rtgui_button_t* open_btn;

	view = demo_view(workbench, "图标视图演示");

	if (item_icon == RT_NULL)
		item_icon = rtgui_image_create_from_mem("xpm",
			(const rt_uint8_t*)image_xpm, sizeof(image_xpm), RT_TRUE);
	if (exit_icon == RT_NULL)
		exit_icon = rtgui_image_create_from_mem("xpm",
			(const rt_uint8_t*)exit_xpm, sizeof(exit_xpm), RT_TRUE);

	/* 添加动作按钮 */
	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("打开图标列表");
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn));
	rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
	rtgui_button_set_onbutton(open_btn, open_btn_onbutton);

	return view;
}
Example #15
0
struct rtgui_menu* rtgui_menu_create(const char* title, struct rtgui_menu* parent_menu, 
	const struct rtgui_menu_item* items, rt_uint16_t count)
{
	rtgui_rect_t rect = {0, 0, 100, 100};
    struct rtgui_menu* menu;

    menu = (struct rtgui_menu*) rtgui_widget_create ( RTGUI_MENU_TYPE );
	if (menu != RT_NULL)
	{
		rtgui_win_set_title(RTGUI_WIN(menu), title);
		menu->parent_menu = parent_menu;
		menu->items = items;
		menu->items_count = count;

		rtgui_widget_set_rect(RTGUI_WIDGET(menu), &rect);
		rtgui_rect_inflate(&rect, -1);
		/* create menu item list */
		menu->items_list = rtgui_listctrl_create((rt_uint32_t)items, count, &rect, _rtgui_menu_item_ondraw); 
		RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(menu->items_list)) = rtgui_theme_default_bc();
		rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(menu->items_list));
		rtgui_listctrl_set_onitem(menu->items_list, _rtgui_menu_onitem);
	}

	return menu;
}
Example #16
0
rtgui_terminal_t* rtgui_terminal_create(pvoid parent,const char* text, int left,int top,int w,int h)
{
	rtgui_container_t *container;
	rtgui_terminal_t* tma;

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

	tma = rtgui_widget_create(RTGUI_TERMINAL_TYPE);
	if(tma != RT_NULL)
	{
		rtgui_rect_t rect;
		rtgui_widget_get_rect(container, &rect);
		rtgui_widget_rect_to_device(container,&rect);
		rect.x1 += left;
		rect.y1 += top;
		rect.x2 = rect.x1+w;
		rect.y2 = rect.y1+h;
		rtgui_widget_set_rect(tma,&rect);
		rtgui_container_add_child(container, tma);

		/* calculate line width and line page count */
		rtgui_terminal_calc_width(tma);
		/* set text */
		rtgui_terminal_calc_line(tma, text);
	}

	return tma;
}
Example #17
0
int main(int argc, char** argv)
{
	struct rtgui_app* application;
	struct rtgui_win* win;
    struct rtgui_button *button;

	application = rtgui_app_create("button");
	if (application != RT_NULL)
	{
		rtgui_rect_t rect;

		win = rtgui_mainwin_create(RT_NULL, "button",
			RTGUI_WIN_STYLE_MAINWIN | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
        rtgui_widget_get_extent(RTGUI_WIDGET(win), &rect);

		/* create lable in app window */
        button = rtgui_button_create("close");
		rtgui_button_set_onbutton(button, _on_close);
        rect.x2 -= 5; rect.y2 -= 5;
        rect.x1 = rect.x2 - 80; rect.y1 = rect.y2 - 25;
		rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
		rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(button));

		rtgui_win_show(win, RT_TRUE);
		rtgui_app_destroy(application);
	}

    return 0;
}
Example #18
0
int creat_software_ver_not_match_win(struct rtgui_widget* widget)
{
	rtgui_rect_t rect = {60, 45, 260, 160};
	rtgui_label_t *label1;
	rtgui_label_t *label2;
	rtgui_toplevel_t *parent;

	if (RT_NULL != software_version_not_match_win)
		return FAIL;

	parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget));

	software_version_not_match_win = rtgui_win_create(parent,
		"致命错误", &rect, RTGUI_WIN_STYLE_MODAL);

	rtgui_widget_get_extent(RTGUI_WIDGET(software_version_not_match_win),&rect);
	rect.x1 += 20;
	rect.x2 -= 20;
	rect.y1 += 20;
	rect.y2 = rect.y1 + 30;
	label1 = rtgui_label_create("接收端与lcd软件版本");
	if (NULL != label1) {
		rtgui_widget_set_rect(RTGUI_WIDGET(label1), &rect);
		rtgui_container_add_child(RTGUI_CONTAINER(software_version_not_match_win), RTGUI_WIDGET(label1));
	}

	rtgui_widget_get_extent(RTGUI_WIDGET(software_version_not_match_win),&rect);
	rect.x1 += 70;
	rect.x2 -= 30;
	rect.y1 += 50;
	rect.y2 = rect.y1 + 30;
	label2 = rtgui_label_create("不匹配!");
	if (NULL != label2) {
		rtgui_widget_set_rect(RTGUI_WIDGET(label2), &rect);
		rtgui_container_add_child(RTGUI_CONTAINER(software_version_not_match_win), RTGUI_WIDGET(label2));
	}

	send_cmd_to_rxe(1, SWITCH2PT);

	rtgui_win_show(software_version_not_match_win, RT_TRUE);

	rtgui_win_destroy(software_version_not_match_win);
	software_version_not_match_win = RT_NULL;

	return SUCC;
}
rtgui_view_t *demo_view_progressbar(rtgui_workbench_t* workbench)
{
	rtgui_view_t *view;
	rtgui_rect_t rect;
	rtgui_label_t *label;

	/* create a demo view */
	view = demo_view(workbench, "ProgressBar View");

	/* get demo view rect */
	demo_view_get_rect(view, &rect);
	label = rtgui_label_create("邦峠序業訳:");
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
	rect.x1 += 5;
	rect.x2 -= 5;
	rect.y1 += 5;
	rect.y2 = rect.y1 + 18;
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
	rect.y1 += 20;
	rect.y2 = rect.y1 + 18;
	hbar = rtgui_progressbar_create(RTGUI_HORIZONTAL, 100, &rect);
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(hbar));

	/* get demo view rect */
	demo_view_get_rect(view, &rect);
	label = rtgui_label_create("換岷序業訳:");
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
	rect.x1 += 5;
	rect.x2 -= 5;
	rect.y1 += 45;
	rect.y2 = rect.y1 + 18;
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
	rect.x1 += 110;
	rect.x2 = rect.x1 + 20;
	rect.y1 += 18 + 5;
	rect.y2 = rect.y1 + 150;
	vbar = rtgui_progressbar_create(RTGUI_VERTICAL, 100, &rect);
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(vbar));

	bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,
								   progressbar_timeout, RT_NULL);
	rtgui_timer_start(bar_timer);

	return view;
}
rtgui_container_t *demo_view_scrollbar(void)
{
    rtgui_container_t *container;
    rtgui_rect_t rect;
    rtgui_label_t *label;
    rtgui_scrollbar_t *hbar;
    rtgui_scrollbar_t *vbar;

    /* create a demo container */
    container = demo_view("ScrollBar View");

    /* get demo container rect */
    demo_view_get_rect(container, &rect);
    label = rtgui_label_create("horizontal bar:");
    rtgui_container_add_child(container, RTGUI_WIDGET(label));
    rect.x1 += 5;
    rect.x2 -= 5;
    rect.y1 += 5;
    rect.y2 = rect.y1 + 18;
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    rect.y1 += 20;
    rect.y2 = rect.y1 + 18;
    hbar = rtgui_scrollbar_create(RTGUI_HORIZONTAL, &rect);
    rtgui_container_add_child(container, RTGUI_WIDGET(hbar));

    /* get demo container rect */
    demo_view_get_rect(container, &rect);
    label = rtgui_label_create("vertical bar:");
    rtgui_container_add_child(container, RTGUI_WIDGET(label));
    rect.x1 += 5;
    rect.x2 -= 5;
    rect.y1 += 45;
    rect.y2 = rect.y1 + 18;
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    rect.x1 += 110;
    rect.x2 = rect.x1 + 20;
    rect.y1 += 18 + 5;
    rect.y2 = rect.y1 + 150;
    vbar = rtgui_scrollbar_create(RTGUI_VERTICAL, &rect);
    rtgui_container_add_child(container, RTGUI_WIDGET(vbar));
    rtgui_scrollbar_set_line_step(vbar, 1);
    // RTGUI_WIDGET_DISABLE(vbar);

    return container;
}
Example #21
0
void rtgui_workbench_add_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
{
	rtgui_container_add_child(RTGUI_CONTAINER(workbench), RTGUI_WIDGET(view));
	/* hide view in default */
	RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view));

	/* reset view extent */
	rtgui_widget_set_rect(RTGUI_WIDGET(view), &(RTGUI_WIDGET(workbench)->extent));
}
Example #22
0
static rt_bool_t rtgui_combobox_onmouse_button(struct rtgui_combobox* box, struct rtgui_event_mouse* event)
{
	struct rtgui_rect rect;

	/* get widget rect */
	rect = RTGUI_WIDGET(box)->extent;

	/* move to the pull down button */
	rect.x1 = rect.x2 - RTGUI_COMBOBOX_BUTTON_WIDTH;
	if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK)
	{
		/* handle mouse button on pull down button */
		if (event->button & RTGUI_MOUSE_BUTTON_LEFT &&
			event->button & RTGUI_MOUSE_BUTTON_DOWN)
		{
			box->pd_pressed = RT_TRUE;
			rtgui_widget_update(RTGUI_WIDGET(box));
		}
		else if (event->button & RTGUI_MOUSE_BUTTON_LEFT &&
			event->button & RTGUI_MOUSE_BUTTON_UP)
		{
			box->pd_pressed = RT_FALSE;
			rtgui_widget_update(RTGUI_WIDGET(box));

			/* pop pull down window */
			if (box->pd_win == RT_NULL)
			{
				rtgui_listbox_t  *list;

				/* create pull down window */
				rect = RTGUI_WIDGET(box)->extent;
				rect.y1 = rect.y2;
				rect.y2 = rect.y1 + 5 * (2 + rtgui_theme_get_selected_height());
				box->pd_win = rtgui_win_create(RT_NULL, "combo", &rect, RTGUI_WIN_STYLE_NO_TITLE);
				rtgui_win_set_ondeactivate(RTGUI_WIN(box->pd_win), rtgui_combobox_pulldown_hide);
				/* set user data to parent combobox */
				box->pd_win->user_data = (rt_uint32_t)box;

				/* create list box */
				rtgui_rect_inflate(&rect, -1);
				list = rtgui_listbox_create(box->items, box->items_count, &rect);
				rtgui_container_add_child(RTGUI_CONTAINER(box->pd_win), RTGUI_WIDGET(list));
				rtgui_widget_focus(RTGUI_WIDGET(list));

				rtgui_listbox_set_onitem(list, rtgui_combobox_pdwin_onitem);
				rtgui_win_set_ondeactivate(box->pd_win, rtgui_combobox_pdwin_ondeactive);
			}

			/* show combo box pull down window */
			rtgui_win_show(RTGUI_WIN(box->pd_win), RT_FALSE);
		}

		return RT_TRUE;
	}

	return RT_FALSE;
}
rtgui_view_t *demo_view_slider(rtgui_workbench_t* workbench)
{
	rtgui_view_t *view;
	rtgui_rect_t rect;
	rtgui_label_t *label;
	rtgui_slider_t *slider;

	/* create a demo view */
	view = demo_view(workbench, "Slider View");

	/* get demo view rect */
	demo_view_get_rect(view, &rect);
	label = rtgui_label_create("horizontal slider:");
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
	rect.x1 += 5;
	rect.x2 -= 5;
	rect.y1 += 5;
	rect.y2 = rect.y1 + 18;
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
	rect.y1 += 20;
	rect.y2 = rect.y1 + 18;
	slider = rtgui_slider_create(0, 100, RTGUI_HORIZONTAL);
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(slider));
	rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect);

	/* get demo view rect */
	demo_view_get_rect(view, &rect);
	label = rtgui_label_create("vertical slider:");
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
	rect.x1 += 5;
	rect.x2 -= 5;
	rect.y1 += 50;
	rect.y2 = rect.y1 + 18;
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
	rect.x1 += 110;
	rect.x2 = rect.x1 + 20;
	rect.y1 += 18 + 5;
	rect.y2 = rect.y1 + 150;
	slider = rtgui_slider_create(0, 100, RTGUI_VERTICAL);
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(slider));
	rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect);

	return view;
}
Example #24
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);
}
/* 创建用于演示radiobox控件的视图 */
rtgui_container_t* demo_view_radiobox(void)
{
	rtgui_rect_t rect;
	rtgui_container_t* container;
	rtgui_radiobox_t* radiobox;

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

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

	/* 创建一个垂直方向显示的radiobox控件,文本项是radio_item_v数组,共5个项 */
	radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item_v, 5);
	/* 设置当前选择的数组是第0项 */
	rtgui_radiobox_set_selection(radiobox, 0);
	/* 添加radiobox控件到视图中 */
	rtgui_container_add_child(container, RTGUI_WIDGET(radiobox));
	/* 设置radiobox控件的位置信息 */
	rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);

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

	/* 创建一个水平方向显示的radiobox控件,文本项是radio_item_h数组,共3个项 */
	radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3);
	/* 设置当前选择的数组是第0项 */
	rtgui_radiobox_set_selection(radiobox, 0);
	/* 添加radiobox控件到视图中 */
	rtgui_container_add_child(container, RTGUI_WIDGET(radiobox));
	/* 设置radiobox控件的位置信息 */
	rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);

	return container;
}
rtgui_container_t *demo_view_progressbar(void)
{
	rtgui_container_t *container;
	rtgui_rect_t rect;
	rtgui_label_t *label;

	/* create a demo container */
	container = demo_view("ProgressBar View");

	/* get demo container rect */
	demo_view_get_rect(container, &rect);
	label = rtgui_label_create("邦峠序業訳:");
	rtgui_container_add_child(container, RTGUI_WIDGET(label));
	rect.x1 += 5; rect.x2 -= 5;
	rect.y1 += 5; rect.y2 = rect.y1 + 18;
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
	rect.y1 += 20; rect.y2 = rect.y1 + 18;
	hbar = rtgui_progressbar_create(RTGUI_HORIZONTAL, 100, &rect);
	rtgui_container_add_child(container, RTGUI_WIDGET(hbar));

	/* get demo container rect */
	demo_view_get_rect(container, &rect);
	label = rtgui_label_create("換岷序業訳:");
	rtgui_container_add_child(container, RTGUI_WIDGET(label));
	rect.x1 += 5; rect.x2 -= 5;
	rect.y1 += 45; rect.y2 = rect.y1 + 18;
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
	rect.x1 += 110; rect.x2 = rect.x1 + 20;
	rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150;
	vbar = rtgui_progressbar_create(RTGUI_VERTICAL, 100, &rect);
	rtgui_container_add_child(container, RTGUI_WIDGET(vbar));

	bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,
										progressbar_timeout, RT_NULL);

	rtgui_widget_set_onshow(RTGUI_WIDGET(container), start_timer);
	rtgui_widget_set_onhide(RTGUI_WIDGET(container), stop_timer);

	return container;
}
Example #27
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;
}
Example #28
0
void picture_show(void)
{
    /* create application */
    struct rtgui_app *app;
    struct rtgui_rect rect1;
    struct rtgui_win *win_main;
    rtgui_timer_t *timer;
    
    app = rtgui_app_create(rt_thread_self(), "gui_app");
    if (app == RT_NULL)
    {
        rt_kprintf("Create application \"gui_app\" failed!\n");
        return;
    }

    rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect1);

    /* create main window */
    win_main = rtgui_win_create(RT_NULL, "main",
                    &rect1,
                    RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE);
    if (win_main == RT_NULL)
    {
        rt_kprintf("Create window \"main\" failed!\n");
                rtgui_app_destroy(app);
        return;
    }

    /* create container in main window */
    container = rtgui_container_create();
    if (container == RT_NULL)
    {
        rt_kprintf("Create container failed!\n");
        return;
    }

    rtgui_widget_set_rect(RTGUI_WIDGET(container), &rect1);
    rtgui_object_set_event_handler(RTGUI_OBJECT(container), picture_view_event_handler);
    rtgui_container_add_child(RTGUI_CONTAINER(win_main), RTGUI_WIDGET(container));

    timer = rtgui_timer_create(500, RT_TIMER_FLAG_PERIODIC, timeout, RT_NULL);
    rtgui_timer_start(timer);
    
    rtgui_win_set_onkey(win_main, onkey_handle);
    rtgui_win_show(win_main, RT_FALSE);

    /* show next picture */
    picture_show_next();

    rtgui_app_run(app);
    rtgui_app_destroy(app);
}
Example #29
0
static void player_entry(void* parameter)
{
    rt_mq_t mq;
    rtgui_rect_t rect;

    mq = rt_mq_create("ply_ui", 256, 4, RT_IPC_FLAG_FIFO);
    rtgui_thread_register(rt_thread_self(), mq);

    /* create information timer */
    info_timer = rtgui_timer_create(RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC, info_timer_timeout, RT_NULL);

    workbench = rtgui_workbench_create("main", "workbench");
    if (workbench == RT_NULL) return;
    rtgui_widget_set_event_handler(RTGUI_WIDGET(workbench), player_workbench_event_handler);

    /* add home view */
    home_view = rtgui_view_create("Home");
    rtgui_widget_set_event_handler(RTGUI_WIDGET(home_view), home_view_event_handler);

    rtgui_workbench_add_view(workbench, home_view);
    /* this view can be focused */
    RTGUI_WIDGET(home_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
    /* set widget focus */
    rtgui_widget_focus(RTGUI_WIDGET(home_view));

	rtgui_widget_get_rect(RTGUI_WIDGET(home_view), &rect);
	rect.x1 += 6; rect.y1 += 150 + 25;
	rect.x2 = rect.x1 + 228; rect.y2 = rect.y1 + 145;
	music_listbox = rtgui_listbox_create(RT_NULL, 0, &rect);
	/* none focusable widget */
	RTGUI_WIDGET(music_listbox)->flag &= ~RTGUI_WIDGET_FLAG_FOCUSABLE;
	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(music_listbox)) = black;
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(music_listbox)) = white;
	rtgui_container_add_child(RTGUI_CONTAINER(home_view), RTGUI_WIDGET(music_listbox));
	rtgui_listbox_set_onitem(music_listbox, player_play_list_onitem);

    rtgui_view_show(home_view, RT_FALSE);

    /* add function view */
    rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
    function_view = rtgui_list_view_create(function_list,
                                           sizeof(function_list)/sizeof(struct rtgui_list_item),
                                           &rect,
										   RTGUI_LIST_VIEW_LIST);
    rtgui_workbench_add_view(workbench, RTGUI_VIEW(function_view));

    rtgui_workbench_event_loop(workbench);

    rtgui_thread_deregister(rt_thread_self());
    rt_mq_delete(mq);
}
/* 创建用于演示label控件的视图 */
rtgui_container_t *demo_view_listctrl(void)
{
    rtgui_rect_t rect;
    rtgui_container_t *container;
    rtgui_label_t *label;
    rtgui_listctrl_t *box;

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

    if (item_icon == RT_NULL)
        item_icon = rtgui_image_create_from_mem("xpm",
                                                (const rt_uint8_t *)image_xpm, sizeof(image_xpm), RT_TRUE);
    items[1].image = item_icon;

    /* 获得视图的位置信息 */
    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("List Control: ");
    /* 设置label的位置 */
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    /* container是一个container控件,调用add_child方法添加这个label控件 */
    rtgui_container_add_child(container, RTGUI_WIDGET(label));

    rect.y1 = rect.y2 + 3;
    rect.y2 = 250;
    box = rtgui_listctrl_create(items, sizeof(items) / sizeof(items[0]), &rect,
                                _rtgui_listctrl_item_draw);
    rtgui_listctrl_set_onitem(box, on_items);
    /* container是一个container控件,调用add_child方法添加这个listctrl控件 */
    rtgui_container_add_child(container, RTGUI_WIDGET(box));

    return container;
}