MapView.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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::map<uint64_t, Point> swipeHistory;
  43. double postSwipeAngle;
  44. double postSwipeSpeed;
  45. void postSwipe(uint32_t msPassed);
  46. public:
  47. void tick(uint32_t msPassed) override;
  48. void show(Canvas & to) override;
  49. MapView(const Point & offset, const Point & dimensions);
  50. /// Moves current view to another level, preserving position
  51. void onMapLevelSwitched();
  52. /// Moves current view by specified distance in pixels
  53. void onMapScrolled(const Point & distance);
  54. /// Moves current view to specified position, in pixels
  55. void onMapSwiped(const Point & viewPosition);
  56. /// Moves current view to specified tile
  57. void onCenteredTile(const int3 & tile);
  58. /// Moves current view to specified object
  59. void onCenteredObject(const CGObjectInstance * target);
  60. /// Switches view to "View Earth" / "View Air" mode, displaying downscaled map with overlay
  61. void onViewSpellActivated(uint32_t tileSize, const std::vector<ObjectPosInfo> & objectPositions, bool showTerrain);
  62. /// Switches view to downscaled View World
  63. void onViewWorldActivated(uint32_t tileSize);
  64. /// Changes zoom level / tile size of current view by specified factor
  65. void onMapZoomLevelChanged(int stepsChange);
  66. /// Switches view from View World mode back to standard view
  67. void onViewMapActivated();
  68. };
  69. /// Main class that represents map view for puzzle map
  70. class PuzzleMapView : public BasicMapView
  71. {
  72. public:
  73. PuzzleMapView(const Point & offset, const Point & dimensions, const int3 & tileToCenter);
  74. };