FloatDataInterface.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include <GraphModel/GraphModelBus.h>
  9. #include <GraphModel/Integration/FloatDataInterface.h>
  10. #include <GraphModel/Integration/IntegrationBus.h>
  11. namespace GraphModelIntegration
  12. {
  13. FloatDataInterface::FloatDataInterface(GraphModel::SlotPtr slot)
  14. : m_slot(slot)
  15. {
  16. }
  17. double FloatDataInterface::GetNumber() const
  18. {
  19. GraphModel::SlotPtr slot = m_slot.lock();
  20. return slot ? slot->GetValue<float>() : 0.0;
  21. }
  22. void FloatDataInterface::SetNumber(double value)
  23. {
  24. GraphModel::SlotPtr slot = m_slot.lock();
  25. if (slot && slot->GetValue<float>() != static_cast<float>(value))
  26. {
  27. const GraphCanvas::GraphId graphCanvasSceneId = GetDisplay()->GetSceneId();
  28. GraphCanvas::ScopedGraphUndoBatch undoBatch(graphCanvasSceneId);
  29. slot->SetValue(static_cast<float>(value));
  30. GraphControllerNotificationBus::Event(graphCanvasSceneId, &GraphControllerNotifications::OnGraphModelSlotModified, slot);
  31. GraphControllerNotificationBus::Event(
  32. graphCanvasSceneId, &GraphControllerNotifications::OnGraphModelGraphModified, slot->GetParentNode());
  33. }
  34. }
  35. double FloatDataInterface::GetMin() const
  36. {
  37. return std::numeric_limits<float>::lowest();
  38. }
  39. double FloatDataInterface::GetMax() const
  40. {
  41. return std::numeric_limits<float>::max();
  42. }
  43. } // namespace GraphModelIntegration