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