CTerrainRect.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. VCMI_LIB_NAMESPACE_END
  16. enum class EMapAnimRedrawStatus;
  17. class CFadeAnimation;
  18. /// Holds information about which tiles of the terrain are shown/not shown at the screen
  19. class CTerrainRect : public CIntObject
  20. {
  21. SDL_Surface * fadeSurface;
  22. EMapAnimRedrawStatus lastRedrawStatus;
  23. std::shared_ptr<CFadeAnimation> fadeAnim;
  24. int3 swipeInitialMapPos;
  25. Point swipeInitialRealPos;
  26. bool isSwiping;
  27. static constexpr float SwipeTouchSlop = 16.0f;
  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. public:
  33. int tilesw, tilesh; //width and height of terrain to blit in tiles
  34. int3 curHoveredTile;
  35. int moveX, moveY; //shift between actual position of screen and the one we wil blit; ranges from -31 to 31 (in pixels)
  36. CGPath * currentPath;
  37. CTerrainRect();
  38. virtual ~CTerrainRect();
  39. void deactivate() override;
  40. void clickLeft(tribool down, bool previousState) override;
  41. void clickRight(tribool down, bool previousState) override;
  42. void clickMiddle(tribool down, bool previousState) override;
  43. void hover(bool on) override;
  44. void mouseMoved (const Point & cursorPosition) override;
  45. void show(SDL_Surface * to) override;
  46. void showAll(SDL_Surface * to) override;
  47. void showAnim(SDL_Surface * to);
  48. void showPath(const Rect &extRect, SDL_Surface * to);
  49. int3 whichTileIsIt(const int x, const int y); //x,y are cursor position
  50. int3 whichTileIsIt(); //uses current cursor pos
  51. /// @returns number of visible tiles on screen respecting current map scaling
  52. int3 tileCountOnScreen();
  53. /// animates view by caching current surface and crossfading it with normal screen
  54. void fadeFromCurrentView();
  55. bool needsAnimUpdate();
  56. };