ScriptCanvasNumericDataInterface.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <GraphCanvas/Components/NodePropertyDisplay/ComboBoxDataInterface.h>
  10. #include <GraphCanvas/Components/NodePropertyDisplay/NumericDataInterface.h>
  11. #include "ScriptCanvasDataInterface.h"
  12. namespace ScriptCanvasEditor
  13. {
  14. // Used for general numeric input.
  15. class ScriptCanvasNumericDataInterface
  16. : public ScriptCanvasDataInterface<GraphCanvas::NumericDataInterface>
  17. {
  18. public:
  19. AZ_CLASS_ALLOCATOR(ScriptCanvasNumericDataInterface, AZ::SystemAllocator);
  20. ScriptCanvasNumericDataInterface(const AZ::EntityId& nodeId, const ScriptCanvas::SlotId& slotId)
  21. : ScriptCanvasDataInterface(nodeId, slotId)
  22. {
  23. }
  24. ~ScriptCanvasNumericDataInterface() = default;
  25. // NumericDataInterface
  26. double GetNumber() const override
  27. {
  28. const ScriptCanvas::Datum* object = GetSlotObject();
  29. if (object)
  30. {
  31. const double* retVal = object->GetAs<double>();
  32. if (retVal)
  33. {
  34. return (*retVal);
  35. }
  36. }
  37. return 0.0;
  38. }
  39. void SetNumber(double value) override
  40. {
  41. ScriptCanvas::ModifiableDatumView datumView;
  42. ModifySlotObject(datumView);
  43. if (datumView.IsValid())
  44. {
  45. datumView.SetAs(value);
  46. PostUndoPoint();
  47. PropertyGridRequestBus::Broadcast(&PropertyGridRequests::RefreshPropertyGrid);
  48. }
  49. }
  50. ////
  51. };
  52. }