MapView.h 2.6 KB

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