123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #pragma once
- #include <GraphCanvas/Components/NodePropertyDisplay/VectorDataInterface.h>
- #include "ScriptCanvasDataInterface.h"
- namespace ScriptCanvasEditor
- {
- template<class Type, int ElementCount>
- class ScriptCanvasVectorizedDataInterface
- : public ScriptCanvasDataInterface<GraphCanvas::VectorDataInterface>
- {
- public:
- AZ_CLASS_ALLOCATOR(ScriptCanvasVectorizedDataInterface, AZ::SystemAllocator);
- ScriptCanvasVectorizedDataInterface(const AZ::EntityId& nodeId, const ScriptCanvas::SlotId& slotId)
- : ScriptCanvasDataInterface(nodeId, slotId)
- {
- }
-
- ~ScriptCanvasVectorizedDataInterface() = default;
-
- int GetElementCount() const override
- {
- return ElementCount;
- }
-
- double GetValue(int index) const override
- {
- if (index < GetElementCount())
- {
- if (const ScriptCanvas::Datum* object = GetSlotObject())
- {
- if (const Type* retVal = object->GetAs<Type>())
- {
- return aznumeric_cast<double>(static_cast<float>(retVal->GetElement(index)));
- }
- }
- }
-
- return 0.0;
- }
- void SetValue(int index, double value) override
- {
- if (index < GetElementCount())
- {
- ScriptCanvas::ModifiableDatumView datumView;
- ModifySlotObject(datumView);
- if (datumView.IsValid())
- {
- Type currentValue = (*datumView.GetAs<Type>());
- currentValue.SetElement(index, aznumeric_cast<float>(value));
- datumView.SetAs<Type>(currentValue);
- PostUndoPoint();
- PropertyGridRequestBus::Broadcast(&PropertyGridRequests::RefreshPropertyGrid);
- }
- }
- }
- };
- template<class Type, int ElementCount>
- class ScriptCanvasVectorDataInterface
- : public ScriptCanvasVectorizedDataInterface<Type, ElementCount>
- {
- public:
- AZ_CLASS_ALLOCATOR(ScriptCanvasVectorDataInterface, AZ::SystemAllocator);
- ScriptCanvasVectorDataInterface(const AZ::EntityId& nodeId, const ScriptCanvas::SlotId& slotId)
- : ScriptCanvasVectorizedDataInterface<Type, ElementCount>(nodeId, slotId)
- {
- }
- ~ScriptCanvasVectorDataInterface() = default;
- const char* GetLabel(int index) const override
- {
- if (index == 0)
- {
- return "X";
- }
- else if (index == 1)
- {
- return "Y";
- }
- else if (index == 2)
- {
- return "Z";
- }
- else if (index == 3)
- {
- return "W";
- }
- return "???";
- }
- AZStd::string GetStyle() const override
- {
- return "vectorized";
- }
- AZStd::string GetElementStyle(int index) const override
- {
- return AZStd::string::format("vector_%i", index);
- }
- };
- }
|