1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PEN_H 17 #define PEN_H 18 19 #include "draw/brush.h" 20 #include "draw/color.h" 21 #include "effect/filter.h" 22 #include "effect/path_effect.h" 23 #include "utils/rect.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 namespace Drawing { 28 class DRAWING_API Pen { 29 public: 30 enum class JoinStyle { 31 MITER_JOIN, 32 ROUND_JOIN, 33 BEVEL_JOIN, 34 DEFAULT_JOIN = MITER_JOIN 35 }; 36 37 enum class CapStyle { 38 FLAT_CAP, 39 SQUARE_CAP, 40 ROUND_CAP, 41 DEFAULT_CAP = FLAT_CAP 42 }; 43 44 Pen() noexcept; 45 Pen(const Pen& p) noexcept = default; 46 Pen(const Color& c) noexcept; 47 Pen(int rgba) noexcept; ~Pen()48 ~Pen() {}; 49 50 Color GetColor() const; 51 void SetColor(const Color& c); 52 void SetColor(int c); 53 void SetARGB(int a, int r, int g, int b); 54 55 Color4f GetColor4f(); 56 std::shared_ptr<ColorSpace> GetColorSpace() const; 57 void SetColor(const Color4f& cf, std::shared_ptr<ColorSpace> s); 58 59 uint32_t GetAlpha() const; 60 scalar GetAlphaF() const; 61 void SetAlpha(uint32_t a); 62 void SetAlphaF(scalar a); 63 64 scalar GetWidth() const; 65 void SetWidth(scalar width); 66 67 scalar GetMiterLimit() const; 68 void SetMiterLimit(scalar limit); 69 70 CapStyle GetCapStyle() const; 71 void SetCapStyle(CapStyle cs); 72 73 JoinStyle GetJoinStyle() const; 74 void SetJoinStyle(JoinStyle js); 75 76 BlendMode GetBlendMode() const; 77 void SetBlendMode(BlendMode mode); 78 79 bool IsAntiAlias() const; 80 void SetAntiAlias(bool aa); 81 82 void SetPathEffect(std::shared_ptr<PathEffect> e); 83 std::shared_ptr<PathEffect> GetPathEffect() const; 84 85 void SetFilter(const Filter& filter); 86 Filter GetFilter() const; 87 bool HasFilter() const; 88 89 void SetShaderEffect(std::shared_ptr<ShaderEffect> e); 90 std::shared_ptr<ShaderEffect> GetShaderEffect() const; 91 92 void Reset(); 93 94 friend DRAWING_API bool operator==(const Pen& p1, const Pen& p2); 95 friend DRAWING_API bool operator!=(const Pen& p1, const Pen& p2); 96 97 private: 98 scalar width_; 99 scalar miterLimit_; 100 JoinStyle join_; 101 CapStyle cap_; 102 std::shared_ptr<PathEffect> pathEffect_; 103 104 Brush brush_; 105 }; 106 } // namespace Drawing 107 } // namespace Rosen 108 } // namespace OHOS 109 #endif