pm_wheel.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * File : pm_wheel.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009-2016 RT-Thread Develop Team
  5. */
  6. #ifndef PM_WHEEL_H__
  7. #define PM_WHEEL_H__
  8. #include <vector>
  9. #include <pm_container.h>
  10. #include <sigslot.h>
  11. #include <pm_timer.h>
  12. namespace Persimmon
  13. {
  14. class Wheel : public Container
  15. {
  16. public:
  17. enum type
  18. {
  19. VERTICAL = 0,
  20. HORIZONTAL = 1,
  21. };
  22. Wheel(const Rect& rect, enum type tp = HORIZONTAL);
  23. virtual ~Wheel();
  24. void fixSelItem(void);
  25. void fixItemPtich(void);
  26. virtual bool handleGestureEvent(struct rtgui_event_gesture *gev, const struct rtgui_gesture *gest);
  27. virtual void render(struct rtgui_dc* dc, const Point &dcPoint = Point(), const Rect &srcRect = Rect(), RenderFlag flags = DrawNormal);
  28. virtual void act(int num)
  29. {
  30. rt_kprintf(" act num : %d\n", num);
  31. }
  32. virtual void end(int num)
  33. {
  34. rt_kprintf(" end num : %d\n", num);
  35. }
  36. void setShowSize(int normal, int center = 0)
  37. {
  38. normalSize = normal;
  39. centerSize = normal > center ? normal : center;
  40. }
  41. void setShowItems(int items)
  42. {
  43. showItems = items;
  44. }
  45. void setItemSize(int size)
  46. {
  47. itemSize = size;
  48. }
  49. int getCenterSelNum(void)
  50. {
  51. return centerSelNum;
  52. }
  53. protected:
  54. void onAnimation(void);
  55. void stopAnimation(void);
  56. enum type mtype;
  57. int movePitch, gestPitch;
  58. int centerSelNum;
  59. int normalSize, centerSize, showItems, itemSize;
  60. int firstItemPitch, firstItemNum, itemMovePitch;
  61. int centerNum, oldNum;
  62. Timer *animTimer;
  63. int animMovePitch, animMoveProgress;
  64. bool isFirstRender, isAnim, isStopAnim;
  65. };
  66. class xxWheel : public Wheel
  67. {
  68. public:
  69. xxWheel(const Rect& rect);
  70. virtual ~xxWheel();
  71. void addImg(Image *img, int size = 0);
  72. virtual void render(struct rtgui_dc* dc, const Point &dcPoint = Point(),
  73. const Rect &srcRect = Rect(),
  74. RenderFlag flags = DrawNormal);
  75. void setCoverSize(int size)
  76. {
  77. coverSize = size;
  78. }
  79. void setReductionSize(int size)
  80. {
  81. reductionSize = size;
  82. }
  83. protected:
  84. std::vector<Image *> image[5];
  85. private:
  86. int getCorrectPitch(int num, int pitch)
  87. {
  88. int i, totalPitch = 0;
  89. for (i = 1; i < num; i++)
  90. {
  91. totalPitch += pitch * i;
  92. }
  93. totalPitch += pitch * num / 2;
  94. return totalPitch;
  95. }
  96. int reductionSize, coverSize;
  97. };
  98. }
  99. #endif