MapView.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. BasicMapView(const Point & offset, const Point & dimensions);
  32. ~BasicMapView() override;
  33. void tick(uint32_t msPassed) override;
  34. void show(Canvas & to) override;
  35. void showAll(Canvas & to) override;
  36. };
  37. /// Main class that represents visible section of adventure map
  38. /// Contains all public interface of view and translates calls to internal model
  39. class MapView : public BasicMapView
  40. {
  41. std::shared_ptr<MapViewActions> actions;
  42. std::vector<std::pair<uint32_t, Point>> swipeHistory;
  43. double postSwipeAngle = 0.0;
  44. double postSwipeSpeed = 0.0;
  45. int postSwipeCatchIntervalMs;
  46. const double postSwipeSlowdownSpeed = 0.006;
  47. const double postSwipeMinimalSpeed = 0.1;
  48. void postSwipe(uint32_t msPassed);
  49. public:
  50. void tick(uint32_t msPassed) override;
  51. void show(Canvas & to) override;
  52. MapView(const Point & offset, const Point & dimensions);
  53. /// Moves current view to another level, preserving position
  54. void onMapLevelSwitched();
  55. /// Moves current view by specified distance in pixels
  56. void onMapScrolled(const Point & distance);
  57. /// Moves current view to specified position, in pixels
  58. void onMapSwiped(const Point & viewPosition);
  59. /// Moves current view to specified tile
  60. void onCenteredTile(const int3 & tile);
  61. /// Moves current view to specified object
  62. void onCenteredObject(const CGObjectInstance * target);
  63. /// Switches view to "View Earth" / "View Air" mode, displaying downscaled map with overlay
  64. void onViewSpellActivated(uint32_t tileSize, const std::vector<ObjectPosInfo> & objectPositions, bool showTerrain);
  65. /// Switches view to downscaled View World
  66. void onViewWorldActivated(uint32_t tileSize);
  67. /// Changes zoom level / tile size of current view by specified factor
  68. void onMapZoomLevelChanged(int stepsChange);
  69. /// Switches view from View World mode back to standard view
  70. void onViewMapActivated();
  71. };
  72. /// Main class that represents map view for puzzle map
  73. class PuzzleMapView : public BasicMapView
  74. {
  75. public:
  76. PuzzleMapView(const Point & offset, const Point & dimensions, const int3 & tileToCenter);
  77. };