1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/*
* 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"
#include "MapViewModel.h"
#include "../CGameInfo.h"
#include "../adventureMap/AdventureMapInterface.h"
#include "../gui/CGuiHandler.h"
#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)
, dragActive(false)
{
pos.w = model->getPixelsVisibleDimensions().x;
pos.h = model->getPixelsVisibleDimensions().y;
addUsedEvents(LCLICK | SHOW_POPUP | DRAG | DRAG_POPUP | GESTURE | HOVER | MOVE | WHEEL);
}
void MapViewActions::setContext(const std::shared_ptr<IMapRendererContext> & context)
{
this->context = context;
}
void MapViewActions::clickPressed(const Point & cursorPosition)
{
if (!settings["adventure"]["leftButtonDrag"].Bool())
{
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
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);
}
void MapViewActions::showPopupWindow(const Point & cursorPosition)
{
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
if(context->isInMap(tile))
adventureInt->onTileRightClicked(tile);
}
void MapViewActions::closePopupWindow(bool alreadyClosed)
{
if(alreadyClosed)
dragActive = false;
}
void MapViewActions::mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance)
{
handleHover(cursorPosition);
}
void MapViewActions::wheelScrolled(int distance)
{
adventureInt->hotkeyZoom(distance * 4, true);
}
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);
}
void MapViewActions::mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance)
{
dragActive = true;
owner.onMapSwiped(lastUpdateDistance);
}
void MapViewActions::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
{
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, true);
pinchZoomFactor = newZoom;
}
void MapViewActions::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
{
dragActive = on;
pinchZoomFactor = 1.0;
}
void MapViewActions::handleHover(const Point & cursorPosition)
{
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
if(!context->isInMap(tile))
{
CCS->curh->set(Cursor::Map::POINTER);
return;
}
adventureInt->onTileHovered(tile);
}
void MapViewActions::hover(bool on)
{
if(!on)
{
GH.statusbar()->clear();
CCS->curh->set(Cursor::Map::POINTER);
}
}
|