1a3e0fd82Sopenharmony_ci/* 2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License. 5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at 6a3e0fd82Sopenharmony_ci * 7a3e0fd82Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a3e0fd82Sopenharmony_ci * 9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and 13a3e0fd82Sopenharmony_ci * limitations under the License. 14a3e0fd82Sopenharmony_ci */ 15a3e0fd82Sopenharmony_ci 16a3e0fd82Sopenharmony_ci/** 17a3e0fd82Sopenharmony_ci * @addtogroup UI_Components 18a3e0fd82Sopenharmony_ci * @{ 19a3e0fd82Sopenharmony_ci * 20a3e0fd82Sopenharmony_ci * @brief Defines UI components such as buttons, texts, images, lists, and progress bars. 21a3e0fd82Sopenharmony_ci * 22a3e0fd82Sopenharmony_ci * @since 1.0 23a3e0fd82Sopenharmony_ci * @version 1.0 24a3e0fd82Sopenharmony_ci */ 25a3e0fd82Sopenharmony_ci 26a3e0fd82Sopenharmony_ci/** 27a3e0fd82Sopenharmony_ci * @file ui_texture_mapper.h 28a3e0fd82Sopenharmony_ci * 29a3e0fd82Sopenharmony_ci * @brief Defines the attributes and functions of a texture mapper. 30a3e0fd82Sopenharmony_ci * 31a3e0fd82Sopenharmony_ci * @since 1.0 32a3e0fd82Sopenharmony_ci * @version 1.0 33a3e0fd82Sopenharmony_ci */ 34a3e0fd82Sopenharmony_ci 35a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_UI_TEXTURE_MAPPER_H 36a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_UI_TEXTURE_MAPPER_H 37a3e0fd82Sopenharmony_ci 38a3e0fd82Sopenharmony_ci#include "components/ui_image_view.h" 39a3e0fd82Sopenharmony_ci#include "animator/animator.h" 40a3e0fd82Sopenharmony_ci#include "animator/easing_equation.h" 41a3e0fd82Sopenharmony_ci 42a3e0fd82Sopenharmony_cinamespace OHOS { 43a3e0fd82Sopenharmony_ci/** 44a3e0fd82Sopenharmony_ci * @brief Rotates and scales images. 45a3e0fd82Sopenharmony_ci * 46a3e0fd82Sopenharmony_ci * @see UIImageView 47a3e0fd82Sopenharmony_ci * @since 1.0 48a3e0fd82Sopenharmony_ci * @version 1.0 49a3e0fd82Sopenharmony_ci */ 50a3e0fd82Sopenharmony_ciclass UITextureMapper : public UIImageView { 51a3e0fd82Sopenharmony_cipublic: 52a3e0fd82Sopenharmony_ci /** 53a3e0fd82Sopenharmony_ci * @brief A constructor used to create a <b>UITextureMapper</b> instance. 54a3e0fd82Sopenharmony_ci * 55a3e0fd82Sopenharmony_ci * @since 1.0 56a3e0fd82Sopenharmony_ci * @version 1.0 57a3e0fd82Sopenharmony_ci */ 58a3e0fd82Sopenharmony_ci UITextureMapper(); 59a3e0fd82Sopenharmony_ci 60a3e0fd82Sopenharmony_ci /** 61a3e0fd82Sopenharmony_ci * @brief A destructor used to delete the <b>UITextureMapper</b> instance. 62a3e0fd82Sopenharmony_ci * 63a3e0fd82Sopenharmony_ci * @since 1.0 64a3e0fd82Sopenharmony_ci * @version 1.0 65a3e0fd82Sopenharmony_ci */ 66a3e0fd82Sopenharmony_ci virtual ~UITextureMapper(); 67a3e0fd82Sopenharmony_ci 68a3e0fd82Sopenharmony_ci /** 69a3e0fd82Sopenharmony_ci * @brief Obtains the view type. 70a3e0fd82Sopenharmony_ci * 71a3e0fd82Sopenharmony_ci * @return Returns the view type, as defined in {@link UIViewType}. 72a3e0fd82Sopenharmony_ci * @since 1.0 73a3e0fd82Sopenharmony_ci * @version 1.0 74a3e0fd82Sopenharmony_ci */ 75a3e0fd82Sopenharmony_ci UIViewType GetViewType() const override 76a3e0fd82Sopenharmony_ci { 77a3e0fd82Sopenharmony_ci return UI_TEXTURE_MAPPER; 78a3e0fd82Sopenharmony_ci } 79a3e0fd82Sopenharmony_ci 80a3e0fd82Sopenharmony_ci /** 81a3e0fd82Sopenharmony_ci * @brief Starts this animator. 82a3e0fd82Sopenharmony_ci * 83a3e0fd82Sopenharmony_ci * @since 1.0 84a3e0fd82Sopenharmony_ci * @version 1.0 85a3e0fd82Sopenharmony_ci */ 86a3e0fd82Sopenharmony_ci void Start(); 87a3e0fd82Sopenharmony_ci 88a3e0fd82Sopenharmony_ci /** 89a3e0fd82Sopenharmony_ci * @brief Sets the start angle of rotation for this image. 90a3e0fd82Sopenharmony_ci * 91a3e0fd82Sopenharmony_ci * By default, the image starts to rotate from the current angle of this stopped animator. 92a3e0fd82Sopenharmony_ci * 93a3e0fd82Sopenharmony_ci * @param start Indicates the start angle to set. The default value is <b>0</b>. 94a3e0fd82Sopenharmony_ci * @since 1.0 95a3e0fd82Sopenharmony_ci * @version 1.0 96a3e0fd82Sopenharmony_ci */ 97a3e0fd82Sopenharmony_ci void SetRotateStart(int16_t start) 98a3e0fd82Sopenharmony_ci { 99a3e0fd82Sopenharmony_ci rotateCur_ = start; 100a3e0fd82Sopenharmony_ci } 101a3e0fd82Sopenharmony_ci 102a3e0fd82Sopenharmony_ci /** 103a3e0fd82Sopenharmony_ci * @brief Sets the end angle of rotation for this image. 104a3e0fd82Sopenharmony_ci * 105a3e0fd82Sopenharmony_ci * @param end Indicates the end angle of rotation to set. The default value is <b>0</b>. 106a3e0fd82Sopenharmony_ci * @since 1.0 107a3e0fd82Sopenharmony_ci * @version 1.0 108a3e0fd82Sopenharmony_ci */ 109a3e0fd82Sopenharmony_ci void SetRotateEnd(int16_t end) 110a3e0fd82Sopenharmony_ci { 111a3e0fd82Sopenharmony_ci rotateEnd_ = end; 112a3e0fd82Sopenharmony_ci } 113a3e0fd82Sopenharmony_ci 114a3e0fd82Sopenharmony_ci /** 115a3e0fd82Sopenharmony_ci * @brief Sets the start ratio for scaling this image. 116a3e0fd82Sopenharmony_ci * 117a3e0fd82Sopenharmony_ci * By default, the image starts to scale from the current ratio of this stopped animator. \n 118a3e0fd82Sopenharmony_ci * The X and Y directions are scaled at the same ratio. Single-direction scaling is not supported. \n 119a3e0fd82Sopenharmony_ci * 120a3e0fd82Sopenharmony_ci * @param start Indicates the start ratio to set. The default value is <b>1</b>. 121a3e0fd82Sopenharmony_ci * @since 1.0 122a3e0fd82Sopenharmony_ci * @version 1.0 123a3e0fd82Sopenharmony_ci */ 124a3e0fd82Sopenharmony_ci void SetScaleStart(float start) 125a3e0fd82Sopenharmony_ci { 126a3e0fd82Sopenharmony_ci scaleCur_ = static_cast<int16_t>(FloatToInt64(start)); 127a3e0fd82Sopenharmony_ci } 128a3e0fd82Sopenharmony_ci 129a3e0fd82Sopenharmony_ci /** 130a3e0fd82Sopenharmony_ci * @brief Sets the end ratio for scaling this image. 131a3e0fd82Sopenharmony_ci * 132a3e0fd82Sopenharmony_ci * @param end Indicates the end ratio to set. The default value is <b>1</b>. 133a3e0fd82Sopenharmony_ci * @since 1.0 134a3e0fd82Sopenharmony_ci * @version 1.0 135a3e0fd82Sopenharmony_ci */ 136a3e0fd82Sopenharmony_ci void SetScaleEnd(float end) 137a3e0fd82Sopenharmony_ci { 138a3e0fd82Sopenharmony_ci scaleEnd_ = static_cast<int16_t>(FloatToInt64(end)); 139a3e0fd82Sopenharmony_ci } 140a3e0fd82Sopenharmony_ci 141a3e0fd82Sopenharmony_ci /** 142a3e0fd82Sopenharmony_ci * @brief Sets the duration for this animator, in milliseconds. 143a3e0fd82Sopenharmony_ci * 144a3e0fd82Sopenharmony_ci * The durations of image scaling and rotation are the same and cannot be set separately. 145a3e0fd82Sopenharmony_ci * 146a3e0fd82Sopenharmony_ci * @param durationTime Indicates the duration to set. 147a3e0fd82Sopenharmony_ci * @since 1.0 148a3e0fd82Sopenharmony_ci * @version 1.0 149a3e0fd82Sopenharmony_ci */ 150a3e0fd82Sopenharmony_ci void SetDurationTime(uint16_t durationTime) 151a3e0fd82Sopenharmony_ci { 152a3e0fd82Sopenharmony_ci animator_.SetTime(durationTime + delayTime_); 153a3e0fd82Sopenharmony_ci } 154a3e0fd82Sopenharmony_ci 155a3e0fd82Sopenharmony_ci /** 156a3e0fd82Sopenharmony_ci * @brief Sets the delay time for this animator, in milliseconds. 157a3e0fd82Sopenharmony_ci * 158a3e0fd82Sopenharmony_ci * The delays of image scaling and rotation are the same and cannot be set separately. 159a3e0fd82Sopenharmony_ci * 160a3e0fd82Sopenharmony_ci * @param delayTime Indicates the delay time to set. 161a3e0fd82Sopenharmony_ci * @since 1.0 162a3e0fd82Sopenharmony_ci * @version 1.0 163a3e0fd82Sopenharmony_ci */ 164a3e0fd82Sopenharmony_ci void SetDelayTime(uint16_t delayTime) 165a3e0fd82Sopenharmony_ci { 166a3e0fd82Sopenharmony_ci animator_.SetTime(animator_.GetTime() - delayTime_ + delayTime); 167a3e0fd82Sopenharmony_ci delayTime_ = delayTime; 168a3e0fd82Sopenharmony_ci } 169a3e0fd82Sopenharmony_ci 170a3e0fd82Sopenharmony_ci /** 171a3e0fd82Sopenharmony_ci * @brief Sets the easing function for this animator. 172a3e0fd82Sopenharmony_ci * 173a3e0fd82Sopenharmony_ci * The easing functions for image scaling and rotation are the same and cannot be set separately. 174a3e0fd82Sopenharmony_ci * 175a3e0fd82Sopenharmony_ci * @param easingFunc Indicates the easing function to set. The animation moves at a constant velocity by default. 176a3e0fd82Sopenharmony_ci * For details, see {@link EasingEquation}. 177a3e0fd82Sopenharmony_ci * @since 1.0 178a3e0fd82Sopenharmony_ci * @version 1.0 179a3e0fd82Sopenharmony_ci */ 180a3e0fd82Sopenharmony_ci void SetEasingFunc(EasingFunc easingFunc) 181a3e0fd82Sopenharmony_ci { 182a3e0fd82Sopenharmony_ci easingFunc_ = easingFunc; 183a3e0fd82Sopenharmony_ci } 184a3e0fd82Sopenharmony_ci 185a3e0fd82Sopenharmony_ci /** 186a3e0fd82Sopenharmony_ci * @brief Cancels this animator. 187a3e0fd82Sopenharmony_ci * 188a3e0fd82Sopenharmony_ci * After being cancelled, the animator will stop in the current playback state. 189a3e0fd82Sopenharmony_ci * 190a3e0fd82Sopenharmony_ci * @since 1.0 191a3e0fd82Sopenharmony_ci * @version 1.0 192a3e0fd82Sopenharmony_ci */ 193a3e0fd82Sopenharmony_ci void Cancel(); 194a3e0fd82Sopenharmony_ci 195a3e0fd82Sopenharmony_ci /** 196a3e0fd82Sopenharmony_ci * @brief Displays the original image. 197a3e0fd82Sopenharmony_ci * 198a3e0fd82Sopenharmony_ci * The configured parameters are reserved and will not be reset. 199a3e0fd82Sopenharmony_ci * 200a3e0fd82Sopenharmony_ci * @since 1.0 201a3e0fd82Sopenharmony_ci * @version 1.0 202a3e0fd82Sopenharmony_ci */ 203a3e0fd82Sopenharmony_ci void Reset(); 204a3e0fd82Sopenharmony_ci 205a3e0fd82Sopenharmony_ci /** 206a3e0fd82Sopenharmony_ci * @brief Sets the coordinates of the rotation and scaling pivots for this image. 207a3e0fd82Sopenharmony_ci * 208a3e0fd82Sopenharmony_ci * The coordinates represent the position relative to this image. For example, setting the x-coordinate and 209a3e0fd82Sopenharmony_ci * y-coordinate of the rotation or scaling center to the half of the image width and height respectively 210a3e0fd82Sopenharmony_ci * means the rotation or scaling is going to be performed around the center of this image. 211a3e0fd82Sopenharmony_ci * 212a3e0fd82Sopenharmony_ci * @param x Indicates the x-coordinate to set. 213a3e0fd82Sopenharmony_ci * @param y Indicates the y-coordinate to set. 214a3e0fd82Sopenharmony_ci * @since 1.0 215a3e0fd82Sopenharmony_ci * @version 1.0 216a3e0fd82Sopenharmony_ci */ 217a3e0fd82Sopenharmony_ci void SetPivot(float x, float y) 218a3e0fd82Sopenharmony_ci { 219a3e0fd82Sopenharmony_ci pivot_.x_ = x; 220a3e0fd82Sopenharmony_ci pivot_.y_ = y; 221a3e0fd82Sopenharmony_ci } 222a3e0fd82Sopenharmony_ci 223a3e0fd82Sopenharmony_ci /** 224a3e0fd82Sopenharmony_ci * @brief Represents a listener that contains a callback to be invoked when this animator stops. 225a3e0fd82Sopenharmony_ci * 226a3e0fd82Sopenharmony_ci * @since 1.0 227a3e0fd82Sopenharmony_ci * @version 1.0 228a3e0fd82Sopenharmony_ci */ 229a3e0fd82Sopenharmony_ci class AnimatorStopListener : public HeapBase { 230a3e0fd82Sopenharmony_ci public: 231a3e0fd82Sopenharmony_ci /** 232a3e0fd82Sopenharmony_ci * @brief A destructor used to delete an <b>AnimatorStopListener</b> instance. 233a3e0fd82Sopenharmony_ci * 234a3e0fd82Sopenharmony_ci * @since 1.0 235a3e0fd82Sopenharmony_ci * @version 1.0 236a3e0fd82Sopenharmony_ci */ 237a3e0fd82Sopenharmony_ci virtual ~AnimatorStopListener() {} 238a3e0fd82Sopenharmony_ci 239a3e0fd82Sopenharmony_ci /** 240a3e0fd82Sopenharmony_ci * @brief Called when this animator stops. This is a pure virtual function, which needs 241a3e0fd82Sopenharmony_ci * your inheritance and implementation. 242a3e0fd82Sopenharmony_ci * 243a3e0fd82Sopenharmony_ci * @param view Indicates the instance of this view. 244a3e0fd82Sopenharmony_ci * @since 1.0 245a3e0fd82Sopenharmony_ci * @version 1.0 246a3e0fd82Sopenharmony_ci */ 247a3e0fd82Sopenharmony_ci virtual void OnAnimatorStop(UIView& view) = 0; 248a3e0fd82Sopenharmony_ci }; 249a3e0fd82Sopenharmony_ci 250a3e0fd82Sopenharmony_ci /** 251a3e0fd82Sopenharmony_ci * @brief Sets the listener for the stop of this animator. 252a3e0fd82Sopenharmony_ci * 253a3e0fd82Sopenharmony_ci * @param listener Indicates the listener to set. For details, see {@link AnimatorStopListener}. 254a3e0fd82Sopenharmony_ci * @since 1.0 255a3e0fd82Sopenharmony_ci * @version 1.0 256a3e0fd82Sopenharmony_ci */ 257a3e0fd82Sopenharmony_ci void SetAnimatorStopListener(AnimatorStopListener* listener) 258a3e0fd82Sopenharmony_ci { 259a3e0fd82Sopenharmony_ci listener_ = listener; 260a3e0fd82Sopenharmony_ci } 261a3e0fd82Sopenharmony_ci 262a3e0fd82Sopenharmony_ciprivate: 263a3e0fd82Sopenharmony_ci class TextureMapperAnimatorCallback : public AnimatorCallback { 264a3e0fd82Sopenharmony_ci public: 265a3e0fd82Sopenharmony_ci virtual ~TextureMapperAnimatorCallback() {} 266a3e0fd82Sopenharmony_ci 267a3e0fd82Sopenharmony_ci void Callback(UIView* view) override; 268a3e0fd82Sopenharmony_ci 269a3e0fd82Sopenharmony_ci void OnStop(UIView& view) override; 270a3e0fd82Sopenharmony_ci }; 271a3e0fd82Sopenharmony_ci 272a3e0fd82Sopenharmony_ci static constexpr int16_t SCALE_CONVERTION = 256; 273a3e0fd82Sopenharmony_ci 274a3e0fd82Sopenharmony_ci void Callback(); 275a3e0fd82Sopenharmony_ci 276a3e0fd82Sopenharmony_ci TextureMapperAnimatorCallback animatorCallback_; 277a3e0fd82Sopenharmony_ci Animator animator_; 278a3e0fd82Sopenharmony_ci AnimatorStopListener* listener_; 279a3e0fd82Sopenharmony_ci 280a3e0fd82Sopenharmony_ci Vector2<float> pivot_; 281a3e0fd82Sopenharmony_ci int16_t rotateCur_; 282a3e0fd82Sopenharmony_ci int16_t rotateStart_; 283a3e0fd82Sopenharmony_ci int16_t rotateEnd_; 284a3e0fd82Sopenharmony_ci int16_t scaleCur_; 285a3e0fd82Sopenharmony_ci int16_t scaleStart_; 286a3e0fd82Sopenharmony_ci int16_t scaleEnd_; 287a3e0fd82Sopenharmony_ci uint16_t delayTime_; 288a3e0fd82Sopenharmony_ci EasingFunc easingFunc_; 289a3e0fd82Sopenharmony_ci}; 290a3e0fd82Sopenharmony_ci} // namespace OHOS 291a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_UI_TEXTURE_MAPPER_H 292