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 15:18:34 +03:00
|
|
|
#include "../adventureMap/AdventureMapInterface.h"
|
2023-02-23 19:46:41 +02:00
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
|
#include "../gui/CursorHandler.h"
|
2023-05-18 23:31:05 +03:00
|
|
|
#include "../gui/MouseButton.h"
|
2023-02-23 19:46:41 +02:00
|
|
|
|
2023-05-31 16:15:15 +03: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 16:15:15 +03:00
|
|
|
, pinchZoomFactor(1.0)
|
2023-07-16 12:00:40 +03:00
|
|
|
, dragActive(false)
|
2023-02-23 19:46:41 +02:00
|
|
|
{
|
|
|
|
pos.w = model->getPixelsVisibleDimensions().x;
|
|
|
|
pos.h = model->getPixelsVisibleDimensions().y;
|
|
|
|
|
2023-07-16 12:00:40 +03:00
|
|
|
addUsedEvents(LCLICK | SHOW_POPUP | DRAG | 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 14:33:04 +03:00
|
|
|
void MapViewActions::clickPressed(const Point & cursorPosition)
|
2023-02-23 19:46:41 +02:00
|
|
|
{
|
2023-07-16 12:00:40 +03:00
|
|
|
if (!settings["adventure"]["leftButtonDrag"].Bool())
|
|
|
|
{
|
|
|
|
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
|
2023-02-23 19:46:41 +02:00
|
|
|
|
2023-07-16 12:00:40 +03:00
|
|
|
if(context->isInMap(tile))
|
|
|
|
adventureInt->onTileLeftClicked(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapViewActions::clickReleased(const Point & cursorPosition)
|
|
|
|
{
|
|
|
|
if (!dragActive && settings["adventure"]["leftButtonDrag"].Bool())
|
|
|
|
{
|
|
|
|
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
|
|
|
|
|
|
|
|
if(context->isInMap(tile))
|
|
|
|
adventureInt->onTileLeftClicked(tile);
|
|
|
|
}
|
|
|
|
dragActive = false;
|
|
|
|
dragDistance = Point(0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapViewActions::clickCancel(const Point & cursorPosition)
|
|
|
|
{
|
|
|
|
dragActive = false;
|
|
|
|
dragDistance = Point(0,0);
|
2023-02-23 19:46:41 +02:00
|
|
|
}
|
|
|
|
|
2023-07-08 14:33:04 +03:00
|
|
|
void MapViewActions::showPopupWindow(const Point & cursorPosition)
|
2023-02-23 19:46:41 +02:00
|
|
|
{
|
2023-07-08 14:33:04 +03:00
|
|
|
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
|
2023-02-23 19:46:41 +02:00
|
|
|
|
2023-06-11 18:20:10 +03:00
|
|
|
if(context->isInMap(tile))
|
2023-02-23 19:46:41 +02:00
|
|
|
adventureInt->onTileRightClicked(tile);
|
|
|
|
}
|
|
|
|
|
2023-06-22 22:11:48 +03:00
|
|
|
void MapViewActions::mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance)
|
2023-02-23 19:46:41 +02:00
|
|
|
{
|
|
|
|
handleHover(cursorPosition);
|
|
|
|
}
|
|
|
|
|
2023-05-29 13:08:08 +03:00
|
|
|
void MapViewActions::wheelScrolled(int distance)
|
2023-05-17 00:49:24 +03:00
|
|
|
{
|
2023-05-31 16:15:15 +03:00
|
|
|
adventureInt->hotkeyZoom(distance * 4);
|
2023-05-17 00:49:24 +03:00
|
|
|
}
|
|
|
|
|
2023-07-16 12:00:40 +03:00
|
|
|
void MapViewActions::mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance)
|
|
|
|
{
|
|
|
|
dragDistance += lastUpdateDistance;
|
|
|
|
|
|
|
|
if (dragDistance.length() > 16)
|
|
|
|
dragActive = true;
|
|
|
|
|
|
|
|
if (dragActive && settings["adventure"]["leftButtonDrag"].Bool())
|
|
|
|
owner.onMapSwiped(lastUpdateDistance);
|
|
|
|
}
|
|
|
|
|
2023-05-31 00:33:10 +03:00
|
|
|
void MapViewActions::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
|
2023-02-23 19:46:41 +02:00
|
|
|
{
|
2023-05-31 00:33:10 +03:00
|
|
|
owner.onMapSwiped(lastUpdateDistance);
|
2023-02-23 19:46:41 +02:00
|
|
|
}
|
|
|
|
|
2023-05-31 16:15:15 +03: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 12:54:07 +03:00
|
|
|
void MapViewActions::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
|
2023-05-31 16:15:15 +03:00
|
|
|
{
|
2023-08-27 00:22:29 +02:00
|
|
|
dragActive = on;
|
|
|
|
|
2023-05-31 16:15:15 +03: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 18:34:23 +03:00
|
|
|
GH.statusbar()->clear();
|
2023-02-23 19:46:41 +02:00
|
|
|
CCS->curh->set(Cursor::Map::POINTER);
|
|
|
|
}
|
|
|
|
}
|