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_circle_progress.h 28a3e0fd82Sopenharmony_ci * 29a3e0fd82Sopenharmony_ci * @brief Defines the attributes and common functions of a circular progress bar. 30a3e0fd82Sopenharmony_ci * 31a3e0fd82Sopenharmony_ci * @since 1.0 32a3e0fd82Sopenharmony_ci * @version 1.0 33a3e0fd82Sopenharmony_ci */ 34a3e0fd82Sopenharmony_ci 35a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_UI_CIRCLE_PROGRESS_H 36a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_UI_CIRCLE_PROGRESS_H 37a3e0fd82Sopenharmony_ci 38a3e0fd82Sopenharmony_ci#include "components/ui_abstract_progress.h" 39a3e0fd82Sopenharmony_ci 40a3e0fd82Sopenharmony_cinamespace OHOS { 41a3e0fd82Sopenharmony_ci/** 42a3e0fd82Sopenharmony_ci * @brief Represents a circular progress bar. 43a3e0fd82Sopenharmony_ci * 44a3e0fd82Sopenharmony_ci * This class is used to set the start and end angles, range, and current value to display the circular progress bar. 45a3e0fd82Sopenharmony_ci * 46a3e0fd82Sopenharmony_ci * @see UIAbstractProgress 47a3e0fd82Sopenharmony_ci * @since 1.0 48a3e0fd82Sopenharmony_ci * @version 1.0 49a3e0fd82Sopenharmony_ci */ 50a3e0fd82Sopenharmony_ciclass UICircleProgress : public UIAbstractProgress { 51a3e0fd82Sopenharmony_cipublic: 52a3e0fd82Sopenharmony_ci /** 53a3e0fd82Sopenharmony_ci * @brief A constructor used to create a <b>UICircleProgress</b> instance. 54a3e0fd82Sopenharmony_ci * 55a3e0fd82Sopenharmony_ci * @since 1.0 56a3e0fd82Sopenharmony_ci * @version 1.0 57a3e0fd82Sopenharmony_ci */ 58a3e0fd82Sopenharmony_ci UICircleProgress(); 59a3e0fd82Sopenharmony_ci 60a3e0fd82Sopenharmony_ci /** 61a3e0fd82Sopenharmony_ci * @brief A destructor used to delete the <b>UICircleProgress</b> instance. 62a3e0fd82Sopenharmony_ci * 63a3e0fd82Sopenharmony_ci * @since 1.0 64a3e0fd82Sopenharmony_ci * @version 1.0 65a3e0fd82Sopenharmony_ci */ 66a3e0fd82Sopenharmony_ci virtual ~UICircleProgress() {} 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_CIRCLE_PROGRESS; 78a3e0fd82Sopenharmony_ci } 79a3e0fd82Sopenharmony_ci 80a3e0fd82Sopenharmony_ci bool OnPreDraw(Rect& invalidatedArea) const override 81a3e0fd82Sopenharmony_ci { 82a3e0fd82Sopenharmony_ci return false; 83a3e0fd82Sopenharmony_ci } 84a3e0fd82Sopenharmony_ci 85a3e0fd82Sopenharmony_ci void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override; 86a3e0fd82Sopenharmony_ci 87a3e0fd82Sopenharmony_ci /** 88a3e0fd82Sopenharmony_ci * @brief Sets the coordinates of the center point for this circular progress bar. 89a3e0fd82Sopenharmony_ci * 90a3e0fd82Sopenharmony_ci * The coordinates of the center point refer to the position relative to the view. 91a3e0fd82Sopenharmony_ci * 92a3e0fd82Sopenharmony_ci * @param x Indicates the x-coordinate to set. The default value is 0. 93a3e0fd82Sopenharmony_ci * @param y Indicates the y-coordinate to set. The default value is 0. 94a3e0fd82Sopenharmony_ci * @see GetCenterPosition 95a3e0fd82Sopenharmony_ci * @since 1.0 96a3e0fd82Sopenharmony_ci * @version 1.0 97a3e0fd82Sopenharmony_ci */ 98a3e0fd82Sopenharmony_ci void SetCenterPosition(int16_t x, int16_t y); 99a3e0fd82Sopenharmony_ci 100a3e0fd82Sopenharmony_ci /** 101a3e0fd82Sopenharmony_ci * @brief Obtains the coordinates of the center point for this circular progress bar. 102a3e0fd82Sopenharmony_ci * 103a3e0fd82Sopenharmony_ci * The coordinates of the center point refer to the position relative to the view. 104a3e0fd82Sopenharmony_ci * 105a3e0fd82Sopenharmony_ci * @return Returns the coordinates of the center point. 106a3e0fd82Sopenharmony_ci * @see SetCenterPosition 107a3e0fd82Sopenharmony_ci * @since 1.0 108a3e0fd82Sopenharmony_ci * @version 1.0 109a3e0fd82Sopenharmony_ci */ 110a3e0fd82Sopenharmony_ci Point GetCenterPosition() const 111a3e0fd82Sopenharmony_ci { 112a3e0fd82Sopenharmony_ci return center_; 113a3e0fd82Sopenharmony_ci } 114a3e0fd82Sopenharmony_ci 115a3e0fd82Sopenharmony_ci /** 116a3e0fd82Sopenharmony_ci * @brief Sets the outer radius for this circular progress bar. 117a3e0fd82Sopenharmony_ci * 118a3e0fd82Sopenharmony_ci * @param radius Indicates the outer radius to set. 119a3e0fd82Sopenharmony_ci * @see GetRadius 120a3e0fd82Sopenharmony_ci * @since 1.0 121a3e0fd82Sopenharmony_ci * @version 1.0 122a3e0fd82Sopenharmony_ci */ 123a3e0fd82Sopenharmony_ci void SetRadius(uint16_t radius) 124a3e0fd82Sopenharmony_ci { 125a3e0fd82Sopenharmony_ci radius_ = radius; 126a3e0fd82Sopenharmony_ci } 127a3e0fd82Sopenharmony_ci 128a3e0fd82Sopenharmony_ci /** 129a3e0fd82Sopenharmony_ci * @brief Obtains the outer radius of this circular progress bar. 130a3e0fd82Sopenharmony_ci * 131a3e0fd82Sopenharmony_ci * @return Returns the outer radius. 132a3e0fd82Sopenharmony_ci * @see SetRadius 133a3e0fd82Sopenharmony_ci * @since 1.0 134a3e0fd82Sopenharmony_ci * @version 1.0 135a3e0fd82Sopenharmony_ci */ 136a3e0fd82Sopenharmony_ci uint16_t GetRadius() const 137a3e0fd82Sopenharmony_ci { 138a3e0fd82Sopenharmony_ci return radius_; 139a3e0fd82Sopenharmony_ci } 140a3e0fd82Sopenharmony_ci 141a3e0fd82Sopenharmony_ci /** 142a3e0fd82Sopenharmony_ci * @brief Sets the start angle. 143a3e0fd82Sopenharmony_ci * 144a3e0fd82Sopenharmony_ci * The 12-clock direction is 0 degrees, and the 3-clock direction is 90 degrees. \n 145a3e0fd82Sopenharmony_ci * If the start angle is smaller than the end angle, the progress bar is clockwise. 146a3e0fd82Sopenharmony_ci * Otherwise, the progress bar is anticlockwise. \n 147a3e0fd82Sopenharmony_ci * The maximum range of a progress bar is a circle. If the difference between the start angle and end angle 148a3e0fd82Sopenharmony_ci * exceeds 360 degrees, a circular progress bar is created. \n 149a3e0fd82Sopenharmony_ci * 150a3e0fd82Sopenharmony_ci * @param startAngle Indicates the start angle to set, which can be any value represented by <b>int16_t</b>. 151a3e0fd82Sopenharmony_ci * The default value is 0. 152a3e0fd82Sopenharmony_ci * @see GetStartAngle | SetEndAngle 153a3e0fd82Sopenharmony_ci * @since 1.0 154a3e0fd82Sopenharmony_ci * @version 1.0 155a3e0fd82Sopenharmony_ci */ 156a3e0fd82Sopenharmony_ci void SetStartAngle(int16_t startAngle); 157a3e0fd82Sopenharmony_ci 158a3e0fd82Sopenharmony_ci /** 159a3e0fd82Sopenharmony_ci * @brief Obtains the start angle. 160a3e0fd82Sopenharmony_ci * 161a3e0fd82Sopenharmony_ci * @return Returns the start angle. 162a3e0fd82Sopenharmony_ci * @see SetStartAngle 163a3e0fd82Sopenharmony_ci * @since 1.0 164a3e0fd82Sopenharmony_ci * @version 1.0 165a3e0fd82Sopenharmony_ci */ 166a3e0fd82Sopenharmony_ci int16_t GetStartAngle() const 167a3e0fd82Sopenharmony_ci { 168a3e0fd82Sopenharmony_ci return startAngle_; 169a3e0fd82Sopenharmony_ci } 170a3e0fd82Sopenharmony_ci 171a3e0fd82Sopenharmony_ci /** 172a3e0fd82Sopenharmony_ci * @brief Sets the end angle. 173a3e0fd82Sopenharmony_ci * 174a3e0fd82Sopenharmony_ci * The 12-clock direction is 0 degrees, and the 3-clock direction is 90 degrees. \n 175a3e0fd82Sopenharmony_ci * If the start angle is smaller than the end angle, the progress bar is clockwise. 176a3e0fd82Sopenharmony_ci * Otherwise, the progress bar is anticlockwise. \n 177a3e0fd82Sopenharmony_ci * The maximum range of a progress bar is a circle. If the difference between the start angle and end angle 178a3e0fd82Sopenharmony_ci * exceeds 360 degrees, a circular progress bar is created. \n 179a3e0fd82Sopenharmony_ci * 180a3e0fd82Sopenharmony_ci * @param endAngle Indicates the end angle to set, which can be any value represented by <b>int16_t</b>. 181a3e0fd82Sopenharmony_ci * The default value is 360. 182a3e0fd82Sopenharmony_ci * @see GetEndAngle | SetStartAngle 183a3e0fd82Sopenharmony_ci * @since 1.0 184a3e0fd82Sopenharmony_ci * @version 1.0 185a3e0fd82Sopenharmony_ci */ 186a3e0fd82Sopenharmony_ci void SetEndAngle(int16_t endAngle); 187a3e0fd82Sopenharmony_ci 188a3e0fd82Sopenharmony_ci /** 189a3e0fd82Sopenharmony_ci * @brief Obtains the end angle. 190a3e0fd82Sopenharmony_ci * 191a3e0fd82Sopenharmony_ci * @return Returns the end angle. 192a3e0fd82Sopenharmony_ci * @see SetEndAngle 193a3e0fd82Sopenharmony_ci * @since 1.0 194a3e0fd82Sopenharmony_ci * @version 1.0 195a3e0fd82Sopenharmony_ci */ 196a3e0fd82Sopenharmony_ci int16_t GetEndAngle() const 197a3e0fd82Sopenharmony_ci { 198a3e0fd82Sopenharmony_ci return endAngle_; 199a3e0fd82Sopenharmony_ci } 200a3e0fd82Sopenharmony_ci 201a3e0fd82Sopenharmony_ci /** 202a3e0fd82Sopenharmony_ci * @brief Sets the coordinates of the foreground image for this progress bar relative to the view. 203a3e0fd82Sopenharmony_ci * 204a3e0fd82Sopenharmony_ci * @param x Indicates the x-coordinate to set. The default value is 0. 205a3e0fd82Sopenharmony_ci * @param y Indicates the y-coordinate to set. The default value is 0. 206a3e0fd82Sopenharmony_ci * @see SetBackgroundImagePosition 207a3e0fd82Sopenharmony_ci * @since 1.0 208a3e0fd82Sopenharmony_ci * @version 1.0 209a3e0fd82Sopenharmony_ci */ 210a3e0fd82Sopenharmony_ci void SetProgressImagePosition(int16_t x, int16_t y) 211a3e0fd82Sopenharmony_ci { 212a3e0fd82Sopenharmony_ci progressImagePos_.x = x + style_->paddingLeft_ + style_->borderWidth_; 213a3e0fd82Sopenharmony_ci progressImagePos_.y = y + style_->paddingTop_ + style_->borderWidth_; 214a3e0fd82Sopenharmony_ci } 215a3e0fd82Sopenharmony_ci 216a3e0fd82Sopenharmony_ci /** 217a3e0fd82Sopenharmony_ci * @brief Sets the coordinates of the background image for this progress bar relative to the view. 218a3e0fd82Sopenharmony_ci * 219a3e0fd82Sopenharmony_ci * @param x Indicates the x-coordinate to set. The default value is 0. 220a3e0fd82Sopenharmony_ci * @param y Indicates the y-coordinate to set. The default value is 0. 221a3e0fd82Sopenharmony_ci * @see SetProgressImagePosition 222a3e0fd82Sopenharmony_ci * @since 1.0 223a3e0fd82Sopenharmony_ci * @version 1.0 224a3e0fd82Sopenharmony_ci */ 225a3e0fd82Sopenharmony_ci void SetBackgroundImagePosition(int16_t x, int16_t y) 226a3e0fd82Sopenharmony_ci { 227a3e0fd82Sopenharmony_ci backgroundImagePos_.x = x + style_->paddingLeft_ + style_->borderWidth_; 228a3e0fd82Sopenharmony_ci backgroundImagePos_.y = y + style_->paddingTop_ + style_->borderWidth_; 229a3e0fd82Sopenharmony_ci } 230a3e0fd82Sopenharmony_ci 231a3e0fd82Sopenharmony_ci /** 232a3e0fd82Sopenharmony_ci * @brief Sets the foreground color for this progress bar. 233a3e0fd82Sopenharmony_ci * 234a3e0fd82Sopenharmony_ci * @param color Indicates the foreground color to set. For details, see {@link ColorType}. 235a3e0fd82Sopenharmony_ci * @since 1.0 236a3e0fd82Sopenharmony_ci * @version 1.0 237a3e0fd82Sopenharmony_ci */ 238a3e0fd82Sopenharmony_ci void SetLineColor(ColorType color) 239a3e0fd82Sopenharmony_ci { 240a3e0fd82Sopenharmony_ci SetForegroundStyle(STYLE_LINE_COLOR, color.full); 241a3e0fd82Sopenharmony_ci } 242a3e0fd82Sopenharmony_ci 243a3e0fd82Sopenharmony_ciprivate: 244a3e0fd82Sopenharmony_ci static constexpr uint16_t MAX_ANGLE_VALUE = CIRCLE_IN_DEGREE; 245a3e0fd82Sopenharmony_ci static constexpr uint16_t MIN_ANGLE_VALUE = 0; 246a3e0fd82Sopenharmony_ci 247a3e0fd82Sopenharmony_ci void GetStartEndAngle(int16_t& start, int16_t& end) const; 248a3e0fd82Sopenharmony_ci void GetAngleRange(int16_t& start, int16_t& end) const; 249a3e0fd82Sopenharmony_ci void GetRedrawAngle(int16_t& start, int16_t& end) const; 250a3e0fd82Sopenharmony_ci void DrawCommonCircle(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea); 251a3e0fd82Sopenharmony_ci 252a3e0fd82Sopenharmony_ci Point center_; 253a3e0fd82Sopenharmony_ci Point backgroundImagePos_; 254a3e0fd82Sopenharmony_ci Point progressImagePos_; 255a3e0fd82Sopenharmony_ci uint16_t radius_; 256a3e0fd82Sopenharmony_ci int16_t startAngle_; 257a3e0fd82Sopenharmony_ci int16_t endAngle_; 258a3e0fd82Sopenharmony_ci}; 259a3e0fd82Sopenharmony_ci} // namespace OHOS 260a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_UI_CIRCLE_PROGRESS_H 261