Exemple #1
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);
}
static void workbench_entry(void* parameter)
{
	rt_mq_t mq;
	rtgui_container_t* view;
	rtgui_label_t* label;
	struct rtgui_workbench* workbench;
	rtgui_rect_t rect;

	mq = rt_mq_create("wmq", 256, 8, RT_IPC_FLAG_FIFO);
	/* 注册当前线程为GUI线程 */
	rtgui_thread_register(rt_thread_self(), mq);
	/* 创建一个工作台 */
	workbench = rtgui_workbench_create("main", "workbench #1");
	if (workbench == RT_NULL) return;

	view = rtgui_container_create("view");
	if (view == RT_NULL) return;
	/* 指定视图的背景色 */
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;

	/* 添加一个label */
	label = rtgui_label_create("你好!RT-Thread!");
	rect.x1 = 10; rect.y1 = 10;
	rect.x2 = 210; rect.y2 = 30;
	/* 设置label的位置 */
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));

	/* 添加到父workbench中 */
	rtgui_workbench_add_view(workbench, view);
	/* 非模式方式显示视图 */
	rtgui_container_show(view, RT_FALSE);

	/* 执行工作台事件循环 */
	rtgui_workbench_event_loop(workbench);

	/* 去注册GUI线程 */
	rtgui_thread_deregister(rt_thread_self());

	/* delete message queue */
	rt_mq_delete(mq);
}
Exemple #3
0
rtgui_container_t *demo_view_bmp(void)
{
	rtgui_rect_t rect;
	rtgui_container_t *container, *showbox;
	rtgui_button_t *button;
	rtgui_textbox_t *box;
	/* 用bmpdt结构体记录一些参数 */
	rt_memset(&bmpdt, 0, sizeof(struct demo_bmp_dt));
	bmpdt.scale = 1.0;
	bmpdt.angle = 0.0;
	/* 创建用于演示本代码的容器控件 */
	container = demo_view("Bmp File:");

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

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

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

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

	/* create a container "showbox" */
	demo_view_get_rect(container, &rect);
	rect.x1 += 5;
	rect.x2 -= 5;
	rect.y1 += 20;
	rect.y2 -= 0;
	showbox = rtgui_container_create();
	rtgui_widget_set_rect(RTGUI_WIDGET(showbox), &rect);
	rtgui_container_add_child(container, RTGUI_WIDGET(showbox));
	rtgui_widget_set_border(RTGUI_WIDGET(showbox), RTGUI_BORDER_SIMPLE);
	bmpdt.showbox = showbox;
	rtgui_object_set_event_handler(RTGUI_OBJECT(showbox), demo_bitmap_showbox);
	rtgui_widget_get_rect(RTGUI_WIDGET(showbox), &bmpdt.lastrect);
	rtgui_rect_inflate(&bmpdt.lastrect, -RTGUI_WIDGET_BORDER(showbox));
	
	return container;
}
rtgui_container_t *demo_view(const char *title)
{
    struct rtgui_container  *container;
    struct rtgui_label      *label;
    struct rtgui_staticline *line;
    struct rtgui_button     *next_btn, *prev_btn;
    struct rtgui_rect       rect;

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

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

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

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

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

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

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

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

    /* 返回创建的视图 */
    return container;
}