rtgui_demo.c 3.0 KB
Newer Older
T
tanek liang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * File      : application.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 */

#include <rtthread.h>
T
tanek liang 已提交
15
#include <finsh.h>
T
tanek liang 已提交
16 17 18 19 20 21 22 23 24 25 26 27
#include "rtgui_demo.h"

#define DEBUG

#ifdef DEBUG
#define DEBUG_PRINTF(...)   rt_kprintf(__VA_ARGS__)
#else
#define DEBUG_PRINTF(...)   
#endif

#ifdef RT_USING_GUIENGINE

T
tanek liang 已提交
28 29 30 31 32 33 34 35
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/rtgui_app.h>

#include <rtgui/widgets/window.h>
#include <rtgui/dc.h>
#include <rtgui/dc_hw.h>

T
tanek liang 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
struct rtgui_win *main_win;
rt_bool_t dc_event_handler(struct rtgui_object *object, rtgui_event_t *event);

static void rt_gui_demo_entry(void *parameter)
{    
    struct rtgui_app *app;
	//struct rtgui_dc *dc;
    
    DEBUG_PRINTF("gui demo entry\n");
	
	/* create gui app */
    app = rtgui_app_create("gui_demo");
    if (app == RT_NULL)
    {
        DEBUG_PRINTF("rtgui_app_create faild\n");
        return;	
    }
    
	/* create main window */
	main_win = rtgui_mainwin_create(RT_NULL, 
									"UiWindow", RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER);
    if (main_win == RT_NULL)
    {
        DEBUG_PRINTF("main_win is null\n");
        rtgui_app_destroy(app);
        return;
    }
	
	rtgui_object_set_event_handler(RTGUI_OBJECT(main_win), dc_event_handler);
	
    DEBUG_PRINTF("rtgui_win_show\n");
	rtgui_win_show(main_win, RT_FALSE);
    
    DEBUG_PRINTF("rtgui_app_run\n");
	rtgui_app_run(app);
    
    DEBUG_PRINTF("rtgui_win_destroy\n");
	rtgui_win_destroy(main_win);
    
    DEBUG_PRINTF("rtgui_app_destroy\n");
	rtgui_app_destroy(app);	
}

rt_bool_t dc_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
    struct rtgui_widget *widget = RTGUI_WIDGET(object);

    if (event->type == RTGUI_EVENT_PAINT)
    {
        struct rtgui_dc *dc;
        rtgui_rect_t rect;
		
		rt_kprintf("\r\n RTGUI_EVENT_PAINT \r\n");
		rtgui_win_event_handler(RTGUI_OBJECT(widget), event);
        
        rtgui_widget_get_rect(widget, &rect);
        DEBUG_PRINTF("widget react x1: %d, y1: %d, x2: %d, y2: %d\r\n",
                                rect.x1, rect.y1, rect.x2, rect.y2);

		dc = rtgui_dc_begin_drawing(widget);
		if(dc == RT_NULL)
		{
			DEBUG_PRINTF("\r\n dc is null \r\n");
			return RT_FALSE;
		}

		rtgui_dc_draw_line(dc, rect.x1, rect.y1, rect.x2, rect.y2);
		rtgui_dc_draw_line(dc, rect.x1, rect.y2, rect.x2, rect.y1);
        
        rect.x1 += (rect.x2 - rect.x1) / 2;
        rect.y1 += (rect.y2 - rect.y1) / 2;
        rtgui_dc_draw_text_stroke(dc, __DATE__"--"__TIME__, &rect, HIGH_LIGHT, BLUE);
        
        
		rtgui_dc_end_drawing(dc);
    }
	return RT_FALSE;
}

int rt_gui_demo_init(void)
{
    rt_thread_t tid;
    tid = rt_thread_create("mygui",
        rt_gui_demo_entry, RT_NULL,
        2048, 25, 10);

    if (tid != RT_NULL)
        rt_thread_startup(tid);
    
    return 0;
}
#endif /* RT_USING_GUIENGINE */