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 .
20 #include <drawinglayer/primitive2d/helplineprimitive2d.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygonclipper.hxx>
23 #include <drawinglayer/geometry/viewinformation2d.hxx>
24 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
25 #include <drawinglayer/primitive2d/PolygonMarkerPrimitive2D.hxx>
28 using namespace com::sun::star
;
31 namespace drawinglayer::primitive2d
33 void HelplinePrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& rViewInformation
) const
35 if(rViewInformation
.getViewport().isEmpty() || getDirection().equalZero())
38 // position to view coordinates, DashLen and DashLen in logic
39 const basegfx::B2DPoint
aViewPosition(rViewInformation
.getObjectToViewTransformation() * getPosition());
43 default : // HelplineStyle2D::Point
45 const double fViewFixValue(15.0);
46 basegfx::B2DVector
aNormalizedDirection(getDirection());
47 aNormalizedDirection
.normalize();
48 aNormalizedDirection
*= fViewFixValue
;
49 const basegfx::B2DPoint
aStartA(aViewPosition
- aNormalizedDirection
);
50 const basegfx::B2DPoint
aEndA(aViewPosition
+ aNormalizedDirection
);
51 basegfx::B2DPolygon aLineA
;
52 aLineA
.append(aStartA
);
54 aLineA
.transform(rViewInformation
.getInverseObjectToViewTransformation());
55 rContainer
.push_back(new PolygonMarkerPrimitive2D(std::move(aLineA
), getRGBColA(), getRGBColB(), getDiscreteDashLength()));
57 const basegfx::B2DVector
aPerpendicularNormalizedDirection(basegfx::getPerpendicular(aNormalizedDirection
));
58 const basegfx::B2DPoint
aStartB(aViewPosition
- aPerpendicularNormalizedDirection
);
59 const basegfx::B2DPoint
aEndB(aViewPosition
+ aPerpendicularNormalizedDirection
);
60 basegfx::B2DPolygon aLineB
;
61 aLineB
.append(aStartB
);
63 aLineB
.transform(rViewInformation
.getInverseObjectToViewTransformation());
64 rContainer
.push_back(new PolygonMarkerPrimitive2D(std::move(aLineB
), getRGBColA(), getRGBColB(), getDiscreteDashLength()));
68 case HelplineStyle2D::Line
:
70 basegfx::B2DPolygon aLine
;
72 if(basegfx::areParallel(getDirection(), basegfx::B2DVector(1.0, 0.0)))
74 // parallel to X-Axis, get cuts with Y-Axes
75 const double fCutA((rViewInformation
.getDiscreteViewport().getMinX() - aViewPosition
.getX()) / getDirection().getX());
76 const double fCutB((rViewInformation
.getDiscreteViewport().getMaxX() - aViewPosition
.getX()) / getDirection().getX());
77 const basegfx::B2DPoint
aPosA(aViewPosition
+ (fCutA
* getDirection()));
78 const basegfx::B2DPoint
aPosB(aViewPosition
+ (fCutB
* getDirection()));
79 const bool bBothLeft(aPosA
.getX() < rViewInformation
.getDiscreteViewport().getMinX() && aPosB
.getX() < rViewInformation
.getDiscreteViewport().getMinX());
80 const bool bBothRight(aPosA
.getX() > rViewInformation
.getDiscreteViewport().getMaxX() && aPosB
.getX() < rViewInformation
.getDiscreteViewport().getMaxX());
82 if(!bBothLeft
&& !bBothRight
)
90 // get cuts with X-Axes
91 const double fCutA((rViewInformation
.getDiscreteViewport().getMinY() - aViewPosition
.getY()) / getDirection().getY());
92 const double fCutB((rViewInformation
.getDiscreteViewport().getMaxY() - aViewPosition
.getY()) / getDirection().getY());
93 const basegfx::B2DPoint
aPosA(aViewPosition
+ (fCutA
* getDirection()));
94 const basegfx::B2DPoint
aPosB(aViewPosition
+ (fCutB
* getDirection()));
95 const bool bBothAbove(aPosA
.getY() < rViewInformation
.getDiscreteViewport().getMinY() && aPosB
.getY() < rViewInformation
.getDiscreteViewport().getMinY());
96 const bool bBothBelow(aPosA
.getY() > rViewInformation
.getDiscreteViewport().getMaxY() && aPosB
.getY() < rViewInformation
.getDiscreteViewport().getMaxY());
98 if(!bBothAbove
&& !bBothBelow
)
107 // clip against visible area
108 const basegfx::B2DPolyPolygon
aResult(basegfx::utils::clipPolygonOnRange(aLine
, rViewInformation
.getDiscreteViewport(), true, true));
110 for(sal_uInt32
a(0); a
< aResult
.count(); a
++)
112 basegfx::B2DPolygon
aPart(aResult
.getB2DPolygon(a
));
113 aPart
.transform(rViewInformation
.getInverseObjectToViewTransformation());
114 rContainer
.push_back(new PolygonMarkerPrimitive2D(std::move(aPart
), getRGBColA(), getRGBColB(), getDiscreteDashLength()));
123 HelplinePrimitive2D::HelplinePrimitive2D(
124 const basegfx::B2DPoint
& rPosition
,
125 const basegfx::B2DVector
& rDirection
,
126 HelplineStyle2D eStyle
,
127 const basegfx::BColor
& rRGBColA
,
128 const basegfx::BColor
& rRGBColB
,
129 double fDiscreteDashLength
)
130 : maPosition(rPosition
),
131 maDirection(rDirection
),
135 mfDiscreteDashLength(fDiscreteDashLength
)
139 bool HelplinePrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
141 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
143 const HelplinePrimitive2D
& rCompare
= static_cast<const HelplinePrimitive2D
&>(rPrimitive
);
145 return (getPosition() == rCompare
.getPosition()
146 && getDirection() == rCompare
.getDirection()
147 && getStyle() == rCompare
.getStyle()
148 && getRGBColA() == rCompare
.getRGBColA()
149 && getRGBColB() == rCompare
.getRGBColB()
150 && getDiscreteDashLength() == rCompare
.getDiscreteDashLength());
156 void HelplinePrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
158 if(!getBuffered2DDecomposition().empty())
160 if(maLastViewport
!= rViewInformation
.getViewport() || maLastObjectToViewTransformation
!= rViewInformation
.getObjectToViewTransformation())
162 // conditions of last local decomposition have changed, delete
163 const_cast< HelplinePrimitive2D
* >(this)->setBuffered2DDecomposition(Primitive2DContainer());
167 if(getBuffered2DDecomposition().empty())
169 // remember ViewRange and ViewTransformation
170 const_cast< HelplinePrimitive2D
* >(this)->maLastObjectToViewTransformation
= rViewInformation
.getObjectToViewTransformation();
171 const_cast< HelplinePrimitive2D
* >(this)->maLastViewport
= rViewInformation
.getViewport();
174 // use parent implementation
175 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor
, rViewInformation
);
179 sal_uInt32
HelplinePrimitive2D::getPrimitive2DID() const
181 return PRIMITIVE2D_ID_HELPLINEPRIMITIVE2D
;
184 } // end of namespace
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */