ui_circle_progress.h 7.5 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
/*
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @addtogroup UI_Components
 * @{
 *
 * @brief Defines UI components such as buttons, texts, images, lists, and progress bars.
 *
 * @since 1.0
 * @version 1.0
 */

/**
 * @file ui_circle_progress.h
 *
 * @brief Defines the attributes and common functions of a circular progress bar.
 *
 * @since 1.0
 * @version 1.0
 */

#ifndef GRAPHIC_LITE_UI_CIRCLE_PROGRESS_H
#define GRAPHIC_LITE_UI_CIRCLE_PROGRESS_H

#include "components/ui_abstract_progress.h"

namespace OHOS {
/**
 * @brief Represents a circular progress bar.
 *
 * This class is used to set the start and end angles, range, and current value to display the circular progress bar.
 *
 * @see UIAbstractProgress
 * @since 1.0
 * @version 1.0
 */
class UICircleProgress : public UIAbstractProgress {
public:
    /**
     * @brief A constructor used to create a <b>UICircleProgress</b> instance.
     *
     * @since 1.0
     * @version 1.0
     */
    UICircleProgress();

    /**
     * @brief A destructor used to delete the <b>UICircleProgress</b> instance.
     *
     * @since 1.0
     * @version 1.0
     */
    virtual ~UICircleProgress() {}

    /**
     * @brief Obtains the view type.
     *
     * @return Returns the view type, as defined in {@link UIViewType}.
     * @since 1.0
     * @version 1.0
     */
    UIViewType GetViewType() const override
    {
        return UI_CIRCLE_PROGRESS;
    }

    bool OnPreDraw(Rect& invalidatedArea) const override
    {
        return false;
    }

N
niulihua 已提交
85
    void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
M
mamingshuai 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249

    /**
     * @brief Sets the coordinates of the center point for this circular progress bar.
     *
     * The coordinates of the center point refer to the position relative to the view.
     *
     * @param x Indicates the x-coordinate to set. The default value is 0.
     * @param y Indicates the y-coordinate to set. The default value is 0.
     * @see GetCenterPosition
     * @since 1.0
     * @version 1.0
     */
    void SetCenterPosition(int16_t x, int16_t y);

    /**
     * @brief Obtains the coordinates of the center point for this circular progress bar.
     *
     * The coordinates of the center point refer to the position relative to the view.
     *
     * @return Returns the coordinates of the center point.
     * @see SetCenterPosition
     * @since 1.0
     * @version 1.0
     */
    Point GetCenterPosition() const
    {
        return center_;
    }

    /**
     * @brief Sets the outer radius for this circular progress bar.
     *
     * @param radius Indicates the outer radius to set.
     * @see GetRadius
     * @since 1.0
     * @version 1.0
     */
    void SetRadius(uint16_t radius)
    {
        radius_ = radius;
    }

    /**
     * @brief Obtains the outer radius of this circular progress bar.
     *
     * @return Returns the outer radius.
     * @see SetRadius
     * @since 1.0
     * @version 1.0
     */
    uint16_t GetRadius() const
    {
        return radius_;
    }

    /**
     * @brief Sets the start angle.
     *
     * The 12-clock direction is 0 degrees, and the 3-clock direction is 90 degrees. \n
     * If the start angle is smaller than the end angle, the progress bar is clockwise.
     * Otherwise, the progress bar is anticlockwise. \n
     * The maximum range of a progress bar is a circle. If the difference between the start angle and end angle
     * exceeds 360 degrees, a circular progress bar is created. \n
     *
     * @param startAngle Indicates the start angle to set, which can be any value represented by <b>int16_t</b>.
     *                   The default value is 0.
     * @see GetStartAngle | SetEndAngle
     * @since 1.0
     * @version 1.0
     */
    void SetStartAngle(int16_t startAngle);

    /**
     * @brief Obtains the start angle.
     *
     * @return Returns the start angle.
     * @see SetStartAngle
     * @since 1.0
     * @version 1.0
     */
    int16_t GetStartAngle() const
    {
        return startAngle_;
    }

    /**
     * @brief Sets the end angle.
     *
     * The 12-clock direction is 0 degrees, and the 3-clock direction is 90 degrees. \n
     * If the start angle is smaller than the end angle, the progress bar is clockwise.
     * Otherwise, the progress bar is anticlockwise. \n
     * The maximum range of a progress bar is a circle. If the difference between the start angle and end angle
     * exceeds 360 degrees, a circular progress bar is created. \n
     *
     * @param endAngle Indicates the end angle to set, which can be any value represented by <b>int16_t</b>.
     *                 The default value is 360.
     * @see GetEndAngle | SetStartAngle
     * @since 1.0
     * @version 1.0
     */
    void SetEndAngle(int16_t endAngle);

    /**
     * @brief Obtains the end angle.
     *
     * @return Returns the end angle.
     * @see SetEndAngle
     * @since 1.0
     * @version 1.0
     */
    int16_t GetEndAngle() const
    {
        return endAngle_;
    }

    /**
     * @brief Sets the coordinates of the foreground image for this progress bar relative to the view.
     *
     * @param x Indicates the x-coordinate to set. The default value is 0.
     * @param y Indicates the y-coordinate to set. The default value is 0.
     * @see SetBackgroundImagePosition
     * @since 1.0
     * @version 1.0
     */
    void SetProgressImagePosition(int16_t x, int16_t y)
    {
        progressImagePos_.x = x + style_->paddingLeft_ + style_->borderWidth_;
        progressImagePos_.y = y + style_->paddingTop_ + style_->borderWidth_;
    }

    /**
     * @brief Sets the coordinates of the background image for this progress bar relative to the view.
     *
     * @param x Indicates the x-coordinate to set. The default value is 0.
     * @param y Indicates the y-coordinate to set. The default value is 0.
     * @see SetProgressImagePosition
     * @since 1.0
     * @version 1.0
     */
    void SetBackgroundImagePosition(int16_t x, int16_t y)
    {
        backgroundImagePos_.x = x + style_->paddingLeft_ + style_->borderWidth_;
        backgroundImagePos_.y = y + style_->paddingTop_ + style_->borderWidth_;
    }

    /**
     * @brief Sets the foreground color for this progress bar.
     *
     * @param color Indicates the foreground color to set. For details, see {@link ColorType}.
     * @since 1.0
     * @version 1.0
     */
    void SetLineColor(ColorType color)
    {
        SetForegroundStyle(STYLE_LINE_COLOR, color.full);
    }

private:
    static constexpr uint16_t MAX_ANGLE_VALUE = CIRCLE_IN_DEGREE;
    static constexpr uint16_t MIN_ANGLE_VALUE = 0;

    void GetStartEndAngle(int16_t& start, int16_t& end) const;
    void GetAngleRange(int16_t& start, int16_t& end) const;
    void GetRedrawAngle(int16_t& start, int16_t& end) const;
N
niulihua 已提交
250
    void DrawCommonCircle(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea);
M
mamingshuai 已提交
251 252 253 254 255 256 257 258 259 260

    Point center_;
    Point backgroundImagePos_;
    Point progressImagePos_;
    uint16_t radius_;
    int16_t startAngle_;
    int16_t endAngle_;
};
} // namespace OHOS
#endif // GRAPHIC_LITE_UI_CIRCLE_PROGRESS_H