gui.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #include <rtgui/rtgui.h>
  2. #include <rtgui/rtgui_system.h>
  3. #include <rtgui/widgets/window.h>
  4. #include <rtgui/widgets/label.h>
  5. #include <finsh.h>
  6. static struct rtgui_timer *timer;
  7. static struct rtgui_label* label;
  8. static struct rtgui_win* msgbox;
  9. static rt_uint8_t label_text[80];
  10. static int cnt = 5;
  11. void diag_close(struct rtgui_timer* timer, void* parameter)
  12. {
  13. rt_sprintf(label_text, "closed then %d second!", cnt);
  14. rtgui_label_set_text(label, label_text);
  15. rtgui_widget_update(RTGUI_WIDGET(label));
  16. if (cnt == 0)
  17. {
  18. rtgui_win_destroy(msgbox);
  19. rtgui_timer_stop(timer);
  20. rtgui_timer_destory(timer);
  21. }
  22. cnt --;
  23. }
  24. void msg()
  25. {
  26. rt_mq_t mq;
  27. rt_thread_t tid;
  28. rt_uint32_t user_data;
  29. struct rtgui_rect rect = {50, 50, 200, 200};
  30. tid = rt_thread_self();
  31. if (tid == RT_NULL) return; /* can't use in none-scheduler environement */
  32. user_data = tid->user_data;
  33. /* create gui message queue */
  34. mq = rt_mq_create("msgbox", 256, 4, RT_IPC_FLAG_FIFO);
  35. /* register message queue on current thread */
  36. rtgui_thread_register(rt_thread_self(), mq);
  37. msgbox = rtgui_win_create(RT_NULL, "Information", &rect, RTGUI_WIN_STYLE_DEFAULT);
  38. if (msgbox != RT_NULL)
  39. {
  40. struct rtgui_box* box = rtgui_box_create(RTGUI_VERTICAL, RT_NULL);
  41. cnt = 5;
  42. rt_sprintf(label_text, "closed then %d second!", cnt);
  43. label = rtgui_label_create(label_text);
  44. rtgui_win_set_box(msgbox, box);
  45. RTGUI_WIDGET(label)->align = RTGUI_ALIGN_CENTER_HORIZONTAL |
  46. RTGUI_ALIGN_CENTER_VERTICAL;
  47. rtgui_widget_set_miniwidth(RTGUI_WIDGET(label),130);
  48. rtgui_box_append(box, RTGUI_WIDGET(label));
  49. rtgui_box_layout(box);
  50. rtgui_win_show(msgbox);
  51. }
  52. timer = rtgui_timer_create(200, RT_TIMER_FLAG_PERIODIC,
  53. diag_close, RT_NULL);
  54. rtgui_timer_start(timer);
  55. rtgui_win_event_loop(msgbox);
  56. rtgui_thread_deregister(rt_thread_self());
  57. /* remove RTGUI message queue */
  58. rt_mq_delete(mq);
  59. /* recover user data */
  60. tid->user_data = user_data;
  61. }
  62. FINSH_FUNCTION_EXPORT(msg, msg on gui)
  63. #include <rtgui/rtgui.h>
  64. #include <rtgui/rtgui_system.h>
  65. #include <rtgui/widgets/box.h>
  66. #include <rtgui/widgets/button.h>
  67. #include <rtgui/widgets/window.h>
  68. #include <rtgui/widgets/textbox.h>
  69. #include <rtgui/widgets/iconbox.h>
  70. #include <rtgui/widgets/view.h>
  71. #include <rtgui/widgets/workbench.h>
  72. /* XPM */
  73. static const char *goto_xpm[] = {
  74. /* columns rows colors chars-per-pixel */
  75. "16 16 43 1",
  76. ". c Black",
  77. "e c #0F0F0F",
  78. "= c #2D2D2D",
  79. "> c #3C3C3C",
  80. "X c #010101",
  81. "$ c #101010",
  82. "% c #1F1F1F",
  83. "r c #090909",
  84. "- c #272727",
  85. "3 c #363636",
  86. "+ c #020202",
  87. "# c #111111",
  88. "2 c #3E3E3E",
  89. "i c #4D4D4D",
  90. "q c #191919",
  91. ", c #373737",
  92. "f c #464646",
  93. "o c #030303",
  94. "u c #121212",
  95. "p c #212121",
  96. "; c #0B0B0B",
  97. " c None",
  98. "7 c #292929",
  99. "O c #040404",
  100. "6 c #131313",
  101. "5 c #222222",
  102. "t c #313131",
  103. "4 c #4F4F4F",
  104. "@ c #0C0C0C",
  105. "a c #1B1B1B",
  106. "* c #2A2A2A",
  107. "0 c #141414",
  108. "< c #0D0D0D",
  109. ": c #3A3A3A",
  110. "9 c #060606",
  111. "& c #151515",
  112. "w c #242424",
  113. "s c #424242",
  114. "d c #1D1D1D",
  115. "8 c #070707",
  116. "1 c #161616",
  117. "g c #252525",
  118. "y c #343434",
  119. /* pixels */
  120. " .XX. ",
  121. " oOOO+ ",
  122. " @####o ",
  123. " $%%%%& ",
  124. " .*===-+ ",
  125. " ;:>,; ",
  126. " <# 12O ",
  127. " 345 .X. ",
  128. " 678 .X++X ",
  129. " +9999o ",
  130. " o0&&&6+ ",
  131. " qwwwwe ",
  132. " rtyy% ",
  133. " +; uip ",
  134. " asd o ",
  135. " $fg "
  136. };
  137. static struct rtgui_image* image = RT_NULL;
  138. static void rtgui_demo_workbench_entry(void* parameter)
  139. {
  140. rt_mq_t mq;
  141. struct rtgui_view* view;
  142. struct rtgui_workbench* workbench;
  143. /* init rtgui demo message queue */
  144. mq = rt_mq_create("mqWB", 256, 4, RT_IPC_FLAG_FIFO);
  145. /* register thread and message queue */
  146. rtgui_thread_register(rt_thread_self(), mq);
  147. /* create container */
  148. workbench = rtgui_workbench_create("main", "widget");
  149. if (workbench == RT_NULL) return;
  150. /************************************************************************/
  151. /* Create View */
  152. /************************************************************************/
  153. view = rtgui_view_create("widget");
  154. rtgui_workbench_add_view(workbench, view);
  155. image = rtgui_image_create_from_mem("xpm", goto_xpm, sizeof(goto_xpm));
  156. {
  157. struct rtgui_box *box = rtgui_box_create(RTGUI_VERTICAL, &rtgui_empty_rect);
  158. struct rtgui_box *hbox = rtgui_box_create(RTGUI_HORIZONTAL, &rtgui_empty_rect);
  159. struct rtgui_button* button = rtgui_button_create("OK");
  160. struct rtgui_textbox *textbox = rtgui_textbox_create("text edit box");
  161. struct rtgui_iconbox *iconbox = rtgui_iconbox_create(image, "icon",
  162. RTGUI_ICONBOX_TEXT_RIGHT);
  163. RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = RTGUI_RGB(255, 255, 224);
  164. rtgui_view_set_box(view, box);
  165. RTGUI_WIDGET(button)->align = RTGUI_ALIGN_CENTER_VERTICAL;
  166. rtgui_widget_set_miniwidth(RTGUI_WIDGET(button), 80);
  167. rtgui_widget_set_miniheight(RTGUI_WIDGET(button), 25);
  168. rtgui_box_append(box, RTGUI_WIDGET(button));
  169. /* add a horizontal box */
  170. rtgui_widget_set_miniwidth(RTGUI_WIDGET(hbox), 20);
  171. rtgui_widget_set_miniheight(RTGUI_WIDGET(hbox), 100);
  172. RTGUI_WIDGET(hbox)->align = RTGUI_ALIGN_EXPAND;
  173. rtgui_box_layout(hbox);
  174. rtgui_box_append(box, RTGUI_WIDGET(hbox));
  175. rtgui_box_append(box, RTGUI_WIDGET(textbox));
  176. /* add icon box */
  177. RTGUI_WIDGET(iconbox)->gc.font = rtgui_font_refer("hz", 16);
  178. rtgui_box_append(box, RTGUI_WIDGET(iconbox));
  179. rtgui_box_layout(box);
  180. }
  181. /* show view */
  182. rtgui_view_show(view);
  183. rtgui_workbench_event_loop(workbench);
  184. }
  185. void rtgui_demo_workbench_init()
  186. {
  187. static rt_bool_t inited = RT_FALSE;
  188. if (inited == RT_FALSE)
  189. {
  190. rt_thread_t tid;
  191. tid = rt_thread_create("tWB",
  192. rtgui_demo_workbench_entry, RT_NULL,
  193. 2048, 25, 10);
  194. if (tid != RT_NULL) rt_thread_startup(tid);
  195. inited = RT_TRUE;
  196. }
  197. }
  198. #ifdef RT_USING_RTGUI
  199. #include <finsh.h>
  200. void w()
  201. {
  202. rtgui_demo_workbench_init();
  203. }
  204. FINSH_FUNCTION_EXPORT(w, workbench demo)
  205. #endif