1 /* 2 * Copyright (c) 2023 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_NG_PATTERNS_IMAGE_IMAGE_MODIFIER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_IMAGE_IMAGE_MODIFIER_H 18 19 #include "core/components_ng/base/modifier.h" 20 #include "core/components_ng/pattern/image/image_render_property.h" 21 #include "core/components_ng/property/property.h" 22 #include "core/components_ng/render/animation_utils.h" 23 #include "core/components_ng/render/canvas_image.h" 24 #include "core/components_ng/render/image_painter.h" 25 26 namespace OHOS::Ace::NG { 27 constexpr float ANIMATION_END = 1.0f; // The image animation end with 1.0 28 constexpr uint32_t TWICE = 2; // use to calculate image new width and height 29 constexpr double EPSILON = 0.0001; // use to judge the end of action 30 31 // not in use, causes performance issues 32 class ImageModifier : public ContentModifier { 33 DECLARE_ACE_TYPE(ImageModifier, ContentModifier); 34 35 public: 36 ImageModifier(); 37 ~ImageModifier() override = default; 38 void onDraw(DrawingContext& context) override; 39 void SetImageFit(ImageFit imagefit); 40 void UpdateImageData(const WeakPtr<CanvasImage>& canvasImage, const OffsetF& offset, const SizeF& contentSize); 41 void Modify(); 42 void SetIsAltImage(bool isAltImage); 43 44 private: 45 float GetValue(float value) const; 46 void DrawImageWithAnimation(DrawingContext& context); 47 void DrawImageWithoutAnimation(DrawingContext& context) const; 48 void UpdatePaintConfig(float ratio); 49 OffsetF offset_; 50 SizeF contentSize_; 51 RectF startSrcRect_; 52 RectF endSrcRect_; 53 RectF startDstRect_; 54 RectF endDstRect_; 55 ImageFit startImageFit_ = ImageFit::COVER; 56 ImageFit endImageFit_ = ImageFit::COVER; 57 bool isFirst_ = true; 58 WeakPtr<CanvasImage> canvasImage_; 59 RefPtr<AnimatablePropertyFloat> imageFit_; 60 RefPtr<PropertyBool> flag_; 61 bool isAltImage_ = false; 62 63 ACE_DISALLOW_COPY_AND_MOVE(ImageModifier); 64 }; 65 } // namespace OHOS::Ace::NG 66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_IMAGE_IMAGE_MODIFIER_H 67