1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <basegfx/matrix/b2dhommatrix.hxx>
23 #include <basegfx/range/b2drange.hxx>
24 #include <basegfx/color/bcolor.hxx>
25 #include <basegfx/utils/gradienttools.hxx>
29 namespace drawinglayer::texture
38 virtual bool operator==(const GeoTexSvx
& rGeoTexSvx
) const;
39 bool operator!=(const GeoTexSvx
& rGeoTexSvx
) const { return !operator==(rGeoTexSvx
); }
41 // virtual base methods
42 virtual void modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const;
43 virtual void modifyOpacity(const basegfx::B2DPoint
& rUV
, double& rfOpacity
) const;
46 class GeoTexSvxGradient
: public GeoTexSvx
49 basegfx::ODFGradientInfo maGradientInfo
;
50 basegfx::B2DRange maDefinitionRange
;
51 sal_uInt32 mnRequestedSteps
;
52 basegfx::BColorStops mnColorStops
;
55 // provide a single buffer entry used for gradient texture
56 // mapping, see ::modifyBColor implementations
57 mutable basegfx::BColorStops::BColorStopRange maLastColorStopRange
;
61 const basegfx::B2DRange
& rDefinitionRange
,
62 sal_uInt32 nRequestedSteps
,
63 const basegfx::BColorStops
& rColorStops
,
65 virtual ~GeoTexSvxGradient() override
;
68 virtual bool operator==(const GeoTexSvx
& rGeoTexSvx
) const override
;
70 // virtual base methods
71 virtual void appendTransformationsAndColors(
72 const std::function
<void(const basegfx::B2DHomMatrix
& rMatrix
, const basegfx::BColor
& rColor
)>& rCallback
) = 0;
75 class GeoTexSvxGradientLinear final
: public GeoTexSvxGradient
82 GeoTexSvxGradientLinear(
83 const basegfx::B2DRange
& rDefinitionRange
,
84 const basegfx::B2DRange
& rOutputRange
,
85 sal_uInt32 nRequestedSteps
,
86 const basegfx::BColorStops
& rColorStops
,
89 virtual ~GeoTexSvxGradientLinear() override
;
91 virtual void appendTransformationsAndColors(
92 const std::function
<void(const basegfx::B2DHomMatrix
& rMatrix
, const basegfx::BColor
& rColor
)>& rCallback
) override
;
93 virtual void modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const override
;
96 class GeoTexSvxGradientAxial final
: public GeoTexSvxGradient
102 GeoTexSvxGradientAxial(
103 const basegfx::B2DRange
& rDefinitionRange
,
104 const basegfx::B2DRange
& rOutputRange
,
105 sal_uInt32 nRequestedSteps
,
106 const basegfx::BColorStops
& rColorStops
,
109 virtual ~GeoTexSvxGradientAxial() override
;
111 virtual void appendTransformationsAndColors(
112 const std::function
<void(const basegfx::B2DHomMatrix
& rMatrix
, const basegfx::BColor
& rColor
)>& rCallback
) override
;
113 virtual void modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const override
;
116 class GeoTexSvxGradientRadial final
: public GeoTexSvxGradient
119 GeoTexSvxGradientRadial(
120 const basegfx::B2DRange
& rDefinitionRange
,
121 sal_uInt32 nRequestedSteps
,
122 const basegfx::BColorStops
& rColorStops
,
126 virtual ~GeoTexSvxGradientRadial() override
;
128 virtual void appendTransformationsAndColors(
129 const std::function
<void(const basegfx::B2DHomMatrix
& rMatrix
, const basegfx::BColor
& rColor
)>& rCallback
) override
;
130 virtual void modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const override
;
133 class GeoTexSvxGradientElliptical final
: public GeoTexSvxGradient
136 GeoTexSvxGradientElliptical(
137 const basegfx::B2DRange
& rDefinitionRange
,
138 sal_uInt32 nRequestedSteps
,
139 const basegfx::BColorStops
& rColorStops
,
144 virtual ~GeoTexSvxGradientElliptical() override
;
146 virtual void appendTransformationsAndColors(
147 const std::function
<void(const basegfx::B2DHomMatrix
& rMatrix
, const basegfx::BColor
& rColor
)>& rCallback
) override
;
148 virtual void modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const override
;
151 class GeoTexSvxGradientSquare final
: public GeoTexSvxGradient
154 GeoTexSvxGradientSquare(
155 const basegfx::B2DRange
& rDefinitionRange
,
156 sal_uInt32 nRequestedSteps
,
157 const basegfx::BColorStops
& rColorStops
,
162 virtual ~GeoTexSvxGradientSquare() override
;
164 virtual void appendTransformationsAndColors(
165 const std::function
<void(const basegfx::B2DHomMatrix
& rMatrix
, const basegfx::BColor
& rColor
)>& rCallback
) override
;
166 virtual void modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const override
;
169 class GeoTexSvxGradientRect final
: public GeoTexSvxGradient
172 GeoTexSvxGradientRect(
173 const basegfx::B2DRange
& rDefinitionRange
,
174 sal_uInt32 nRequestedSteps
,
175 const basegfx::BColorStops
& rColorStops
,
180 virtual ~GeoTexSvxGradientRect() override
;
182 virtual void appendTransformationsAndColors(
183 const std::function
<void(const basegfx::B2DHomMatrix
& rMatrix
, const basegfx::BColor
& rColor
)>& rCallback
) override
;
184 virtual void modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const override
;
187 class GeoTexSvxHatch final
: public GeoTexSvx
189 basegfx::B2DRange maOutputRange
;
190 basegfx::B2DHomMatrix maTextureTransform
;
191 basegfx::B2DHomMatrix maBackTextureTransform
;
196 bool mbDefinitionRangeEqualsOutputRange
: 1;
200 const basegfx::B2DRange
& rDefinitionRange
,
201 const basegfx::B2DRange
& rOutputRange
,
204 virtual ~GeoTexSvxHatch() override
;
207 virtual bool operator==(const GeoTexSvx
& rGeoTexSvx
) const override
;
209 void appendTransformations(::std::vector
< basegfx::B2DHomMatrix
>& rMatrices
);
210 double getDistanceToHatch(const basegfx::B2DPoint
& rUV
) const;
211 const basegfx::B2DHomMatrix
& getBackTextureTransform() const;
214 // This class applies a tiling to the unit range. The given range
215 // will be repeated inside the unit range in X and Y and for each
216 // tile a matrix will be created (by appendTransformations) that
217 // represents the needed transformation to map a filling in unit
218 // coordinates to that tile.
219 // When offsetX is given, every 2nd line will be offsetted by the
220 // given percentage value (offsetX has to be 0.0 <= offsetX <= 1.0).
221 // Accordingly to offsetY. If both are given, offsetX is preferred
222 // and offsetY is ignored.
223 class GeoTexSvxTiled final
: public GeoTexSvx
225 basegfx::B2DRange maRange
;
231 const basegfx::B2DRange
& rRange
,
232 double fOffsetX
= 0.0,
233 double fOffsetY
= 0.0);
234 virtual ~GeoTexSvxTiled() override
;
237 virtual bool operator==(const GeoTexSvx
& rGeoTexSvx
) const override
;
239 // Iterate over created tiles with callback provided.
240 void iterateTiles(std::function
<void(double fPosX
, double fPosY
)> aFunc
) const;
242 void appendTransformations(::std::vector
< basegfx::B2DHomMatrix
>& rMatrices
) const;
243 sal_uInt32
getNumberOfTiles() const;
245 } // end of namespace drawinglayer::texture
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */