MapViewActions.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * MapViewActions.cpp, 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. #include "StdInc.h"
  11. #include "MapViewActions.h"
  12. #include "IMapRendererContext.h"
  13. #include "MapView.h"
  14. #include "MapViewModel.h"
  15. #include "../CGameInfo.h"
  16. #include "../adventureMap/AdventureMapInterface.h"
  17. #include "../gui/CGuiHandler.h"
  18. #include "../gui/CursorHandler.h"
  19. #include "../gui/MouseButton.h"
  20. #include "../../lib/CConfigHandler.h"
  21. MapViewActions::MapViewActions(MapView & owner, const std::shared_ptr<MapViewModel> & model)
  22. : model(model)
  23. , owner(owner)
  24. {
  25. pos.w = model->getPixelsVisibleDimensions().x;
  26. pos.h = model->getPixelsVisibleDimensions().y;
  27. addUsedEvents(LCLICK | RCLICK | GESTURE_PANNING | HOVER | MOVE | WHEEL);
  28. }
  29. void MapViewActions::setContext(const std::shared_ptr<IMapRendererContext> & context)
  30. {
  31. this->context = context;
  32. }
  33. void MapViewActions::clickLeft(tribool down, bool previousState)
  34. {
  35. if(indeterminate(down))
  36. return;
  37. if(down == false)
  38. return;
  39. int3 tile = model->getTileAtPoint(GH.getCursorPosition() - pos.topLeft());
  40. if(context->isInMap(tile))
  41. adventureInt->onTileLeftClicked(tile);
  42. }
  43. void MapViewActions::clickRight(tribool down, bool previousState)
  44. {
  45. int3 tile = model->getTileAtPoint(GH.getCursorPosition() - pos.topLeft());
  46. if(down && context->isInMap(tile))
  47. adventureInt->onTileRightClicked(tile);
  48. }
  49. void MapViewActions::mouseMoved(const Point & cursorPosition)
  50. {
  51. handleHover(cursorPosition);
  52. }
  53. void MapViewActions::wheelScrolled(int distance)
  54. {
  55. adventureInt->hotkeyZoom(distance);
  56. }
  57. void MapViewActions::gesturePanning(const Point & distance)
  58. {
  59. owner.onMapSwiped(distance);
  60. }
  61. void MapViewActions::handleHover(const Point & cursorPosition)
  62. {
  63. int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
  64. if(!context->isInMap(tile))
  65. {
  66. CCS->curh->set(Cursor::Map::POINTER);
  67. return;
  68. }
  69. adventureInt->onTileHovered(tile);
  70. }
  71. void MapViewActions::hover(bool on)
  72. {
  73. if(!on)
  74. {
  75. GH.statusbar()->clear();
  76. CCS->curh->set(Cursor::Map::POINTER);
  77. }
  78. }