MapView.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * MapView.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. VCMI_LIB_NAMESPACE_BEGIN
  13. struct ObjectPosInfo;
  14. class CGObjectInstance;
  15. VCMI_LIB_NAMESPACE_END
  16. class Canvas;
  17. class MapViewActions;
  18. class MapViewController;
  19. class MapViewModel;
  20. class MapViewCache;
  21. /// Internal class that contains logic shared between all map views
  22. class BasicMapView : public CIntObject
  23. {
  24. protected:
  25. std::shared_ptr<MapViewModel> model;
  26. std::shared_ptr<MapViewCache> tilesCache;
  27. std::shared_ptr<MapViewController> controller;
  28. std::shared_ptr<MapViewModel> createModel(const Point & dimensions) const;
  29. void render(Canvas & target, bool fullUpdate);
  30. public:
  31. bool needFullUpdate;
  32. BasicMapView(const Point & offset, const Point & dimensions);
  33. ~BasicMapView() override;
  34. void tick(uint32_t msPassed) override;
  35. void show(Canvas & to) override;
  36. void showAll(Canvas & to) override;
  37. };
  38. /// Main class that represents visible section of adventure map
  39. /// Contains all public interface of view and translates calls to internal model
  40. class MapView : public BasicMapView
  41. {
  42. std::shared_ptr<MapViewActions> actions;
  43. std::vector<std::pair<uint32_t, Point>> swipeHistory;
  44. double postSwipeAngle = 0.0;
  45. double postSwipeSpeed = 0.0;
  46. int postSwipeCatchIntervalMs;
  47. const double postSwipeSlowdownSpeed = 0.006;
  48. const double postSwipeMinimalSpeed = 0.1;
  49. void postSwipe(uint32_t msPassed);
  50. public:
  51. void tick(uint32_t msPassed) override;
  52. void show(Canvas & to) override;
  53. MapView(const Point & offset, const Point & dimensions);
  54. /// Moves current view to another level, preserving position
  55. void onMapLevelSwitched();
  56. /// Moves current view by specified distance in pixels
  57. void onMapScrolled(const Point & distance);
  58. /// Moves current view to specified position, in pixels
  59. void onMapSwiped(const Point & viewPosition);
  60. /// Moves current view to specified tile
  61. void onCenteredTile(const int3 & tile);
  62. /// Moves current view to specified object
  63. void onCenteredObject(const CGObjectInstance * target);
  64. /// Switches view to "View Earth" / "View Air" mode, displaying downscaled map with overlay
  65. void onViewSpellActivated(uint32_t tileSize, const std::vector<ObjectPosInfo> & objectPositions, bool showTerrain);
  66. /// Switches view to downscaled View World
  67. void onViewWorldActivated(uint32_t tileSize);
  68. /// Changes zoom level / tile size of current view by specified factor
  69. void onMapZoomLevelChanged(int stepsChange, bool useDeadZone);
  70. /// Switches view from View World mode back to standard view
  71. void onViewMapActivated();
  72. };
  73. /// Main class that represents map view for puzzle map
  74. class PuzzleMapView : public BasicMapView
  75. {
  76. public:
  77. PuzzleMapView(const Point & offset, const Point & dimensions, const int3 & tileToCenter);
  78. };