CTerrainRect.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. int3 curHoveredTile;
  33. int3 whichTileIsIt(const int x, const int y); //x,y are cursor position
  34. int3 whichTileIsIt(); //uses current cursor pos
  35. void showPath(const Rect &extRect, SDL_Surface * to);
  36. bool needsAnimUpdate();
  37. public:
  38. int tilesw, tilesh; //width and height of terrain to blit in tiles
  39. int moveX, moveY; //shift between actual position of screen and the one we wil blit; ranges from -31 to 31 (in pixels)
  40. CGPath * currentPath;
  41. CTerrainRect();
  42. ~CTerrainRect();
  43. // CIntObject interface implementation
  44. void deactivate() override;
  45. void clickLeft(tribool down, bool previousState) override;
  46. void clickRight(tribool down, bool previousState) override;
  47. void clickMiddle(tribool down, bool previousState) override;
  48. void hover(bool on) override;
  49. void mouseMoved (const Point & cursorPosition) override;
  50. void show(SDL_Surface * to) override;
  51. void showAll(SDL_Surface * to) override;
  52. void showAnim(SDL_Surface * to);
  53. /// @returns number of visible tiles on screen respecting current map scaling
  54. int3 tileCountOnScreen();
  55. /// animates view by caching current surface and crossfading it with normal screen
  56. void fadeFromCurrentView();
  57. };