CTerrainRect.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * CTerrainRect.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. #include "../../lib/int3.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. struct CGPath;
  15. struct ObjectPosInfo;
  16. VCMI_LIB_NAMESPACE_END
  17. class MapView;
  18. /// Holds information about which tiles of the terrain are shown/not shown at the screen
  19. class CTerrainRect : public CIntObject
  20. {
  21. std::shared_ptr<MapView> renderer;
  22. bool swipeEnabled;
  23. bool swipeMovementRequested;
  24. Point swipeTargetPosition;
  25. Point swipeInitialViewPos;
  26. Point swipeInitialRealPos;
  27. bool isSwiping;
  28. void handleHover(const Point & cursorPosition);
  29. void handleSwipeMove(const Point & cursorPosition);
  30. /// handles start/finish of swipe (press/release of corresponding button); returns true if state change was handled
  31. bool handleSwipeStateChange(bool btnPressed);
  32. int3 curHoveredTile;
  33. int3 whichTileIsIt(const Point & position); //x,y are cursor position
  34. int3 whichTileIsIt(); //uses current cursor pos
  35. Point getViewCenter();
  36. public:
  37. CTerrainRect();
  38. /// Handle swipe & selection of object
  39. void setViewCenter(const int3 & coordinates);
  40. void setViewCenter(const Point & position, int level);
  41. /// Edge scrolling
  42. void moveViewBy(const Point & delta);
  43. /// Toggle undeground view button
  44. void setLevel(int level);
  45. int getLevel();
  46. /// World view & View Earth/Air spells
  47. void setTerrainVisibility(bool showAllTerrain);
  48. void setOverlayVisibility(const std::vector<ObjectPosInfo> & objectPositions);
  49. void setTileSize(int sizePixels);
  50. /// Minimap access
  51. /// @returns number of visible tiles on screen respecting current map scaling
  52. Rect visibleTilesArea();
  53. // CIntObject interface implementation
  54. void deactivate() override;
  55. void clickLeft(tribool down, bool previousState) override;
  56. void clickRight(tribool down, bool previousState) override;
  57. void clickMiddle(tribool down, bool previousState) override;
  58. void hover(bool on) override;
  59. void mouseMoved (const Point & cursorPosition) override;
  60. void show(SDL_Surface * to) override;
  61. //void showAll(SDL_Surface * to) override;
  62. //void showAnim(SDL_Surface * to);
  63. };