You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Gems/GraphCanvas/Code/Source/Components/Nodes/NodeLayoutComponent.h

113 lines
3.2 KiB
C++

/*
* 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/Component/Component.h>
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <GraphCanvas/Components/Nodes/NodeLayoutBus.h>
#include <GraphCanvas/Components/SceneBus.h>
class QGraphicsLayout;
namespace GraphCanvas
{
//! Base class for internal Node Layouts to help deal with some book keeping
class NodeLayoutComponent
: public AZ::Component
, public NodeLayoutRequestBus::Handler
{
public:
AZ_COMPONENT(NodeLayoutComponent, "{D3152CCC-1C6D-4E95-829D-0441002440AB}");
static void Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<NodeLayoutComponent, AZ::Component>()
->Version(1)
;
}
}
NodeLayoutComponent()
: m_layout(nullptr)
{
}
virtual ~NodeLayoutComponent()
{
}
// AZ::Component
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(NodeLayoutServiceCrc);
}
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(NodeLayoutServiceCrc);
}
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
{
dependent.push_back(NodeLayoutServiceCrc);
}
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
required.push_back(AZ_CRC("GraphCanvas_NodeService", 0xcc0f32cc));
required.push_back(AZ_CRC("GraphCanvas_StyledGraphicItemService", 0xeae4cdf4));
}
void Init() override
{
}
void Activate() override
{
NodeLayoutRequestBus::Handler::BusConnect(GetEntityId());
}
void Deactivate() override
{
NodeLayoutRequestBus::Handler::BusDisconnect();
}
////
// NodeLayoutRequestBus
QGraphicsLayout* GetLayout() override
{
return m_layout;
}
////
protected:
// Methods to simplify casting in other components
template<class T>
T* GetLayoutAs()
{
return static_cast<T*>(m_layout);
}
template<class T>
const T* GetLayoutAs() const
{
return static_cast<const T*>(m_layout);
}
QGraphicsLayout* m_layout;
};
}