card.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * File : card.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 <vector>
  11. #include <pm_widget.h>
  12. #include <pm_image.h>
  13. #include <pm_container.h>
  14. #include <sigslot.h>
  15. namespace Persimmon
  16. {
  17. class Card : public Container
  18. {
  19. typedef Container super;
  20. public:
  21. enum type
  22. {
  23. VERTICAL = 0,
  24. HORIZONTAL = 1 << 0,
  25. CYCLE = 1 << 1,
  26. };
  27. DEFINE_CLASS_ENUM_FLAG_OPERATORS(type);
  28. Card (const Rect& rect, enum type tp = HORIZONTAL);
  29. Card (Image *dot_nor, Image *dot_sel, const Rect& rect, enum type tp = HORIZONTAL);
  30. virtual ~Card();
  31. virtual void addChild(Widget* widget);
  32. virtual void removeChild(Widget* widget);
  33. void setDotIndicator(Image *dot_nor, Image *dot_sel)
  34. {
  35. if (this->dot_nor)
  36. delete this->dot_nor;
  37. if (this->dot_sel)
  38. delete this->dot_sel;
  39. this->dot_nor = dot_nor;
  40. this->dot_sel = dot_sel;
  41. }
  42. void nextCardPage(void)
  43. {
  44. changeCardPage(currentIndex + 1);
  45. }
  46. void prevCardPage(void)
  47. {
  48. changeCardPage(currentIndex - 1);
  49. }
  50. void selectCardPage(int index)
  51. {
  52. /* set currentIndex */
  53. if (index < 0 || index >= children.size())
  54. return;
  55. children[currentIndex]->hide();
  56. currentIndex = index;
  57. children[currentIndex]->show();
  58. }
  59. int getCurrentCardPage()
  60. {
  61. return currentIndex;
  62. }
  63. int pageCount(void)
  64. {
  65. return children.size();
  66. }
  67. void setActiveValue(unsigned int value)
  68. {
  69. activeValue = value;
  70. }
  71. void setMinMovePitch(unsigned int value)
  72. {
  73. minMovePitch = value;
  74. }
  75. virtual void render(struct rtgui_dc* dc, const Point &dcPoint = Point(),
  76. const Rect &srcRect = Rect(),
  77. RenderFlag flags = DrawNormal);
  78. virtual bool handleGestureEvent(struct rtgui_event_gesture *gev,
  79. const struct rtgui_gesture *gest);
  80. virtual Widget* getMouseOwner(int x, int y);
  81. Signal<int> changed;
  82. Signal<void> moving;
  83. protected:
  84. enum type mtype;
  85. int currentIndex, old_pitch;
  86. struct rtgui_dc *mvdc;
  87. bool old_mvnext, is_moveing, is_boundary;
  88. Image *dot_nor, *dot_sel;
  89. private:
  90. void changeCardPage(int index);
  91. void moveCard(struct rtgui_event_gesture* event, const struct rtgui_gesture *gesture);
  92. struct rtgui_dc* getAnimationDC(bool left);
  93. struct rtgui_dc* getAnimationDC(int first, int last);
  94. void renderIndicator(struct rtgui_dc *dc, const Point &point);
  95. unsigned int activeValue, minMovePitch;
  96. };
  97. }