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) 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) level(0)
{ {
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); 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.w = background->pos.w;
pos.h = background->pos.h; 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): 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())); backgroundWithHexes = std::make_unique<Canvas>(Point(background->width(), background->height()));
updateAccessibleHexes(); updateAccessibleHexes();
addUsedEvents(LCLICK | SHOW_POPUP | MOVE | TIME | GESTURE_PANNING); addUsedEvents(LCLICK | SHOW_POPUP | MOVE | TIME | GESTURE);
} }
void BattleFieldController::activate() void BattleFieldController::activate()
@ -176,7 +176,7 @@ void BattleFieldController::createHeroes()
owner.defendingHero = std::make_shared<BattleHero>(owner, owner.defendingHeroInstance, true); 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)) if (!on && pos.isInside(finalPosition))
clickLeft(false, false); clickLeft(false, false);

View File

@ -88,7 +88,7 @@ class BattleFieldController : public CIntObject
bool isPixelInHex(Point const & position); bool isPixelInHex(Point const & position);
size_t selectBattleCursor(BattleHex myNumber); 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 gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override;
void mouseMoved(const Point & cursorPosition) override; void mouseMoved(const Point & cursorPosition) override;
void clickLeft(tribool down, bool previousState) override; void clickLeft(tribool down, bool previousState) override;

View File

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

View File

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

View File

@ -53,6 +53,13 @@ void AEventsReceiver::activateEvents(ui16 what)
void AEventsReceiver::deactivateEvents(ui16 what) void AEventsReceiver::deactivateEvents(ui16 what)
{ {
if (what & GENERAL) if (what & GENERAL)
{
assert((what & activeState) == activeState);
activeState &= ~GENERAL; 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); GH.events().deactivateElement(this, what & activeState);
} }

View File

@ -41,6 +41,7 @@ protected:
/// Called when user pans screen by specified distance /// Called when user pans screen by specified distance
virtual void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) {} 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 gesturePinch(const Point & centerPosition, double lastUpdateFactor) {}
virtual void wheelScrolled(int distance) {} virtual void wheelScrolled(int distance) {}
@ -49,8 +50,8 @@ protected:
/// Called when UI element hover status changes /// Called when UI element hover status changes
virtual void hover(bool on) {} virtual void hover(bool on) {}
/// Called when UI element panning gesture status changes /// Called when UI element gesture status changes
virtual void panning(bool on, const Point & initialPosition, const Point & finalPosition) {} virtual void gesture(bool on, const Point & initialPosition, const Point & finalPosition) {}
virtual void textInputed(const std::string & enteredText) {} virtual void textInputed(const std::string & enteredText) {}
virtual void textEdited(const std::string & enteredText) {} virtual void textEdited(const std::string & enteredText) {}
@ -70,7 +71,20 @@ public:
virtual ~AEventsReceiver() = default; virtual ~AEventsReceiver() = default;
/// These are the arguments that can be used to determine what kind of input UI element will receive /// 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 /// Returns true if element is currently hovered by mouse
bool isHovered() const; bool isHovered() const;

View File

@ -33,7 +33,7 @@ MapViewActions::MapViewActions(MapView & owner, const std::shared_ptr<MapViewMod
pos.w = model->getPixelsVisibleDimensions().x; pos.w = model->getPixelsVisibleDimensions().x;
pos.h = model->getPixelsVisibleDimensions().y; 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) void MapViewActions::setContext(const std::shared_ptr<IMapRendererContext> & context)
@ -91,7 +91,7 @@ void MapViewActions::gesturePinch(const Point & centerPosition, double lastUpdat
pinchZoomFactor = newZoom; 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; pinchZoomFactor = 1.0;
} }

View File

@ -36,7 +36,7 @@ public:
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;
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 mouseMoved(const Point & cursorPosition) override;
void wheelScrolled(int distance) override; void wheelScrolled(int distance) override;
}; };

View File

@ -12,7 +12,7 @@
#include "Scrollable.h" #include "Scrollable.h"
Scrollable::Scrollable(int used, Point position, Orientation orientation) Scrollable::Scrollable(int used, Point position, Orientation orientation)
: CIntObject(used | WHEEL | GESTURE_PANNING, position) : CIntObject(used | WHEEL | GESTURE, position)
, scrollStep(1) , scrollStep(1)
, panningDistanceSingle(32) , panningDistanceSingle(32)
, panningDistanceAccumulated(0) , 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; panningDistanceAccumulated = 0;
} }
@ -88,7 +88,7 @@ void Scrollable::setPanningStep(int to)
void Scrollable::setScrollingEnabled(bool on) void Scrollable::setScrollingEnabled(bool on)
{ {
if (on) if (on)
addUsedEvents(WHEEL | GESTURE_PANNING); addUsedEvents(WHEEL | GESTURE);
else else
removeUsedEvents(WHEEL | GESTURE_PANNING); removeUsedEvents(WHEEL | GESTURE);
} }

View File

@ -33,7 +33,7 @@ class Scrollable : public CIntObject
protected: protected:
Scrollable(int used, Point position, Orientation orientation); 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 wheelScrolled(int distance) 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;

View File

@ -151,7 +151,7 @@ void CSlider::clickLeft(tribool down, bool previousState)
bool CSlider::receiveEvent(const Point &position, int eventType) const 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); return CIntObject::receiveEvent(position, eventType);
} }

View File

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

View File

@ -16,7 +16,6 @@ class CGStatusBar;
class CWindowObject : public WindowBase class CWindowObject : public WindowBase
{ {
std::shared_ptr<CPicture> createBg(std::string imageName, bool playerColored); std::shared_ptr<CPicture> createBg(std::string imageName, bool playerColored);
int getUsedEvents(int options);
std::vector<std::shared_ptr<CPicture>> shadowParts; 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) CRClickPopupInt::CRClickPopupInt(std::shared_ptr<CIntObject> our)
{ {
CCS->curh->hide(); CCS->curh->hide();

View File

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