1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: overlayobject.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/sdr/overlay/overlaytools.hxx>
35 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
38 #include <basegfx/polygon/b2dpolygon.hxx>
39 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
40 #include <basegfx/polygon/b2dpolygontools.hxx>
41 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
42 #include <drawinglayer/geometry/viewinformation2d.hxx>
44 //////////////////////////////////////////////////////////////////////////////
46 namespace drawinglayer
50 OverlayBitmapExPrimitive::OverlayBitmapExPrimitive(
51 const BitmapEx
& rBitmapEx
,
52 const basegfx::B2DPoint
& rBasePosition
,
55 : DiscreteMetricDependentPrimitive2D(),
56 maBitmapEx(rBitmapEx
),
57 maBasePosition(rBasePosition
),
62 Primitive2DSequence
OverlayBitmapExPrimitive::createLocalDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
64 Primitive2DSequence aRetval
;
65 const Size
aBitmapSize(getBitmapEx().GetSizePixel());
67 if(aBitmapSize
.Width() && aBitmapSize
.Height() && basegfx::fTools::more(getDiscreteUnit(), 0.0))
69 // calculate back from internal bitmap's extreme coordinates (the edges)
70 // to logical coordinates. Only use a unified scaling value (getDiscreteUnit(),
71 // the prepared one which expresses how many logic units form a discrete unit)
72 // for this step. This primitive is to be displayed always unscaled (in it's pixel size)
73 // and unrotated, more like a marker
74 const double fLeft(((0.0 - getCenterX()) * getDiscreteUnit()) + getBasePosition().getX());
75 const double fTop(((0.0 - getCenterY()) * getDiscreteUnit()) + getBasePosition().getY());
76 const double fRight((((aBitmapSize
.getWidth() - 1.0) - getCenterX()) * getDiscreteUnit()) + getBasePosition().getX());
77 const double fBottom((((aBitmapSize
.getHeight() - 1.0) - getCenterY()) * getDiscreteUnit()) + getBasePosition().getY());
79 // create a BitmapPrimitive2D using those positions
80 basegfx::B2DHomMatrix aTransform
;
82 aTransform
.set(0, 0, fRight
- fLeft
);
83 aTransform
.set(1, 1, fBottom
- fTop
);
84 aTransform
.set(0, 2, fLeft
);
85 aTransform
.set(1, 2, fTop
);
87 const Primitive2DReference
aPrimitive(new BitmapPrimitive2D(getBitmapEx(), aTransform
));
88 aRetval
= Primitive2DSequence(&aPrimitive
, 1);
94 bool OverlayBitmapExPrimitive::operator==( const BasePrimitive2D
& rPrimitive
) const
96 if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive
))
98 const OverlayBitmapExPrimitive
& rCompare
= static_cast< const OverlayBitmapExPrimitive
& >(rPrimitive
);
100 return (getBitmapEx() == rCompare
.getBitmapEx()
101 && getBasePosition() == rCompare
.getBasePosition()
102 && getCenterX() == rCompare
.getCenterX()
103 && getCenterY() == rCompare
.getCenterY());
109 ImplPrimitrive2DIDBlock(OverlayBitmapExPrimitive
, PRIMITIVE2D_ID_OVERLAYBITMAPEXPRIMITIVE
)
111 } // end of namespace primitive2d
112 } // end of namespace drawinglayer
114 //////////////////////////////////////////////////////////////////////////////
116 namespace drawinglayer
118 namespace primitive2d
120 OverlayCrosshairPrimitive::OverlayCrosshairPrimitive(
121 const basegfx::B2DPoint
& rBasePosition
,
122 const basegfx::BColor
& rRGBColorA
,
123 const basegfx::BColor
& rRGBColorB
,
124 double fDiscreteDashLength
)
125 : ViewportDependentPrimitive2D(),
126 maBasePosition(rBasePosition
),
127 maRGBColorA(rRGBColorA
),
128 maRGBColorB(rRGBColorB
),
129 mfDiscreteDashLength(fDiscreteDashLength
)
132 Primitive2DSequence
OverlayCrosshairPrimitive::createLocalDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
134 // use the prepared Viewport information accessible using getViewport()
135 Primitive2DSequence aRetval
;
137 if(!getViewport().isEmpty())
140 basegfx::B2DPolygon aPolygon
;
142 aPolygon
.append(basegfx::B2DPoint(getViewport().getMinX(), getBasePosition().getY()));
143 aPolygon
.append(basegfx::B2DPoint(getViewport().getMaxX(), getBasePosition().getY()));
145 aRetval
[0] = Primitive2DReference(
146 new PolygonMarkerPrimitive2D(
150 getDiscreteDashLength()));
153 aPolygon
.append(basegfx::B2DPoint(getBasePosition().getX(), getViewport().getMinY()));
154 aPolygon
.append(basegfx::B2DPoint(getBasePosition().getX(), getViewport().getMaxY()));
156 aRetval
[1] = Primitive2DReference(
157 new PolygonMarkerPrimitive2D(
161 getDiscreteDashLength()));
167 bool OverlayCrosshairPrimitive::operator==( const BasePrimitive2D
& rPrimitive
) const
169 if(ViewportDependentPrimitive2D::operator==(rPrimitive
))
171 const OverlayCrosshairPrimitive
& rCompare
= static_cast< const OverlayCrosshairPrimitive
& >(rPrimitive
);
173 return (getBasePosition() == rCompare
.getBasePosition()
174 && getRGBColorA() == rCompare
.getRGBColorA()
175 && getRGBColorB() == rCompare
.getRGBColorB()
176 && getDiscreteDashLength() == rCompare
.getDiscreteDashLength());
182 ImplPrimitrive2DIDBlock(OverlayCrosshairPrimitive
, PRIMITIVE2D_ID_OVERLAYCROSSHAIRPRIMITIVE
)
184 } // end of namespace primitive2d
185 } // end of namespace drawinglayer
187 //////////////////////////////////////////////////////////////////////////////
189 namespace drawinglayer
191 namespace primitive2d
193 OverlayHatchRectanglePrimitive::OverlayHatchRectanglePrimitive(
194 const basegfx::B2DRange
& rObjectRange
,
195 double fDiscreteHatchDistance
,
196 double fHatchRotation
,
197 const basegfx::BColor
& rHatchColor
,
198 double fDiscreteGrow
,
199 double fDiscreteShrink
,
201 : DiscreteMetricDependentPrimitive2D(),
202 maObjectRange(rObjectRange
),
203 mfDiscreteHatchDistance(fDiscreteHatchDistance
),
204 mfHatchRotation(fHatchRotation
),
205 maHatchColor(rHatchColor
),
206 mfDiscreteGrow(fDiscreteGrow
),
207 mfDiscreteShrink(fDiscreteShrink
),
208 mfRotation(fRotation
)
211 Primitive2DSequence
OverlayHatchRectanglePrimitive::createLocalDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
213 Primitive2DSequence aRetval
;
215 if(basegfx::fTools::more(getDiscreteUnit(), 0.0))
217 basegfx::B2DRange
aInnerRange(getObjectRange());
218 basegfx::B2DRange
aOuterRange(getObjectRange());
219 basegfx::B2DPolyPolygon aHatchPolyPolygon
;
221 aOuterRange
.grow(getDiscreteUnit() * getDiscreteGrow());
222 aInnerRange
.grow(getDiscreteUnit() * -getDiscreteShrink());
224 aHatchPolyPolygon
.append(basegfx::tools::createPolygonFromRect(aOuterRange
));
226 if(!aInnerRange
.isEmpty())
228 aHatchPolyPolygon
.append(basegfx::tools::createPolygonFromRect(aInnerRange
));
231 if(!basegfx::fTools::equalZero(getRotation()))
233 basegfx::B2DHomMatrix aTransform
;
235 aTransform
.translate(-getObjectRange().getMinX(), -getObjectRange().getMinY());
236 aTransform
.rotate(getRotation());
237 aTransform
.translate(getObjectRange().getMinX(), getObjectRange().getMinY());
239 aHatchPolyPolygon
.transform(aTransform
);
242 const basegfx::BColor
aEmptyColor(0.0, 0.0, 0.0);
243 const drawinglayer::attribute::FillHatchAttribute
aFillHatchAttribute(
244 drawinglayer::attribute::HATCHSTYLE_SINGLE
,
245 getDiscreteHatchDistance() * getDiscreteUnit(),
246 getHatchRotation() - getRotation(),
249 const Primitive2DReference
aPrimitive(
250 new PolyPolygonHatchPrimitive2D(
253 aFillHatchAttribute
));
255 aRetval
= Primitive2DSequence(&aPrimitive
, 1);
261 bool OverlayHatchRectanglePrimitive::operator==( const BasePrimitive2D
& rPrimitive
) const
263 if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive
))
265 const OverlayHatchRectanglePrimitive
& rCompare
= static_cast< const OverlayHatchRectanglePrimitive
& >(rPrimitive
);
267 return (getObjectRange() == rCompare
.getObjectRange()
268 && getDiscreteHatchDistance() == rCompare
.getDiscreteHatchDistance()
269 && getHatchRotation() == rCompare
.getHatchRotation()
270 && getHatchColor() == rCompare
.getHatchColor()
271 && getDiscreteGrow() == rCompare
.getDiscreteGrow()
272 && getDiscreteShrink() == rCompare
.getDiscreteShrink()
273 && getRotation() == rCompare
.getRotation());
279 ImplPrimitrive2DIDBlock(OverlayHatchRectanglePrimitive
, PRIMITIVE2D_ID_OVERLAYHATCHRECTANGLEPRIMITIVE
)
281 } // end of namespace primitive2d
282 } // end of namespace drawinglayer
284 //////////////////////////////////////////////////////////////////////////////
286 namespace drawinglayer
288 namespace primitive2d
290 OverlayHelplineStripedPrimitive::OverlayHelplineStripedPrimitive(
291 const basegfx::B2DPoint
& rBasePosition
,
292 HelplineStyle eStyle
,
293 const basegfx::BColor
& rRGBColorA
,
294 const basegfx::BColor
& rRGBColorB
,
295 double fDiscreteDashLength
)
296 : ViewportDependentPrimitive2D(),
297 maBasePosition(rBasePosition
),
299 maRGBColorA(rRGBColorA
),
300 maRGBColorB(rRGBColorB
),
301 mfDiscreteDashLength(fDiscreteDashLength
)
304 Primitive2DSequence
OverlayHelplineStripedPrimitive::createLocalDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
306 // use the prepared Viewport information accessible using getViewport()
307 Primitive2DSequence aRetval
;
309 if(!getViewport().isEmpty())
313 case HELPLINESTYLE_VERTICAL
:
316 basegfx::B2DPolygon aLine
;
318 aLine
.append(basegfx::B2DPoint(getBasePosition().getX(), getViewport().getMinY()));
319 aLine
.append(basegfx::B2DPoint(getBasePosition().getX(), getViewport().getMaxY()));
321 aRetval
[0] = Primitive2DReference(
322 new PolygonMarkerPrimitive2D(
326 getDiscreteDashLength()));
330 case HELPLINESTYLE_HORIZONTAL
:
333 basegfx::B2DPolygon aLine
;
335 aLine
.append(basegfx::B2DPoint(getViewport().getMinX(), getBasePosition().getY()));
336 aLine
.append(basegfx::B2DPoint(getViewport().getMaxX(), getBasePosition().getY()));
338 aRetval
[0] = Primitive2DReference(
339 new PolygonMarkerPrimitive2D(
343 getDiscreteDashLength()));
347 default: // case HELPLINESTYLE_POINT :
349 const double fDiscreteUnit((rViewInformation
.getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 0.0)).getLength());
351 basegfx::B2DPolygon aLineA
, aLineB
;
353 aLineA
.append(basegfx::B2DPoint(getBasePosition().getX(), getBasePosition().getY() - fDiscreteUnit
));
354 aLineA
.append(basegfx::B2DPoint(getBasePosition().getX(), getBasePosition().getY() + fDiscreteUnit
));
356 aRetval
[0] = Primitive2DReference(
357 new PolygonMarkerPrimitive2D(
361 getDiscreteDashLength()));
363 aLineB
.append(basegfx::B2DPoint(getBasePosition().getX() - fDiscreteUnit
, getBasePosition().getY()));
364 aLineB
.append(basegfx::B2DPoint(getBasePosition().getX() + fDiscreteUnit
, getBasePosition().getY()));
366 aRetval
[1] = Primitive2DReference(
367 new PolygonMarkerPrimitive2D(
371 getDiscreteDashLength()));
381 bool OverlayHelplineStripedPrimitive::operator==( const BasePrimitive2D
& rPrimitive
) const
383 if(ViewportDependentPrimitive2D::operator==(rPrimitive
))
385 const OverlayHelplineStripedPrimitive
& rCompare
= static_cast< const OverlayHelplineStripedPrimitive
& >(rPrimitive
);
387 return (getBasePosition() == rCompare
.getBasePosition()
388 && getStyle() == rCompare
.getStyle()
389 && getRGBColorA() == rCompare
.getRGBColorA()
390 && getRGBColorB() == rCompare
.getRGBColorB()
391 && getDiscreteDashLength() == rCompare
.getDiscreteDashLength());
397 ImplPrimitrive2DIDBlock(OverlayHelplineStripedPrimitive
, PRIMITIVE2D_ID_OVERLAYHELPLINESTRIPEDPRIMITIVE
)
399 } // end of namespace primitive2d
400 } // end of namespace drawinglayer
402 //////////////////////////////////////////////////////////////////////////////
404 namespace drawinglayer
406 namespace primitive2d
408 OverlayRollingRectanglePrimitive::OverlayRollingRectanglePrimitive(
409 const basegfx::B2DRange
& aRollingRectangle
,
410 const basegfx::BColor
& rRGBColorA
,
411 const basegfx::BColor
& rRGBColorB
,
412 double fDiscreteDashLength
)
413 : ViewportDependentPrimitive2D(),
414 maRollingRectangle(aRollingRectangle
),
415 maRGBColorA(rRGBColorA
),
416 maRGBColorB(rRGBColorB
),
417 mfDiscreteDashLength(fDiscreteDashLength
)
420 Primitive2DSequence
OverlayRollingRectanglePrimitive::createLocalDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
422 // use the prepared Viewport information accessible using getViewport()
423 Primitive2DSequence aRetval
;
425 if(!getViewport().isEmpty())
427 basegfx::B2DPolygon aLine
;
431 aLine
.append(basegfx::B2DPoint(getViewport().getMinX(), getRollingRectangle().getMinY()));
432 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getRollingRectangle().getMinY()));
433 aRetval
[0] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
436 aLine
.append(basegfx::B2DPoint(getViewport().getMinX(), getRollingRectangle().getMaxY()));
437 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getRollingRectangle().getMaxY()));
438 aRetval
[1] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
442 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getRollingRectangle().getMinY()));
443 aLine
.append(basegfx::B2DPoint(getViewport().getMaxX(), getRollingRectangle().getMinY()));
444 aRetval
[2] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
447 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getRollingRectangle().getMaxY()));
448 aLine
.append(basegfx::B2DPoint(getViewport().getMaxX(), getRollingRectangle().getMaxY()));
449 aRetval
[3] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
453 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getViewport().getMinY()));
454 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getRollingRectangle().getMinY()));
455 aRetval
[4] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
458 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getViewport().getMinY()));
459 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getRollingRectangle().getMinY()));
460 aRetval
[5] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
464 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getRollingRectangle().getMaxY()));
465 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getViewport().getMaxY()));
466 aRetval
[6] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
469 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getRollingRectangle().getMaxY()));
470 aLine
.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getViewport().getMaxY()));
471 aRetval
[7] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine
, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
477 bool OverlayRollingRectanglePrimitive::operator==( const BasePrimitive2D
& rPrimitive
) const
479 if(ViewportDependentPrimitive2D::operator==(rPrimitive
))
481 const OverlayRollingRectanglePrimitive
& rCompare
= static_cast< const OverlayRollingRectanglePrimitive
& >(rPrimitive
);
483 return (getRollingRectangle() == rCompare
.getRollingRectangle()
484 && getRGBColorA() == rCompare
.getRGBColorA()
485 && getRGBColorB() == rCompare
.getRGBColorB()
486 && getDiscreteDashLength() == rCompare
.getDiscreteDashLength());
492 ImplPrimitrive2DIDBlock(OverlayRollingRectanglePrimitive
, PRIMITIVE2D_ID_OVERLAYROLLINGRECTANGLEPRIMITIVE
)
494 } // end of namespace primitive2d
495 } // end of namespace drawinglayer
497 //////////////////////////////////////////////////////////////////////////////