1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Added map swipe option

This commit is contained in:
Ivan Savenko
2023-03-05 23:53:06 +02:00
parent 2e69a4769d
commit b7025125d5
6 changed files with 123 additions and 75 deletions

View File

@@ -26,11 +26,6 @@ MapViewActions::MapViewActions(MapView & owner, const std::shared_ptr<MapViewMod
, owner(owner)
, curHoveredTile(-1, -1, -1)
, isSwiping(false)
#if defined(VCMI_ANDROID) || defined(VCMI_IOS)
, swipeEnabled(settings["general"]["swipe"].Bool())
#else
, swipeEnabled(settings["general"]["swipeDesktop"].Bool())
#endif
{
pos.w = model->getPixelsVisibleDimensions().x;
pos.h = model->getPixelsVisibleDimensions().y;
@@ -38,6 +33,15 @@ MapViewActions::MapViewActions(MapView & owner, const std::shared_ptr<MapViewMod
addUsedEvents(LCLICK | RCLICK | MCLICK | HOVER | MOVE);
}
bool MapViewActions::swipeEnabled() const
{
#if defined(VCMI_ANDROID) || defined(VCMI_IOS)
return settings["general"]["swipe"].Bool();
#else
return settings["general"]["swipeDesktop"].Bool();
#endif
}
void MapViewActions::setContext(const std::shared_ptr<IMapRendererContext> & context)
{
this->context = context;
@@ -59,7 +63,7 @@ void MapViewActions::clickLeft(tribool down, bool previousState)
if(indeterminate(down))
return;
if(swipeEnabled)
if(swipeEnabled())
{
if(handleSwipeStateChange(static_cast<bool>(down)))
{
@@ -103,11 +107,11 @@ void MapViewActions::mouseMoved(const Point & cursorPosition)
void MapViewActions::handleSwipeMove(const Point & cursorPosition)
{
// unless swipe is enabled, swipe move only works with middle mouse button
if(!swipeEnabled && !GH.isMouseButtonPressed(MouseButton::MIDDLE))
if(!swipeEnabled() && !GH.isMouseButtonPressed(MouseButton::MIDDLE))
return;
// on mobile platforms with enabled swipe any button is enough
if(swipeEnabled && (!GH.isMouseButtonPressed() || GH.multifinger))
if(swipeEnabled() && (!GH.isMouseButtonPressed() || GH.multifinger))
return;
if(!isSwiping)