mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-25 00:37:24 +02:00
Implemented pinch gesture to scale adventure map
This commit is contained in:
@ -20,11 +20,15 @@
|
||||
#include "../gui/CursorHandler.h"
|
||||
#include "../gui/MouseButton.h"
|
||||
|
||||
#include "../CPlayerInterface.h"
|
||||
#include "../adventureMap/CInGameConsole.h"
|
||||
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
|
||||
MapViewActions::MapViewActions(MapView & owner, const std::shared_ptr<MapViewModel> & model)
|
||||
: model(model)
|
||||
, owner(owner)
|
||||
, pinchZoomFactor(1.0)
|
||||
{
|
||||
pos.w = model->getPixelsVisibleDimensions().x;
|
||||
pos.h = model->getPixelsVisibleDimensions().y;
|
||||
@ -66,7 +70,7 @@ void MapViewActions::mouseMoved(const Point & cursorPosition)
|
||||
|
||||
void MapViewActions::wheelScrolled(int distance)
|
||||
{
|
||||
adventureInt->hotkeyZoom(distance);
|
||||
adventureInt->hotkeyZoom(distance * 4);
|
||||
}
|
||||
|
||||
void MapViewActions::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
|
||||
@ -74,6 +78,24 @@ void MapViewActions::gesturePanning(const Point & initialPosition, const Point &
|
||||
owner.onMapSwiped(lastUpdateDistance);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void MapViewActions::panning(bool on, const Point & initialPosition, const Point & finalPosition)
|
||||
{
|
||||
pinchZoomFactor = 1.0;
|
||||
}
|
||||
|
||||
void MapViewActions::handleHover(const Point & cursorPosition)
|
||||
{
|
||||
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
|
||||
|
Reference in New Issue
Block a user