MapView.h 2.6 KB

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