demo_application.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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(rt_thread_self(), "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. #if 0
  83. #if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
  84. demo_view_image();
  85. #endif
  86. #ifdef RT_USING_MODULE
  87. #if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
  88. demo_view_module();
  89. #endif
  90. #endif
  91. demo_listview_view();
  92. demo_listview_icon_view();
  93. #if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
  94. demo_fn_view();
  95. #endif
  96. #endif
  97. rtgui_win_show(main_win, RT_FALSE);
  98. /* 执行工作台事件循环 */
  99. rtgui_app_run(app);
  100. rtgui_app_destroy(app);
  101. }
  102. void application_init()
  103. {
  104. static rt_bool_t inited = RT_FALSE;
  105. if (inited == RT_FALSE) /* 避免重复初始化而做的保护 */
  106. {
  107. rt_thread_t tid;
  108. tid = rt_thread_create("wb",
  109. application_entry, RT_NULL,
  110. 2048 * 2, 25, 10);
  111. if (tid != RT_NULL)
  112. rt_thread_startup(tid);
  113. inited = RT_TRUE;
  114. }
  115. }
  116. #ifdef RT_USING_FINSH
  117. #include <finsh.h>
  118. void application()
  119. {
  120. application_init();
  121. }
  122. /* finsh的命令输出,可以直接执行application()函数以执行上面的函数 */
  123. FINSH_FUNCTION_EXPORT(application, application demo)
  124. #endif