1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

map drag with right mouse

This commit is contained in:
Laserlicht
2024-08-28 22:17:05 +02:00
parent 247be94015
commit be7d27234f
9 changed files with 67 additions and 5 deletions

View File

@@ -33,7 +33,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;
@@ -41,6 +41,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

@@ -316,7 +316,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",