2023-05-18 12:31:26 +02:00
|
|
|
/*
|
|
|
|
* EventsReceiver.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "EventsReceiver.h"
|
|
|
|
|
|
|
|
#include "MouseButton.h"
|
|
|
|
#include "CGuiHandler.h"
|
|
|
|
#include "EventDispatcher.h"
|
|
|
|
|
|
|
|
AEventsReceiver::AEventsReceiver()
|
|
|
|
: activeState(0)
|
|
|
|
, hoveredState(false)
|
2023-05-29 18:02:23 +02:00
|
|
|
, panningState(false)
|
2023-06-13 18:27:43 +02:00
|
|
|
, mouseClickedState(false)
|
2023-05-18 12:31:26 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AEventsReceiver::isHovered() const
|
|
|
|
{
|
|
|
|
return hoveredState;
|
|
|
|
}
|
|
|
|
|
2023-06-16 14:31:59 +02:00
|
|
|
bool AEventsReceiver::isGesturing() const
|
2023-05-29 12:08:08 +02:00
|
|
|
{
|
|
|
|
return panningState;
|
|
|
|
}
|
|
|
|
|
2023-05-18 12:31:26 +02:00
|
|
|
bool AEventsReceiver::isActive() const
|
|
|
|
{
|
|
|
|
return activeState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AEventsReceiver::activateEvents(ui16 what)
|
|
|
|
{
|
|
|
|
assert((what & GENERAL) || (activeState & GENERAL));
|
|
|
|
|
|
|
|
activeState |= GENERAL;
|
2023-05-20 00:51:10 +02:00
|
|
|
GH.events().activateElement(this, what);
|
2023-05-18 12:31:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AEventsReceiver::deactivateEvents(ui16 what)
|
|
|
|
{
|
|
|
|
if (what & GENERAL)
|
2023-06-16 11:54:07 +02:00
|
|
|
{
|
|
|
|
assert((what & activeState) == activeState);
|
2023-05-18 12:31:26 +02:00
|
|
|
activeState &= ~GENERAL;
|
2023-06-16 11:54:07 +02:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2023-05-20 00:51:10 +02:00
|
|
|
GH.events().deactivateElement(this, what & activeState);
|
2023-07-16 16:56:47 +02:00
|
|
|
|
|
|
|
if (!(activeState & GESTURE) && panningState)
|
|
|
|
panningState = false;
|
|
|
|
|
|
|
|
if (!(activeState & LCLICK) && mouseClickedState)
|
|
|
|
mouseClickedState = false;
|
|
|
|
|
|
|
|
// FIXME: might lead to regressions, recheck before enabling
|
|
|
|
// if (!(activeState & HOVER))
|
|
|
|
// hoveredState = false;
|
2023-05-18 12:31:26 +02:00
|
|
|
}
|