rtgui_demo.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. */
  13. #include <rtthread.h>
  14. #include <finsh.h>
  15. #include "rtgui_demo.h"
  16. #define DEBUG
  17. #ifdef DEBUG
  18. #define DEBUG_PRINTF(...) rt_kprintf(__VA_ARGS__)
  19. #else
  20. #define DEBUG_PRINTF(...)
  21. #endif
  22. #ifdef RT_USING_GUIENGINE
  23. #include <rtgui/rtgui.h>
  24. #include <rtgui/rtgui_system.h>
  25. #include <rtgui/rtgui_app.h>
  26. #include <rtgui/widgets/window.h>
  27. #include <rtgui/dc.h>
  28. #include <rtgui/dc_hw.h>
  29. struct rtgui_win *main_win;
  30. rt_bool_t dc_event_handler(struct rtgui_object *object, rtgui_event_t *event);
  31. static void rt_gui_demo_entry(void *parameter)
  32. {
  33. struct rtgui_app *app;
  34. //struct rtgui_dc *dc;
  35. DEBUG_PRINTF("gui demo entry\n");
  36. /* create gui app */
  37. app = rtgui_app_create("gui_demo");
  38. if (app == RT_NULL)
  39. {
  40. DEBUG_PRINTF("rtgui_app_create faild\n");
  41. return;
  42. }
  43. /* create main window */
  44. main_win = rtgui_mainwin_create(RT_NULL,
  45. "UiWindow", RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER);
  46. if (main_win == RT_NULL)
  47. {
  48. DEBUG_PRINTF("main_win is null\n");
  49. rtgui_app_destroy(app);
  50. return;
  51. }
  52. rtgui_object_set_event_handler(RTGUI_OBJECT(main_win), dc_event_handler);
  53. DEBUG_PRINTF("rtgui_win_show\n");
  54. rtgui_win_show(main_win, RT_FALSE);
  55. DEBUG_PRINTF("rtgui_app_run\n");
  56. rtgui_app_run(app);
  57. DEBUG_PRINTF("rtgui_win_destroy\n");
  58. rtgui_win_destroy(main_win);
  59. DEBUG_PRINTF("rtgui_app_destroy\n");
  60. rtgui_app_destroy(app);
  61. }
  62. rt_bool_t dc_event_handler(struct rtgui_object *object, rtgui_event_t *event)
  63. {
  64. struct rtgui_widget *widget = RTGUI_WIDGET(object);
  65. if (event->type == RTGUI_EVENT_PAINT)
  66. {
  67. struct rtgui_dc *dc;
  68. rtgui_rect_t rect;
  69. rt_kprintf("\r\n RTGUI_EVENT_PAINT \r\n");
  70. rtgui_win_event_handler(RTGUI_OBJECT(widget), event);
  71. rtgui_widget_get_rect(widget, &rect);
  72. DEBUG_PRINTF("widget react x1: %d, y1: %d, x2: %d, y2: %d\r\n",
  73. rect.x1, rect.y1, rect.x2, rect.y2);
  74. dc = rtgui_dc_begin_drawing(widget);
  75. if(dc == RT_NULL)
  76. {
  77. DEBUG_PRINTF("\r\n dc is null \r\n");
  78. return RT_FALSE;
  79. }
  80. rtgui_dc_draw_line(dc, rect.x1, rect.y1, rect.x2, rect.y2);
  81. rtgui_dc_draw_line(dc, rect.x1, rect.y2, rect.x2, rect.y1);
  82. rect.x1 += (rect.x2 - rect.x1) / 2;
  83. rect.y1 += (rect.y2 - rect.y1) / 2;
  84. rtgui_dc_draw_text_stroke(dc, __DATE__"--"__TIME__, &rect, HIGH_LIGHT, BLUE);
  85. rtgui_dc_end_drawing(dc);
  86. }
  87. return RT_FALSE;
  88. }
  89. int rt_gui_demo_init(void)
  90. {
  91. rt_thread_t tid;
  92. tid = rt_thread_create("mygui",
  93. rt_gui_demo_entry, RT_NULL,
  94. 2048, 25, 10);
  95. if (tid != RT_NULL)
  96. rt_thread_startup(tid);
  97. return 0;
  98. }
  99. #endif /* RT_USING_GUIENGINE */