fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / drawinglayer / source / primitive2d / discreteshadowprimitive2d.cxx
blob5acebe6e1107b1c084821d5a3e2b4ab6bff47ba7
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 #include <drawinglayer/primitive2d/discreteshadowprimitive2d.hxx>
21 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
22 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
23 #include <basegfx/matrix/b2dhommatrixtools.hxx>
24 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
25 #include <drawinglayer/geometry/viewinformation2d.hxx>
27 //////////////////////////////////////////////////////////////////////////////
29 namespace drawinglayer
31 namespace primitive2d
33 DiscreteShadow::DiscreteShadow(const BitmapEx& rBitmapEx)
34 : maBitmapEx(rBitmapEx),
35 maTopLeft(),
36 maTop(),
37 maTopRight(),
38 maRight(),
39 maBottomRight(),
40 maBottom(),
41 maBottomLeft(),
42 maLeft()
44 const Size& rBitmapSize = getBitmapEx().GetSizePixel();
46 if(rBitmapSize.Width() != rBitmapSize.Height() || rBitmapSize.Width() < 7)
48 OSL_ENSURE(false, "DiscreteShadowPrimitive2D: wrong bitmap format (!)");
49 maBitmapEx = BitmapEx();
53 const BitmapEx& DiscreteShadow::getTopLeft() const
55 if(maTopLeft.IsEmpty())
57 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
58 const_cast< DiscreteShadow* >(this)->maTopLeft = getBitmapEx();
59 const_cast< DiscreteShadow* >(this)->maTopLeft.Crop(
60 Rectangle(Point(0,0),Size(nQuarter*2+1,nQuarter*2+1)));
63 return maTopLeft;
66 const BitmapEx& DiscreteShadow::getTop() const
68 if(maTop.IsEmpty())
70 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
71 const_cast< DiscreteShadow* >(this)->maTop = getBitmapEx();
72 const_cast< DiscreteShadow* >(this)->maTop.Crop(
73 Rectangle(Point(nQuarter*2+1,0),Size(1,nQuarter+1)));
76 return maTop;
79 const BitmapEx& DiscreteShadow::getTopRight() const
81 if(maTopRight.IsEmpty())
83 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
84 const_cast< DiscreteShadow* >(this)->maTopRight = getBitmapEx();
85 const_cast< DiscreteShadow* >(this)->maTopRight.Crop(
86 Rectangle(Point(nQuarter*2+2,0),Size(nQuarter*2+1,nQuarter*2+1)));
89 return maTopRight;
92 const BitmapEx& DiscreteShadow::getRight() const
94 if(maRight.IsEmpty())
96 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
97 const_cast< DiscreteShadow* >(this)->maRight = getBitmapEx();
98 const_cast< DiscreteShadow* >(this)->maRight.Crop(
99 Rectangle(Point(nQuarter*3+2,nQuarter*2+1),Size(nQuarter+1,1)));
102 return maRight;
105 const BitmapEx& DiscreteShadow::getBottomRight() const
107 if(maBottomRight.IsEmpty())
109 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
110 const_cast< DiscreteShadow* >(this)->maBottomRight = getBitmapEx();
111 const_cast< DiscreteShadow* >(this)->maBottomRight.Crop(
112 Rectangle(Point(nQuarter*2+2,nQuarter*2+2),Size(nQuarter*2+1,nQuarter*2+1)));
115 return maBottomRight;
118 const BitmapEx& DiscreteShadow::getBottom() const
120 if(maBottom.IsEmpty())
122 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
123 const_cast< DiscreteShadow* >(this)->maBottom = getBitmapEx();
124 const_cast< DiscreteShadow* >(this)->maBottom.Crop(
125 Rectangle(Point(nQuarter*2+1,nQuarter*3+2),Size(1,nQuarter+1)));
128 return maBottom;
131 const BitmapEx& DiscreteShadow::getBottomLeft() const
133 if(maBottomLeft.IsEmpty())
135 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
136 const_cast< DiscreteShadow* >(this)->maBottomLeft = getBitmapEx();
137 const_cast< DiscreteShadow* >(this)->maBottomLeft.Crop(
138 Rectangle(Point(0,nQuarter*2+2),Size(nQuarter*2+1,nQuarter*2+1)));
141 return maBottomLeft;
144 const BitmapEx& DiscreteShadow::getLeft() const
146 if(maLeft.IsEmpty())
148 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
149 const_cast< DiscreteShadow* >(this)->maLeft = getBitmapEx();
150 const_cast< DiscreteShadow* >(this)->maLeft.Crop(
151 Rectangle(Point(0,nQuarter*2+1),Size(nQuarter+1,1)));
154 return maLeft;
157 } // end of namespace primitive2d
158 } // end of namespace drawinglayer
160 //////////////////////////////////////////////////////////////////////////////
162 namespace drawinglayer
164 namespace primitive2d
166 Primitive2DSequence DiscreteShadowPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
168 Primitive2DSequence xRetval;
170 if(!getDiscreteShadow().getBitmapEx().IsEmpty())
172 const sal_Int32 nQuarter((getDiscreteShadow().getBitmapEx().GetSizePixel().Width() - 3) >> 2);
173 const basegfx::B2DVector aScale(getTransform() * basegfx::B2DVector(1.0, 1.0));
174 const double fSingleX(getDiscreteUnit() / aScale.getX());
175 const double fSingleY(getDiscreteUnit() / aScale.getY());
176 const double fBorderX(fSingleX * nQuarter);
177 const double fBorderY(fSingleY * nQuarter);
178 const double fBigLenX((fBorderX * 2.0) + fSingleX);
179 const double fBigLenY((fBorderY * 2.0) + fSingleY);
181 xRetval.realloc(8);
183 // TopLeft
184 xRetval[0] = Primitive2DReference(
185 new BitmapPrimitive2D(
186 getDiscreteShadow().getTopLeft(),
187 basegfx::tools::createScaleTranslateB2DHomMatrix(
188 fBigLenX,
189 fBigLenY,
190 -fBorderX,
191 -fBorderY)));
193 // Top
194 xRetval[1] = Primitive2DReference(
195 new BitmapPrimitive2D(
196 getDiscreteShadow().getTop(),
197 basegfx::tools::createScaleTranslateB2DHomMatrix(
198 1.0 - (2.0 * fBorderX) - fSingleX,
199 fBorderY + fSingleY,
200 fBorderX + fSingleX,
201 -fBorderY)));
203 // TopRight
204 xRetval[2] = Primitive2DReference(
205 new BitmapPrimitive2D(
206 getDiscreteShadow().getTopRight(),
207 basegfx::tools::createScaleTranslateB2DHomMatrix(
208 fBigLenX,
209 fBigLenY,
210 1.0 - fBorderX,
211 -fBorderY)));
213 // Right
214 xRetval[3] = Primitive2DReference(
215 new BitmapPrimitive2D(
216 getDiscreteShadow().getRight(),
217 basegfx::tools::createScaleTranslateB2DHomMatrix(
218 fBorderX + fSingleX,
219 1.0 - (2.0 * fBorderY) - fSingleY,
220 1.0,
221 fBorderY + fSingleY)));
223 // BottomRight
224 xRetval[4] = Primitive2DReference(
225 new BitmapPrimitive2D(
226 getDiscreteShadow().getBottomRight(),
227 basegfx::tools::createScaleTranslateB2DHomMatrix(
228 fBigLenX,
229 fBigLenY,
230 1.0 - fBorderX,
231 1.0 - fBorderY)));
233 // Bottom
234 xRetval[5] = Primitive2DReference(
235 new BitmapPrimitive2D(
236 getDiscreteShadow().getBottom(),
237 basegfx::tools::createScaleTranslateB2DHomMatrix(
238 1.0 - (2.0 * fBorderX) - fSingleX,
239 fBorderY + fSingleY,
240 fBorderX + fSingleX,
241 1.0)));
243 // BottomLeft
244 xRetval[6] = Primitive2DReference(
245 new BitmapPrimitive2D(
246 getDiscreteShadow().getBottomLeft(),
247 basegfx::tools::createScaleTranslateB2DHomMatrix(
248 fBigLenX,
249 fBigLenY,
250 -fBorderX,
251 1.0 - fBorderY)));
253 // Left
254 xRetval[7] = Primitive2DReference(
255 new BitmapPrimitive2D(
256 getDiscreteShadow().getLeft(),
257 basegfx::tools::createScaleTranslateB2DHomMatrix(
258 fBorderX + fSingleX,
259 1.0 - (2.0 * fBorderY) - fSingleY,
260 -fBorderX,
261 fBorderY + fSingleY)));
263 // put all in object transformation to get to target positions
264 const Primitive2DReference xTransformed(
265 new TransformPrimitive2D(
266 getTransform(),
267 xRetval));
269 xRetval = Primitive2DSequence(&xTransformed, 1);
272 return xRetval;
275 DiscreteShadowPrimitive2D::DiscreteShadowPrimitive2D(
276 const basegfx::B2DHomMatrix& rTransform,
277 const DiscreteShadow& rDiscreteShadow)
278 : DiscreteMetricDependentPrimitive2D(),
279 maTransform(rTransform),
280 maDiscreteShadow(rDiscreteShadow)
284 bool DiscreteShadowPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
286 if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
288 const DiscreteShadowPrimitive2D& rCompare = (DiscreteShadowPrimitive2D&)rPrimitive;
290 return (getTransform() == rCompare.getTransform()
291 && getDiscreteShadow() == rCompare.getDiscreteShadow());
294 return false;
297 basegfx::B2DRange DiscreteShadowPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
299 if(getDiscreteShadow().getBitmapEx().IsEmpty())
301 // no graphics without valid bitmap definition
302 return basegfx::B2DRange();
304 else
306 // prepare normal objectrange
307 basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
308 aRetval.transform(getTransform());
310 // extract discrete shadow size and grow
311 const basegfx::B2DVector aScale(rViewInformation.getViewTransformation() * basegfx::B2DVector(1.0, 1.0));
312 const sal_Int32 nQuarter((getDiscreteShadow().getBitmapEx().GetSizePixel().Width() - 3) >> 2);
313 const double fGrowX((1.0 / aScale.getX()) * nQuarter);
314 const double fGrowY((1.0 / aScale.getY()) * nQuarter);
315 aRetval.grow(std::max(fGrowX, fGrowY));
317 return aRetval;
321 // provide unique ID
322 ImplPrimitive2DIDBlock(DiscreteShadowPrimitive2D, PRIMITIVE2D_ID_DISCRETESHADOWPRIMITIVE2D)
324 } // end of namespace primitive2d
325 } // end of namespace drawinglayer
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */