Scrollable.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Scrollable.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../gui/CIntObject.h"
  12. enum class Orientation
  13. {
  14. HORIZONTAL,
  15. VERTICAL
  16. };
  17. /// Simple class that provides scrolling functionality via either mouse wheel or touchscreen gesture
  18. class Scrollable : public CIntObject
  19. {
  20. /// how many elements will be scrolled via one wheel action, default = 1
  21. int scrollStep;
  22. /// How far player must move finger/mouse to move slider by 1 via gesture
  23. int panningDistanceSingle;
  24. /// How far have player moved finger/mouse via gesture so far.
  25. int panningDistanceAccumulated;
  26. Orientation orientation;
  27. protected:
  28. Scrollable(int used, Point position, Orientation orientation);
  29. void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
  30. void wheelScrolled(int distance) override;
  31. void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override;
  32. int getScrollStep() const;
  33. Orientation getOrientation() const;
  34. public:
  35. /// Scrolls view by specified number of items
  36. virtual void scrollBy(int distance) = 0;
  37. /// Scrolls view by 1 item, identical to scrollBy(+1)
  38. virtual void scrollNext();
  39. /// Scrolls view by 1 item, identical to scrollBy(-1)
  40. virtual void scrollPrev();
  41. /// Controls how many items wil be scrolled via one click
  42. void setScrollStep(int to);
  43. /// Controls size of panning step needed to move list by 1 item
  44. void setPanningStep(int to);
  45. /// Enables or disabled scrolling
  46. void setScrollingEnabled(bool on);
  47. };