panel.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * File : panel.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2012-07-07 Bernard implement panel as a widget
  13. */
  14. #include <rtgui/dc.h>
  15. #include <rtgui/widgets/panel.h>
  16. #include <rtgui/rtgui_system.h>
  17. #include <rtgui/rtgui_theme.h>
  18. static void _rtgui_panel_constructor(rtgui_panel_t *panel)
  19. {
  20. /* init widget and set event handler */
  21. rtgui_object_set_event_handler(RTGUI_OBJECT(panel), rtgui_panel_event_handler);
  22. /* set field */
  23. panel->border_style = RTGUI_BORDER_NONE;
  24. }
  25. DEFINE_CLASS_TYPE(panel, "panel",
  26. RTGUI_CONTAINER_TYPE,
  27. _rtgui_panel_constructor,
  28. RT_NULL,
  29. sizeof(struct rtgui_panel));
  30. rt_bool_t rtgui_panel_event_handler(struct rtgui_object *object, struct rtgui_event* event)
  31. {
  32. struct rtgui_panel* panel;
  33. panel = RTGUI_PANEL(object);
  34. switch (event->type)
  35. {
  36. case RTGUI_EVENT_PAINT:
  37. {
  38. struct rtgui_dc* dc;
  39. struct rtgui_rect rect;
  40. rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
  41. dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(object));
  42. if (dc == RT_NULL) return RT_FALSE;
  43. rtgui_dc_fill_rect(dc, &rect);
  44. // rtgui_rect_inflate(&rect, RTGUI_WIDGET(panel)->);
  45. rtgui_dc_draw_border(dc, &rect, panel->border_style);
  46. /* paint on each child */
  47. rtgui_container_dispatch_event(RTGUI_CONTAINER(panel), event);
  48. rtgui_dc_end_drawing(dc);
  49. }
  50. break;
  51. default:
  52. return rtgui_container_event_handler(object, event);
  53. }
  54. return RT_FALSE;
  55. }
  56. rtgui_panel_t* rtgui_panel_create(int border_style)
  57. {
  58. struct rtgui_panel* panel;
  59. panel = (struct rtgui_panel*) rtgui_widget_create(RTGUI_PANEL_TYPE);
  60. if (panel != RT_NULL)
  61. {
  62. rtgui_rect_t rect = {0, 0, 100, 100};
  63. rtgui_widget_set_rect(RTGUI_WIDGET(panel), &rect);
  64. panel->border_style = border_style;
  65. }
  66. return panel;
  67. }
  68. void rtgui_panel_destroy(rtgui_panel_t* panel)
  69. {
  70. rtgui_object_destroy(RTGUI_OBJECT(panel));
  71. }