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_abstract_progress.h 28a3e0fd82Sopenharmony_ci * 29a3e0fd82Sopenharmony_ci * @brief Defines the base class attributes and common functions of a progress bar. 30a3e0fd82Sopenharmony_ci * 31a3e0fd82Sopenharmony_ci * @since 1.0 32a3e0fd82Sopenharmony_ci * @version 1.0 33a3e0fd82Sopenharmony_ci */ 34a3e0fd82Sopenharmony_ci 35a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_UI_ABSTRACT_PROGRESS_H 36a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_UI_ABSTRACT_PROGRESS_H 37a3e0fd82Sopenharmony_ci 38a3e0fd82Sopenharmony_ci#include "common/image.h" 39a3e0fd82Sopenharmony_ci#include "components/ui_view.h" 40a3e0fd82Sopenharmony_ci 41a3e0fd82Sopenharmony_cinamespace OHOS { 42a3e0fd82Sopenharmony_ci/** 43a3e0fd82Sopenharmony_ci * @brief Represents the abstract base class which provides functions related to the progress bar. 44a3e0fd82Sopenharmony_ci * 45a3e0fd82Sopenharmony_ci * @see UIView 46a3e0fd82Sopenharmony_ci * @since 1.0 47a3e0fd82Sopenharmony_ci * @version 1.0 48a3e0fd82Sopenharmony_ci */ 49a3e0fd82Sopenharmony_ciclass UIAbstractProgress : public UIView { 50a3e0fd82Sopenharmony_cipublic: 51a3e0fd82Sopenharmony_ci /** 52a3e0fd82Sopenharmony_ci * @brief A constructor used to create a <b>UIAbstractProgress</b> instance. 53a3e0fd82Sopenharmony_ci * 54a3e0fd82Sopenharmony_ci * @since 1.0 55a3e0fd82Sopenharmony_ci * @version 1.0 56a3e0fd82Sopenharmony_ci */ 57a3e0fd82Sopenharmony_ci UIAbstractProgress(); 58a3e0fd82Sopenharmony_ci 59a3e0fd82Sopenharmony_ci /** 60a3e0fd82Sopenharmony_ci * @brief A destructor used to delete the <b>UIAbstractProgress</b> instance. 61a3e0fd82Sopenharmony_ci * 62a3e0fd82Sopenharmony_ci * @since 1.0 63a3e0fd82Sopenharmony_ci * @version 1.0 64a3e0fd82Sopenharmony_ci */ 65a3e0fd82Sopenharmony_ci virtual ~UIAbstractProgress(); 66a3e0fd82Sopenharmony_ci 67a3e0fd82Sopenharmony_ci /** 68a3e0fd82Sopenharmony_ci * @brief Obtains the component type. 69a3e0fd82Sopenharmony_ci * 70a3e0fd82Sopenharmony_ci * @return Returns the component type, as defined in {@link UIViewType}. 71a3e0fd82Sopenharmony_ci * @since 1.0 72a3e0fd82Sopenharmony_ci * @version 1.0 73a3e0fd82Sopenharmony_ci */ 74a3e0fd82Sopenharmony_ci UIViewType GetViewType() const override 75a3e0fd82Sopenharmony_ci { 76a3e0fd82Sopenharmony_ci return UI_ABSTRACT_PROGRESS; 77a3e0fd82Sopenharmony_ci } 78a3e0fd82Sopenharmony_ci 79a3e0fd82Sopenharmony_ci /** 80a3e0fd82Sopenharmony_ci * @brief Sets whether the background of the progress bar is visible. 81a3e0fd82Sopenharmony_ci * 82a3e0fd82Sopenharmony_ci * @param enable Specifies whether the background of the progress bar is visible. <b>true</b> (the default value) 83a3e0fd82Sopenharmony_ci * indicates that the background is visible, and <b>false</b> indicates the opposite case. 84a3e0fd82Sopenharmony_ci * @since 1.0 85a3e0fd82Sopenharmony_ci * @version 1.0 86a3e0fd82Sopenharmony_ci */ 87a3e0fd82Sopenharmony_ci void EnableBackground(bool enable) 88a3e0fd82Sopenharmony_ci { 89a3e0fd82Sopenharmony_ci enableBackground_ = enable; 90a3e0fd82Sopenharmony_ci } 91a3e0fd82Sopenharmony_ci 92a3e0fd82Sopenharmony_ci /** 93a3e0fd82Sopenharmony_ci * @brief Sets the current value for this progress bar. 94a3e0fd82Sopenharmony_ci * 95a3e0fd82Sopenharmony_ci * @param value Indicates the current value of this progress bar, within [rangeMin, rangeMax] specified by 96a3e0fd82Sopenharmony_ci * {@link SetRange}. If the value is less than <b>rangeMin</b>, <b>rangeMin</b> is used; 97a3e0fd82Sopenharmony_ci * if the value is greater than <b>rangeMax</b>, <b>rangeMax</b> is used. 98a3e0fd82Sopenharmony_ci * @see SetRange | GetValue 99a3e0fd82Sopenharmony_ci * @since 1.0 100a3e0fd82Sopenharmony_ci * @version 1.0 101a3e0fd82Sopenharmony_ci */ 102a3e0fd82Sopenharmony_ci void SetValue(int32_t value); 103a3e0fd82Sopenharmony_ci 104a3e0fd82Sopenharmony_ci /** 105a3e0fd82Sopenharmony_ci * @brief Obtains the current value of this progress bar. 106a3e0fd82Sopenharmony_ci * 107a3e0fd82Sopenharmony_ci * @return Returns the current value of this progress bar. 108a3e0fd82Sopenharmony_ci * @see SetValue 109a3e0fd82Sopenharmony_ci * @since 1.0 110a3e0fd82Sopenharmony_ci * @version 1.0 111a3e0fd82Sopenharmony_ci */ 112a3e0fd82Sopenharmony_ci int32_t GetValue() const 113a3e0fd82Sopenharmony_ci { 114a3e0fd82Sopenharmony_ci return curValue_; 115a3e0fd82Sopenharmony_ci } 116a3e0fd82Sopenharmony_ci 117a3e0fd82Sopenharmony_ci /** 118a3e0fd82Sopenharmony_ci * @brief Sets the range for this progress bar. 119a3e0fd82Sopenharmony_ci * 120a3e0fd82Sopenharmony_ci * <b>rangeMin</b> and <b>rangeMax</b> can be any value represented by <b>int32_t</b>. 121a3e0fd82Sopenharmony_ci * <b>rangeMax</b> must be greater than or equal to <b>rangeMin</b>. 122a3e0fd82Sopenharmony_ci * Otherwise, the setting does not take effect and the original value is used. 123a3e0fd82Sopenharmony_ci * 124a3e0fd82Sopenharmony_ci * @param rangeMax Indicates the maximum value of this progress bar. The default value is 100. 125a3e0fd82Sopenharmony_ci * @param rangeMin Indicates the minimum value of this progress bar. The default value is 0. 126a3e0fd82Sopenharmony_ci * @see GetRangeMin | GetRangeMax 127a3e0fd82Sopenharmony_ci * @since 1.0 128a3e0fd82Sopenharmony_ci * @version 1.0 129a3e0fd82Sopenharmony_ci */ 130a3e0fd82Sopenharmony_ci void SetRange(int32_t rangeMax, int32_t rangeMin); 131a3e0fd82Sopenharmony_ci 132a3e0fd82Sopenharmony_ci /** 133a3e0fd82Sopenharmony_ci * @brief Obtains the minimum value of this progress bar. 134a3e0fd82Sopenharmony_ci * 135a3e0fd82Sopenharmony_ci * @return Returns the minimum value of this progress bar. 136a3e0fd82Sopenharmony_ci * @see SetRange | GetRangeMax 137a3e0fd82Sopenharmony_ci * @since 1.0 138a3e0fd82Sopenharmony_ci * @version 1.0 139a3e0fd82Sopenharmony_ci */ 140a3e0fd82Sopenharmony_ci int32_t GetRangeMin() const 141a3e0fd82Sopenharmony_ci { 142a3e0fd82Sopenharmony_ci return rangeMin_; 143a3e0fd82Sopenharmony_ci } 144a3e0fd82Sopenharmony_ci 145a3e0fd82Sopenharmony_ci /** 146a3e0fd82Sopenharmony_ci * @brief Obtains the maximum value of this progress bar. 147a3e0fd82Sopenharmony_ci * 148a3e0fd82Sopenharmony_ci * @return Returns the maximum value of this progress bar. 149a3e0fd82Sopenharmony_ci * @see SetRange | GetRangeMin 150a3e0fd82Sopenharmony_ci * @since 1.0 151a3e0fd82Sopenharmony_ci * @version 1.0 152a3e0fd82Sopenharmony_ci */ 153a3e0fd82Sopenharmony_ci int32_t GetRangeMax() const 154a3e0fd82Sopenharmony_ci { 155a3e0fd82Sopenharmony_ci return rangeMax_; 156a3e0fd82Sopenharmony_ci } 157a3e0fd82Sopenharmony_ci 158a3e0fd82Sopenharmony_ci /** 159a3e0fd82Sopenharmony_ci * @brief Sets the image for this progress bar. 160a3e0fd82Sopenharmony_ci * 161a3e0fd82Sopenharmony_ci * The size of the image must be the same as that of the progress bar to ensure a normal display. 162a3e0fd82Sopenharmony_ci * If the value of any input parameter is <b>nullptr</b>, image filling is canceled. 163a3e0fd82Sopenharmony_ci * Instead, color filling will be adopted. 164a3e0fd82Sopenharmony_ci * 165a3e0fd82Sopenharmony_ci * @param foregroundImage Indicates the foreground image of the progress bar. The default value is <b>nullptr</b>. 166a3e0fd82Sopenharmony_ci * @param backgroundImage Indicates the background image of the progress bar. The default value is <b>nullptr</b>. 167a3e0fd82Sopenharmony_ci * @since 1.0 168a3e0fd82Sopenharmony_ci * @version 1.0 169a3e0fd82Sopenharmony_ci */ 170a3e0fd82Sopenharmony_ci void SetImage(const char* foregroundImage, const char* backgroundImage = nullptr); 171a3e0fd82Sopenharmony_ci 172a3e0fd82Sopenharmony_ci /** 173a3e0fd82Sopenharmony_ci * @brief Sets the image as a pixel map for this progress bar. 174a3e0fd82Sopenharmony_ci * 175a3e0fd82Sopenharmony_ci * The size of the image must be the same as that of the progress bar to ensure a normal display. 176a3e0fd82Sopenharmony_ci * If the value of any input parameter is <b>nullptr</b>, image filling is canceled. 177a3e0fd82Sopenharmony_ci * Instead, color filling will be adopted. 178a3e0fd82Sopenharmony_ci * 179a3e0fd82Sopenharmony_ci * @param foregroundImage Indicates the foreground image of the progress bar. The default value is <b>nullptr</b>. 180a3e0fd82Sopenharmony_ci * @param backgroundImage Indicates the background image of the progress bar. The default value is <b>nullptr</b>. 181a3e0fd82Sopenharmony_ci * @since 1.0 182a3e0fd82Sopenharmony_ci * @version 1.0 183a3e0fd82Sopenharmony_ci */ 184a3e0fd82Sopenharmony_ci void SetImage(const ImageInfo* foregroundImage, const ImageInfo* backgroundImage = nullptr); 185a3e0fd82Sopenharmony_ci 186a3e0fd82Sopenharmony_ci /** 187a3e0fd82Sopenharmony_ci * @brief Sets the step for this progress bar. 188a3e0fd82Sopenharmony_ci * 189a3e0fd82Sopenharmony_ci * The step is used to control the update frequency of the progress bar. When the value change exceeds the step, 190a3e0fd82Sopenharmony_ci * the progress bar is redrawn. \n 191a3e0fd82Sopenharmony_ci * For example, when the step is set to 10 and the current progress value is 5, the progress bar will not be 192a3e0fd82Sopenharmony_ci * redrawn if the progress value becomes 14, but will be redrawn if the progress value becomes 15. \n 193a3e0fd82Sopenharmony_ci * In addition, when its current value changes to be the maximum or minimum value, 194a3e0fd82Sopenharmony_ci * the progress bar is redrawn regardless of the step you set. \n 195a3e0fd82Sopenharmony_ci * 196a3e0fd82Sopenharmony_ci * @param step Indicates the step to set. The default value is 1. 197a3e0fd82Sopenharmony_ci * @see GetStep 198a3e0fd82Sopenharmony_ci * @since 1.0 199a3e0fd82Sopenharmony_ci * @version 1.0 200a3e0fd82Sopenharmony_ci */ 201a3e0fd82Sopenharmony_ci void SetStep(uint32_t step) 202a3e0fd82Sopenharmony_ci { 203a3e0fd82Sopenharmony_ci step_ = step; 204a3e0fd82Sopenharmony_ci } 205a3e0fd82Sopenharmony_ci 206a3e0fd82Sopenharmony_ci /** 207a3e0fd82Sopenharmony_ci * @brief Obtains the current step of this progress bar. 208a3e0fd82Sopenharmony_ci * 209a3e0fd82Sopenharmony_ci * @return Returns the current step. 210a3e0fd82Sopenharmony_ci * @see SetStep 211a3e0fd82Sopenharmony_ci * @since 1.0 212a3e0fd82Sopenharmony_ci * @version 1.0 213a3e0fd82Sopenharmony_ci */ 214a3e0fd82Sopenharmony_ci uint32_t GetStep() const 215a3e0fd82Sopenharmony_ci { 216a3e0fd82Sopenharmony_ci return step_; 217a3e0fd82Sopenharmony_ci } 218a3e0fd82Sopenharmony_ci 219a3e0fd82Sopenharmony_ci /** 220a3e0fd82Sopenharmony_ci * @brief Sets the background style for this progress bar. 221a3e0fd82Sopenharmony_ci * 222a3e0fd82Sopenharmony_ci * @param style Indicates the background style of the progress bar. For details, see {@link Style}. 223a3e0fd82Sopenharmony_ci * @see SetForegroundStyle | GetBackgroundStyle 224a3e0fd82Sopenharmony_ci * @since 1.0 225a3e0fd82Sopenharmony_ci * @version 1.0 226a3e0fd82Sopenharmony_ci */ 227a3e0fd82Sopenharmony_ci void SetBackgroundStyle(const Style& style); 228a3e0fd82Sopenharmony_ci 229a3e0fd82Sopenharmony_ci /** 230a3e0fd82Sopenharmony_ci * @brief Sets a background style for this progress bar. 231a3e0fd82Sopenharmony_ci * 232a3e0fd82Sopenharmony_ci * @param key Indicates the key of the style to set. 233a3e0fd82Sopenharmony_ci * @param value Indicates the value matching the key. 234a3e0fd82Sopenharmony_ci * @since 1.0 235a3e0fd82Sopenharmony_ci * @version 1.0 236a3e0fd82Sopenharmony_ci */ 237a3e0fd82Sopenharmony_ci void SetBackgroundStyle(uint8_t key, int64_t value); 238a3e0fd82Sopenharmony_ci 239a3e0fd82Sopenharmony_ci /** 240a3e0fd82Sopenharmony_ci * @brief Obtains the background style of this progress bar. 241a3e0fd82Sopenharmony_ci * 242a3e0fd82Sopenharmony_ci * @return Returns the background style. 243a3e0fd82Sopenharmony_ci * @See SetBackgroundStyle 244a3e0fd82Sopenharmony_ci * @since 1.0 245a3e0fd82Sopenharmony_ci * @version 1.0 246a3e0fd82Sopenharmony_ci */ 247a3e0fd82Sopenharmony_ci const Style& GetBackgroundStyle() const; 248a3e0fd82Sopenharmony_ci 249a3e0fd82Sopenharmony_ci /** 250a3e0fd82Sopenharmony_ci * @brief Obtains the value of a background style of this progress bar. 251a3e0fd82Sopenharmony_ci * 252a3e0fd82Sopenharmony_ci * @param key Indicates the key of the style. 253a3e0fd82Sopenharmony_ci * @return Returns the value of the style. 254a3e0fd82Sopenharmony_ci * @since 1.0 255a3e0fd82Sopenharmony_ci * @version 1.0 256a3e0fd82Sopenharmony_ci */ 257a3e0fd82Sopenharmony_ci int64_t GetBackgroundStyle(uint8_t key) const; 258a3e0fd82Sopenharmony_ci 259a3e0fd82Sopenharmony_ci /** 260a3e0fd82Sopenharmony_ci * @brief Sets the foreground style for this progress bar. 261a3e0fd82Sopenharmony_ci * 262a3e0fd82Sopenharmony_ci * @param style Indicates the foreground style of this progress bar. For details, see {@link Style}. 263a3e0fd82Sopenharmony_ci * @see SetBackgroundStyle | GetForegroundStyle 264a3e0fd82Sopenharmony_ci * @since 1.0 265a3e0fd82Sopenharmony_ci * @version 1.0 266a3e0fd82Sopenharmony_ci */ 267a3e0fd82Sopenharmony_ci void SetForegroundStyle(const Style& style); 268a3e0fd82Sopenharmony_ci 269a3e0fd82Sopenharmony_ci /** 270a3e0fd82Sopenharmony_ci * @brief Sets a foreground style for this progress bar. 271a3e0fd82Sopenharmony_ci * 272a3e0fd82Sopenharmony_ci * @param key Indicates the key of the style to set. 273a3e0fd82Sopenharmony_ci * @param value Indicates the value matching the key. 274a3e0fd82Sopenharmony_ci * @since 1.0 275a3e0fd82Sopenharmony_ci * @version 1.0 276a3e0fd82Sopenharmony_ci */ 277a3e0fd82Sopenharmony_ci void SetForegroundStyle(uint8_t key, int64_t value); 278a3e0fd82Sopenharmony_ci 279a3e0fd82Sopenharmony_ci /** 280a3e0fd82Sopenharmony_ci * @brief Obtains the foreground style of this progress bar. 281a3e0fd82Sopenharmony_ci * 282a3e0fd82Sopenharmony_ci * @return Returns the foreground style. 283a3e0fd82Sopenharmony_ci * @See SetForegroundStyle 284a3e0fd82Sopenharmony_ci * @since 1.0 285a3e0fd82Sopenharmony_ci * @version 1.0 286a3e0fd82Sopenharmony_ci */ 287a3e0fd82Sopenharmony_ci const Style& GetForegroundStyle() const; 288a3e0fd82Sopenharmony_ci 289a3e0fd82Sopenharmony_ci /** 290a3e0fd82Sopenharmony_ci * @brief Obtains the value of a foreground style of this progress bar. 291a3e0fd82Sopenharmony_ci * 292a3e0fd82Sopenharmony_ci * @param key Indicates the key of the style. 293a3e0fd82Sopenharmony_ci * @return Returns the value of the style. 294a3e0fd82Sopenharmony_ci * @since 1.0 295a3e0fd82Sopenharmony_ci * @version 1.0 296a3e0fd82Sopenharmony_ci */ 297a3e0fd82Sopenharmony_ci int64_t GetForegroundStyle(uint8_t key) const; 298a3e0fd82Sopenharmony_ci 299a3e0fd82Sopenharmony_ci /** 300a3e0fd82Sopenharmony_ci * @brief Sets the type of caps on the background and foreground of the progress bar. 301a3e0fd82Sopenharmony_ci * 302a3e0fd82Sopenharmony_ci * @param cap Indicates the cap type. For details, see {@link CapType}. 303a3e0fd82Sopenharmony_ci * @since 1.0 304a3e0fd82Sopenharmony_ci * @version 1.0 305a3e0fd82Sopenharmony_ci */ 306a3e0fd82Sopenharmony_ci void SetCapType(CapType cap) 307a3e0fd82Sopenharmony_ci { 308a3e0fd82Sopenharmony_ci SetBackgroundStyle(STYLE_LINE_CAP, cap); 309a3e0fd82Sopenharmony_ci SetForegroundStyle(STYLE_LINE_CAP, cap); 310a3e0fd82Sopenharmony_ci } 311a3e0fd82Sopenharmony_ci 312a3e0fd82Sopenharmony_ciprotected: 313a3e0fd82Sopenharmony_ci static constexpr uint16_t MAX_PERCENT_VALUE = 100; 314a3e0fd82Sopenharmony_ci static constexpr uint16_t MIN_PERCENT_VALUE = 0; 315a3e0fd82Sopenharmony_ci 316a3e0fd82Sopenharmony_ci uint32_t GetRangeSize() const; 317a3e0fd82Sopenharmony_ci int16_t GetCurrentPos(int16_t distance) const; 318a3e0fd82Sopenharmony_ci virtual bool InitImage(); 319a3e0fd82Sopenharmony_ci bool enableBackground_ : 1; 320a3e0fd82Sopenharmony_ci bool backgroundStyleAllocFlag_ : 1; 321a3e0fd82Sopenharmony_ci bool foregroundStyleAllocFlag_ : 1; 322a3e0fd82Sopenharmony_ci Style* backgroundStyle_; 323a3e0fd82Sopenharmony_ci Style* foregroundStyle_; 324a3e0fd82Sopenharmony_ci Image* backgroundImage_; 325a3e0fd82Sopenharmony_ci Image* foregroundImage_; 326a3e0fd82Sopenharmony_ci int32_t rangeMax_; 327a3e0fd82Sopenharmony_ci int32_t rangeMin_; 328a3e0fd82Sopenharmony_ci int32_t curValue_; 329a3e0fd82Sopenharmony_ci uint32_t step_; 330a3e0fd82Sopenharmony_ci int32_t lastValue_; 331a3e0fd82Sopenharmony_ci}; 332a3e0fd82Sopenharmony_ci} // namespace OHOS 333a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_UI_ABSTRACT_PROGRESS_H 334