staticline.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include <rtgui/dc.h>
  2. #include <rtgui/rtgui_theme.h>
  3. #include <rtgui/widgets/staticline.h>
  4. static void _rtgui_staticline_constructor(rtgui_staticline_t *staticline)
  5. {
  6. /* init widget and set event handler */
  7. rtgui_rect_t rect = {0, 0, 100, 2};
  8. rtgui_widget_set_rect(RTGUI_WIDGET(staticline), &rect);
  9. staticline->orientation= RTGUI_HORIZONTAL;
  10. /* set background color */
  11. RTGUI_WIDGET(staticline)->gc.background = RTGUI_RGB(64, 64, 64);
  12. rtgui_widget_set_event_handler(RTGUI_WIDGET(staticline), rtgui_staticline_event_handler);
  13. }
  14. rtgui_type_t *rtgui_staticline_type_get(void)
  15. {
  16. static rtgui_type_t *staticline_type = RT_NULL;
  17. if (!staticline_type)
  18. {
  19. staticline_type = rtgui_type_create("staticline", RTGUI_WIDGET_TYPE,
  20. sizeof(rtgui_staticline_t), RTGUI_CONSTRUCTOR(_rtgui_staticline_constructor), RT_NULL);
  21. }
  22. return staticline_type;
  23. }
  24. rt_bool_t rtgui_staticline_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
  25. {
  26. struct rtgui_staticline* staticline;
  27. RT_ASSERT(widget != RT_NULL);
  28. staticline = (struct rtgui_staticline*) widget;
  29. switch (event->type)
  30. {
  31. case RTGUI_EVENT_PAINT:
  32. #ifndef RTGUI_USING_SMALL_SIZE
  33. if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
  34. else
  35. #endif
  36. rtgui_theme_draw_staticline(staticline);
  37. break;
  38. }
  39. return RT_FALSE;
  40. }
  41. rtgui_staticline_t * rtgui_staticline_create(int orientation)
  42. {
  43. rtgui_staticline_t* staticline;
  44. staticline = (struct rtgui_staticline*) rtgui_widget_create(RTGUI_STATICLINE_TYPE);
  45. if (staticline!= RT_NULL)
  46. {
  47. rtgui_staticline_set_orientation(staticline, orientation);
  48. }
  49. return staticline;
  50. }
  51. void rtgui_staticline_destroy(rtgui_staticline_t* staticline)
  52. {
  53. rtgui_widget_destroy(RTGUI_WIDGET(staticline));
  54. }
  55. void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orientation)
  56. {
  57. RT_ASSERT(staticline != RT_NULL);
  58. staticline->orientation = orientation;
  59. #ifndef RTGUI_USING_SMALL_SIZE
  60. if (orientation == RTGUI_HORIZONTAL)
  61. {
  62. /* HORIZONTAL */
  63. rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 2);
  64. rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 100);
  65. }
  66. else
  67. {
  68. /* VERTICAL */
  69. rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 2);
  70. rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 100);
  71. }
  72. #endif
  73. }