1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Renamed gesture-related methods, remove unused code

This commit is contained in:
Ivan Savenko 2023-06-16 12:54:07 +03:00
parent 563d7dd41f
commit 06437cbde6
17 changed files with 44 additions and 45 deletions

View File

@ -88,7 +88,7 @@ void CMinimapInstance::showAll(Canvas & to)
}
CMinimap::CMinimap(const Rect & position)
: CIntObject(LCLICK | SHOW_POPUP | HOVER | MOVE | GESTURE_PANNING, position.topLeft()),
: CIntObject(LCLICK | SHOW_POPUP | HOVER | MOVE | GESTURE, position.topLeft()),
level(0)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);

View File

@ -34,8 +34,6 @@ CResDataBar::CResDataBar(const std::string & imageName, const Point & position)
pos.w = background->pos.w;
pos.h = background->pos.h;
addUsedEvents(SHOW_POPUP);
}
CResDataBar::CResDataBar(const std::string & defname, int x, int y, int offx, int offy, int resdist, int datedist):

View File

@ -155,7 +155,7 @@ BattleFieldController::BattleFieldController(BattleInterface & owner):
backgroundWithHexes = std::make_unique<Canvas>(Point(background->width(), background->height()));
updateAccessibleHexes();
addUsedEvents(LCLICK | SHOW_POPUP | MOVE | TIME | GESTURE_PANNING);
addUsedEvents(LCLICK | SHOW_POPUP | MOVE | TIME | GESTURE);
}
void BattleFieldController::activate()
@ -176,7 +176,7 @@ void BattleFieldController::createHeroes()
owner.defendingHero = std::make_shared<BattleHero>(owner, owner.defendingHeroInstance, true);
}
void BattleFieldController::panning(bool on, const Point & initialPosition, const Point & finalPosition)
void BattleFieldController::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
{
if (!on && pos.isInside(finalPosition))
clickLeft(false, false);

View File

@ -88,7 +88,7 @@ class BattleFieldController : public CIntObject
bool isPixelInHex(Point const & position);
size_t selectBattleCursor(BattleHex myNumber);
void panning(bool on, const Point & initialPosition, const Point & finalPosition) override;
void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override;
void mouseMoved(const Point & cursorPosition) override;
void clickLeft(tribool down, bool previousState) override;

View File

@ -90,7 +90,7 @@ void CIntObject::deactivate()
if (!isActive())
return;
deactivateEvents(ALL);
deactivateEvents(used | GENERAL);
assert(!isActive());

View File

@ -36,7 +36,7 @@ void EventDispatcher::processLists(ui16 activityFlag, const Functor & cb)
processList(AEventsReceiver::WHEEL, wheelInterested);
processList(AEventsReceiver::DOUBLECLICK, doubleClickInterested);
processList(AEventsReceiver::TEXTINPUT, textInterested);
processList(AEventsReceiver::GESTURE_PANNING, panningInterested);
processList(AEventsReceiver::GESTURE, panningInterested);
}
void EventDispatcher::activateElement(AEventsReceiver * elem, ui16 activityFlag)
@ -228,9 +228,9 @@ void EventDispatcher::dispatchGesturePanningStarted(const Point & initialPositio
for(auto it : copied)
{
if (it->receiveEvent(initialPosition, AEventsReceiver::GESTURE_PANNING))
if (it->receiveEvent(initialPosition, AEventsReceiver::GESTURE))
{
it->panning(true, initialPosition, initialPosition);
it->gesture(true, initialPosition, initialPosition);
it->panningState = true;
}
}
@ -244,7 +244,7 @@ void EventDispatcher::dispatchGesturePanningEnded(const Point & initialPosition,
{
if (it->isPanning())
{
it->panning(false, initialPosition, finalPosition);
it->gesture(false, initialPosition, finalPosition);
it->panningState = false;
}
}

View File

@ -53,6 +53,13 @@ void AEventsReceiver::activateEvents(ui16 what)
void AEventsReceiver::deactivateEvents(ui16 what)
{
if (what & GENERAL)
{
assert((what & activeState) == activeState);
activeState &= ~GENERAL;
// sanity check to avoid unexpected behavior if assertion above fails (e.g. in release)
// if element is deactivated (has GENERAL flag) then all existing active events should also be deactivated
what = activeState;
}
GH.events().deactivateElement(this, what & activeState);
}

View File

@ -41,6 +41,7 @@ protected:
/// Called when user pans screen by specified distance
virtual void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) {}
/// Called when user pitches screen, requesting scaling by specified factor
virtual void gesturePinch(const Point & centerPosition, double lastUpdateFactor) {}
virtual void wheelScrolled(int distance) {}
@ -49,8 +50,8 @@ protected:
/// Called when UI element hover status changes
virtual void hover(bool on) {}
/// Called when UI element panning gesture status changes
virtual void panning(bool on, const Point & initialPosition, const Point & finalPosition) {}
/// Called when UI element gesture status changes
virtual void gesture(bool on, const Point & initialPosition, const Point & finalPosition) {}
virtual void textInputed(const std::string & enteredText) {}
virtual void textEdited(const std::string & enteredText) {}
@ -70,7 +71,20 @@ public:
virtual ~AEventsReceiver() = default;
/// These are the arguments that can be used to determine what kind of input UI element will receive
enum {LCLICK=1, SHOW_POPUP=2, HOVER=4, MOVE=8, KEYBOARD=16, TIME=32, GENERAL=64, WHEEL=128, DOUBLECLICK=256, TEXTINPUT=512, GESTURE_PANNING=1024, ALL=0xffff};
enum
{
LCLICK = 1,
SHOW_POPUP = 2,
HOVER = 4,
MOVE = 8,
KEYBOARD = 16,
TIME = 32,
GENERAL = 64,
WHEEL = 128,
DOUBLECLICK = 256,
TEXTINPUT = 512,
GESTURE = 1024,
};
/// Returns true if element is currently hovered by mouse
bool isHovered() const;

View File

@ -33,7 +33,7 @@ MapViewActions::MapViewActions(MapView & owner, const std::shared_ptr<MapViewMod
pos.w = model->getPixelsVisibleDimensions().x;
pos.h = model->getPixelsVisibleDimensions().y;
addUsedEvents(LCLICK | SHOW_POPUP | GESTURE_PANNING | HOVER | MOVE | WHEEL);
addUsedEvents(LCLICK | SHOW_POPUP | GESTURE | HOVER | MOVE | WHEEL);
}
void MapViewActions::setContext(const std::shared_ptr<IMapRendererContext> & context)
@ -91,7 +91,7 @@ void MapViewActions::gesturePinch(const Point & centerPosition, double lastUpdat
pinchZoomFactor = newZoom;
}
void MapViewActions::panning(bool on, const Point & initialPosition, const Point & finalPosition)
void MapViewActions::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
{
pinchZoomFactor = 1.0;
}

View File

@ -36,7 +36,7 @@ public:
void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override;
void gesturePinch(const Point & centerPosition, double lastUpdateFactor) override;
void hover(bool on) override;
void panning(bool on, const Point & initialPosition, const Point & finalPosition) override;
void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
void mouseMoved(const Point & cursorPosition) override;
void wheelScrolled(int distance) override;
};

View File

@ -12,7 +12,7 @@
#include "Scrollable.h"
Scrollable::Scrollable(int used, Point position, Orientation orientation)
: CIntObject(used | WHEEL | GESTURE_PANNING, position)
: CIntObject(used | WHEEL | GESTURE, position)
, scrollStep(1)
, panningDistanceSingle(32)
, panningDistanceAccumulated(0)
@ -20,7 +20,7 @@ Scrollable::Scrollable(int used, Point position, Orientation orientation)
{
}
void Scrollable::panning(bool on, const Point & initialPosition, const Point & finalPosition)
void Scrollable::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
{
panningDistanceAccumulated = 0;
}
@ -88,7 +88,7 @@ void Scrollable::setPanningStep(int to)
void Scrollable::setScrollingEnabled(bool on)
{
if (on)
addUsedEvents(WHEEL | GESTURE_PANNING);
addUsedEvents(WHEEL | GESTURE);
else
removeUsedEvents(WHEEL | GESTURE_PANNING);
removeUsedEvents(WHEEL | GESTURE);
}

View File

@ -33,7 +33,7 @@ class Scrollable : public CIntObject
protected:
Scrollable(int used, Point position, Orientation orientation);
void panning(bool on, const Point & initialPosition, const Point & finalPosition) override;
void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
void wheelScrolled(int distance) override;
void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override;

View File

@ -151,7 +151,7 @@ void CSlider::clickLeft(tribool down, bool previousState)
bool CSlider::receiveEvent(const Point &position, int eventType) const
{
if (eventType != WHEEL && eventType != GESTURE_PANNING)
if (eventType != WHEEL && eventType != GESTURE)
{
return CIntObject::receiveEvent(position, eventType);
}

View File

@ -34,7 +34,7 @@
#include <SDL_surface.h>
CWindowObject::CWindowObject(int options_, std::string imageName, Point centerAt):
WindowBase(getUsedEvents(options_), Point()),
WindowBase(0, Point()),
options(options_),
background(createBg(imageName, options & PLAYER_COLORED))
{
@ -55,7 +55,7 @@ CWindowObject::CWindowObject(int options_, std::string imageName, Point centerAt
}
CWindowObject::CWindowObject(int options_, std::string imageName):
WindowBase(getUsedEvents(options_), Point()),
WindowBase(0, Point()),
options(options_),
background(createBg(imageName, options_ & PLAYER_COLORED))
{
@ -107,13 +107,6 @@ void CWindowObject::setBackground(std::string filename)
updateShadow();
}
int CWindowObject::getUsedEvents(int options)
{
if (options & RCLICK_POPUP)
return SHOW_POPUP;
return 0;
}
void CWindowObject::updateShadow()
{
setShadow(false);

View File

@ -16,7 +16,6 @@ class CGStatusBar;
class CWindowObject : public WindowBase
{
std::shared_ptr<CPicture> createBg(std::string imageName, bool playerColored);
int getUsedEvents(int options);
std::vector<std::shared_ptr<CPicture>> shadowParts;

View File

@ -338,15 +338,6 @@ void CRClickPopup::createAndPush(const CGObjectInstance * obj, const Point & p,
}
}
CRClickPopup::CRClickPopup()
{
addUsedEvents(SHOW_POPUP);
}
CRClickPopup::~CRClickPopup()
{
}
CRClickPopupInt::CRClickPopupInt(std::shared_ptr<CIntObject> our)
{
CCS->curh->hide();

View File

@ -78,9 +78,6 @@ public:
virtual void close();
bool isPopupWindow() const override;
CRClickPopup();
virtual ~CRClickPopup();
static std::shared_ptr<WindowBase> createInfoWin(Point position, const CGObjectInstance * specific);
static void createAndPush(const std::string & txt, const CInfoWindow::TCompsInfo &comps = CInfoWindow::TCompsInfo());
static void createAndPush(const std::string & txt, std::shared_ptr<CComponent> component);