Esempio n. 1
0
struct rtgui_animation* rtgui_anim_create(struct rtgui_widget *parent,
                                          int interval)
{
    struct rtgui_animation *anim = rtgui_malloc(sizeof(*anim));

    if (anim == RT_NULL)
        return RT_NULL;

    anim->timer = rtgui_timer_create(interval, RT_TIMER_FLAG_PERIODIC,
                                     _anim_timeout, anim);
    if (anim->timer == RT_NULL)
    {
        rtgui_free(anim);
        return RT_NULL;
    }

    anim->parent = parent;

    anim->fg_buf = RT_NULL;
    anim->dc_cnt = 0;

    anim->tick = 0;
    anim->tick_interval = interval;
    anim->max_tick = 0;

    /* Set default handlers. */
    anim->motion = rtgui_anim_motion_linear;
    anim->engine = RT_NULL;
    anim->eng_ctx = RT_NULL;
    anim->on_finish = _animation_default_finish;
    anim->state = _ANIM_STOPPED;

    return anim;
}
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;
}
Esempio n. 3
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);
}
Esempio n. 4
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);
}
Esempio n. 5
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);
}
Esempio n. 6
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);
}
Esempio n. 7
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);
}
rtgui_view_t *demo_gui_progressbar(rtgui_view_t* parent_view)
{
	rtgui_view_t *view;
	rtgui_progressbar_t *hbar, *vbar;
	rtgui_timer_t *timer = RT_NULL;
	
	/* create a demo view */
	view = demo_view_create(parent_view, "ProgressBar View");
	
	rtgui_label_create(view, "邦峠序業訳:", 5, 40, 100, 20);
	hbar = rtgui_progressbar_create(view, RTGUI_HORIZONTAL, 100, 10, 70, 150, 15);

	rtgui_label_create(view, "換岷序業訳:", 5, 90, 100, 20);
	vbar = rtgui_progressbar_create(view, RTGUI_VERTICAL, 100, 10, 110, 15, 60);

	timer = rtgui_timer_create(20, RT_TIMER_FLAG_PERIODIC, hbar_timeout, hbar);
	rtgui_timer_start(timer);

	timer = rtgui_timer_create(20, RT_TIMER_FLAG_PERIODIC, vbar_timeout, vbar);
	rtgui_timer_start(timer);

	return view;
}
Esempio n. 9
0
File: edit.c Progetto: amsl/RTGUI
static rt_bool_t rtgui_edit_onfocus(pvoid wdt, rtgui_event_t* event)
{
	struct rtgui_edit* edit = RTGUI_EDIT(wdt);

	edit->caret_timer = rtgui_timer_create("edit", 100, RT_TIMER_FLAG_PERIODIC,
											rtgui_edit_timeout, (void*)edit);
	/* set caret to show */
	edit->flag |= RTGUI_EDIT_CARET;
	/* start caret timer */
	if(edit->caret_timer != RT_NULL)
		rtgui_timer_start(edit->caret_timer);

	return RT_TRUE;
}
Esempio n. 10
0
static rt_bool_t rtgui_textbox_onfocus(struct rtgui_object *widget, rtgui_event_t *event)
{
	rtgui_textbox_t *box = RTGUI_TEXTBOX(widget);

	/* if there is already a timer, don't create another one. */
	if (box->caret_timer == RT_NULL)
	{
		box->caret_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC, rtgui_textbox_timeout, box);
		/* set caret to show */
		box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
		/* start caret timer */
		if (box->caret_timer != RT_NULL)
			rtgui_timer_start(box->caret_timer);
	}

	return RT_TRUE;
}
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_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;
}
Esempio n. 13
0
void picture_show(void* parameter)
{
    /* create application */
    struct rtgui_app *app;
    struct rtgui_rect rect1;
    rtgui_timer_t *timer;
    
    app = rtgui_app_create(rt_thread_self(), "picture");
    if (app == RT_NULL)
    {
        rt_kprintf("Create application \"picture\" failed!\n");
        return;
    }

    rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect1);

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

    timer = rtgui_timer_create(500, RT_TIMER_FLAG_PERIODIC, timeout, (void*)win);
    rtgui_timer_start(timer);
    
    rtgui_object_set_event_handler(RTGUI_OBJECT(win), picture_view_event_handler);
    rtgui_win_set_onkey(win, onkey_handle);
    rtgui_win_show(win, RT_FALSE);

    /* show next picture */
    picture_show_next(RTGUI_WIDGET(win));

    rtgui_app_run(app);
    rtgui_app_destroy(app);
}
Esempio n. 14
0
void snake_main(void)
{
    struct rtgui_app *application;
    struct rtgui_win *win;
    rtgui_rect_t rect;

    application = rtgui_app_create(rt_thread_self(), "sanke_app");
    if (application != RT_NULL)
    {
        rtgui_get_screen_rect(&rect);
        rtgui_set_mainwin_rect(&rect);
        win = rtgui_mainwin_create(RT_NULL,
                                   "sanke_win",
                                   RTGUI_WIN_STYLE_MAINWIN | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
        if (win == RT_NULL)
        {
            rt_kprintf("sanke_win create fail!\r\n");
            return;
        }

        rtgui_object_set_event_handler(RTGUI_OBJECT(win), event_handler);

        timer = rtgui_timer_create(RT_TICK_PER_SECOND / 2,
                                   RT_TIMER_FLAG_PERIODIC,
                                   timeout,
                                   (void *)win);

        rtgui_win_show(win, RT_TRUE);

        //Í˳öºó²Å·µ»Ø
        map_deinit(map);
        snake_deinit();
        food_deinit();
        rtgui_app_destroy(application);
    }
}