draw_arc.h 4.8 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
/*
 * 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.
 */

#ifndef GRAPHIC_LITE_DRAW_ARC_H
#define GRAPHIC_LITE_DRAW_ARC_H
#include "common/image.h"
#include "draw_image.h"
#include "draw_utils.h"
Z
zhangguyuan 已提交
21 22
#include "gfx_utils/graphic_math.h"
#include "gfx_utils/heap_base.h"
M
mamingshuai 已提交
23
#include "imgdecode/cache_manager.h"
Z
zhangguyuan 已提交
24
#include "gfx_utils/style.h"
M
mamingshuai 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37

namespace OHOS {
struct ArcInfo {
    Point center;
    Point imgPos;
    uint16_t radius;
    int16_t startAngle;
    int16_t endAngle;
    const Image* imgSrc;
};

class DrawArc : public HeapBase {
public:
Z
zhdengc 已提交
38
    static DrawArc* GetInstance();
M
mamingshuai 已提交
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 85 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

    void GetDrawRange(int16_t& start, int16_t& end);

    void Draw(ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opaScale, uint8_t cap);

private:
    static constexpr uint8_t DRAW_ARC_QUADRANT_NUM = 4;
    static constexpr uint8_t ARC_QUADRANT_ONE = 0;
    static constexpr uint8_t ARC_QUADRANT_TWO = 1;
    static constexpr uint8_t ARC_QUADRANT_THREE = 2;
    static constexpr uint8_t ARC_QUADRANT_FOUR = 3;
    static constexpr int16_t IN_DEGREE_RANG = 0;
    static constexpr int16_t OUT_DEGREE_RANG = 1;
    static constexpr int16_t INTERSECT = 2;
    static constexpr int16_t DOUBLE_INTERSECT = 3;

    int16_t lineStart_;
    int16_t lineEnd_;
    int16_t outAntiStart_;
    int16_t outAntiEnd_;
    int16_t inAntiStart_;
    int16_t inAntiEnd_;
    int16_t y_;
    int16_t outRadius_;
    int16_t inRadius_;
    uint32_t ySqr_;
    uint32_t outRadiusSqr_;
    uint32_t inRadiusSqr_;
    bool isCircle_;
    uint32_t antiOutRadiusSqr_;
    uint32_t antiInRadiusSqr_;

    DrawArc()
        : lineStart_(0),
          lineEnd_(0),
          outAntiStart_(0),
          outAntiEnd_(0),
          inAntiStart_(0),
          inAntiEnd_(0),
          y_(0),
          outRadius_(0),
          inRadius_(0),
          ySqr_(0),
          outRadiusSqr_(0),
          inRadiusSqr_(0),
          isCircle_(false),
          antiOutRadiusSqr_(0),
          antiInRadiusSqr_(0)
    {
    }
    ~DrawArc() {}
    void DrawVerLine(const Point& begin,
                     const Point& imgPos,
                     const Rect& mask,
                     int16_t len,
                     const Style& style,
                     uint8_t opaScale,
                     const Image* imgSrc);

    void DrawHorLine(const Point& begin,
                     const Point& imgPos,
                     const Rect& mask,
                     int16_t len,
                     const Style& style,
                     uint8_t opaScale,
                     const Image* imgSrc);

    void DrawImg(const Point& imgPos,
                 Rect& area,
                 const Rect& invalidatedArea,
                 const Style& style,
                 uint8_t opaScale,
                 const Image* imgSrc);

    int16_t GetDegreeRangeIntersectState(uint16_t degreeStart, uint16_t degreeEnd, uint16_t start, uint16_t end);
    uint16_t CalculateTanDegree(uint16_t x, uint16_t y);
    int16_t GetDrawAngle(int16_t angle);
    void DrawCircleNoEndpoint(ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opa, bool anti);
    void DrawAxisLine(ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opa);
    void DrawLineWithDegree(ArcInfo& arcInfo,
                            int16_t start,
                            int16_t end,
                            int16_t y,
                            const Rect& mask,
                            const Style& style,
                            uint8_t opaScale,
                            uint8_t quadrant);
    int16_t DrawLineWithDegreeInner(ArcInfo& arcInfo,
                                    int16_t start,
                                    int16_t end,
                                    int16_t y,
                                    const Rect& mask,
                                    const Style& style,
                                    uint8_t opaScale,
                                    uint8_t quadrant);
#if ENABLE_ANTIALIAS
    void DrawLineAnti(ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opa);
    void DrawPointAnti(ArcInfo& arcInfo, int16_t x, const Rect& mask, const Style& style, uint8_t antiOpa);
#endif
    uint16_t GetDegreeInQuadrant(uint16_t degree, uint8_t quadrant);
    void SetArcInfo(ArcInfo& arcInfo, const Style& style);
};
} // namespace OHOS
#endif // GRAPHIC_LITE_DRAW_ARC_H