1 /* 2 * Copyright (c) 2023 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 PAINT_H 17 #define PAINT_H 18 19 #include "draw/brush.h" 20 #include "draw/pen.h" 21 22 namespace OHOS { 23 namespace Rosen { 24 namespace Drawing { 25 class DRAWING_API Paint { 26 public: 27 Paint() noexcept; 28 Paint(const Paint& other) noexcept; 29 Paint(const Color& c, std::shared_ptr<ColorSpace> colorSpace = nullptr) noexcept; 30 Paint& operator=(const Paint& other); ~Paint()31 ~Paint() {}; 32 33 static bool CanCombinePaint(const Paint& pen, const Paint& brush); 34 void AttachBrush(const Brush& brush); 35 void AttachPen(const Pen& pen); 36 37 enum PaintStyle : uint8_t { 38 PAINT_NONE = 0x00, 39 PAINT_FILL = 0x01, 40 PAINT_STROKE = 0x02, 41 PAINT_FILL_STROKE = 0x03 42 }; 43 44 void SetStyle(const PaintStyle& style); GetStyle()45 PaintStyle GetStyle() const { return style_; } IsValid()46 bool IsValid() const { return style_ != PaintStyle::PAINT_NONE; } 47 bool HasStrokeStyle() const; 48 49 void SetColor(const Color& c); 50 void SetARGB(int a, int r, int g, int b); 51 void SetColor(const Color4f& cf, std::shared_ptr<ColorSpace> colorSpace = nullptr); GetColor()52 const Color& GetColor() const { return color_; } GetColor4f()53 Color4f GetColor4f() { return color_.GetColor4f(); } GetColorSpace()54 std::shared_ptr<ColorSpace> GetColorSpace() const { return colorSpace_; } 55 56 void SetAlpha(uint32_t a); 57 void SetAlphaF(scalar a); GetAlpha()58 inline uint32_t GetAlpha() const { return color_.GetAlpha(); } GetAlphaF()59 inline scalar GetAlphaF() const { return color_.GetAlphaF(); } 60 61 void SetWidth(scalar width); GetWidth()62 scalar GetWidth() const { return width_; } 63 64 void SetMiterLimit(scalar limit); GetMiterLimit()65 scalar GetMiterLimit() const { return miterLimit_; } 66 67 void SetCapStyle(Pen::CapStyle cs); GetCapStyle()68 Pen::CapStyle GetCapStyle() const { return cap_; } 69 70 void SetJoinStyle(Pen::JoinStyle js); GetJoinStyle()71 Pen::JoinStyle GetJoinStyle() const { return join_; } 72 73 void SetBlendMode(BlendMode mode); GetBlendMode()74 BlendMode GetBlendMode() const { return blendMode_; } 75 76 void SetFilter(const Filter& filter); GetFilter()77 Filter GetFilter() const { return filter_; } HasFilter()78 bool HasFilter() const { return hasFilter_; } 79 80 void SetShaderEffect(std::shared_ptr<ShaderEffect> e); GetShaderEffect()81 const std::shared_ptr<ShaderEffect> GetShaderEffect() const { return shaderEffect_; } 82 83 void SetPathEffect(std::shared_ptr<PathEffect> e); GetPathEffect()84 const std::shared_ptr<PathEffect> GetPathEffect() const { return pathEffect_; } 85 86 void SetAntiAlias(bool aa); IsAntiAlias()87 bool IsAntiAlias() const { return antiAlias_; } 88 89 void Reset(); 90 void Disable(); 91 92 friend bool operator==(const Paint& p1, const Paint& p2); 93 friend bool operator!=(const Paint& p1, const Paint& p2); 94 95 private: 96 const scalar DEFAULT_MITER_VAL = 4.0f; 97 bool antiAlias_ = false; 98 Color color_ = Color::COLOR_BLACK; 99 BlendMode blendMode_ = BlendMode::SRC_OVER; 100 PaintStyle style_ = PaintStyle::PAINT_NONE; 101 scalar width_ = 0.0f; 102 scalar miterLimit_ = DEFAULT_MITER_VAL; // the same as default val of skia 103 Pen::JoinStyle join_ = Pen::JoinStyle::DEFAULT_JOIN; 104 Pen::CapStyle cap_ = Pen::CapStyle::DEFAULT_CAP; 105 106 bool hasFilter_ = false; 107 Filter filter_; 108 109 std::shared_ptr<ColorSpace> colorSpace_ = nullptr; 110 std::shared_ptr<ShaderEffect> shaderEffect_ = nullptr; 111 std::shared_ptr<PathEffect> pathEffect_ = nullptr; 112 }; 113 } // namespace Drawing 114 } // namespace Rosen 115 } // namespace OHOS 116 #endif // PAINT_H