statusbar.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #include "statusbar.h"
  2. #include <rtgui/dc.h>
  3. #include <rtgui/image.h>
  4. #include "xpm/start.xpm"
  5. static const rtgui_color_t _status_bar_pixels[] =
  6. {
  7. RTGUI_RGB(228,228,228),
  8. RTGUI_RGB(182,186,192),
  9. RTGUI_RGB(92,158,200),
  10. RTGUI_RGB(30,117,176),
  11. RTGUI_RGB(30,116,175),
  12. RTGUI_RGB(29,115,174),
  13. RTGUI_RGB(29,114,173),
  14. RTGUI_RGB(29,114,172),
  15. RTGUI_RGB(29,113,171),
  16. RTGUI_RGB(28,112,170),
  17. RTGUI_RGB(28,111,170),
  18. RTGUI_RGB(28,111,169),
  19. RTGUI_RGB(28,110,168),
  20. RTGUI_RGB(27,109,167),
  21. RTGUI_RGB(27,108,166),
  22. RTGUI_RGB(27,108,165),
  23. RTGUI_RGB(26,107,164),
  24. RTGUI_RGB(26,106,163),
  25. RTGUI_RGB(26,105,163),
  26. RTGUI_RGB(26,105,162),
  27. RTGUI_RGB(25,104,161),
  28. RTGUI_RGB(25,103,160),
  29. RTGUI_RGB(25,102,159),
  30. RTGUI_RGB(25,101,158),
  31. RTGUI_RGB(24,101,157),
  32. RTGUI_RGB(24,100,156),
  33. RTGUI_RGB(24,99,156),
  34. RTGUI_RGB(24,98,155),
  35. RTGUI_RGB(23,98,154),
  36. RTGUI_RGB(23,97,153),
  37. RTGUI_RGB(23,96,153),
  38. RTGUI_RGB(23,95,152),
  39. RTGUI_RGB(22,94,150),
  40. RTGUI_RGB(22,94,149),
  41. RTGUI_RGB(22,93,148),
  42. RTGUI_RGB(21,92,147),
  43. RTGUI_RGB(21,91,146),
  44. RTGUI_RGB(21,91,145),
  45. RTGUI_RGB(20,90,143),
  46. RTGUI_RGB(20,89,142),
  47. RTGUI_RGB(20,88,141),
  48. RTGUI_RGB(19,87,139),
  49. RTGUI_RGB(19,86,138),
  50. RTGUI_RGB(19,85,136),
  51. RTGUI_RGB(18,85,138),
  52. RTGUI_RGB(18,84,137),
  53. RTGUI_RGB(18,83,137),
  54. RTGUI_RGB(18,82,136),
  55. RTGUI_RGB(47,91,135),
  56. RTGUI_RGB(255,255,255),
  57. };
  58. void dc_draw_bar(struct rtgui_dc* dc, const rtgui_color_t *bar_pixel, struct rtgui_rect *rect, int style)
  59. {
  60. rt_uint32_t index;
  61. struct rtgui_gc *gc;
  62. rtgui_color_t fg;
  63. gc = rtgui_dc_get_gc(dc);
  64. fg = gc->foreground;
  65. if (style == RTGUI_HORIZONTAL)
  66. {
  67. /* horizontal */
  68. for (index = rect->y1; index < rect->y2; index ++)
  69. {
  70. gc->foreground = bar_pixel[index - rect->y1];
  71. rtgui_dc_draw_hline(dc, rect->x1, rect->x2, index);
  72. }
  73. }
  74. else
  75. {
  76. /* vertical */
  77. for (index = rect->x1; index < rect->x2; index ++)
  78. {
  79. gc->foreground = bar_pixel[index - rect->x1];
  80. rtgui_dc_draw_vline(dc, index, rect->y1, rect->y2);
  81. }
  82. }
  83. gc->foreground = fg;
  84. }
  85. rt_bool_t statusbar_event_handler(struct rtgui_object* object, struct rtgui_event* event)
  86. {
  87. switch (event->type)
  88. {
  89. case RTGUI_EVENT_PAINT:
  90. {
  91. struct rtgui_dc *dc;
  92. struct rtgui_rect rect;
  93. struct rtgui_image *image;
  94. /* create start image */
  95. image = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)start_xpm, sizeof(start_xpm), RT_FALSE);
  96. rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
  97. dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(object));
  98. dc_draw_bar(dc, _status_bar_pixels, &rect, RTGUI_HORIZONTAL);
  99. rect.x1 += 15;
  100. rtgui_image_blit(image, dc, &rect);
  101. /* dispatch event */
  102. rtgui_container_dispatch_event(RTGUI_CONTAINER(object), event);
  103. rtgui_dc_end_drawing(dc);
  104. rtgui_image_destroy(image);
  105. }
  106. break;
  107. case RTGUI_EVENT_MOUSE_BUTTON:
  108. {
  109. struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
  110. struct rtgui_rect start_rect;
  111. rtgui_widget_get_extent(RTGUI_WIDGET(object), &start_rect);
  112. start_rect.x1 += 15;
  113. start_rect.x2 = start_rect.x1 + 48;
  114. /* it's not this widget event, clean status */
  115. if (rtgui_rect_contains_point(&start_rect, emouse->x, emouse->y) == RT_EOK &&
  116. emouse->button & (RTGUI_MOUSE_BUTTON_UP))
  117. {
  118. rtgui_app_activate(rtgui_app_self());
  119. break;
  120. }
  121. return RT_TRUE;
  122. }
  123. default:
  124. return rtgui_win_event_handler(object, event);
  125. }
  126. return RT_FALSE;
  127. }
  128. void statusbar_init(void)
  129. {
  130. rtgui_rect_t rect;
  131. struct rtgui_win* win;
  132. /* get scree rect */
  133. rtgui_get_screen_rect(&rect);
  134. rect.y2 = rect.y1 + 50;
  135. /* create status bar window */
  136. win = rtgui_win_create(RT_NULL, "StatusBar", &rect, RTGUI_WIN_STYLE_NO_BORDER |
  137. RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_ONTOP);
  138. rtgui_object_set_event_handler(RTGUI_OBJECT(win), statusbar_event_handler);
  139. rtgui_get_screen_rect(&rect);
  140. rect.y1 = 50;
  141. /* set the rect information of main window */
  142. rtgui_set_mainwin_rect(&rect);
  143. rtgui_win_show(win, RT_FALSE);
  144. }