/src/libreoffice/include/drawinglayer/primitive2d/fillgradientprimitive2d.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <drawinglayer/drawinglayerdllapi.h> |
23 | | |
24 | | #include <drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx> |
25 | | #include <drawinglayer/attribute/fillgradientattribute.hxx> |
26 | | |
27 | | |
28 | | // predefines |
29 | | |
30 | | namespace basegfx { class B2DPolygon; } |
31 | | namespace basegfx { class BColor; } |
32 | | |
33 | | |
34 | | // FillGradientPrimitive2D class |
35 | | |
36 | | namespace drawinglayer::primitive2d |
37 | | { |
38 | | /** FillGradientPrimitive2D class |
39 | | |
40 | | This class defines a gradient filling for a rectangular area. The |
41 | | Range is defined by the Transformation, the gradient by the FillGradientAttribute. |
42 | | |
43 | | The decomposition will deliver the decomposed gradient, e.g. for an ellipse |
44 | | gradient the various ellipses in various color steps will be created. |
45 | | |
46 | | I have added functionality to create both versions of filled decompositions: |
47 | | Those who overlap and non-overlapping ones. The overlapping version is the |
48 | | default one since it works with and without AntiAliasing. The non-overlapping |
49 | | version is used in the MetafilePrimitive2D decomposition when the old XOR |
50 | | paint was recorded. |
51 | | |
52 | | SDPR: Have now added to directly support alpha in the definition so that |
53 | | all implementations of primitive renderers may use it. Be aware that if a |
54 | | renderer does not support using that alpha it is advised to use the |
55 | | decomposition which separates content and alpha in a TransparencePrimitive2D. |
56 | | That way all stuff being used to that before will work unchanged. |
57 | | */ |
58 | | class DRAWINGLAYER_DLLPUBLIC FillGradientPrimitive2D : public BufferedDecompositionPrimitive2D |
59 | | { |
60 | | private: |
61 | | /// the geometrically visible area |
62 | | basegfx::B2DRange maOutputRange; |
63 | | |
64 | | /// the area the gradient definition is based on |
65 | | /// in the simplest case identical to OutputRange |
66 | | basegfx::B2DRange maDefinitionRange; |
67 | | |
68 | | /// the gradient definition |
69 | | attribute::FillGradientAttribute maFillGradient; |
70 | | |
71 | | /// evtl. fitting alphaGradient definition |
72 | | attribute::FillGradientAttribute maAlphaGradient; |
73 | | |
74 | | /// the transparency in range [0.0 .. 1.0] |
75 | | double mfTransparency; |
76 | | |
77 | | protected: |
78 | | /// local helper |
79 | | Primitive2DReference createFill(bool bOverlapping) const; |
80 | | |
81 | | /// local decomposition. |
82 | | virtual Primitive2DReference create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const override; |
83 | | |
84 | | public: |
85 | | /// helpers that support e.g. direct paint/geometry creation |
86 | | basegfx::B2DPolygon getUnitPolygon() const; |
87 | | basegfx::BColor getOuterColor() const; |
88 | | void generateMatricesAndColors( |
89 | | std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)> aCallback) const; |
90 | | |
91 | | /// constructors. The one without definition range will use output range as definition range |
92 | | FillGradientPrimitive2D( |
93 | | const basegfx::B2DRange& rOutputRange, |
94 | | const attribute::FillGradientAttribute& rFillGradient); |
95 | | FillGradientPrimitive2D( |
96 | | const basegfx::B2DRange& rOutputRange, |
97 | | const basegfx::B2DRange& rDefinitionRange, |
98 | | const attribute::FillGradientAttribute& rFillGradient, |
99 | | const attribute::FillGradientAttribute* pAlphaGradient = nullptr, |
100 | | double fTransparency = 0.0); |
101 | | |
102 | | /// data read access |
103 | 0 | const basegfx::B2DRange& getOutputRange() const { return maOutputRange; } |
104 | 0 | const basegfx::B2DRange& getDefinitionRange() const { return maDefinitionRange; } |
105 | 0 | const attribute::FillGradientAttribute& getFillGradient() const { return maFillGradient; } |
106 | | |
107 | 0 | const attribute::FillGradientAttribute& getAlphaGradient() const { return maAlphaGradient; } |
108 | 0 | bool hasAlphaGradient() const { return !maAlphaGradient.isDefault(); } |
109 | | |
110 | 0 | double getTransparency() const { return mfTransparency; } |
111 | 0 | bool hasTransparency() const { return !basegfx::fTools::equalZero(mfTransparency); } |
112 | | |
113 | | /// compare operator |
114 | | virtual bool operator==(const BasePrimitive2D& rPrimitive) const override final; |
115 | | |
116 | | /// get range |
117 | | virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const override final; |
118 | | |
119 | | /// provide unique ID |
120 | | virtual sal_uInt32 getPrimitive2DID() const override final; |
121 | | }; |
122 | | } // end of namespace drawinglayer::primitive2d |
123 | | |
124 | | |
125 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |