1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 #include <svx/sdr/overlay/overlayrollingrectangle.hxx>
27 #include <tools/gen.hxx>
28 #include <vcl/salbtype.hxx>
29 #include <vcl/outdev.hxx>
30 #include <basegfx/matrix/b2dhommatrix.hxx>
31 #include <svx/sdr/overlay/overlaytools.hxx>
32 #include <svx/sdr/overlay/overlaymanager.hxx>
33 #include <basegfx/polygon/b2dpolygontools.hxx>
34 #include <basegfx/polygon/b2dpolygon.hxx>
35 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
36 
37 //////////////////////////////////////////////////////////////////////////////
38 
39 namespace sdr
40 {
41 	namespace overlay
42 	{
createOverlayObjectPrimitive2DSequence()43 		drawinglayer::primitive2d::Primitive2DSequence OverlayRollingRectangleStriped::createOverlayObjectPrimitive2DSequence()
44 		{
45 			drawinglayer::primitive2d::Primitive2DSequence aRetval;
46 
47             if(getOverlayManager() && (getShowBounds() || getExtendedLines()))
48             {
49                 const basegfx::BColor aRGBColorA(getOverlayManager()->getStripeColorA().getBColor());
50                 const basegfx::BColor aRGBColorB(getOverlayManager()->getStripeColorB().getBColor());
51                 const double fStripeLengthPixel(getOverlayManager()->getStripeLengthPixel());
52                 const basegfx::B2DRange aRollingRectangle(getBasePosition(), getSecondPosition());
53 
54                 if(getShowBounds())
55                 {
56                     // view-independent part, create directly
57                     const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(aRollingRectangle));
58 
59                     aRetval.realloc(2);
60                     aRetval[0] = new drawinglayer::primitive2d::PolyPolygonMarkerPrimitive2D(
61                         basegfx::B2DPolyPolygon(aPolygon),
62                         aRGBColorA,
63                         aRGBColorB,
64                         fStripeLengthPixel);
65 
66                     const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
67                     const basegfx::BColor aHilightColor(aSvtOptionsDrawinglayer.getHilightColor().getBColor());
68                     const double fTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() * 0.01);
69 
70                     aRetval[1] = new drawinglayer::primitive2d::PolyPolygonSelectionPrimitive2D(
71                         basegfx::B2DPolyPolygon(aPolygon),
72                         aHilightColor,
73                         fTransparence,
74                         3.0,
75                         false);
76                 }
77 
78                 if(getExtendedLines())
79                 {
80                     // view-dependent part, use helper primitive
81                     const drawinglayer::primitive2d::Primitive2DReference aReference(
82                         new drawinglayer::primitive2d::OverlayRollingRectanglePrimitive(
83                             aRollingRectangle,
84                             aRGBColorA,
85                             aRGBColorB,
86                             fStripeLengthPixel));
87 
88                     drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aReference);
89                 }
90             }
91 
92             return aRetval;
93 		}
94 
stripeDefinitionHasChanged()95 		void OverlayRollingRectangleStriped::stripeDefinitionHasChanged()
96 		{
97 			// react on OverlayManager's stripe definition change
98 			objectChange();
99 		}
100 
OverlayRollingRectangleStriped(const basegfx::B2DPoint & rBasePos,const basegfx::B2DPoint & rSecondPos,bool bExtendedLines,bool bShowBounds)101 		OverlayRollingRectangleStriped::OverlayRollingRectangleStriped(
102 			const basegfx::B2DPoint& rBasePos,
103 			const basegfx::B2DPoint& rSecondPos,
104 			bool bExtendedLines,
105 			bool bShowBounds)
106 		:	OverlayObjectWithBasePosition(rBasePos, Color(COL_BLACK)),
107 			maSecondPosition(rSecondPos),
108 			mbExtendedLines(bExtendedLines),
109 			mbShowBounds(bShowBounds)
110 		{
111 		}
112 
~OverlayRollingRectangleStriped()113 		OverlayRollingRectangleStriped::~OverlayRollingRectangleStriped()
114 		{
115 		}
116 
setSecondPosition(const basegfx::B2DPoint & rNew)117 		void OverlayRollingRectangleStriped::setSecondPosition(const basegfx::B2DPoint& rNew)
118 		{
119 			if(rNew != maSecondPosition)
120 			{
121 				// remember new value
122 				maSecondPosition = rNew;
123 
124 				// register change (after change)
125 				objectChange();
126 			}
127 		}
128 
setExtendedLines(bool bNew)129 		void OverlayRollingRectangleStriped::setExtendedLines(bool bNew)
130 		{
131 			if(bNew != (bool)mbExtendedLines)
132 			{
133 				// remember new value
134 				mbExtendedLines = bNew;
135 
136 				// register change (after change)
137 				objectChange();
138 			}
139 		}
140 
setShowBounds(bool bNew)141 		void OverlayRollingRectangleStriped::setShowBounds(bool bNew)
142 		{
143 			if(bNew != (bool)mbShowBounds)
144 			{
145 				// remember new value
146 				mbShowBounds = bNew;
147 
148 				// register change (after change)
149 				objectChange();
150 			}
151 		}
152 	} // end of namespace overlay
153 } // end of namespace sdr
154 
155 //////////////////////////////////////////////////////////////////////////////
156 // eof
157