1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Implemented minimap panning gesture

This commit is contained in:
Ivan Savenko
2023-05-31 14:30:24 +03:00
parent 84934d931a
commit e6e91c64b6
3 changed files with 12 additions and 7 deletions

View File

@@ -88,7 +88,7 @@ void CMinimapInstance::showAll(Canvas & to)
} }
CMinimap::CMinimap(const Rect & position) CMinimap::CMinimap(const Rect & position)
: CIntObject(LCLICK | RCLICK | HOVER | MOVE, position.topLeft()), : CIntObject(LCLICK | RCLICK | HOVER | MOVE | GESTURE_PANNING, position.topLeft()),
level(0) level(0)
{ {
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
@@ -126,9 +126,9 @@ Point CMinimap::tileToPixels(const int3 &tile) const
return Point(x,y); return Point(x,y);
} }
void CMinimap::moveAdvMapSelection() void CMinimap::moveAdvMapSelection(const Point & positionGlobal)
{ {
int3 newLocation = pixelToTile(GH.getCursorPosition() - pos.topLeft()); int3 newLocation = pixelToTile(positionGlobal - pos.topLeft());
adventureInt->centerOnTile(newLocation); adventureInt->centerOnTile(newLocation);
if (!(adventureInt->isActive())) if (!(adventureInt->isActive()))
@@ -137,10 +137,15 @@ void CMinimap::moveAdvMapSelection()
redraw();//redraw only this redraw();//redraw only this
} }
void CMinimap::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
{
moveAdvMapSelection(currentPosition);
}
void CMinimap::clickLeft(tribool down, bool previousState) void CMinimap::clickLeft(tribool down, bool previousState)
{ {
if(down) if(down)
moveAdvMapSelection(); moveAdvMapSelection(GH.getCursorPosition());
} }
void CMinimap::clickRight(tribool down, bool previousState) void CMinimap::clickRight(tribool down, bool previousState)
@@ -160,7 +165,7 @@ void CMinimap::hover(bool on)
void CMinimap::mouseMoved(const Point & cursorPosition) void CMinimap::mouseMoved(const Point & cursorPosition)
{ {
if(isMouseButtonPressed(MouseButton::LEFT)) if(isMouseButtonPressed(MouseButton::LEFT))
moveAdvMapSelection(); moveAdvMapSelection(cursorPosition);
} }
void CMinimap::showAll(Canvas & to) void CMinimap::showAll(Canvas & to)

View File

@@ -43,13 +43,14 @@ class CMinimap : public CIntObject
Rect screenArea; Rect screenArea;
int level; int level;
void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override;
void clickLeft(tribool down, bool previousState) override; void clickLeft(tribool down, bool previousState) override;
void clickRight(tribool down, bool previousState) override; void clickRight(tribool down, bool previousState) override;
void hover (bool on) override; void hover (bool on) override;
void mouseMoved (const Point & cursorPosition) override; void mouseMoved (const Point & cursorPosition) override;
/// relocates center of adventure map screen to currently hovered tile /// relocates center of adventure map screen to currently hovered tile
void moveAdvMapSelection(); void moveAdvMapSelection(const Point & positionGlobal);
protected: protected:
/// computes coordinates of tile below cursor pos /// computes coordinates of tile below cursor pos

View File

@@ -29,7 +29,6 @@
#include "../../lib/CConfigHandler.h" #include "../../lib/CConfigHandler.h"
#include <SDL_events.h> #include <SDL_events.h>
#include <SDL_hints.h>
InputHandler::InputHandler() InputHandler::InputHandler()
: mouseHandler(std::make_unique<InputSourceMouse>()) : mouseHandler(std::make_unique<InputSourceMouse>())