rtgui_demo.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <rtgui/rtgui.h>
  15. #include <rtgui/rtgui_system.h>
  16. #include <rtgui/rtgui_app.h>
  17. #include <rtgui/widgets/window.h>
  18. #include <rtgui/dc.h>
  19. #include "finsh.h"
  20. #include "rtgui_demo.h"
  21. #define DEBUG
  22. #ifdef DEBUG
  23. #define DEBUG_PRINTF(...) rt_kprintf(__VA_ARGS__)
  24. #else
  25. #define DEBUG_PRINTF(...)
  26. #endif
  27. #ifdef PKG_USING_GUIENGINE
  28. struct rtgui_win *main_win;
  29. rt_bool_t dc_event_handler(struct rtgui_object *object, rtgui_event_t *event);
  30. static void rt_gui_demo_entry(void *parameter)
  31. {
  32. struct rtgui_app *app;
  33. //struct rtgui_dc *dc;
  34. DEBUG_PRINTF("gui demo entry\n");
  35. /* create gui app */
  36. app = rtgui_app_create("gui_demo");
  37. if (app == RT_NULL)
  38. {
  39. DEBUG_PRINTF("rtgui_app_create faild\n");
  40. return;
  41. }
  42. /* create main window */
  43. main_win = rtgui_mainwin_create(RT_NULL,
  44. "UiWindow", RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER);
  45. if (main_win == RT_NULL)
  46. {
  47. DEBUG_PRINTF("main_win is null\n");
  48. rtgui_app_destroy(app);
  49. return;
  50. }
  51. rtgui_object_set_event_handler(RTGUI_OBJECT(main_win), dc_event_handler);
  52. DEBUG_PRINTF("rtgui_win_show\n");
  53. rtgui_win_show(main_win, RT_FALSE);
  54. DEBUG_PRINTF("rtgui_app_run\n");
  55. rtgui_app_run(app);
  56. DEBUG_PRINTF("rtgui_win_destroy\n");
  57. rtgui_win_destroy(main_win);
  58. DEBUG_PRINTF("rtgui_app_destroy\n");
  59. rtgui_app_destroy(app);
  60. }
  61. rt_bool_t dc_event_handler(struct rtgui_object *object, rtgui_event_t *event)
  62. {
  63. struct rtgui_widget *widget = RTGUI_WIDGET(object);
  64. if (event->type == RTGUI_EVENT_PAINT)
  65. {
  66. struct rtgui_dc *dc;
  67. rtgui_rect_t rect;
  68. rt_kprintf("\r\n RTGUI_EVENT_PAINT \r\n");
  69. rtgui_win_event_handler(RTGUI_OBJECT(widget), event);
  70. rtgui_widget_get_rect(widget, &rect);
  71. DEBUG_PRINTF("widget react x1: %d, y1: %d, x2: %d, y2: %d\r\n",
  72. rect.x1, rect.y1, rect.x2, rect.y2);
  73. dc = rtgui_dc_begin_drawing(widget);
  74. if(dc == RT_NULL)
  75. {
  76. DEBUG_PRINTF("\r\n dc is null \r\n");
  77. return RT_FALSE;
  78. }
  79. rtgui_dc_draw_line(dc,0,0,240,320);
  80. rtgui_dc_draw_line(dc,0,320,240,0);
  81. //rtgui_dc_draw_text(dc, __DATE__, &rect);
  82. rtgui_dc_draw_text_stroke(dc, __DATE__, &rect, HIGH_LIGHT, BLUE);
  83. rect.y1 += 20;
  84. rect.y2 += 20;
  85. rtgui_dc_draw_text_stroke(dc, __TIME__, &rect, HIGH_LIGHT, BLACK);
  86. rtgui_dc_end_drawing(dc, RT_TRUE);
  87. }
  88. return RT_FALSE;
  89. }
  90. int rt_gui_demo_init(void)
  91. {
  92. rt_thread_t tid;
  93. tid = rt_thread_create("mygui",
  94. rt_gui_demo_entry, RT_NULL,
  95. 2048, 25, 10);
  96. if (tid != RT_NULL)
  97. rt_thread_startup(tid);
  98. return 0;
  99. }
  100. #endif /* PKG_USING_GUIENGINE */