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. 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 show(SDL_Surface * to) override;
  33. void showAll(SDL_Surface * to) override;
  34. };
  35. /// Main class that represents visible section of adventure map
  36. /// Contains all public interface of view and translates calls to internal model
  37. class MapView : public BasicMapView
  38. {
  39. std::shared_ptr<MapViewActions> actions;
  40. bool isSwiping;
  41. public:
  42. void show(SDL_Surface * 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. /// Ends swiping mode and allows normal map scrolling once again
  51. void onMapSwipeEnded();
  52. /// Moves current view to specified tile
  53. void onCenteredTile(const int3 & tile);
  54. /// Moves current view to specified object
  55. void onCenteredObject(const CGObjectInstance * target);
  56. /// Switches view to "View Earth" / "View Air" mode, displaying downscaled map with overlay
  57. void onViewSpellActivated(uint32_t tileSize, const std::vector<ObjectPosInfo> & objectPositions, bool showTerrain);
  58. /// Switches view to downscaled View World
  59. void onViewWorldActivated(uint32_t tileSize);
  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. };