demo_application.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include <rtgui/rtgui.h>
  2. #include <rtgui/rtgui_system.h>
  3. #include <rtgui/rtgui_app.h>
  4. #include <rtgui/widgets/window.h>
  5. #include <rtgui/widgets/notebook.h>
  6. struct rtgui_notebook *the_notebook;
  7. static rt_bool_t demo_handle_key(struct rtgui_object *object, struct rtgui_event *event)
  8. {
  9. struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
  10. if (ekbd->type == RTGUI_KEYUP)
  11. {
  12. if (ekbd->key == RTGUIK_RIGHT)
  13. {
  14. demo_view_next(RT_NULL, RT_NULL);
  15. return RT_TRUE;
  16. }
  17. else if (ekbd->key == RTGUIK_LEFT)
  18. {
  19. demo_view_prev(RT_NULL, RT_NULL);
  20. return RT_TRUE;
  21. }
  22. }
  23. return RT_TRUE;
  24. }
  25. struct rtgui_win *main_win;
  26. static void application_entry(void *parameter)
  27. {
  28. struct rtgui_app *app;
  29. struct rtgui_rect rect;
  30. app = rtgui_app_create("gui_demo");
  31. if (app == RT_NULL)
  32. return;
  33. /* create a full screen window */
  34. rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect);
  35. main_win = rtgui_win_create(RT_NULL, "demo_win", &rect,
  36. RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE);
  37. if (main_win == RT_NULL)
  38. {
  39. rtgui_app_destroy(app);
  40. return;
  41. }
  42. rtgui_win_set_onkey(main_win, demo_handle_key);
  43. /* create a no title notebook that we can switch demo on it easily. */
  44. the_notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_NOTAB);
  45. if (the_notebook == RT_NULL)
  46. {
  47. rtgui_win_destroy(main_win);
  48. rtgui_app_destroy(app);
  49. return;
  50. }
  51. rtgui_container_add_child(RTGUI_CONTAINER(main_win), RTGUI_WIDGET(the_notebook));
  52. //demo_view_box();
  53. /* 初始化各个例子的视图 */
  54. demo_view_benchmark();
  55. demo_view_dc();
  56. #ifdef RTGUI_USING_TTF
  57. demo_view_ttf();
  58. #endif
  59. #ifndef RTGUI_USING_SMALL_SIZE
  60. demo_view_dc_buffer();
  61. #endif
  62. demo_view_animation();
  63. #ifndef RTGUI_USING_SMALL_SIZE
  64. demo_view_buffer_animation();
  65. demo_view_instrument_panel();
  66. #endif
  67. demo_view_window();
  68. demo_view_label();
  69. demo_view_button();
  70. demo_view_checkbox();
  71. demo_view_progressbar();
  72. demo_view_scrollbar();
  73. demo_view_radiobox();
  74. demo_view_textbox();
  75. demo_view_listbox();
  76. demo_view_menu();
  77. demo_view_listctrl();
  78. demo_view_combobox();
  79. demo_view_slider();
  80. demo_view_notebook();
  81. demo_view_mywidget();
  82. demo_plot();
  83. demo_view_digtube();
  84. #if defined(RTGUI_USING_DFS_FILERW)
  85. demo_view_edit();
  86. demo_view_bmp();
  87. #endif
  88. #if 0
  89. #if defined(RTGUI_USING_DFS_FILERW)
  90. demo_view_image();
  91. #endif
  92. #ifdef RT_USING_MODULE
  93. #if defined(RTGUI_USING_DFS_FILERW)
  94. demo_view_module();
  95. #endif
  96. #endif
  97. demo_listview_view();
  98. demo_listview_icon_view();
  99. #if defined(RTGUI_USING_DFS_FILERW)
  100. demo_fn_view();
  101. #endif
  102. #endif
  103. rtgui_win_show(main_win, RT_FALSE);
  104. /* 执行工作台事件循环 */
  105. rtgui_app_run(app);
  106. rtgui_app_destroy(app);
  107. }
  108. void application_init()
  109. {
  110. static rt_bool_t inited = RT_FALSE;
  111. if (inited == RT_FALSE) /* 避免重复初始化而做的保护 */
  112. {
  113. rt_thread_t tid;
  114. tid = rt_thread_create("wb",
  115. application_entry, RT_NULL,
  116. 2048 * 2, 25, 10);
  117. if (tid != RT_NULL)
  118. rt_thread_startup(tid);
  119. inited = RT_TRUE;
  120. }
  121. }
  122. #ifdef RT_USING_FINSH
  123. #include <finsh.h>
  124. void application()
  125. {
  126. application_init();
  127. }
  128. /* finsh的命令输出,可以直接执行application()函数以执行上面的函数 */
  129. FINSH_FUNCTION_EXPORT(application, application demo)
  130. #endif