Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,64 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#include <AzCore/Component/EntityId.h>
#include <GraphCanvas/Types/Endpoint.h>
#include <GraphCanvas/Editor/EditorTypes.h>
namespace GraphCanvas
{
struct Connectability;
class ConnectionFilter
{
public:
AZ_RTTI(ConnectionFilter, "{E8319FDC-DDC5-40DD-A601-5E8C41B019A8}");
virtual ~ConnectionFilter() = default;
void SetEntityId(const AZ::EntityId& entityId)
{
m_entityId = entityId;
}
const AZ::EntityId& GetEntityId() const
{
return m_entityId;
}
virtual bool CanConnectWith(const Endpoint& endpoint, const ConnectionMoveType& moveType) const = 0;
private:
AZ::EntityId m_entityId;
};
//! Requests that are serviced by objects that want to filter slot connections based on a set of predicates
//! connections can either be filtered for inclusion or exclusion
class ConnectionFilterRequests : public AZ::EBusTraits
{
public:
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
using BusIdType = AZ::EntityId;
//! Add a connection filter to the given slot.
//! Params: ConnectionFilter* the filter to be added, ownership is taken by the Slot.
virtual void AddFilter(ConnectionFilter*) = 0;
virtual bool CanConnectWith(const Endpoint& endpoint, const ConnectionMoveType& moveType) const = 0;
};
using ConnectionFilterRequestBus = AZ::EBus<ConnectionFilterRequests>;
}
@@ -0,0 +1,143 @@
/*
* All or Portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/std/containers/unordered_set.h>
#include <GraphCanvas/Components/Connections/ConnectionBus.h>
#include <GraphCanvas/Components/Connections/ConnectionFilters/ConnectionFilterBus.h>
#include <GraphCanvas/Components/Slots/SlotBus.h>
namespace GraphCanvas
{
enum class ConnectionFilterType : AZ::u32
{
Include = 0,
Exclude,
Invalid
};
class SlotTypeFilter
: public ConnectionFilter
{
friend class SlotConnectionFilterComponent;
public:
AZ_RTTI(SlotTypeFilter, "{210FB521-041E-4932-BC7F-C91079125F68}", ConnectionFilter);
AZ_CLASS_ALLOCATOR(SlotTypeFilter, AZ::SystemAllocator, 0);
SlotTypeFilter()
: m_filterType(ConnectionFilterType::Invalid)
{
}
SlotTypeFilter(ConnectionFilterType filterType)
: m_filterType(filterType)
{
}
void AddSlotType(SlotType slotType)
{
m_slotTypes.insert(slotType);
}
bool CanConnectWith(const Endpoint& endpoint, const ConnectionMoveType& moveType) const override
{
AZ_UNUSED(moveType);
SlotType connectingSlotType = SlotTypes::Invalid;
SlotRequestBus::EventResult(connectingSlotType, endpoint.GetSlotId(), &SlotRequests::GetSlotType);
AZ_Assert(connectingSlotType != SlotGroups::Invalid, "Slot %s is in an invalid slot type. Connections to it are disabled", endpoint.GetSlotId().ToString().c_str());
bool canConnect = false;
if (connectingSlotType != SlotTypes::Invalid)
{
bool isInFilter = m_slotTypes.count(connectingSlotType) != 0;
switch (m_filterType)
{
case ConnectionFilterType::Include:
canConnect = isInFilter;
break;
case ConnectionFilterType::Exclude:
canConnect = !isInFilter;
break;
}
}
return canConnect;
}
private:
AZStd::unordered_set<SlotType> m_slotTypes;
ConnectionFilterType m_filterType;
};
class ConnectionTypeFilter
: public ConnectionFilter
{
friend class SlotConnectionFilterComponent;
public:
AZ_RTTI(ConnectionTypeFilter, "{57D65203-51AB-47A8-A7D2-248AFF92E058}", ConnectionFilter);
AZ_CLASS_ALLOCATOR(ConnectionTypeFilter, AZ::SystemAllocator, 0);
ConnectionTypeFilter()
: m_filterType(ConnectionFilterType::Invalid)
{
}
ConnectionTypeFilter(ConnectionFilterType filterType)
: m_filterType(filterType)
{
}
void AddConnectionType(ConnectionType connectionType)
{
m_connectionTypes.insert(connectionType);
}
bool CanConnectWith(const Endpoint& endpoint, const ConnectionMoveType& moveType) const override
{
AZ_UNUSED(moveType);
ConnectionType connectionType = ConnectionType::CT_Invalid;
SlotRequestBus::EventResult(connectionType, endpoint.GetSlotId(), &SlotRequests::GetConnectionType);
AZ_Assert(connectionType != ConnectionType::CT_Invalid, "Slot %s is in an invalid slot type. Connections to it are disabled", endpoint.GetSlotId().ToString().c_str())
bool canConnect = false;
if (connectionType != ConnectionType::CT_Invalid)
{
bool isInFilter = m_connectionTypes.count(connectionType) != 0;
switch (m_filterType)
{
case ConnectionFilterType::Include:
canConnect = isInFilter;
break;
case ConnectionFilterType::Exclude:
canConnect = !isInFilter;
break;
}
}
return canConnect;
}
private:
AZStd::unordered_set<ConnectionType> m_connectionTypes;
ConnectionFilterType m_filterType;
};
}
@@ -0,0 +1,135 @@
/*
* All or Portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/std/containers/unordered_set.h>
#include <GraphCanvas/Components/Connections/ConnectionFilters/ConnectionFilterBus.h>
#include <GraphCanvas/Components/Slots/Data/DataSlotBus.h>
#include <GraphCanvas/Editor/GraphModelBus.h>
namespace GraphCanvas
{
class DataSlotTypeFilter
: public ConnectionFilter
{
friend class SlotConnectionFilter;
public:
AZ_RTTI(DataSlotTypeFilter, "{D625AE2F-5F71-461E-A553-554402A824BF}", ConnectionFilter);
AZ_CLASS_ALLOCATOR(DataSlotTypeFilter, AZ::SystemAllocator, 0);
DataSlotTypeFilter()
{
}
bool CanConnectWith(const Endpoint& endpoint, const ConnectionMoveType& moveType) const override
{
AZ::EntityId sceneId;
SceneMemberRequestBus::EventResult(sceneId, GetEntityId(), &SceneMemberRequests::GetScene);
DataSlotType sourceType = DataSlotType::Unknown;
DataSlotType targetType = DataSlotType::Unknown;
Endpoint sourceEndpoint;
Endpoint targetEndpoint;
// We want to look at the connection we are trying to create.
// Since this runs on the target of the connections.
// We need to look at this from the perspective of the thing asking us for the connection.
ConnectionType connectionType = CT_None;
SlotRequestBus::EventResult(connectionType, endpoint.GetSlotId(), &SlotRequests::GetConnectionType);
if (connectionType == CT_Input)
{
sourceEndpoint.m_slotId = GetEntityId();
SlotRequestBus::EventResult(sourceEndpoint.m_nodeId, GetEntityId(), &SlotRequests::GetNode);
targetEndpoint = endpoint;
}
else if (connectionType == CT_Output)
{
sourceEndpoint = endpoint;
targetEndpoint.m_slotId = GetEntityId();
SlotRequestBus::EventResult(targetEndpoint.m_nodeId, GetEntityId(), &SlotRequests::GetNode);
}
else
{
return false;
}
DataSlotRequestBus::EventResult(sourceType, sourceEndpoint.GetSlotId(), &DataSlotRequests::GetDataSlotType);
DataSlotRequestBus::EventResult(targetType, targetEndpoint.GetSlotId(), &DataSlotRequests::GetDataSlotType);
bool acceptConnection = false;
// We don't want to allow any connections to a reference pin.
// But we do want to allow connections from a reference pin.
if (sourceType == DataSlotType::Reference)
{
if (targetType == DataSlotType::Reference)
{
acceptConnection = true;
}
}
else if (sourceType == DataSlotType::Value)
{
if (targetType == DataSlotType::Value)
{
acceptConnection = true;
}
}
if (!acceptConnection)
{
if (moveType == ConnectionMoveType::Source)
{
if (targetType == DataSlotType::Reference)
{
bool hasConnections = false;
SlotRequestBus::EventResult(hasConnections, sourceEndpoint.GetSlotId(), &SlotRequests::HasConnections);
// Only want to try to convert to references when we have no connections
if (!hasConnections)
{
DataSlotRequestBus::EventResult(acceptConnection, sourceEndpoint.GetSlotId(), &DataSlotRequests::CanConvertToReference);
}
}
else if (targetType == DataSlotType::Value)
{
DataSlotRequestBus::EventResult(acceptConnection, sourceEndpoint.GetSlotId(), &DataSlotRequests::CanConvertToValue);
}
}
else if (moveType == ConnectionMoveType::Target)
{
if (sourceType == DataSlotType::Reference)
{
bool hasConnections = false;
SlotRequestBus::EventResult(hasConnections, targetEndpoint.GetSlotId(), &SlotRequests::HasConnections);
// Only want to try to convert to references when we have no connections
if (!hasConnections)
{
DataSlotRequestBus::EventResult(acceptConnection, targetEndpoint.GetSlotId(), &DataSlotRequests::CanConvertToReference);
}
}
else if (sourceType == DataSlotType::Value)
{
DataSlotRequestBus::EventResult(acceptConnection, targetEndpoint.GetSlotId(), &DataSlotRequests::CanConvertToValue);
}
}
}
return acceptConnection;
}
};
}
@@ -0,0 +1,616 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <type_traits>
AZ_PUSH_DISABLE_WARNING(4251 4800 4244, "-Wunknown-warning-option")
#include <QGraphicsSceneEvent>
#include <QGraphicsItem>
#include <QGraphicsView>
#include <QDebug>
AZ_POP_DISABLE_WARNING
#include <AzCore/Component/TickBus.h>
#include <AzCore/std/chrono/chrono.h>
#include <GraphCanvas/Components/GeometryBus.h>
#include <GraphCanvas/Components/SceneBus.h>
#include <GraphCanvas/Components/StyleBus.h>
#include <GraphCanvas/Components/ViewBus.h>
#include <GraphCanvas/Components/VisualBus.h>
#include <GraphCanvas/Styling/definitions.h>
#include <GraphCanvas/tools.h>
#include <GraphCanvas/Utils/StateControllers/PrioritizedStateController.h>
#include <GraphCanvas/Utils/ConversionUtils.h>
namespace AZ
{
AZ_TYPE_INFO_SPECIALIZE(QGraphicsItem, "{054358C3-B3D7-4035-9A74-2D7B2741271A}");
}
namespace GraphCanvas
{
// Number just to cap the movement at a reasonable speed to avoid slow jittery movement
constexpr float minimumAnimationPixelsPerSecond = 50.0f;
//! Generates EBus notifications for some QGraphicsItem events.
template<typename GraphicsItem>
class RootGraphicsItem
: public GraphicsItem
, public ViewSceneNotificationBus::Handler
, public RootGraphicsItemRequestBus::Handler
, public StateController<RootGraphicsItemDisplayState>::Notifications::Handler
, public AZ::TickBus::Handler
{
static_assert(std::is_base_of<QGraphicsItem, GraphicsItem>::value, "GraphicsItem must be a descendant of QGraphicsItem");
public:
using GraphicsItem::setAcceptHoverEvents;
RootGraphicsItem(AZ::EntityId itemId)
: m_resizeToGrid(false)
, m_snapToGrid(false)
, m_gridX(1)
, m_gridY(1)
, m_animationDuration(0.0f)
, m_currentAnimationTime(0.0f)
, m_allowQuickDeletion(true)
, m_itemId(itemId)
, m_anchorPoint(0,0)
, m_enabledState(RootGraphicsItemEnabledState::ES_Enabled)
, m_forcedStateDisplayState(RootGraphicsItemDisplayState::Neutral)
, m_internalDisplayState(RootGraphicsItemDisplayState::Neutral)
, m_actualDisplayState(RootGraphicsItemDisplayState::Neutral)
{
setAcceptHoverEvents(true);
RootGraphicsItemRequestBus::Handler::BusConnect(GetEntityId());
StateController<RootGraphicsItemDisplayState>::Notifications::Handler::BusConnect(&m_forcedStateDisplayState);
m_gridSize = AZ::Vector2(aznumeric_cast<float>(m_gridX), aznumeric_cast<float>(m_gridY));
}
~RootGraphicsItem() override = default;
// QGraphicsItem
enum
{
Type = QGraphicsItem::UserType + 1
};
AZ::EntityId GetEntityId() const
{
return m_itemId;
}
bool IsSnappedToGrid() const
{
return m_snapToGrid;
}
bool IsResizedToGrid() const
{
return m_resizeToGrid;
}
int GetGridXStep() const
{
return m_gridX;
}
int GetGridYStep() const
{
return m_gridY;
}
void SetSnapToGridEnabled(bool enabled)
{
if (m_snapToGrid != enabled)
{
m_snapToGrid = enabled;
if (m_snapToGrid)
{
GraphicsItem* thisItem = static_cast<GraphicsItem*>(this);
thisItem->setPos(CalculatePosition(thisItem->pos()));
}
}
}
void SetResizeToGridEnabled(bool enabled)
{
m_resizeToGrid = enabled;
}
void SetGridSize(const AZ::Vector2& gridSize)
{
if (gridSize.GetX() >= 0)
{
m_gridX = static_cast<unsigned int>(gridSize.GetX());
}
else
{
m_gridX = 1;
AZ_Error("VisualNotificationsHelper", false, "Invalid X-Step to snap grid to.");
}
if (gridSize.GetY() >= 0)
{
m_gridY = static_cast<unsigned int>(gridSize.GetY());
}
else
{
m_gridY = 1;
AZ_Error("VisualNotificationsHelper", false, "Invalid Y-Step to snap grid to.");
}
m_gridSize = AZ::Vector2(aznumeric_cast<float>(m_gridX), aznumeric_cast<float>(m_gridY));
}
void SetAnchorPoint(const AZ::Vector2& anchorPoint)
{
m_anchorPoint = anchorPoint;
}
// StateController<RootGraphicsItemDisplayState>
void OnStateChanged([[maybe_unused]] const RootGraphicsItemDisplayState& displayState)
{
UpdateActualDisplayState();
}
////
// TickBus
void OnTick(float delta, AZ::ScriptTimePoint)
{
m_currentAnimationTime += delta;
if (m_currentAnimationTime >= m_animationDuration)
{
m_currentAnimationTime = m_animationDuration;
CleanUpAnimation();
}
else
{
float percentage = m_currentAnimationTime / m_animationDuration;
AZ::Vector2 position = m_startPoint.Lerp(m_targetPoint, percentage);
GeometryRequestBus::Event(GetEntityId(), &GeometryRequests::SetPosition, position);
}
}
////
// RootGraphicsItemRequestBus
void AnimatePositionTo(const QPointF& scenePoint, const AZStd::chrono::milliseconds& duration)
{
if (!AZ::TickBus::Handler::BusIsConnected())
{
GeometryRequestBus::EventResult(m_startPoint, GetEntityId(), &GeometryRequests::GetPosition);
AZ::TickBus::Handler::BusConnect();
}
else
{
float percentage = m_currentAnimationTime / m_animationDuration;
m_startPoint = m_startPoint.Lerp(m_targetPoint, percentage);
}
m_targetPoint = ConversionUtils::QPointToVector(scenePoint);
if (m_snapToGrid)
{
m_targetPoint = ConversionUtils::QPointToVector(CalculatePosition(ConversionUtils::AZToQPoint(m_targetPoint)));
}
VisualNotificationBus::Event(GetEntityId(), &VisualNotifications::OnPositionAnimateBegin, m_targetPoint);
// Maintain a certain 'velocity' for the nodes so they don't like slowly dribble around.
float minimumDuration = (m_targetPoint - m_startPoint).GetLength();
minimumDuration /= minimumAnimationPixelsPerSecond;
m_animationDuration = AZStd::min(minimumDuration, duration.count() * 0.001f);
m_currentAnimationTime = 0.0f;
}
void CancelAnimation()
{
m_currentAnimationTime = m_animationDuration;
CleanUpAnimation();
}
StateController<RootGraphicsItemDisplayState>* GetDisplayStateStateController() override
{
return &m_forcedStateDisplayState;
}
RootGraphicsItemDisplayState GetDisplayState() const override
{
return m_actualDisplayState;
}
void SetEnabledState(RootGraphicsItemEnabledState state) override
{
if (m_enabledState != state)
{
m_enabledState = state;
OnEnabledStateChanged(state);
UpdateActualDisplayState();
RootGraphicsItemNotificationBus::Event(GetEntityId(), &RootGraphicsItemNotifications::OnEnabledChanged, m_enabledState);
}
}
RootGraphicsItemEnabledState GetEnabledState() const
{
return m_enabledState;
}
////
protected:
RootGraphicsItem(const RootGraphicsItem&) = delete;
void SetDisplayState(RootGraphicsItemDisplayState displayState)
{
if (m_internalDisplayState != displayState)
{
m_internalDisplayState = displayState;
UpdateActualDisplayState();
}
}
// ViewSceneNotifications
void OnAltModifier(bool enabled) override
{
if (m_allowQuickDeletion)
{
if (enabled)
{
SetDisplayState(RootGraphicsItemDisplayState::Deletion);
}
else
{
SetDisplayState(RootGraphicsItemDisplayState::Inspection);
}
}
}
////
// QGraphicsItem
void hoverEnterEvent(QGraphicsSceneHoverEvent* hoverEvent) override
{
AZ::EntityId sceneId;
SceneMemberRequestBus::EventResult(sceneId, GetEntityId(), &SceneMemberRequests::GetScene);
ViewSceneNotificationBus::Handler::BusConnect(sceneId);
if (hoverEvent->modifiers() & Qt::KeyboardModifier::AltModifier)
{
SetDisplayState(RootGraphicsItemDisplayState::Deletion);
}
else
{
SetDisplayState(RootGraphicsItemDisplayState::Inspection);
}
GraphicsItem::hoverEnterEvent(hoverEvent);
}
void hoverLeaveEvent(QGraphicsSceneHoverEvent* hoverEvent) override
{
ViewSceneNotificationBus::Handler::BusDisconnect();
SetDisplayState(RootGraphicsItemDisplayState::Neutral);
GraphicsItem::hoverLeaveEvent(hoverEvent);
}
void mousePressEvent(QGraphicsSceneMouseEvent* event) override
{
if (event->modifiers() & Qt::KeyboardModifier::AltModifier)
{
OnDeleteItem();
}
else
{
bool result = false;
VisualNotificationBus::EventResult(result, GetEntityId(), &VisualNotifications::OnMousePress, GetEntityId(), event);
if (!result)
{
GraphicsItem::mousePressEvent(event);
}
}
}
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override
{
bool result = false;
VisualNotificationBus::EventResult(result, GetEntityId(), &VisualNotifications::OnMouseRelease, GetEntityId(), event);
if (!result)
{
GraphicsItem::mouseReleaseEvent(event);
}
}
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* mouseEvent) override
{
bool result = false;
VisualNotificationBus::EventResult(result, GetEntityId(), &VisualNotifications::OnMouseDoubleClick, mouseEvent);
if (!result)
{
GraphicsItem::mouseDoubleClickEvent(mouseEvent);
}
}
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant& value) override
{
if (change == QAbstractGraphicsShapeItem::ItemPositionChange)
{
QVariant snappedValue(CalculatePosition(value.toPointF()));
VisualNotificationBus::Event(GetEntityId(), &VisualNotifications::OnItemChange, GetEntityId(), change, snappedValue);
return snappedValue;
}
else
{
VisualNotificationBus::Event(GetEntityId(), &VisualNotifications::OnItemChange, GetEntityId(), change, value);
}
return GraphicsItem::itemChange(change, value);
}
virtual QRectF GetBoundingRect() const = 0;
int type() const override
{
return Type;
}
////
virtual void OnDeleteItem()
{
AZ::EntityId graphId;
SceneMemberRequestBus::EventResult(graphId, GetEntityId(), &SceneMemberRequests::GetScene);
AZStd::unordered_set<AZ::EntityId> deleteIds = { GetEntityId() };
SceneRequestBus::Event(graphId, &SceneRequests::Delete, deleteIds);
}
virtual void OnEnabledStateChanged(RootGraphicsItemEnabledState enabledState)
{
AZ_UNUSED(enabledState);
}
void SetAllowQuickDeletion(bool enabled)
{
m_allowQuickDeletion = enabled;
}
private:
void UpdateActualDisplayState()
{
RootGraphicsItemDisplayState desiredDisplayState = m_internalDisplayState;
if (m_forcedStateDisplayState.HasState())
{
desiredDisplayState = m_forcedStateDisplayState.GetState();
}
else if (m_enabledState != RootGraphicsItemEnabledState::ES_Enabled)
{
if (desiredDisplayState <= RootGraphicsItemDisplayState::Disabled)
{
if (m_enabledState == RootGraphicsItemEnabledState::ES_Disabled)
{
desiredDisplayState = RootGraphicsItemDisplayState::Disabled;
}
else
{
desiredDisplayState = RootGraphicsItemDisplayState::PartialDisabled;
}
}
}
if (desiredDisplayState != m_actualDisplayState)
{
RootGraphicsItemDisplayState oldDisplayState = m_actualDisplayState;
switch (m_actualDisplayState)
{
case RootGraphicsItemDisplayState::Deletion:
LeaveDeletionState();
break;
case RootGraphicsItemDisplayState::Disabled:
LeaveDisabledState();
break;
case RootGraphicsItemDisplayState::PartialDisabled:
LeavePartialDisabledState();
break;
case RootGraphicsItemDisplayState::InspectionTransparent:
LeaveInspectionTransparentState();
break;
case RootGraphicsItemDisplayState::Inspection:
LeaveInspectionState();
break;
case RootGraphicsItemDisplayState::GroupHighlight:
LeaveGroupHighlightState();
break;
case RootGraphicsItemDisplayState::Preview:
LeavePreviewState();
break;
case RootGraphicsItemDisplayState::Neutral:
LeaveNeutralState();
break;
default:
break;
}
m_actualDisplayState = desiredDisplayState;
switch (m_actualDisplayState)
{
case RootGraphicsItemDisplayState::Deletion:
EnterDeletionState();
break;
case RootGraphicsItemDisplayState::Disabled:
EnterDisabledState();
break;
case RootGraphicsItemDisplayState::PartialDisabled:
EnterPartialDisabledState();
break;
case RootGraphicsItemDisplayState::InspectionTransparent:
EnterInspectionTransparentState();
break;
case RootGraphicsItemDisplayState::Inspection:
EnterInspectionState();
break;
case RootGraphicsItemDisplayState::GroupHighlight:
EnterGroupHighlightState();
break;
case RootGraphicsItemDisplayState::Preview:
EnterPreviewState();
break;
case RootGraphicsItemDisplayState::Neutral:
EnterNeutralState();
break;
default:
break;
}
RootGraphicsItemNotificationBus::Event(GetEntityId(), &RootGraphicsItemNotifications::OnDisplayStateChanged, oldDisplayState, m_actualDisplayState);
}
}
void EnterPreviewState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::AddSelectorState, Styling::States::Preview);
}
void LeavePreviewState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::RemoveSelectorState, Styling::States::Preview);
}
void EnterDeletionState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::AddSelectorState, Styling::States::Deletion);
}
void LeaveDeletionState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::RemoveSelectorState, Styling::States::Deletion);
}
void EnterPartialDisabledState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::AddSelectorState, Styling::States::PartialDisabled);
}
void LeavePartialDisabledState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::RemoveSelectorState, Styling::States::PartialDisabled);
}
void EnterDisabledState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::AddSelectorState, Styling::States::Disabled);
}
void LeaveDisabledState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::RemoveSelectorState, Styling::States::Disabled);
}
void EnterInspectionState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::AddSelectorState, Styling::States::Hovered);
}
void LeaveInspectionState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::RemoveSelectorState, Styling::States::Hovered);
}
void EnterInspectionTransparentState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::AddSelectorState, Styling::States::InspectionTransparent);
}
void LeaveInspectionTransparentState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::RemoveSelectorState, Styling::States::InspectionTransparent);
}
void EnterGroupHighlightState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::AddSelectorState, Styling::States::Hovered);
}
void LeaveGroupHighlightState()
{
StyledEntityRequestBus::Event(GetEntityId(), &StyledEntityRequests::RemoveSelectorState, Styling::States::Hovered);
}
void EnterNeutralState()
{
}
void LeaveNeutralState()
{
}
QPointF CalculatePosition(QPointF position) const
{
if (m_snapToGrid && !AZ::TickBus::Handler::BusIsConnected())
{
return GraphUtils::CalculateGridSnapPosition(position, m_anchorPoint, GetBoundingRect(), m_gridSize);
}
else
{
return GraphUtils::CalculateAnchorPoint(position, m_anchorPoint, GetBoundingRect());
}
}
void CleanUpAnimation()
{
AZ::TickBus::Handler::BusDisconnect();
VisualNotificationBus::Event(GetEntityId(), &VisualNotifications::OnPositionAnimateEnd);
}
bool m_resizeToGrid;
bool m_snapToGrid;
unsigned int m_gridX;
unsigned int m_gridY;
AZ::Vector2 m_gridSize;
float m_animationDuration;
float m_currentAnimationTime;
AZ::Vector2 m_targetPoint;
AZ::Vector2 m_startPoint;
bool m_allowQuickDeletion;
RootGraphicsItemEnabledState m_enabledState;
PrioritizedStateController<RootGraphicsItemDisplayState> m_forcedStateDisplayState;
RootGraphicsItemDisplayState m_internalDisplayState;
RootGraphicsItemDisplayState m_actualDisplayState;
AZ::EntityId m_itemId;
AZ::Vector2 m_anchorPoint;
};
}
@@ -0,0 +1,64 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
AZ_PUSH_DISABLE_WARNING(4251 4800 4244, "-Wunknown-warning-option")
#include <QDebug>
#include <QPoint>
#include <QString>
AZ_POP_DISABLE_WARNING
#include <AzCore/Component/EntityId.h>
#include <AzCore/std/string/string.h>
#include <AzCore/Math/Vector2.h>
namespace AZ
{
class Component;
class Entity;
class Vector2;
}
QDebug operator<<(QDebug debug, const AZ::Entity* entity);
QDebug operator<<(QDebug debug, const AZ::EntityId& entity);
QDebug operator<<(QDebug debug, const AZ::Component* component);
QDebug operator<<(QDebug debug, const AZ::Vector2& position);
namespace GraphCanvas
{
static const int GraphicsItemName = 0;
namespace Tools
{
inline QString qStringFromUtf8(const AZStd::string& native)
{
return QString::fromUtf8(native.data(), static_cast<int>(native.size()));
}
inline AZStd::string utf8FromqString(const QString& qt)
{
const QByteArray utf8 = qt.toUtf8();
return AZStd::string(utf8.constData(), utf8.size());
}
inline bool IsClose(const QPointF& left, const QPointF& right)
{
return AZ::Vector2(aznumeric_cast<float>(left.x()), aznumeric_cast<float>(left.y())).IsClose(AZ::Vector2(aznumeric_cast<float>(right.x()), aznumeric_cast<float>(right.y())));
}
inline bool IsClose(qreal left, qreal right, float tolerance)
{
return AZ::IsClose(static_cast<float>(left), static_cast<float>(right), tolerance);
}
} // namespace Tools
} // namespace GraphCanvas