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_box_progress.h 28a3e0fd82Sopenharmony_ci * 29a3e0fd82Sopenharmony_ci * @brief Defines the attributes and common functions of a linear progress bar. 30a3e0fd82Sopenharmony_ci * 31a3e0fd82Sopenharmony_ci * @since 1.0 32a3e0fd82Sopenharmony_ci * @version 1.0 33a3e0fd82Sopenharmony_ci */ 34a3e0fd82Sopenharmony_ci 35a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_UI_BOX_PROGRESS_H 36a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_UI_BOX_PROGRESS_H 37a3e0fd82Sopenharmony_ci 38a3e0fd82Sopenharmony_ci#include "components/ui_abstract_progress.h" 39a3e0fd82Sopenharmony_ci 40a3e0fd82Sopenharmony_cinamespace OHOS { 41a3e0fd82Sopenharmony_ci/** 42a3e0fd82Sopenharmony_ci * @brief Represents a linear progress bar. 43a3e0fd82Sopenharmony_ci * 44a3e0fd82Sopenharmony_ci * This class is used to set the range and current value to display the linear progress bar 45a3e0fd82Sopenharmony_ci * which can be in multiple directions. 46a3e0fd82Sopenharmony_ci * 47a3e0fd82Sopenharmony_ci * @see UIAbstractProgress 48a3e0fd82Sopenharmony_ci * @since 1.0 49a3e0fd82Sopenharmony_ci * @version 1.0 50a3e0fd82Sopenharmony_ci */ 51a3e0fd82Sopenharmony_ciclass UIBoxProgress : public UIAbstractProgress { 52a3e0fd82Sopenharmony_cipublic: 53a3e0fd82Sopenharmony_ci /** 54a3e0fd82Sopenharmony_ci * @brief Enumerates the directions of the progress bar. 55a3e0fd82Sopenharmony_ci */ 56a3e0fd82Sopenharmony_ci enum class Direction : uint8_t { 57a3e0fd82Sopenharmony_ci /** Filling from left to right */ 58a3e0fd82Sopenharmony_ci DIR_LEFT_TO_RIGHT, 59a3e0fd82Sopenharmony_ci /** Filling from right to left */ 60a3e0fd82Sopenharmony_ci DIR_RIGHT_TO_LEFT, 61a3e0fd82Sopenharmony_ci /** Filling from top to bottom */ 62a3e0fd82Sopenharmony_ci DIR_TOP_TO_BOTTOM, 63a3e0fd82Sopenharmony_ci /** Filling from bottom to top */ 64a3e0fd82Sopenharmony_ci DIR_BOTTOM_TO_TOP, 65a3e0fd82Sopenharmony_ci }; 66a3e0fd82Sopenharmony_ci 67a3e0fd82Sopenharmony_ci /** 68a3e0fd82Sopenharmony_ci * @brief A constructor used to create a <b>UIBoxProgress</b> instance. 69a3e0fd82Sopenharmony_ci * 70a3e0fd82Sopenharmony_ci * @since 1.0 71a3e0fd82Sopenharmony_ci * @version 1.0 72a3e0fd82Sopenharmony_ci */ 73a3e0fd82Sopenharmony_ci UIBoxProgress(); 74a3e0fd82Sopenharmony_ci 75a3e0fd82Sopenharmony_ci /** 76a3e0fd82Sopenharmony_ci * @brief A destructor used to delete the <b>UIBoxProgress</b> instance. 77a3e0fd82Sopenharmony_ci * 78a3e0fd82Sopenharmony_ci * @since 1.0 79a3e0fd82Sopenharmony_ci * @version 1.0 80a3e0fd82Sopenharmony_ci */ 81a3e0fd82Sopenharmony_ci virtual ~UIBoxProgress() {} 82a3e0fd82Sopenharmony_ci 83a3e0fd82Sopenharmony_ci /** 84a3e0fd82Sopenharmony_ci * @brief Obtains the view type. 85a3e0fd82Sopenharmony_ci * 86a3e0fd82Sopenharmony_ci * @return Returns the view type, as defined in {@link UIViewType}. 87a3e0fd82Sopenharmony_ci * @since 1.0 88a3e0fd82Sopenharmony_ci * @version 1.0 89a3e0fd82Sopenharmony_ci */ 90a3e0fd82Sopenharmony_ci UIViewType GetViewType() const override 91a3e0fd82Sopenharmony_ci { 92a3e0fd82Sopenharmony_ci return UI_BOX_PROGRESS; 93a3e0fd82Sopenharmony_ci } 94a3e0fd82Sopenharmony_ci 95a3e0fd82Sopenharmony_ci /** 96a3e0fd82Sopenharmony_ci * @brief Sets the width for the view holding this progress bar. 97a3e0fd82Sopenharmony_ci * 98a3e0fd82Sopenharmony_ci * The width of the view must be greater than or equal to the actual width of the progress bar 99a3e0fd82Sopenharmony_ci * to ensure a normal display. \n 100a3e0fd82Sopenharmony_ci * 101a3e0fd82Sopenharmony_ci * @param width Indicates the width of the view. 102a3e0fd82Sopenharmony_ci * @see SetHeight | SetValidWidth | SetValidHeight 103a3e0fd82Sopenharmony_ci * @since 1.0 104a3e0fd82Sopenharmony_ci * @version 1.0 105a3e0fd82Sopenharmony_ci */ 106a3e0fd82Sopenharmony_ci void SetWidth(int16_t width) override 107a3e0fd82Sopenharmony_ci { 108a3e0fd82Sopenharmony_ci UIView::SetWidth(width); 109a3e0fd82Sopenharmony_ci if (!isValidWidthSet_) { 110a3e0fd82Sopenharmony_ci progressWidth_ = width; 111a3e0fd82Sopenharmony_ci } 112a3e0fd82Sopenharmony_ci } 113a3e0fd82Sopenharmony_ci 114a3e0fd82Sopenharmony_ci /** 115a3e0fd82Sopenharmony_ci * @brief Sets the height for this view. 116a3e0fd82Sopenharmony_ci * 117a3e0fd82Sopenharmony_ci * The height of the view must be greater than or equal to the actual height of the progress bar 118a3e0fd82Sopenharmony_ci * to ensure a normal display. \n 119a3e0fd82Sopenharmony_ci * 120a3e0fd82Sopenharmony_ci * @param height Indicates the height to set. 121a3e0fd82Sopenharmony_ci * @see SetWidth | SetValidWidth | SetValidHeight 122a3e0fd82Sopenharmony_ci * @since 1.0 123a3e0fd82Sopenharmony_ci * @version 1.0 124a3e0fd82Sopenharmony_ci */ 125a3e0fd82Sopenharmony_ci void SetHeight(int16_t height) override 126a3e0fd82Sopenharmony_ci { 127a3e0fd82Sopenharmony_ci UIView::SetHeight(height); 128a3e0fd82Sopenharmony_ci if (!isValidHeightSet_) { 129a3e0fd82Sopenharmony_ci progressHeight_ = height; 130a3e0fd82Sopenharmony_ci } 131a3e0fd82Sopenharmony_ci } 132a3e0fd82Sopenharmony_ci 133a3e0fd82Sopenharmony_ci /** 134a3e0fd82Sopenharmony_ci * @brief Sets the direction for this progress bar. 135a3e0fd82Sopenharmony_ci * 136a3e0fd82Sopenharmony_ci * @param direction Indicates the direction to set. The default direction is from left to right. 137a3e0fd82Sopenharmony_ci * For details, see {@link Direction}. 138a3e0fd82Sopenharmony_ci * @see GetDirection 139a3e0fd82Sopenharmony_ci * @since 1.0 140a3e0fd82Sopenharmony_ci * @version 1.0 141a3e0fd82Sopenharmony_ci */ 142a3e0fd82Sopenharmony_ci void SetDirection(const Direction& direction) 143a3e0fd82Sopenharmony_ci { 144a3e0fd82Sopenharmony_ci direction_ = direction; 145a3e0fd82Sopenharmony_ci } 146a3e0fd82Sopenharmony_ci 147a3e0fd82Sopenharmony_ci /** 148a3e0fd82Sopenharmony_ci * @brief Obtains the direction of this progress bar. 149a3e0fd82Sopenharmony_ci * 150a3e0fd82Sopenharmony_ci * @return Returns the direction of this progress bar, as defined in {@link Direction}. 151a3e0fd82Sopenharmony_ci * @see SetDirection 152a3e0fd82Sopenharmony_ci * @since 1.0 153a3e0fd82Sopenharmony_ci * @version 1.0 154a3e0fd82Sopenharmony_ci */ 155a3e0fd82Sopenharmony_ci Direction GetDirection() const 156a3e0fd82Sopenharmony_ci { 157a3e0fd82Sopenharmony_ci return direction_; 158a3e0fd82Sopenharmony_ci } 159a3e0fd82Sopenharmony_ci 160a3e0fd82Sopenharmony_ci /** 161a3e0fd82Sopenharmony_ci * @brief Sets the actual width for this progress bar. 162a3e0fd82Sopenharmony_ci * 163a3e0fd82Sopenharmony_ci * The progress bar is centered in the view after the setting. By default, the width of the progress bar 164a3e0fd82Sopenharmony_ci * is the same as that of the view. \n 165a3e0fd82Sopenharmony_ci * If the width of the progress bar is greater than that of the view, the excess part cannot be displayed. \n 166a3e0fd82Sopenharmony_ci * 167a3e0fd82Sopenharmony_ci * @param width Indicates the actual width of this progress bar. 168a3e0fd82Sopenharmony_ci * @see GetValidWidth 169a3e0fd82Sopenharmony_ci * @since 1.0 170a3e0fd82Sopenharmony_ci * @version 1.0 171a3e0fd82Sopenharmony_ci */ 172a3e0fd82Sopenharmony_ci void SetValidWidth(int16_t width) 173a3e0fd82Sopenharmony_ci { 174a3e0fd82Sopenharmony_ci progressWidth_ = width; 175a3e0fd82Sopenharmony_ci isValidWidthSet_ = true; 176a3e0fd82Sopenharmony_ci } 177a3e0fd82Sopenharmony_ci 178a3e0fd82Sopenharmony_ci /** 179a3e0fd82Sopenharmony_ci * @brief Obtains the actual width of this progress bar. 180a3e0fd82Sopenharmony_ci * 181a3e0fd82Sopenharmony_ci * @return Returns the actual width of this progress bar. 182a3e0fd82Sopenharmony_ci * @see SetValidWidth 183a3e0fd82Sopenharmony_ci * @since 1.0 184a3e0fd82Sopenharmony_ci * @version 1.0 185a3e0fd82Sopenharmony_ci */ 186a3e0fd82Sopenharmony_ci int16_t GetValidWidth() const 187a3e0fd82Sopenharmony_ci { 188a3e0fd82Sopenharmony_ci return progressWidth_; 189a3e0fd82Sopenharmony_ci } 190a3e0fd82Sopenharmony_ci 191a3e0fd82Sopenharmony_ci /** 192a3e0fd82Sopenharmony_ci * @brief Sets the actual height for this progress bar. 193a3e0fd82Sopenharmony_ci * 194a3e0fd82Sopenharmony_ci * The progress bar is centered in the view after the setting. By default, the height of the progress bar 195a3e0fd82Sopenharmony_ci * is the same as that of the view. \n 196a3e0fd82Sopenharmony_ci * If the height of the progress bar is greater than that of the view, the excess part cannot be displayed. \n 197a3e0fd82Sopenharmony_ci * 198a3e0fd82Sopenharmony_ci * @param height Indicates the actual height to set. 199a3e0fd82Sopenharmony_ci * @see GetValidHeight 200a3e0fd82Sopenharmony_ci * @since 1.0 201a3e0fd82Sopenharmony_ci * @version 1.0 202a3e0fd82Sopenharmony_ci */ 203a3e0fd82Sopenharmony_ci void SetValidHeight(int16_t height) 204a3e0fd82Sopenharmony_ci { 205a3e0fd82Sopenharmony_ci progressHeight_ = height; 206a3e0fd82Sopenharmony_ci isValidHeightSet_ = true; 207a3e0fd82Sopenharmony_ci } 208a3e0fd82Sopenharmony_ci 209a3e0fd82Sopenharmony_ci /** 210a3e0fd82Sopenharmony_ci * @brief Obtains the actual height of this progress bar. 211a3e0fd82Sopenharmony_ci * 212a3e0fd82Sopenharmony_ci * @return Returns the actual height of this progress bar. 213a3e0fd82Sopenharmony_ci * @see SetValidHeight 214a3e0fd82Sopenharmony_ci * @since 1.0 215a3e0fd82Sopenharmony_ci * @version 1.0 216a3e0fd82Sopenharmony_ci */ 217a3e0fd82Sopenharmony_ci int16_t GetValidHeight() const 218a3e0fd82Sopenharmony_ci { 219a3e0fd82Sopenharmony_ci return progressHeight_; 220a3e0fd82Sopenharmony_ci } 221a3e0fd82Sopenharmony_ci 222a3e0fd82Sopenharmony_ci void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override; 223a3e0fd82Sopenharmony_ci 224a3e0fd82Sopenharmony_ciprotected: 225a3e0fd82Sopenharmony_ci void GetBackgroundParam(Point& startPoint, int16_t& width, int16_t& height, uint16_t& radius, const Style& style); 226a3e0fd82Sopenharmony_ci void DrawBackground(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea); 227a3e0fd82Sopenharmony_ci void DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, Rect& coords); 228a3e0fd82Sopenharmony_ci void DrawRoundCap(BufferInfo& gfxDstBuffer, 229a3e0fd82Sopenharmony_ci const Image* image, 230a3e0fd82Sopenharmony_ci const Point& imgPos, 231a3e0fd82Sopenharmony_ci const Rect& rect, 232a3e0fd82Sopenharmony_ci const Rect& invalidatedArea, 233a3e0fd82Sopenharmony_ci uint16_t radius, 234a3e0fd82Sopenharmony_ci const Style& style); 235a3e0fd82Sopenharmony_ci void DrawValidRect(BufferInfo& gfxDstBuffer, 236a3e0fd82Sopenharmony_ci const Image* image, 237a3e0fd82Sopenharmony_ci const Rect& rect, 238a3e0fd82Sopenharmony_ci const Rect& invalidatedArea, 239a3e0fd82Sopenharmony_ci const Style& style, 240a3e0fd82Sopenharmony_ci uint16_t radius); 241a3e0fd82Sopenharmony_ci 242a3e0fd82Sopenharmony_ci uint16_t progressWidth_; 243a3e0fd82Sopenharmony_ci uint16_t progressHeight_; 244a3e0fd82Sopenharmony_ci Direction direction_; 245a3e0fd82Sopenharmony_ci bool isValidWidthSet_ : 1; 246a3e0fd82Sopenharmony_ci bool isValidHeightSet_ : 1; 247a3e0fd82Sopenharmony_ci}; 248a3e0fd82Sopenharmony_ci} // namespace OHOS 249a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_UI_BOX_PROGRESS_H 250