PropertyHandlerVec.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 <AzCore/base.h>
  10. #include <AzCore/Memory/SystemAllocator.h>
  11. #include <AzToolsFramework/UI/PropertyEditor/PropertyVectorCtrl.hxx>
  12. #include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
  13. #include <LyShine/UiBase.h>
  14. template <class TypeBeingHandled>
  15. class LegacyVectorPropertyHandlerBase
  16. : public AzToolsFramework::PropertyHandler < TypeBeingHandled, AzQtComponents::VectorInput >
  17. {
  18. protected:
  19. AzToolsFramework::VectorPropertyHandlerCommon m_common;
  20. public:
  21. LegacyVectorPropertyHandlerBase(int elementCount, int elementsPerRow = -1, AZStd::string customLabels = "")
  22. : m_common(elementCount, elementsPerRow, customLabels)
  23. {
  24. }
  25. AZ::u32 GetHandlerName(void) const override
  26. {
  27. return AZ_CRC_CE("Legacy_Vector_Property_Handler");
  28. }
  29. bool IsDefaultHandler() const override
  30. {
  31. return true;
  32. }
  33. QWidget* GetFirstInTabOrder(AzQtComponents::VectorInput* widget) override
  34. {
  35. return widget->GetFirstInTabOrder();
  36. }
  37. QWidget* GetLastInTabOrder(AzQtComponents::VectorInput* widget) override
  38. {
  39. return widget->GetLastInTabOrder();
  40. }
  41. void UpdateWidgetInternalTabbing(AzQtComponents::VectorInput* widget) override
  42. {
  43. widget->UpdateTabOrder();
  44. }
  45. QWidget* CreateGUI(QWidget* pParent) override
  46. {
  47. return m_common.ConstructGUI(pParent);
  48. }
  49. void ConsumeAttribute(AzQtComponents::VectorInput* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override
  50. {
  51. m_common.ConsumeAttributes(GUI, attrib, attrValue, debugName);
  52. }
  53. void WriteGUIValuesIntoProperty(size_t, AzQtComponents::VectorInput* GUI, TypeBeingHandled& instance, AzToolsFramework::InstanceDataNode*) override
  54. {
  55. AzQtComponents::VectorElement** elements = GUI->getElements();
  56. TypeBeingHandled actualValue = instance;
  57. for (int idx = 0; idx < m_common.GetElementCount(); ++idx)
  58. {
  59. if (elements[idx]->wasValueEditedByUser())
  60. {
  61. actualValue[idx] = aznumeric_cast<typename TypeBeingHandled::value_type>(elements[idx]->getValue());
  62. }
  63. }
  64. instance = actualValue;
  65. }
  66. bool ReadValuesIntoGUI(size_t, AzQtComponents::VectorInput* GUI, const TypeBeingHandled& instance, AzToolsFramework::InstanceDataNode*) override
  67. {
  68. GUI->blockSignals(true);
  69. for (int idx = 0; idx < m_common.GetElementCount(); ++idx)
  70. {
  71. GUI->setValuebyIndex(instance[idx], idx);
  72. }
  73. GUI->blockSignals(false);
  74. return false;
  75. }
  76. };
  77. class PropertyHandlerVec2
  78. : public LegacyVectorPropertyHandlerBase<Vec2>
  79. {
  80. public:
  81. AZ_CLASS_ALLOCATOR(PropertyHandlerVec2, AZ::SystemAllocator);
  82. PropertyHandlerVec2()
  83. : LegacyVectorPropertyHandlerBase(2)
  84. {
  85. }
  86. AZ::u32 GetHandlerName(void) const override { return AZ_CRC_CE("Vec2"); }
  87. };
  88. //////////////////////////////////////////////////////////////////////////
  89. class PropertyHandlerVec3
  90. : public LegacyVectorPropertyHandlerBase<Vec3>
  91. {
  92. public:
  93. AZ_CLASS_ALLOCATOR(PropertyHandlerVec3, AZ::SystemAllocator);
  94. PropertyHandlerVec3()
  95. : LegacyVectorPropertyHandlerBase(3)
  96. {
  97. }
  98. AZ::u32 GetHandlerName(void) const override { return AZ_CRC_CE("Vec3"); }
  99. };
  100. //////////////////////////////////////////////////////////////////////////
  101. class PropertyHandlerVec4
  102. : public LegacyVectorPropertyHandlerBase<Vec4>
  103. {
  104. public:
  105. AZ_CLASS_ALLOCATOR(PropertyHandlerVec3, AZ::SystemAllocator);
  106. PropertyHandlerVec4()
  107. : LegacyVectorPropertyHandlerBase(4)
  108. {
  109. }
  110. AZ::u32 GetHandlerName(void) const override { return AZ_CRC_CE("Vec4"); }
  111. };
  112. //////////////////////////////////////////////////////////////////////////
  113. void PropertyHandlerVecRegister();