Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / drawinglayer / inc / texture / texture.hxx
blob5128a30cf2a86594ef8547632c7eab869ba3e204
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include <basegfx/matrix/b2dhommatrix.hxx>
23 #include <basegfx/range/b2drange.hxx>
24 #include <basegfx/color/bcolor.hxx>
25 #include <basegfx/utils/gradienttools.hxx>
26 #include <vector>
27 #include <functional>
29 namespace drawinglayer::texture
31 class GeoTexSvx
33 public:
34 GeoTexSvx();
35 virtual ~GeoTexSvx();
37 // compare operator
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
48 protected:
49 basegfx::ODFGradientInfo maGradientInfo;
50 basegfx::B2DRange maDefinitionRange;
51 sal_uInt32 mnRequestedSteps;
52 basegfx::BColorStops mnColorStops;
53 double mfBorder;
55 // provide a single buffer entry used for gradient texture
56 // mapping, see ::modifyBColor implementations
57 mutable basegfx::BColorStops::BColorStopRange maLastColorStopRange;
59 public:
60 GeoTexSvxGradient(
61 const basegfx::B2DRange& rDefinitionRange,
62 sal_uInt32 nRequestedSteps,
63 const basegfx::BColorStops& rColorStops,
64 double fBorder);
65 virtual ~GeoTexSvxGradient() override;
67 // compare operator
68 virtual bool operator==(const GeoTexSvx& rGeoTexSvx) const override;
70 // virtual base methods
71 virtual void appendTransformationsAndColors(
72 std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)> aCallback) = 0;
75 class GeoTexSvxGradientLinear final : public GeoTexSvxGradient
77 double mfUnitMinX;
78 double mfUnitWidth;
79 double mfUnitMaxY;
81 public:
82 GeoTexSvxGradientLinear(
83 const basegfx::B2DRange& rDefinitionRange,
84 const basegfx::B2DRange& rOutputRange,
85 sal_uInt32 nRequestedSteps,
86 const basegfx::BColorStops& rColorStops,
87 double fBorder,
88 double fAngle);
89 virtual ~GeoTexSvxGradientLinear() override;
91 virtual void appendTransformationsAndColors(
92 std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)> aCallback) override;
93 virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const override;
96 class GeoTexSvxGradientAxial final : public GeoTexSvxGradient
98 double mfUnitMinX;
99 double mfUnitWidth;
101 public:
102 GeoTexSvxGradientAxial(
103 const basegfx::B2DRange& rDefinitionRange,
104 const basegfx::B2DRange& rOutputRange,
105 sal_uInt32 nRequestedSteps,
106 const basegfx::BColorStops& rColorStops,
107 double fBorder,
108 double fAngle);
109 virtual ~GeoTexSvxGradientAxial() override;
111 virtual void appendTransformationsAndColors(
112 std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)> aCallback) override;
113 virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const override;
116 class GeoTexSvxGradientRadial final : public GeoTexSvxGradient
118 public:
119 GeoTexSvxGradientRadial(
120 const basegfx::B2DRange& rDefinitionRange,
121 sal_uInt32 nRequestedSteps,
122 const basegfx::BColorStops& rColorStops,
123 double fBorder,
124 double fOffsetX,
125 double fOffsetY);
126 virtual ~GeoTexSvxGradientRadial() override;
128 virtual void appendTransformationsAndColors(
129 std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)> aCallback) override;
130 virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const override;
133 class GeoTexSvxGradientElliptical final : public GeoTexSvxGradient
135 public:
136 GeoTexSvxGradientElliptical(
137 const basegfx::B2DRange& rDefinitionRange,
138 sal_uInt32 nRequestedSteps,
139 const basegfx::BColorStops& rColorStops,
140 double fBorder,
141 double fOffsetX,
142 double fOffsetY,
143 double fAngle);
144 virtual ~GeoTexSvxGradientElliptical() override;
146 virtual void appendTransformationsAndColors(
147 std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)> aCallback) override;
148 virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const override;
151 class GeoTexSvxGradientSquare final : public GeoTexSvxGradient
153 public:
154 GeoTexSvxGradientSquare(
155 const basegfx::B2DRange& rDefinitionRange,
156 sal_uInt32 nRequestedSteps,
157 const basegfx::BColorStops& rColorStops,
158 double fBorder,
159 double fOffsetX,
160 double fOffsetY,
161 double fAngle);
162 virtual ~GeoTexSvxGradientSquare() override;
164 virtual void appendTransformationsAndColors(
165 std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)> aCallback) override;
166 virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const override;
169 class GeoTexSvxGradientRect final : public GeoTexSvxGradient
171 public:
172 GeoTexSvxGradientRect(
173 const basegfx::B2DRange& rDefinitionRange,
174 sal_uInt32 nRequestedSteps,
175 const basegfx::BColorStops& rColorStops,
176 double fBorder,
177 double fOffsetX,
178 double fOffsetY,
179 double fAngle);
180 virtual ~GeoTexSvxGradientRect() override;
182 virtual void appendTransformationsAndColors(
183 std::function<void(const basegfx::B2DHomMatrix& rMatrix, const basegfx::BColor& rColor)> aCallback) 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;
192 double mfDistance;
193 double mfAngle;
194 sal_uInt32 mnSteps;
196 bool mbDefinitionRangeEqualsOutputRange : 1;
198 public:
199 GeoTexSvxHatch(
200 const basegfx::B2DRange& rDefinitionRange,
201 const basegfx::B2DRange& rOutputRange,
202 double fDistance,
203 double fAngle);
204 virtual ~GeoTexSvxHatch() override;
206 // compare operator
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;
226 double mfOffsetX;
227 double mfOffsetY;
229 public:
230 GeoTexSvxTiled(
231 const basegfx::B2DRange& rRange,
232 double fOffsetX = 0.0,
233 double fOffsetY = 0.0);
234 virtual ~GeoTexSvxTiled() override;
236 // compare operator
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: */