pm_window.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * File : pm_window.h
  3. * COPYRIGHT (C) 2012-2017, Shanghai Real-Thread Technology Co., Ltd
  4. *
  5. * Change Logs:
  6. * Date Author Notes
  7. * 2017-11-05 realthread the first version
  8. */
  9. #pragma once
  10. #include <rtgui/widgets/window.h>
  11. #include <pm_widget.h>
  12. #include <pm_container.h>
  13. #include <vector>
  14. #include <pm_animation.h>
  15. namespace Persimmon
  16. {
  17. class Window : public Container
  18. {
  19. typedef Container super;
  20. public:
  21. enum AnimType
  22. {
  23. AnimNone = 0x00,
  24. AnimFade = 0x01,
  25. AnimMove = 0x02,
  26. AnimMoveUp = 0x04,
  27. AnimMoveDown = 0x08,
  28. AnimMoveLeft = 0x10,
  29. AnimMoveRight = 0x20,
  30. };
  31. DEFINE_CLASS_ENUM_FLAG_OPERATORS(AnimType);
  32. /* create a main window */
  33. Window(const char *title);
  34. /* create a normal window */
  35. Window(struct rtgui_win *parent, const char *title, rtgui_rect_t *rect, rt_uint16_t style);
  36. virtual ~Window();
  37. virtual int show(rt_bool_t isModal = RT_FALSE);
  38. virtual void close(int code = 0);
  39. void hide()
  40. {
  41. rtgui_win_hide(getWindow());
  42. }
  43. void move(int x, int y);
  44. struct rtgui_win* getWindow(void)
  45. {
  46. return RTGUI_WIN(widget);
  47. }
  48. rt_bool_t privateEventHandler(struct rtgui_event *event);
  49. virtual rt_bool_t eventHandler(struct rtgui_event *event);
  50. virtual bool dealKbd(struct rtgui_event_kbd *kev);
  51. virtual bool dealCmd(struct rtgui_event_command *cmd);
  52. void saveClip(struct rtgui_region &region);
  53. void restoreClip(struct rtgui_region &region);
  54. void addFloatingWidget(Widget *widget);
  55. void removeFloatingWidget(Widget *widget);
  56. void _renderFloatingWidget(struct rtgui_dc *dc, rtgui_rect_t *rect);
  57. void renderFloatingWidget(rtgui_rect_t *rect);
  58. void _renderLogo(struct rtgui_dc *dc, rtgui_rect_t *rect);
  59. void setAnimType(enum AnimType type, bool anim = true)
  60. {
  61. animType = type;
  62. doAnim = anim;
  63. }
  64. void doAnimShow(void);
  65. void doAnimHide(void);
  66. void paintWindow(void);
  67. void cancelGesture(void);
  68. protected:
  69. void paintChildren();
  70. bool dealMouseButton(struct rtgui_event_mouse *mev);
  71. bool dealMouseMotion(struct rtgui_event_mouse *mev);
  72. bool dealGesture(struct rtgui_event_gesture *gev);
  73. void renderLogo(rtgui_rect_t *rect);
  74. private:
  75. void setupMouseOwner(struct rtgui_event_mouse *mev);
  76. Widget *setupMouseOwnerFloating(struct rtgui_event_mouse *mev);
  77. struct rtgui_gesture gesture;
  78. Widget *mouseEventOwner;
  79. rt_uint32_t curMouseId;
  80. bool RTGUI_MOUSE_BUTTON_IS_DOWN;
  81. /* floating widget */
  82. std::vector<Widget*> childrenFloating;
  83. /* anim show type */
  84. enum AnimType animType;
  85. bool doAnim;
  86. };
  87. }