1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-29 21:56:54 +02:00

add smooth drag for RMB & fix drag for new windows

This commit is contained in:
Laserlicht 2025-01-19 00:30:23 +01:00
parent 364286e1b9
commit 2ebf1daf0d
6 changed files with 52 additions and 19 deletions

View File

@ -201,10 +201,20 @@ void EventDispatcher::dispatchShowPopup(const Point & position, int tolerance)
void EventDispatcher::dispatchClosePopup(const Point & position) void EventDispatcher::dispatchClosePopup(const Point & position)
{ {
if (GH.windows().isTopWindowPopup()) bool popupOpen = GH.windows().isTopWindowPopup(); // popup can already be closed for mouse dragging with RMB
GH.windows().popWindows(1);
assert(!GH.windows().isTopWindowPopup()); auto hlp = rclickable;
for(auto & i : hlp)
{
if(!vstd::contains(rclickable, i))
continue;
i->closePopupWindow(!popupOpen);
}
if(popupOpen)
GH.windows().popWindows(1);
} }
void EventDispatcher::handleLeftButtonClick(const Point & position, int tolerance, bool isPressed) void EventDispatcher::handleLeftButtonClick(const Point & position, int tolerance, bool isPressed)

View File

@ -50,6 +50,7 @@ public:
virtual void clickReleased(const Point & cursorPosition, bool lastActivated); virtual void clickReleased(const Point & cursorPosition, bool lastActivated);
virtual void clickCancel(const Point & cursorPosition) {} virtual void clickCancel(const Point & cursorPosition) {}
virtual void showPopupWindow(const Point & cursorPosition) {} virtual void showPopupWindow(const Point & cursorPosition) {}
virtual void closePopupWindow(bool alreadyClosed) {}
virtual void clickDouble(const Point & cursorPosition) {} virtual void clickDouble(const Point & cursorPosition) {}
virtual void notFocusedClick() {}; virtual void notFocusedClick() {};

View File

@ -80,6 +80,12 @@ void MapViewActions::showPopupWindow(const Point & cursorPosition)
adventureInt->onTileRightClicked(tile); adventureInt->onTileRightClicked(tile);
} }
void MapViewActions::closePopupWindow(bool alreadyClosed)
{
if(alreadyClosed)
dragActive = false;
}
void MapViewActions::mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) void MapViewActions::mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance)
{ {
handleHover(cursorPosition); handleHover(cursorPosition);
@ -103,6 +109,7 @@ void MapViewActions::mouseDragged(const Point & cursorPosition, const Point & la
void MapViewActions::mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) void MapViewActions::mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance)
{ {
dragActive = true;
owner.onMapSwiped(lastUpdateDistance); owner.onMapSwiped(lastUpdateDistance);
} }

View File

@ -36,6 +36,7 @@ public:
void clickReleased(const Point & cursorPosition) override; void clickReleased(const Point & cursorPosition) override;
void clickCancel(const Point & cursorPosition) override; void clickCancel(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override; void showPopupWindow(const Point & cursorPosition) override;
void closePopupWindow(bool alreadyClosed) override;
void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override; void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override;
void gesturePinch(const Point & centerPosition, double lastUpdateFactor) override; void gesturePinch(const Point & centerPosition, double lastUpdateFactor) override;
void hover(bool on) override; void hover(bool on) override;

View File

@ -269,7 +269,14 @@ void CRClickPopupInt::mouseDraggedPopup(const Point & cursorPosition, const Poin
close(); close();
} }
void CInfoBoxPopup::mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) template<typename... Args>
AdventureMapPopup::AdventureMapPopup(Args&&... args) :
CWindowObject(std::forward<Args>(args)...), dragDistance(Point(0, 0))
{
addUsedEvents(DRAG_POPUP);
}
void AdventureMapPopup::mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance)
{ {
if(!settings["adventure"]["rightButtonDrag"].Bool()) if(!settings["adventure"]["rightButtonDrag"].Bool())
return; return;
@ -282,7 +289,7 @@ void CInfoBoxPopup::mouseDraggedPopup(const Point & cursorPosition, const Point
CInfoBoxPopup::CInfoBoxPopup(Point position, const CGTownInstance * town) CInfoBoxPopup::CInfoBoxPopup(Point position, const CGTownInstance * town)
: CWindowObject(RCLICK_POPUP | PLAYER_COLORED, ImagePath::builtin("TOWNQVBK"), position) : AdventureMapPopup(RCLICK_POPUP | PLAYER_COLORED, ImagePath::builtin("TOWNQVBK"), position)
{ {
InfoAboutTown iah; InfoAboutTown iah;
LOCPLINT->cb->getTownInfo(town, iah, LOCPLINT->localState->getCurrentArmy()); //todo: should this be nearest hero? LOCPLINT->cb->getTownInfo(town, iah, LOCPLINT->localState->getCurrentArmy()); //todo: should this be nearest hero?
@ -296,7 +303,7 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGTownInstance * town)
} }
CInfoBoxPopup::CInfoBoxPopup(Point position, const CGHeroInstance * hero) CInfoBoxPopup::CInfoBoxPopup(Point position, const CGHeroInstance * hero)
: CWindowObject(RCLICK_POPUP | PLAYER_COLORED, ImagePath::builtin("HEROQVBK"), position) : AdventureMapPopup(RCLICK_POPUP | PLAYER_COLORED, ImagePath::builtin("HEROQVBK"), position)
{ {
InfoAboutHero iah; InfoAboutHero iah;
LOCPLINT->cb->getHeroInfo(hero, iah, LOCPLINT->localState->getCurrentArmy()); //todo: should this be nearest hero? LOCPLINT->cb->getHeroInfo(hero, iah, LOCPLINT->localState->getCurrentArmy()); //todo: should this be nearest hero?
@ -310,7 +317,7 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGHeroInstance * hero)
} }
CInfoBoxPopup::CInfoBoxPopup(Point position, const CGGarrison * garr) CInfoBoxPopup::CInfoBoxPopup(Point position, const CGGarrison * garr)
: CWindowObject(RCLICK_POPUP | PLAYER_COLORED, ImagePath::builtin("TOWNQVBK"), position) : AdventureMapPopup(RCLICK_POPUP | PLAYER_COLORED, ImagePath::builtin("TOWNQVBK"), position)
{ {
InfoAboutTown iah; InfoAboutTown iah;
LOCPLINT->cb->getTownInfo(garr, iah); LOCPLINT->cb->getTownInfo(garr, iah);
@ -324,7 +331,7 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGGarrison * garr)
} }
CInfoBoxPopup::CInfoBoxPopup(Point position, const CGCreature * creature) CInfoBoxPopup::CInfoBoxPopup(Point position, const CGCreature * creature)
: CWindowObject(RCLICK_POPUP | BORDERED, ImagePath::builtin("DIBOXBCK"), position) : AdventureMapPopup(RCLICK_POPUP | BORDERED, ImagePath::builtin("DIBOXBCK"), position)
{ {
OBJECT_CONSTRUCTION; OBJECT_CONSTRUCTION;
tooltip = std::make_shared<CreatureTooltip>(Point(9, 10), creature); tooltip = std::make_shared<CreatureTooltip>(Point(9, 10), creature);
@ -389,7 +396,7 @@ void MinimapWithIcons::addIcon(const int3 & coordinates, const ImagePath & image
} }
TeleporterPopup::TeleporterPopup(const Point & position, const CGTeleport * teleporter) TeleporterPopup::TeleporterPopup(const Point & position, const CGTeleport * teleporter)
: CWindowObject(BORDERED | RCLICK_POPUP) : AdventureMapPopup(BORDERED | RCLICK_POPUP)
{ {
OBJECT_CONSTRUCTION; OBJECT_CONSTRUCTION;
pos.w = 322; pos.w = 322;
@ -430,7 +437,7 @@ TeleporterPopup::TeleporterPopup(const Point & position, const CGTeleport * tele
} }
KeymasterPopup::KeymasterPopup(const Point & position, const CGKeys * keymasterOrGuard) KeymasterPopup::KeymasterPopup(const Point & position, const CGKeys * keymasterOrGuard)
: CWindowObject(BORDERED | RCLICK_POPUP) : AdventureMapPopup(BORDERED | RCLICK_POPUP)
{ {
OBJECT_CONSTRUCTION; OBJECT_CONSTRUCTION;
pos.w = 322; pos.w = 322;
@ -469,7 +476,7 @@ KeymasterPopup::KeymasterPopup(const Point & position, const CGKeys * keymasterO
} }
ObeliskPopup::ObeliskPopup(const Point & position, const CGObelisk * obelisk) ObeliskPopup::ObeliskPopup(const Point & position, const CGObelisk * obelisk)
: CWindowObject(BORDERED | RCLICK_POPUP) : AdventureMapPopup(BORDERED | RCLICK_POPUP)
{ {
OBJECT_CONSTRUCTION; OBJECT_CONSTRUCTION;
pos.w = 322; pos.w = 322;

View File

@ -93,20 +93,27 @@ public:
void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) override; void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) override;
}; };
/// adventure map popup
class AdventureMapPopup : public CWindowObject
{
Point dragDistance;
public:
template<typename... Args>
AdventureMapPopup(Args&&... args);
void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) override;
};
/// popup on adventure map for town\hero and other objects with customized popup content /// popup on adventure map for town\hero and other objects with customized popup content
class CInfoBoxPopup : public CWindowObject class CInfoBoxPopup : public AdventureMapPopup
{ {
std::shared_ptr<CIntObject> tooltip; std::shared_ptr<CIntObject> tooltip;
Point dragDistance;
public: public:
CInfoBoxPopup(Point position, const CGTownInstance * town); CInfoBoxPopup(Point position, const CGTownInstance * town);
CInfoBoxPopup(Point position, const CGHeroInstance * hero); CInfoBoxPopup(Point position, const CGHeroInstance * hero);
CInfoBoxPopup(Point position, const CGGarrison * garr); CInfoBoxPopup(Point position, const CGGarrison * garr);
CInfoBoxPopup(Point position, const CGCreature * creature); CInfoBoxPopup(Point position, const CGCreature * creature);
void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) override;
}; };
/// component selection window /// component selection window
@ -134,7 +141,7 @@ public:
void addIcon(const int3 & coordinates, const ImagePath & image); void addIcon(const int3 & coordinates, const ImagePath & image);
}; };
class TeleporterPopup : public CWindowObject class TeleporterPopup : public AdventureMapPopup
{ {
std::shared_ptr<FilledTexturePlayerColored> filledBackground; std::shared_ptr<FilledTexturePlayerColored> filledBackground;
std::shared_ptr<MinimapWithIcons> minimap; std::shared_ptr<MinimapWithIcons> minimap;
@ -144,7 +151,7 @@ public:
TeleporterPopup(const Point & position, const CGTeleport * teleporter); TeleporterPopup(const Point & position, const CGTeleport * teleporter);
}; };
class KeymasterPopup : public CWindowObject class KeymasterPopup : public AdventureMapPopup
{ {
std::shared_ptr<FilledTexturePlayerColored> filledBackground; std::shared_ptr<FilledTexturePlayerColored> filledBackground;
std::shared_ptr<MinimapWithIcons> minimap; std::shared_ptr<MinimapWithIcons> minimap;
@ -155,7 +162,7 @@ public:
KeymasterPopup(const Point & position, const CGKeys * keymasterOrGuard); KeymasterPopup(const Point & position, const CGKeys * keymasterOrGuard);
}; };
class ObeliskPopup : public CWindowObject class ObeliskPopup : public AdventureMapPopup
{ {
std::shared_ptr<FilledTexturePlayerColored> filledBackground; std::shared_ptr<FilledTexturePlayerColored> filledBackground;
std::shared_ptr<MinimapWithIcons> minimap; std::shared_ptr<MinimapWithIcons> minimap;