|
@@ -25,21 +25,11 @@
|
|
|
MapViewActions::MapViewActions(MapView & owner, const std::shared_ptr<MapViewModel> & model)
|
|
|
: model(model)
|
|
|
, owner(owner)
|
|
|
- , isSwiping(false)
|
|
|
{
|
|
|
pos.w = model->getPixelsVisibleDimensions().x;
|
|
|
pos.h = model->getPixelsVisibleDimensions().y;
|
|
|
|
|
|
- addUsedEvents(LCLICK | RCLICK | MCLICK | HOVER | MOVE | WHEEL);
|
|
|
-}
|
|
|
-
|
|
|
-bool MapViewActions::swipeEnabled() const
|
|
|
-{
|
|
|
-#if defined(VCMI_ANDROID) || defined(VCMI_IOS)
|
|
|
- return settings["general"]["swipe"].Bool();
|
|
|
-#else
|
|
|
- return settings["general"]["swipeDesktop"].Bool();
|
|
|
-#endif
|
|
|
+ addUsedEvents(LCLICK | RCLICK | GESTURE_PANNING | HOVER | MOVE | WHEEL);
|
|
|
}
|
|
|
|
|
|
void MapViewActions::setContext(const std::shared_ptr<IMapRendererContext> & context)
|
|
@@ -52,18 +42,8 @@ void MapViewActions::clickLeft(tribool down, bool previousState)
|
|
|
if(indeterminate(down))
|
|
|
return;
|
|
|
|
|
|
- if(swipeEnabled())
|
|
|
- {
|
|
|
- if(handleSwipeStateChange(static_cast<bool>(down)))
|
|
|
- {
|
|
|
- return; // if swipe is enabled, we don't process "down" events and wait for "up" (to make sure this wasn't a swiping gesture)
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if(down == false)
|
|
|
- return;
|
|
|
- }
|
|
|
+ if(down == false)
|
|
|
+ return;
|
|
|
|
|
|
int3 tile = model->getTileAtPoint(GH.getCursorPosition() - pos.topLeft());
|
|
|
|
|
@@ -73,24 +53,15 @@ void MapViewActions::clickLeft(tribool down, bool previousState)
|
|
|
|
|
|
void MapViewActions::clickRight(tribool down, bool previousState)
|
|
|
{
|
|
|
- if(isSwiping)
|
|
|
- return;
|
|
|
-
|
|
|
int3 tile = model->getTileAtPoint(GH.getCursorPosition() - pos.topLeft());
|
|
|
|
|
|
if(down && context->isInMap(tile))
|
|
|
adventureInt->onTileRightClicked(tile);
|
|
|
}
|
|
|
|
|
|
-void MapViewActions::clickMiddle(tribool down, bool previousState)
|
|
|
-{
|
|
|
- handleSwipeStateChange(static_cast<bool>(down));
|
|
|
-}
|
|
|
-
|
|
|
void MapViewActions::mouseMoved(const Point & cursorPosition)
|
|
|
{
|
|
|
handleHover(cursorPosition);
|
|
|
- handleSwipeMove(cursorPosition);
|
|
|
}
|
|
|
|
|
|
void MapViewActions::wheelScrolled(bool down, bool in)
|
|
@@ -100,49 +71,9 @@ void MapViewActions::wheelScrolled(bool down, bool in)
|
|
|
adventureInt->hotkeyZoom(down ? -1 : +1);
|
|
|
}
|
|
|
|
|
|
-void MapViewActions::handleSwipeMove(const Point & cursorPosition)
|
|
|
+void MapViewActions::gesturePanning(const Point & distance)
|
|
|
{
|
|
|
- // unless swipe is enabled, swipe move only works with middle mouse button
|
|
|
- if(!swipeEnabled() && !GH.isMouseButtonPressed(MouseButton::MIDDLE))
|
|
|
- return;
|
|
|
-
|
|
|
- // on mobile platforms with enabled swipe we use left button
|
|
|
- if(swipeEnabled() && !GH.isMouseButtonPressed(MouseButton::LEFT))
|
|
|
- return;
|
|
|
-
|
|
|
- if(!isSwiping)
|
|
|
- {
|
|
|
- static constexpr int touchSwipeSlop = 16;
|
|
|
- Point distance = (cursorPosition - swipeInitialRealPos);
|
|
|
-
|
|
|
- // try to distinguish if this touch was meant to be a swipe or just fat-fingering press
|
|
|
- if(std::abs(distance.x) + std::abs(distance.y) > touchSwipeSlop)
|
|
|
- isSwiping = true;
|
|
|
- }
|
|
|
-
|
|
|
- if(isSwiping)
|
|
|
- {
|
|
|
- Point swipeTargetPosition = swipeInitialViewPos + swipeInitialRealPos - cursorPosition;
|
|
|
- owner.onMapSwiped(swipeTargetPosition);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-bool MapViewActions::handleSwipeStateChange(bool btnPressed)
|
|
|
-{
|
|
|
- if(btnPressed)
|
|
|
- {
|
|
|
- swipeInitialRealPos = GH.getCursorPosition();
|
|
|
- swipeInitialViewPos = model->getMapViewCenter();
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- if(isSwiping) // only accept this touch if it wasn't a swipe
|
|
|
- {
|
|
|
- owner.onMapSwipeEnded();
|
|
|
- isSwiping = false;
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
+ owner.onMapSwiped(distance);
|
|
|
}
|
|
|
|
|
|
void MapViewActions::handleHover(const Point & cursorPosition)
|