about_view.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * File : about_view.c
  3. * This file is part of RTGUI in RT-Thread RTOS
  4. * COPYRIGHT (C) 2010, 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. * 2010-01-06 Bernard first version
  13. */
  14. #include <rtgui/rtgui_theme.h>
  15. #include <rtgui/widgets/about_view.h>
  16. static void _rtgui_about_view_constructor(struct rtgui_about_view *view)
  17. {
  18. /* default rect */
  19. struct rtgui_rect rect = {0, 0, 200, 200};
  20. /* set default widget rect and set event handler */
  21. rtgui_widget_set_event_handler(RTGUI_WIDGET(view),rtgui_about_view_event_handler);
  22. rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
  23. RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
  24. view->logo = RT_NULL;
  25. view->description = RT_NULL;
  26. RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL;
  27. }
  28. rtgui_type_t *rtgui_about_view_type_get(void)
  29. {
  30. static rtgui_type_t *list_view_type = RT_NULL;
  31. if (!list_view_type)
  32. {
  33. list_view_type = rtgui_type_create("aboutview", RTGUI_VIEW_TYPE,
  34. sizeof(rtgui_about_view_t), RTGUI_CONSTRUCTOR(_rtgui_about_view_constructor), RT_NULL);
  35. }
  36. return list_view_type;
  37. }
  38. void rtgui_about_view_ondraw(struct rtgui_about_view* view)
  39. {
  40. struct rtgui_rect rect;
  41. struct rtgui_dc* dc;
  42. dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
  43. if (dc == RT_NULL) return;
  44. rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
  45. rtgui_dc_fill_rect(dc, &rect);
  46. if (view->logo != RT_NULL)
  47. rtgui_image_blit(view->logo, dc, &rect);
  48. rect.y1 += view->logo->h + 5;
  49. if (view->description != RT_NULL)
  50. rtgui_dc_draw_text(dc, view->description, &rect);
  51. rect.y1 += rtgui_dc_get_gc(dc)->font->height;
  52. rtgui_dc_draw_hline(dc, rect.x1 + 3, rect.x2 - 3, rect.y1);
  53. RTGUI_DC_FC(dc) = white;
  54. rtgui_dc_draw_hline(dc, rect.x1 + 4, rect.x2 - 2, rect.y1 + 1);
  55. rtgui_dc_end_drawing(dc);
  56. }
  57. rt_bool_t rtgui_about_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
  58. {
  59. struct rtgui_about_view* view = RT_NULL;
  60. view = RTGUI_ABOUT_VIEW(widget);
  61. switch (event->type)
  62. {
  63. case RTGUI_EVENT_PAINT:
  64. rtgui_about_view_ondraw(view);
  65. return RT_FALSE;
  66. }
  67. /* use view event handler */
  68. return rtgui_view_event_handler(widget, event);
  69. }
  70. rtgui_about_view_t* rtgui_about_view_create(rtgui_image_t *logo, const char* description)
  71. {
  72. struct rtgui_about_view* view = RT_NULL;
  73. view = (struct rtgui_about_view*) rtgui_widget_create(RTGUI_ABOUT_VIEW_TYPE);
  74. if (view != RT_NULL)
  75. {
  76. view->logo = logo;
  77. view->description = description;
  78. }
  79. return view;
  80. }
  81. void rtgui_about_view_destroy(rtgui_about_view_t* view)
  82. {
  83. /* destroy view */
  84. rtgui_widget_destroy(RTGUI_WIDGET(view));
  85. }