| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /*
- * 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
- *
- */
- #include "LyShineExamplesSerialize.h"
- #include <LyShine/UiSerializeHelpers.h>
- #include <LyShineExamples/UiCustomImageBus.h>
- #include <AzCore/RTTI/BehaviorContext.h>
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- // NAMESPACE FUNCTIONS
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- namespace LyShineExamplesSerialize
- {
- //////////////////////////////////////////////////////////////////////////
- void UVCoordsScriptConstructor(UiCustomImageInterface::UVRect* thisPtr, AZ::ScriptDataContext& dc)
- {
- int numArgs = dc.GetNumArguments();
- const int noArgsGiven = 0;
- const int allArgsGiven = 4;
- switch (numArgs)
- {
- case noArgsGiven:
- {
- *thisPtr = UiCustomImageInterface::UVRect();
- }
- break;
- case allArgsGiven:
- {
- if (dc.IsNumber(0) && dc.IsNumber(1) && dc.IsNumber(2) && dc.IsNumber(3))
- {
- float left = 0;
- float top = 0;
- float right = 0;
- float bottom = 0;
- dc.ReadArg(0, left);
- dc.ReadArg(1, top);
- dc.ReadArg(2, right);
- dc.ReadArg(3, bottom);
- *thisPtr = UiCustomImageInterface::UVRect(left, top, right, bottom);
- }
- else
- {
- dc.GetScriptContext()->Error(AZ::ScriptContext::ErrorType::Error, true, "When providing 4 arguments to UVCoords(), all must be numbers!");
- }
- }
- break;
- default:
- {
- dc.GetScriptContext()->Error(AZ::ScriptContext::ErrorType::Error, true, "UVCoords() accepts only 0 or 4 arguments, not %d!", numArgs);
- }
- break;
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- void ReflectTypes(AZ::ReflectContext* context)
- {
- AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
- AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context);
- // Serialize the UVs struct
- {
- if (serializeContext)
- {
- serializeContext->Class<UiCustomImageInterface::UVRect>()->
- Field("left", &UiCustomImageInterface::UVRect::m_left)->
- Field("top", &UiCustomImageInterface::UVRect::m_top)->
- Field("right", &UiCustomImageInterface::UVRect::m_right)->
- Field("bottom", &UiCustomImageInterface::UVRect::m_bottom);
- AZ::EditContext* ec = serializeContext->GetEditContext();
- if (ec)
- {
- auto editInfo = ec->Class<UiCustomImageInterface::UVRect>(0, "");
- editInfo->ClassElement(AZ::Edit::ClassElements::EditorData, "UVRect")
- ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly);
- editInfo->DataElement(0, &UiCustomImageInterface::UVRect::m_left, "Left", "The lower X UV coordinate.");
- editInfo->DataElement(0, &UiCustomImageInterface::UVRect::m_top, "Top", "The higher Y UV coordinate.");
- editInfo->DataElement(0, &UiCustomImageInterface::UVRect::m_right, "Right", "The higher X UV coordinate.");
- editInfo->DataElement(0, &UiCustomImageInterface::UVRect::m_bottom, "Bottom", "The lower Y UV coordinate.");
- }
- }
- if (behaviorContext)
- {
- behaviorContext->Class<UiCustomImageInterface::UVRect>("UVCoords")
- ->Constructor<>()
- ->Constructor<float, float, float, float>()
- ->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
- ->Attribute(AZ::Script::Attributes::ConstructorOverride, &UVCoordsScriptConstructor)
- ->Property("left", BehaviorValueProperty(&UiCustomImageInterface::UVRect::m_left))
- ->Property("top", BehaviorValueProperty(&UiCustomImageInterface::UVRect::m_top))
- ->Property("right", BehaviorValueProperty(&UiCustomImageInterface::UVRect::m_right))
- ->Property("bottom", BehaviorValueProperty(&UiCustomImageInterface::UVRect::m_bottom))
- ->Method("SetLeft", [](UiCustomImageInterface::UVRect* thisPtr, float left) { thisPtr->m_left = left; })
- ->Method("SetTop", [](UiCustomImageInterface::UVRect* thisPtr, float top) { thisPtr->m_top = top; })
- ->Method("SetRight", [](UiCustomImageInterface::UVRect* thisPtr, float right) { thisPtr->m_right = right; })
- ->Method("SetBottom", [](UiCustomImageInterface::UVRect* thisPtr, float bottom) { thisPtr->m_bottom= bottom; })
- ->Method("SetUVCoords", [](UiCustomImageInterface::UVRect* thisPtr, float left, float top, float right, float bottom)
- {
- thisPtr->m_left = left;
- thisPtr->m_top = top;
- thisPtr->m_right = right;
- thisPtr->m_bottom = bottom;
- });
- }
- }
- }
- }
|