CTerrainRect.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * CAdvmapInterface.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 "../widgets/AdventureMapClasses.h"
  12. #include "CWindowObject.h"
  13. #include "../widgets/TextControls.h"
  14. #include "../widgets/Buttons.h"
  15. #include "../../lib/spells/ViewSpellInt.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. struct CGPath;
  18. struct CGPathNode;
  19. class CGHeroInstance;
  20. class CGTownInstance;
  21. class CSpell;
  22. class IShipyard;
  23. VCMI_LIB_NAMESPACE_END
  24. class CCallback;
  25. class CAdvMapInt;
  26. class CHeroWindow;
  27. enum class EMapAnimRedrawStatus;
  28. class CFadeAnimation;
  29. struct MapDrawingInfo;
  30. /// Holds information about which tiles of the terrain are shown/not shown at the screen
  31. class CTerrainRect : public CIntObject
  32. {
  33. SDL_Surface * fadeSurface;
  34. EMapAnimRedrawStatus lastRedrawStatus;
  35. std::shared_ptr<CFadeAnimation> fadeAnim;
  36. int3 swipeInitialMapPos;
  37. int3 swipeInitialRealPos;
  38. bool isSwiping;
  39. static constexpr float SwipeTouchSlop = 16.0f;
  40. void handleHover(const SDL_MouseMotionEvent & sEvent);
  41. void handleSwipeMove(const SDL_MouseMotionEvent & sEvent);
  42. /// handles start/finish of swipe (press/release of corresponding button); returns true if state change was handled
  43. bool handleSwipeStateChange(bool btnPressed);
  44. public:
  45. int tilesw, tilesh; //width and height of terrain to blit in tiles
  46. int3 curHoveredTile;
  47. int moveX, moveY; //shift between actual position of screen and the one we wil blit; ranges from -31 to 31 (in pixels)
  48. CGPath * currentPath;
  49. CTerrainRect();
  50. virtual ~CTerrainRect();
  51. void deactivate() override;
  52. void clickLeft(tribool down, bool previousState) override;
  53. void clickRight(tribool down, bool previousState) override;
  54. void clickMiddle(tribool down, bool previousState) override;
  55. void hover(bool on) override;
  56. void mouseMoved (const SDL_MouseMotionEvent & sEvent) override;
  57. void show(SDL_Surface * to) override;
  58. void showAll(SDL_Surface * to) override;
  59. void showAnim(SDL_Surface * to);
  60. void showPath(const Rect &extRect, SDL_Surface * to);
  61. int3 whichTileIsIt(const int x, const int y); //x,y are cursor position
  62. int3 whichTileIsIt(); //uses current cursor pos
  63. /// @returns number of visible tiles on screen respecting current map scaling
  64. int3 tileCountOnScreen();
  65. /// animates view by caching current surface and crossfading it with normal screen
  66. void fadeFromCurrentView();
  67. bool needsAnimUpdate();
  68. };