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 #include "core/components/image/image_animator_component.h" 17 18 #include "core/components/image/image_animator_element.h" 19 20 namespace OHOS::Ace { 21 namespace { 22 23 const char* PREFIX = "ImageAnimator"; 24 uint32_t g_componentId = 0; 25 26 } // namespace 27 ImageAnimatorComponent(const std::string & name)28ImageAnimatorComponent::ImageAnimatorComponent(const std::string& name) : ComposedComponent(GenerateComponentId(), name) 29 { 30 if (!imageAnimatorController_) { 31 imageAnimatorController_ = AceType::MakeRefPtr<ImageAnimatorController>(); 32 } 33 if (!declaration_) { 34 declaration_ = AceType::MakeRefPtr<ImageAnimatorDeclaration>(); 35 declaration_->Init(); 36 } 37 } 38 CreateElement()39RefPtr<Element> ImageAnimatorComponent::CreateElement() 40 { 41 return AceType::MakeRefPtr<ImageAnimatorElement>(GetId()); 42 } 43 SetFillMode(FillMode fillMode)44void ImageAnimatorComponent::SetFillMode(FillMode fillMode) 45 { 46 declaration_->SetFillMode(fillMode); 47 } 48 GetFillMode() const49FillMode ImageAnimatorComponent::GetFillMode() const 50 { 51 return declaration_->GetFillMode(); 52 } 53 SetStatus(Animator::Status status)54void ImageAnimatorComponent::SetStatus(Animator::Status status) 55 { 56 declaration_->SetStatus(status); 57 } 58 GetStatus() const59Animator::Status ImageAnimatorComponent::GetStatus() const 60 { 61 return declaration_->GetStatus(); 62 } 63 SetIteration(int32_t iteration)64void ImageAnimatorComponent::SetIteration(int32_t iteration) 65 { 66 declaration_->SetIteration(iteration); 67 } 68 GetIteration() const69int32_t ImageAnimatorComponent::GetIteration() const 70 { 71 return declaration_->GetIteration(); 72 } 73 SetPreDecode(int32_t preDecode)74void ImageAnimatorComponent::SetPreDecode(int32_t preDecode) 75 { 76 declaration_->SetPreDecode(preDecode); 77 } 78 GetPreDecode() const79int32_t ImageAnimatorComponent::GetPreDecode() const 80 { 81 return declaration_->GetPreDecode(); 82 } 83 SetDuration(int32_t duration)84void ImageAnimatorComponent::SetDuration(int32_t duration) 85 { 86 if (duration <= 0) { 87 declaration_->SetDuration(0); 88 return; 89 } 90 declaration_->SetDuration(duration); 91 } 92 GetDuration() const93int32_t ImageAnimatorComponent::GetDuration() const 94 { 95 return declaration_->GetDuration(); 96 } 97 SetBorder(const Border & border)98void ImageAnimatorComponent::SetBorder(const Border& border) 99 { 100 declaration_->SetBorder(border); 101 } 102 GetBorder() const103const Border& ImageAnimatorComponent::GetBorder() const 104 { 105 return declaration_->GetBorder(); 106 } 107 SetIsReverse(bool isReverse)108void ImageAnimatorComponent::SetIsReverse(bool isReverse) 109 { 110 declaration_->SetIsReverse(isReverse); 111 } 112 GetIsReverse() const113bool ImageAnimatorComponent::GetIsReverse() const 114 { 115 return declaration_->GetIsReverse(); 116 } 117 SetIsFixedSize(bool isFixedSize)118void ImageAnimatorComponent::SetIsFixedSize(bool isFixedSize) 119 { 120 declaration_->SetIsFixedSize(isFixedSize); 121 } 122 GetIsFixedSize() const123bool ImageAnimatorComponent::GetIsFixedSize() const 124 { 125 return declaration_->GetIsFixedSize(); 126 } 127 SetImageProperties(const std::vector<ImageProperties> & images)128void ImageAnimatorComponent::SetImageProperties(const std::vector<ImageProperties>& images) 129 { 130 if (images.empty()) { 131 LOGW("Images are empty."); 132 return; 133 } 134 declaration_->SetImageProperties(images); 135 } 136 GetImageProperties() const137const std::vector<ImageProperties>& ImageAnimatorComponent::GetImageProperties() const 138 { 139 return declaration_->GetImageProperties(); 140 } 141 GenerateComponentId()142ComposeId ImageAnimatorComponent::GenerateComponentId() 143 { 144 return PREFIX + (std::to_string(g_componentId++)); 145 } 146 147 } // namespace OHOS::Ace 148