1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #4531 from Laserlicht/mouse_right_drag

map drag with right mouse
This commit is contained in:
Ivan Savenko 2024-09-19 16:42:33 +03:00 committed by GitHub
commit fb28de5beb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 126 additions and 12 deletions

View File

@ -234,8 +234,10 @@
"vcmi.adventureOptions.borderScroll.help" : "{Border Scrolling}\n\nScroll adventure map when cursor is adjacent to window edge. Can be disabled by holding down CTRL key.",
"vcmi.adventureOptions.infoBarCreatureManagement.hover" : "Info Panel Creature Management",
"vcmi.adventureOptions.infoBarCreatureManagement.help" : "{Info Panel Creature Management}\n\nAllows rearranging creatures in info panel instead of cycling between default components.",
"vcmi.adventureOptions.leftButtonDrag.hover" : "Left Click Drag Map",
"vcmi.adventureOptions.leftButtonDrag.help" : "{Left Click Drag Map}\n\nWhen enabled, moving mouse with left button pressed will drag adventure map view.",
"vcmi.adventureOptions.leftButtonDrag.hover" : "Left Click Drag",
"vcmi.adventureOptions.leftButtonDrag.help" : "{Left Click Drag}\n\nWhen enabled, moving mouse with left button pressed will drag adventure map view.",
"vcmi.adventureOptions.rightButtonDrag.hover" : "Right Click Drag",
"vcmi.adventureOptions.rightButtonDrag.help" : "{Right Click Drag}\n\nWhen enabled, moving mouse with right button pressed will drag adventure map view.",
"vcmi.adventureOptions.smoothDragging.hover" : "Smooth Map Dragging",
"vcmi.adventureOptions.smoothDragging.help" : "{Smooth Map Dragging}\n\nWhen enabled, map dragging has a modern run out effect.",
"vcmi.adventureOptions.skipAdventureMapAnimations.hover" : "Skip fading effects",

View File

@ -234,8 +234,10 @@
"vcmi.adventureOptions.borderScroll.help" : "{Scrollen am Rand}\n\nScrollt die Abenteuerkarte, wenn sich der Cursor neben dem Fensterrand befindet. Kann mit gedrückter STRG-Taste deaktiviert werden.",
"vcmi.adventureOptions.infoBarCreatureManagement.hover" : "Info-Panel Kreaturenmanagement",
"vcmi.adventureOptions.infoBarCreatureManagement.help" : "{Info-Panel Kreaturenmanagement}\n\nErmöglicht die Neuanordnung von Kreaturen im Info-Panel, anstatt zwischen den Standardkomponenten zu wechseln",
"vcmi.adventureOptions.leftButtonDrag.hover" : "Ziehen der Karte mit Links",
"vcmi.adventureOptions.leftButtonDrag.help" : "{Ziehen der Karte mit Links}\n\nWenn aktiviert, wird die Maus bei gedrückter linker Taste in die Kartenansicht gezogen",
"vcmi.adventureOptions.leftButtonDrag.hover" : "Ziehen mit Links",
"vcmi.adventureOptions.leftButtonDrag.help" : "{Ziehen mit Links}\n\nWenn aktiviert, kann mit gedrückter linker Taste die Kartenansicht gezogen werden",
"vcmi.adventureOptions.rightButtonDrag.hover" : "Ziehen mit Rechts",
"vcmi.adventureOptions.rightButtonDrag.help" : "{Ziehen mit Rechts}\n\nWenn aktiviert, kann mit gedrückter rechter Taste die Kartenansicht gezogen werden",
"vcmi.adventureOptions.smoothDragging.hover" : "Nahtloses Ziehen der Karte",
"vcmi.adventureOptions.smoothDragging.help" : "{Nahtloses Ziehen der Karte}\n\nWenn aktiviert hat das Ziehen der Karte einen sanften Auslaufeffekt.",
"vcmi.adventureOptions.skipAdventureMapAnimations.hover" : "Fading-Effekte überspringen",

View File

@ -34,7 +34,7 @@ InputSourceMouse::InputSourceMouse()
void InputSourceMouse::handleEventMouseMotion(const SDL_MouseMotionEvent & motion)
{
Point newPosition = Point(motion.x, motion.y) / GH.screenHandler().getScalingFactor();
Point distance= Point(-motion.xrel, -motion.yrel) / GH.screenHandler().getScalingFactor();
Point distance = Point(-motion.xrel, -motion.yrel) / GH.screenHandler().getScalingFactor();
mouseButtonsMask = motion.state;
@ -42,6 +42,8 @@ void InputSourceMouse::handleEventMouseMotion(const SDL_MouseMotionEvent & motio
GH.events().dispatchGesturePanning(middleClickPosition, newPosition, distance);
else if (mouseButtonsMask & SDL_BUTTON(SDL_BUTTON_LEFT))
GH.events().dispatchMouseDragged(newPosition, distance);
else if (mouseButtonsMask & SDL_BUTTON(SDL_BUTTON_RIGHT))
GH.events().dispatchMouseDraggedPopup(newPosition, distance);
else
GH.input().setCursorPosition(newPosition);
}

View File

@ -35,6 +35,7 @@ void EventDispatcher::processLists(ui16 activityFlag, const Functor & cb)
processList(AEventsReceiver::HOVER, hoverable);
processList(AEventsReceiver::MOVE, motioninterested);
processList(AEventsReceiver::DRAG, draginterested);
processList(AEventsReceiver::DRAG_POPUP, dragPopupInterested);
processList(AEventsReceiver::KEYBOARD, keyinterested);
processList(AEventsReceiver::TIME, timeinterested);
processList(AEventsReceiver::WHEEL, wheelInterested);
@ -433,3 +434,10 @@ void EventDispatcher::dispatchMouseDragged(const Point & currentPosition, const
elem->mouseDragged(currentPosition, lastUpdateDistance);
}
}
void EventDispatcher::dispatchMouseDraggedPopup(const Point & currentPosition, const Point & lastUpdateDistance)
{
EventReceiversList diCopy = dragPopupInterested;
for(auto & elem : diCopy)
elem->mouseDraggedPopup(currentPosition, lastUpdateDistance);
}

View File

@ -30,6 +30,7 @@ class EventDispatcher
EventReceiversList keyinterested;
EventReceiversList motioninterested;
EventReceiversList draginterested;
EventReceiversList dragPopupInterested;
EventReceiversList timeinterested;
EventReceiversList wheelInterested;
EventReceiversList doubleClickInterested;
@ -66,6 +67,7 @@ public:
void dispatchMouseMoved(const Point & distance, const Point & position);
void dispatchMouseDragged(const Point & currentPosition, const Point & lastUpdateDistance);
void dispatchMouseDraggedPopup(const Point & currentPosition, const Point & lastUpdateDistance);
void dispatchShowPopup(const Point & position, int tolerance);
void dispatchClosePopup(const Point & position);

View File

@ -61,6 +61,7 @@ public:
virtual void wheelScrolled(int distance) {}
virtual void mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) {}
virtual void mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance) {}
virtual void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) {}
/// Called when UI element hover status changes
virtual void hover(bool on) {}
@ -97,7 +98,8 @@ public:
TEXTINPUT = 512,
GESTURE = 1024,
DRAG = 2048,
INPUT_MODE_CHANGE = 4096
INPUT_MODE_CHANGE = 4096,
DRAG_POPUP = 8192
};
/// Returns true if element is currently hovered by mouse

View File

@ -34,7 +34,7 @@ MapViewActions::MapViewActions(MapView & owner, const std::shared_ptr<MapViewMod
pos.w = model->getPixelsVisibleDimensions().x;
pos.h = model->getPixelsVisibleDimensions().y;
addUsedEvents(LCLICK | SHOW_POPUP | DRAG | GESTURE | HOVER | MOVE | WHEEL);
addUsedEvents(LCLICK | SHOW_POPUP | DRAG | DRAG_POPUP | GESTURE | HOVER | MOVE | WHEEL);
}
void MapViewActions::setContext(const std::shared_ptr<IMapRendererContext> & context)
@ -101,6 +101,11 @@ void MapViewActions::mouseDragged(const Point & cursorPosition, const Point & la
owner.onMapSwiped(lastUpdateDistance);
}
void MapViewActions::mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance)
{
owner.onMapSwiped(lastUpdateDistance);
}
void MapViewActions::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
{
owner.onMapSwiped(lastUpdateDistance);

View File

@ -42,6 +42,7 @@ public:
void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
void mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) override;
void mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance) override;
void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) override;
void wheelScrolled(int distance) override;
bool dragActive;

View File

@ -245,8 +245,11 @@ void CRClickPopup::createAndPush(const CGObjectInstance * obj, const Point & p,
}
}
CRClickPopupInt::CRClickPopupInt(const std::shared_ptr<CIntObject> & our)
CRClickPopupInt::CRClickPopupInt(const std::shared_ptr<CIntObject> & our) :
dragDistance(Point(0, 0))
{
addUsedEvents(DRAG_POPUP);
CCS->curh->hide();
inner = our;
addChild(our.get(), false);
@ -257,6 +260,17 @@ CRClickPopupInt::~CRClickPopupInt()
CCS->curh->show();
}
void CRClickPopupInt::mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance)
{
if(!settings["adventure"]["rightButtonDrag"].Bool())
return;
dragDistance += lastUpdateDistance;
if(dragDistance.length() > 16)
close();
}
Point CInfoBoxPopup::toScreen(Point p)
{
auto bounds = adventureInt->terrainAreaPixels();
@ -267,6 +281,18 @@ Point CInfoBoxPopup::toScreen(Point p)
return p;
}
void CInfoBoxPopup::mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance)
{
if(!settings["adventure"]["rightButtonDrag"].Bool())
return;
dragDistance += lastUpdateDistance;
if(dragDistance.length() > 16)
close();
}
CInfoBoxPopup::CInfoBoxPopup(Point position, const CGTownInstance * town)
: CWindowObject(RCLICK_POPUP | PLAYER_COLORED, ImagePath::builtin("TOWNQVBK"), toScreen(position))
{
@ -275,6 +301,8 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGTownInstance * town)
OBJECT_CONSTRUCTION;
tooltip = std::make_shared<CTownTooltip>(Point(9, 10), iah);
addUsedEvents(DRAG_POPUP);
}
CInfoBoxPopup::CInfoBoxPopup(Point position, const CGHeroInstance * hero)
@ -285,6 +313,8 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGHeroInstance * hero)
OBJECT_CONSTRUCTION;
tooltip = std::make_shared<CHeroTooltip>(Point(9, 10), iah);
addUsedEvents(DRAG_POPUP);
}
CInfoBoxPopup::CInfoBoxPopup(Point position, const CGGarrison * garr)
@ -295,6 +325,8 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGGarrison * garr)
OBJECT_CONSTRUCTION;
tooltip = std::make_shared<CArmyTooltip>(Point(9, 10), iah);
addUsedEvents(DRAG_POPUP);
}
CInfoBoxPopup::CInfoBoxPopup(Point position, const CGCreature * creature)
@ -302,6 +334,8 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGCreature * creature)
{
OBJECT_CONSTRUCTION;
tooltip = std::make_shared<CreatureTooltip>(Point(9, 10), creature);
addUsedEvents(DRAG_POPUP);
}
std::shared_ptr<WindowBase>

View File

@ -78,9 +78,13 @@ class CRClickPopupInt : public CRClickPopup
{
std::shared_ptr<CIntObject> inner;
Point dragDistance;
public:
CRClickPopupInt(const std::shared_ptr<CIntObject> & our);
~CRClickPopupInt();
void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) override;
};
/// popup on adventure map for town\hero and other objects with customized popup content
@ -89,11 +93,15 @@ class CInfoBoxPopup : public CWindowObject
std::shared_ptr<CIntObject> tooltip;
Point toScreen(Point pos);
Point dragDistance;
public:
CInfoBoxPopup(Point position, const CGTownInstance * town);
CInfoBoxPopup(Point position, const CGHeroInstance * hero);
CInfoBoxPopup(Point position, const CGGarrison * garr);
CInfoBoxPopup(Point position, const CGCreature * creature);
void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) override;
};
/// component selection window

View File

@ -11,6 +11,7 @@
#include "AdventureOptionsTab.h"
#include "../../eventsSDL/InputHandler.h"
#include "../../../lib/filesystem/ResourcePath.h"
#include "../../gui/CGuiHandler.h"
#include "../../widgets/Buttons.h"
@ -36,6 +37,9 @@ AdventureOptionsTab::AdventureOptionsTab()
OBJECT_CONSTRUCTION;
setRedrawParent(true);
addConditional("touchscreen", GH.input().getCurrentInputMode() == InputMode::TOUCH);
addConditional("keyboardMouse", GH.input().getCurrentInputMode() == InputMode::KEYBOARD_AND_MOUSE);
addConditional("controller", GH.input().getCurrentInputMode() == InputMode::CONTROLLER);
#ifdef VCMI_MOBILE
addConditional("mobile", true);
addConditional("desktop", false);
@ -126,6 +130,10 @@ AdventureOptionsTab::AdventureOptionsTab()
{
return setBoolSetting("adventure", "leftButtonDrag", value);
});
addCallback("rightButtonDragChanged", [](bool value)
{
return setBoolSetting("adventure", "rightButtonDrag", value);
});
addCallback("smoothDraggingChanged", [](bool value)
{
return setBoolSetting("adventure", "smoothDragging", value);
@ -177,6 +185,10 @@ AdventureOptionsTab::AdventureOptionsTab()
if (leftButtonDragCheckbox)
leftButtonDragCheckbox->setSelected(settings["adventure"]["leftButtonDrag"].Bool());
std::shared_ptr<CToggleButton> rightButtonDragCheckbox = widget<CToggleButton>("rightButtonDragCheckbox");
if (rightButtonDragCheckbox)
rightButtonDragCheckbox->setSelected(settings["adventure"]["rightButtonDrag"].Bool());
std::shared_ptr<CToggleButton> smoothDraggingCheckbox = widget<CToggleButton>("smoothDraggingCheckbox");
if (smoothDraggingCheckbox)
smoothDraggingCheckbox->setSelected(settings["adventure"]["smoothDragging"].Bool());

View File

@ -97,7 +97,9 @@ GeneralOptionsTab::GeneralOptionsTab()
OBJECT_CONSTRUCTION;
setRedrawParent(true);
addConditional("touchscreen", GH.input().hasTouchInputDevice());
addConditional("touchscreen", GH.input().getCurrentInputMode() == InputMode::TOUCH);
addConditional("keyboardMouse", GH.input().getCurrentInputMode() == InputMode::KEYBOARD_AND_MOUSE);
addConditional("controller", GH.input().getCurrentInputMode() == InputMode::CONTROLLER);
#ifdef VCMI_MOBILE
addConditional("mobile", true);
addConditional("desktop", false);

View File

@ -45,6 +45,8 @@ SettingsMainWindow::SettingsMainWindow(BattleInterface * parentBattleUi) : Inter
addCallback("closeWindow", [this](int) { backButtonCallback(); });
build(config);
addUsedEvents(INPUT_MODE_CHANGE);
std::shared_ptr<CIntObject> background = widget<CIntObject>("background");
pos.w = background->pos.w;
pos.h = background->pos.h;
@ -196,3 +198,8 @@ void SettingsMainWindow::onScreenResize()
if (tab)
tab->updateResolutionSelector();
}
void SettingsMainWindow::inputModeChanged(InputMode mode)
{
tabContentArea->reset();
}

View File

@ -42,5 +42,6 @@ public:
void showAll(Canvas & to) override;
void onScreenResize() override;
void inputModeChanged(InputMode mode) override;
};

View File

@ -322,7 +322,7 @@
"type" : "object",
"additionalProperties" : false,
"default" : {},
"required" : [ "heroMoveTime", "enemyMoveTime", "scrollSpeedPixels", "heroReminder", "quickCombat", "objectAnimation", "terrainAnimation", "forceQuickCombat", "borderScroll", "leftButtonDrag", "smoothDragging", "backgroundDimLevel", "hideBackground", "backgroundDimSmallWindows" ],
"required" : [ "heroMoveTime", "enemyMoveTime", "scrollSpeedPixels", "heroReminder", "quickCombat", "objectAnimation", "terrainAnimation", "forceQuickCombat", "borderScroll", "leftButtonDrag", "rightButtonDrag", "smoothDragging", "backgroundDimLevel", "hideBackground", "backgroundDimSmallWindows" ],
"properties" : {
"heroMoveTime" : {
"type" : "number",

View File

@ -364,13 +364,25 @@
},
{
"text": "vcmi.adventureOptions.leftButtonDrag.hover",
"created" : "desktop"
"created" : "keyboardMouse"
},
{
"text": "vcmi.adventureOptions.smoothDragging.hover"
}
]
},
{
"type": "verticalLayout",
"customType": "labelDescription",
"position": {"x": 225, "y": 415},
"items":
[
{
"text": "vcmi.adventureOptions.rightButtonDrag.hover",
"created" : "keyboardMouse"
}
]
},
{
"type": "verticalLayout",
"customType": "checkbox",
@ -411,7 +423,7 @@
"name": "leftButtonDragCheckbox",
"help": "vcmi.adventureOptions.leftButtonDrag",
"callback": "leftButtonDragChanged",
"created" : "desktop"
"created" : "keyboardMouse"
},
{
"name": "smoothDraggingCheckbox",
@ -419,6 +431,20 @@
"callback": "smoothDraggingChanged"
}
]
},
{
"type": "verticalLayout",
"customType": "checkbox",
"position": {"x": 190, "y": 413},
"items":
[
{
"name": "rightButtonDragCheckbox",
"help": "vcmi.adventureOptions.rightButtonDrag",
"callback": "rightButtonDragChanged",
"created" : "keyboardMouse"
}
]
}
]
}