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: primitivefactory2d.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/primitive2d/sdrprimitivetools.hxx>
34 #include <vcl/bmpacc.hxx>
35 #include <osl/mutex.hxx>
36 #include <basegfx/polygon/b2dpolygon.hxx>
37 #include <basegfx/polygon/b2dpolygontools.hxx>
38 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
39 #include <drawinglayer/primitive2d/hittestprimitive2d.hxx>
40 #include <vcl/lazydelete.hxx>
42 //////////////////////////////////////////////////////////////////////////////
45 namespace drawinglayer
49 BitmapEx
createDefaultCross_3x3(const basegfx::BColor
& rBColor
)
51 static vcl::DeleteOnDeinit
< BitmapEx
> aRetVal(0);
52 static basegfx::BColor aColor
;
55 if(!aRetVal
.get() || rBColor
!= aColor
)
61 Bitmap
aContent(Size(3, 3), 24);
62 Bitmap
aMask(Size(3, 3), 1);
63 BitmapWriteAccess
* pWContent
= aContent
.AcquireWriteAccess();
64 BitmapWriteAccess
* pWMask
= aMask
.AcquireWriteAccess();
65 OSL_ENSURE(pWContent
&& pWMask
, "No WriteAccess to bitmap (!)");
66 const Color
aVCLColor(aColor
);
67 const BitmapColor
aPixColor(aVCLColor
);
68 const BitmapColor
aMaskColor(0x01);
70 // Y,X unusual order (!)
71 pWContent
->SetPixel(0, 1, aPixColor
);
72 pWContent
->SetPixel(1, 0, aPixColor
);
73 pWContent
->SetPixel(1, 1, aPixColor
);
74 pWContent
->SetPixel(1, 2, aPixColor
);
75 pWContent
->SetPixel(2, 1, aPixColor
);
77 pWMask
->SetPixel(0, 0, aMaskColor
);
78 pWMask
->SetPixel(0, 2, aMaskColor
);
79 pWMask
->SetPixel(2, 0, aMaskColor
);
80 pWMask
->SetPixel(2, 2, aMaskColor
);
82 aContent
.ReleaseAccess(pWContent
);
83 aMask
.ReleaseAccess(pWMask
);
85 // create and exchange at aRetVal
86 delete aRetVal
.set(new BitmapEx(aContent
, aMask
));
89 return aRetVal
.get() ? *aRetVal
.get() : BitmapEx();
92 BitmapEx
createDefaultGluepoint_7x7(const basegfx::BColor
& rBColorA
, const basegfx::BColor
& rBColorB
)
94 static vcl::DeleteOnDeinit
< BitmapEx
> aRetVal(0);
95 static basegfx::BColor aColorA
;
96 static basegfx::BColor aColorB
;
99 if(!aRetVal
.get() || rBColorA
!= aColorA
|| rBColorB
!= aColorB
)
106 Bitmap
aContent(Size(7, 7), 24);
107 Bitmap
aMask(Size(7, 7), 1);
108 BitmapWriteAccess
* pWContent
= aContent
.AcquireWriteAccess();
109 BitmapWriteAccess
* pWMask
= aMask
.AcquireWriteAccess();
110 OSL_ENSURE(pWContent
&& pWMask
, "No WriteAccess to bitmap (!)");
111 const Color
aColA(aColorA
);
112 const Color
aColB(aColorB
);
113 const BitmapColor
aPixColorA(aColA
);
114 const BitmapColor
aPixColorB(aColB
);
115 const BitmapColor
aMaskColor(0x01);
117 // Y,X unusual order (!)
118 pWContent
->SetPixel(0, 1, aPixColorA
);
119 pWContent
->SetPixel(0, 5, aPixColorA
);
120 pWContent
->SetPixel(1, 0, aPixColorA
);
121 pWContent
->SetPixel(1, 2, aPixColorA
);
122 pWContent
->SetPixel(1, 4, aPixColorA
);
123 pWContent
->SetPixel(1, 6, aPixColorA
);
124 pWContent
->SetPixel(2, 1, aPixColorA
);
125 pWContent
->SetPixel(2, 3, aPixColorA
);
126 pWContent
->SetPixel(2, 5, aPixColorA
);
127 pWContent
->SetPixel(3, 2, aPixColorA
);
128 pWContent
->SetPixel(3, 4, aPixColorA
);
129 pWContent
->SetPixel(4, 1, aPixColorA
);
130 pWContent
->SetPixel(4, 3, aPixColorA
);
131 pWContent
->SetPixel(4, 5, aPixColorA
);
132 pWContent
->SetPixel(5, 0, aPixColorA
);
133 pWContent
->SetPixel(5, 2, aPixColorA
);
134 pWContent
->SetPixel(5, 4, aPixColorA
);
135 pWContent
->SetPixel(5, 6, aPixColorA
);
136 pWContent
->SetPixel(6, 1, aPixColorA
);
137 pWContent
->SetPixel(6, 5, aPixColorA
);
139 pWContent
->SetPixel(1, 1, aPixColorB
);
140 pWContent
->SetPixel(1, 5, aPixColorB
);
141 pWContent
->SetPixel(2, 2, aPixColorB
);
142 pWContent
->SetPixel(2, 4, aPixColorB
);
143 pWContent
->SetPixel(3, 3, aPixColorB
);
144 pWContent
->SetPixel(4, 2, aPixColorB
);
145 pWContent
->SetPixel(4, 4, aPixColorB
);
146 pWContent
->SetPixel(5, 1, aPixColorB
);
147 pWContent
->SetPixel(5, 5, aPixColorB
);
149 pWMask
->SetPixel(0, 0, aMaskColor
);
150 pWMask
->SetPixel(0, 2, aMaskColor
);
151 pWMask
->SetPixel(0, 3, aMaskColor
);
152 pWMask
->SetPixel(0, 4, aMaskColor
);
153 pWMask
->SetPixel(0, 6, aMaskColor
);
154 pWMask
->SetPixel(1, 3, aMaskColor
);
155 pWMask
->SetPixel(2, 0, aMaskColor
);
156 pWMask
->SetPixel(2, 6, aMaskColor
);
157 pWMask
->SetPixel(3, 0, aMaskColor
);
158 pWMask
->SetPixel(3, 1, aMaskColor
);
159 pWMask
->SetPixel(3, 5, aMaskColor
);
160 pWMask
->SetPixel(3, 6, aMaskColor
);
161 pWMask
->SetPixel(4, 0, aMaskColor
);
162 pWMask
->SetPixel(4, 6, aMaskColor
);
163 pWMask
->SetPixel(5, 3, aMaskColor
);
164 pWMask
->SetPixel(6, 0, aMaskColor
);
165 pWMask
->SetPixel(6, 2, aMaskColor
);
166 pWMask
->SetPixel(6, 3, aMaskColor
);
167 pWMask
->SetPixel(6, 4, aMaskColor
);
168 pWMask
->SetPixel(6, 6, aMaskColor
);
170 aContent
.ReleaseAccess(pWContent
);
171 aMask
.ReleaseAccess(pWMask
);
173 // create and exchange at aRetVal
174 delete aRetVal
.set(new BitmapEx(aContent
, aMask
));
177 return aRetVal
.get() ? *aRetVal
.get() : BitmapEx();
181 Primitive2DReference
createFallbackHitTestPrimitive(const basegfx::B2DHomMatrix
& rMatrix
)
183 // create PolygonHairlinePrimitive2D
184 basegfx::B2DPolygon
aUnitOutline(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0)));
185 aUnitOutline
.transform(rMatrix
);
186 const basegfx::BColor
aBlack(0.0, 0.0, 0.0);
187 const Primitive2DReference
xReference(new PolygonHairlinePrimitive2D(aUnitOutline
, aBlack
));
189 // create HitTestPrimitive2D with it
190 const Primitive2DSequence
xSequence(&xReference
, 1);
191 return Primitive2DReference(new HitTestPrimitive2D(xSequence
));
193 } // end of namespace primitive2d
194 } // end of namespace drawinglayer
196 //////////////////////////////////////////////////////////////////////////////