1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_IMAGE_ANIMATOR_IMAGE_ANIMATOR_DECLARATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_IMAGE_ANIMATOR_IMAGE_ANIMATOR_DECLARATION_H 18 19 #include <string> 20 #include "core/components/common/properties/border.h" 21 #include "core/components/declaration/common/declaration.h" 22 #include "frameworks/bridge/common/dom/dom_type.h" 23 #include "frameworks/core/animation/animator.h" 24 25 namespace OHOS::Ace { 26 27 struct ImageProperties { 28 std::string src; 29 std::string bundleName; 30 std::string moduleName; 31 CalcDimension width; 32 CalcDimension height; 33 CalcDimension top; 34 CalcDimension left; 35 int32_t duration = 0; 36 }; 37 38 struct ImageAnimatorAttribute : Attribute { 39 FillMode fillMode = FillMode::FORWARDS; 40 Animator::Status status = Animator::Status::IDLE; 41 int32_t iteration = -1; 42 int32_t duration = 0; 43 int32_t preDecode = 0; 44 bool isReverse = false; 45 bool isFixedSize = true; 46 std::vector<ImageProperties> images; 47 }; 48 49 class ImageAnimatorDeclaration : public Declaration { 50 DECLARE_ACE_TYPE(ImageAnimatorDeclaration, Declaration); 51 52 public: 53 ImageAnimatorDeclaration() = default; 54 ~ImageAnimatorDeclaration() override = default; 55 SetFillMode(FillMode fillMode)56 void SetFillMode(FillMode fillMode) 57 { 58 auto& attribute = MaybeResetAttribute<ImageAnimatorAttribute>(AttributeTag::SPECIALIZED_ATTR); 59 attribute.fillMode = fillMode; 60 } 61 SetStatus(Animator::Status status)62 void SetStatus(Animator::Status status) 63 { 64 auto& attribute = MaybeResetAttribute<ImageAnimatorAttribute>(AttributeTag::SPECIALIZED_ATTR); 65 attribute.status = status; 66 } 67 SetIteration(int32_t iteration)68 void SetIteration(int32_t iteration) 69 { 70 auto& attribute = MaybeResetAttribute<ImageAnimatorAttribute>(AttributeTag::SPECIALIZED_ATTR); 71 attribute.iteration = iteration; 72 } 73 SetDuration(int32_t duration)74 void SetDuration(int32_t duration) 75 { 76 auto& attribute = MaybeResetAttribute<ImageAnimatorAttribute>(AttributeTag::SPECIALIZED_ATTR); 77 attribute.duration = duration; 78 } 79 SetIsReverse(bool isReverse)80 void SetIsReverse(bool isReverse) 81 { 82 auto& attribute = MaybeResetAttribute<ImageAnimatorAttribute>(AttributeTag::SPECIALIZED_ATTR); 83 attribute.isReverse = isReverse; 84 } 85 SetIsFixedSize(bool isFixedSize)86 void SetIsFixedSize(bool isFixedSize) 87 { 88 auto& attribute = MaybeResetAttribute<ImageAnimatorAttribute>(AttributeTag::SPECIALIZED_ATTR); 89 attribute.isFixedSize = isFixedSize; 90 } 91 SetBorder(const Border & border)92 void SetBorder(const Border& border) 93 { 94 border_ = border; 95 } 96 SetImageProperties(const std::vector<ImageProperties> & images)97 void SetImageProperties(const std::vector<ImageProperties>& images) 98 { 99 auto& attribute = MaybeResetAttribute<ImageAnimatorAttribute>(AttributeTag::SPECIALIZED_ATTR); 100 attribute.images = images; 101 } 102 SetPreDecode(int32_t preDecode)103 void SetPreDecode(int32_t preDecode) 104 { 105 auto& attribute = MaybeResetAttribute<ImageAnimatorAttribute>(AttributeTag::SPECIALIZED_ATTR); 106 attribute.preDecode = preDecode; 107 } 108 GetFillMode()109 FillMode GetFillMode() const 110 { 111 auto& attribute = static_cast<ImageAnimatorAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 112 return attribute.fillMode; 113 } 114 GetStatus()115 Animator::Status GetStatus() const 116 { 117 auto& attribute = static_cast<ImageAnimatorAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 118 return attribute.status; 119 } 120 GetIteration()121 int32_t GetIteration() const 122 { 123 auto& attribute = static_cast<ImageAnimatorAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 124 return attribute.iteration; 125 } 126 GetDuration()127 int32_t GetDuration() const 128 { 129 auto& attribute = static_cast<ImageAnimatorAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 130 return attribute.duration; 131 } 132 GetPreDecode()133 int32_t GetPreDecode() const 134 { 135 auto& attribute = static_cast<ImageAnimatorAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 136 return attribute.preDecode; 137 } 138 GetIsReverse()139 bool GetIsReverse() const 140 { 141 auto& attribute = static_cast<ImageAnimatorAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 142 return attribute.isReverse; 143 } 144 GetIsFixedSize()145 bool GetIsFixedSize() const 146 { 147 auto& attribute = static_cast<ImageAnimatorAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 148 return attribute.isFixedSize; 149 } 150 GetBorder()151 const Border& GetBorder() const 152 { 153 return border_; 154 } 155 GetImageProperties()156 const std::vector<ImageProperties>& GetImageProperties() const 157 { 158 auto& attribute = static_cast<ImageAnimatorAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 159 return attribute.images; 160 } 161 162 protected: 163 void InitSpecialized() override; 164 165 private: 166 Border border_; 167 }; 168 169 } // namespace OHOS::Ace 170 171 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_IMAGE_ANIMATOR_IMAGE_ANIMATOR_DECLARATION_H 172