2023-02-23 19:46:41 +02:00
|
|
|
/*
|
|
|
|
* MapViewActions.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "MapViewActions.h"
|
|
|
|
|
|
|
|
#include "IMapRendererContext.h"
|
|
|
|
#include "MapView.h"
|
2023-03-01 18:15:42 +02:00
|
|
|
#include "MapViewModel.h"
|
2023-02-23 19:46:41 +02:00
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
2023-05-08 14:18:34 +02:00
|
|
|
#include "../adventureMap/AdventureMapInterface.h"
|
2023-02-23 19:46:41 +02:00
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
|
#include "../gui/CursorHandler.h"
|
2023-05-18 22:31:05 +02:00
|
|
|
#include "../gui/MouseButton.h"
|
2023-02-23 19:46:41 +02:00
|
|
|
|
2023-05-31 15:15:15 +02:00
|
|
|
#include "../CPlayerInterface.h"
|
|
|
|
#include "../adventureMap/CInGameConsole.h"
|
|
|
|
|
2023-02-23 19:46:41 +02:00
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
|
2023-03-01 18:15:42 +02:00
|
|
|
MapViewActions::MapViewActions(MapView & owner, const std::shared_ptr<MapViewModel> & model)
|
2023-02-23 19:46:41 +02:00
|
|
|
: model(model)
|
|
|
|
, owner(owner)
|
2023-05-31 15:15:15 +02:00
|
|
|
, pinchZoomFactor(1.0)
|
2023-02-23 19:46:41 +02:00
|
|
|
{
|
|
|
|
pos.w = model->getPixelsVisibleDimensions().x;
|
|
|
|
pos.h = model->getPixelsVisibleDimensions().y;
|
|
|
|
|
2023-06-16 11:54:07 +02:00
|
|
|
addUsedEvents(LCLICK | SHOW_POPUP | GESTURE | HOVER | MOVE | WHEEL);
|
2023-03-05 23:53:06 +02:00
|
|
|
}
|
|
|
|
|
2023-02-23 19:46:41 +02:00
|
|
|
void MapViewActions::setContext(const std::shared_ptr<IMapRendererContext> & context)
|
|
|
|
{
|
|
|
|
this->context = context;
|
|
|
|
}
|
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void MapViewActions::clickPressed(const Point & cursorPosition)
|
2023-02-23 19:46:41 +02:00
|
|
|
{
|
2023-07-08 13:33:04 +02:00
|
|
|
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
|
2023-02-23 19:46:41 +02:00
|
|
|
|
2023-03-01 18:15:42 +02:00
|
|
|
if(context->isInMap(tile))
|
2023-02-23 19:46:41 +02:00
|
|
|
adventureInt->onTileLeftClicked(tile);
|
|
|
|
}
|
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void MapViewActions::showPopupWindow(const Point & cursorPosition)
|
2023-02-23 19:46:41 +02:00
|
|
|
{
|
2023-07-08 13:33:04 +02:00
|
|
|
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
|
2023-02-23 19:46:41 +02:00
|
|
|
|
2023-06-11 17:20:10 +02:00
|
|
|
if(context->isInMap(tile))
|
2023-02-23 19:46:41 +02:00
|
|
|
adventureInt->onTileRightClicked(tile);
|
|
|
|
}
|
|
|
|
|
2023-06-22 21:11:48 +02:00
|
|
|
void MapViewActions::mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance)
|
2023-02-23 19:46:41 +02:00
|
|
|
{
|
|
|
|
handleHover(cursorPosition);
|
|
|
|
}
|
|
|
|
|
2023-05-29 12:08:08 +02:00
|
|
|
void MapViewActions::wheelScrolled(int distance)
|
2023-05-16 23:49:24 +02:00
|
|
|
{
|
2023-05-31 15:15:15 +02:00
|
|
|
adventureInt->hotkeyZoom(distance * 4);
|
2023-05-16 23:49:24 +02:00
|
|
|
}
|
|
|
|
|
2023-05-30 23:33:10 +02:00
|
|
|
void MapViewActions::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
|
2023-02-23 19:46:41 +02:00
|
|
|
{
|
2023-05-30 23:33:10 +02:00
|
|
|
owner.onMapSwiped(lastUpdateDistance);
|
2023-02-23 19:46:41 +02:00
|
|
|
}
|
|
|
|
|
2023-05-31 15:15:15 +02:00
|
|
|
void MapViewActions::gesturePinch(const Point & centerPosition, double lastUpdateFactor)
|
|
|
|
{
|
|
|
|
double newZoom = pinchZoomFactor * lastUpdateFactor;
|
|
|
|
|
|
|
|
int newZoomSteps = std::round(std::log(newZoom) / std::log(1.01));
|
|
|
|
int oldZoomSteps = std::round(std::log(pinchZoomFactor) / std::log(1.01));
|
|
|
|
|
|
|
|
if (newZoomSteps != oldZoomSteps)
|
|
|
|
adventureInt->hotkeyZoom(newZoomSteps - oldZoomSteps);
|
|
|
|
|
|
|
|
pinchZoomFactor = newZoom;
|
|
|
|
}
|
|
|
|
|
2023-06-16 11:54:07 +02:00
|
|
|
void MapViewActions::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
|
2023-05-31 15:15:15 +02:00
|
|
|
{
|
|
|
|
pinchZoomFactor = 1.0;
|
|
|
|
}
|
|
|
|
|
2023-02-23 19:46:41 +02:00
|
|
|
void MapViewActions::handleHover(const Point & cursorPosition)
|
|
|
|
{
|
|
|
|
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
|
|
|
|
|
|
|
|
if(!context->isInMap(tile))
|
|
|
|
{
|
|
|
|
CCS->curh->set(Cursor::Map::POINTER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-22 19:49:57 +02:00
|
|
|
adventureInt->onTileHovered(tile);
|
2023-02-23 19:46:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MapViewActions::hover(bool on)
|
|
|
|
{
|
2023-03-01 18:15:42 +02:00
|
|
|
if(!on)
|
2023-02-23 19:46:41 +02:00
|
|
|
{
|
2023-05-16 17:34:23 +02:00
|
|
|
GH.statusbar()->clear();
|
2023-02-23 19:46:41 +02:00
|
|
|
CCS->curh->set(Cursor::Map::POINTER);
|
|
|
|
}
|
|
|
|
}
|