/* * 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 #include #include #include #include #include #include namespace GraphCanvas { class GridGraphicsItem; class GridVisualComponent : public AZ::Component , public VisualRequestBus::Handler , public SceneMemberUIRequestBus::Handler , public GridNotificationBus::Handler { public: AZ_COMPONENT(GridVisualComponent, "{9BAEAE14-A2D3-4D60-AEA8-A8BA3E4D5EC9}", AZ::Component); static void Reflect(AZ::ReflectContext* context); GridVisualComponent(); ~GridVisualComponent() override = default; // AZ::Component static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC("GraphCanvas_GridVisualService", 0xd61e8c93)); provided.push_back(AZ_CRC("GraphCanvas_RootVisualService", 0x9ec46d3b)); provided.push_back(AZ_CRC("GraphCanvas_VisualService", 0xfbb2c871)); } static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC("GraphCanvas_GridVisualService", 0xd61e8c93)); incompatible.push_back(AZ_CRC("GraphCanvas_RootVisualService", 0x9ec46d3b)); incompatible.push_back(AZ_CRC("GraphCanvas_VisualService", 0xfbb2c871)); } static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) { (void)dependent; } static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { required.push_back(AZ_CRC("GraphCanvas_GridService", 0x58f7e1d8)); } void Init() override; void Activate() override; void Deactivate() override; //// // VisualRequestBus QGraphicsItem* AsGraphicsItem() override; bool Contains(const AZ::Vector2&) const override; void SetVisible(bool visible) override; bool IsVisible() const override; //// // SceneMemberUIRequestBus QGraphicsItem* GetRootGraphicsItem() override; QGraphicsLayoutItem* GetRootGraphicsLayoutItem() override; void SetSelected(bool selected) override; bool IsSelected() const override; QPainterPath GetOutline() const override; void SetZValue(qreal zValue) override; qreal GetZValue() const override; //// // GridNotificationBus void OnMajorPitchChanged(const AZ::Vector2& pitch) override; void OnMinorPitchChanged(const AZ::Vector2& pitch) override; //// private: GridVisualComponent(const GridVisualComponent&) = delete; AZ::Vector2 m_majorPitch; AZ::Vector2 m_minorPitch; friend class GridGraphicsItem; AZStd::unique_ptr m_gridVisualUi; }; class GridGraphicsItem : public RootGraphicsItem , protected StyleNotificationBus::Handler { static const int k_stencilScaleFactor; public: AZ_TYPE_INFO(GridGraphicsItem, "{D483E19C-8046-472B-801D-A6B1A9F2FF33}"); AZ_CLASS_ALLOCATOR(GridGraphicsItem, AZ::SystemAllocator, 0); static void Reflect(AZ::ReflectContext* context) = delete; GridGraphicsItem(GridVisualComponent& gridVisual); ~GridGraphicsItem() override = default; void Init(); void Activate(); void Deactivate(); // RootVisualNotificationsHelper QRectF GetBoundingRect() const override; //// // StyleNotificationBus void OnStyleChanged() override; //// // QGraphicsItem QRectF boundingRect(void) const override; //// protected: // QGraphicsItem void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; //// private: GridGraphicsItem(const GridGraphicsItem&) = delete; void CacheStencils(); Styling::StyleHelper m_style; AZStd::fixed_vector< QPixmap*, 4> m_levelOfDetails; int m_majorXOffset; int m_majorYOffset; GridVisualComponent& m_gridVisual; }; }