update dev300-m58
[ooovba.git] / svx / source / sdr / primitive2d / sdrprimitivetools.cxx
blob1066a988ca5f3fd63d0e6683583bb887d14a9b4f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: primitivefactory2d.cxx,v $
11 * $Revision: 1.2 $
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>
41 //////////////////////////////////////////////////////////////////////////////
42 // helper methods
44 namespace drawinglayer
46 namespace primitive2d
48 BitmapEx createDefaultCross_3x3(const basegfx::BColor& rBColor)
50 static BitmapEx* pRetVal = NULL;
51 static basegfx::BColor aColor;
52 ::osl::Mutex m_mutex;
54 if(pRetVal == NULL || rBColor != aColor)
56 // copy values
57 aColor = rBColor;
59 // create bitmap
60 Bitmap aContent(Size(3, 3), 24);
61 Bitmap aMask(Size(3, 3), 1);
62 BitmapWriteAccess* pWContent = aContent.AcquireWriteAccess();
63 BitmapWriteAccess* pWMask = aMask.AcquireWriteAccess();
64 OSL_ENSURE(pWContent && pWMask, "No WriteAccess to bitmap (!)");
65 const Color aVCLColor(aColor);
66 const BitmapColor aPixColor(aVCLColor);
67 const BitmapColor aMaskColor(0x01);
69 // Y,X unusual order (!)
70 pWContent->SetPixel(0, 1, aPixColor);
71 pWContent->SetPixel(1, 0, aPixColor);
72 pWContent->SetPixel(1, 1, aPixColor);
73 pWContent->SetPixel(1, 2, aPixColor);
74 pWContent->SetPixel(2, 1, aPixColor);
76 pWMask->SetPixel(0, 0, aMaskColor);
77 pWMask->SetPixel(0, 2, aMaskColor);
78 pWMask->SetPixel(2, 0, aMaskColor);
79 pWMask->SetPixel(2, 2, aMaskColor);
81 aContent.ReleaseAccess(pWContent);
82 aMask.ReleaseAccess(pWMask);
84 if( pRetVal )
85 delete pRetVal;
87 pRetVal = new BitmapEx(aContent, aMask);
90 return *pRetVal;
93 BitmapEx createDefaultGluepoint_7x7(const basegfx::BColor& rBColorA, const basegfx::BColor& rBColorB)
95 static BitmapEx* pRetVal = NULL;
96 static basegfx::BColor aColorA;
97 static basegfx::BColor aColorB;
98 ::osl::Mutex m_mutex;
100 if(pRetVal == NULL || rBColorA != aColorA || rBColorB != aColorB)
102 // copy values
103 aColorA = rBColorA;
104 aColorB = rBColorB;
106 // create bitmap
107 Bitmap aContent(Size(7, 7), 24);
108 Bitmap aMask(Size(7, 7), 1);
109 BitmapWriteAccess* pWContent = aContent.AcquireWriteAccess();
110 BitmapWriteAccess* pWMask = aMask.AcquireWriteAccess();
111 OSL_ENSURE(pWContent && pWMask, "No WriteAccess to bitmap (!)");
112 const Color aColA(aColorA);
113 const Color aColB(aColorB);
114 const BitmapColor aPixColorA(aColA);
115 const BitmapColor aPixColorB(aColB);
116 const BitmapColor aMaskColor(0x01);
118 // Y,X unusual order (!)
119 pWContent->SetPixel(0, 1, aPixColorA);
120 pWContent->SetPixel(0, 5, aPixColorA);
121 pWContent->SetPixel(1, 0, aPixColorA);
122 pWContent->SetPixel(1, 2, aPixColorA);
123 pWContent->SetPixel(1, 4, aPixColorA);
124 pWContent->SetPixel(1, 6, aPixColorA);
125 pWContent->SetPixel(2, 1, aPixColorA);
126 pWContent->SetPixel(2, 3, aPixColorA);
127 pWContent->SetPixel(2, 5, aPixColorA);
128 pWContent->SetPixel(3, 2, aPixColorA);
129 pWContent->SetPixel(3, 4, aPixColorA);
130 pWContent->SetPixel(4, 1, aPixColorA);
131 pWContent->SetPixel(4, 3, aPixColorA);
132 pWContent->SetPixel(4, 5, aPixColorA);
133 pWContent->SetPixel(5, 0, aPixColorA);
134 pWContent->SetPixel(5, 2, aPixColorA);
135 pWContent->SetPixel(5, 4, aPixColorA);
136 pWContent->SetPixel(5, 6, aPixColorA);
137 pWContent->SetPixel(6, 1, aPixColorA);
138 pWContent->SetPixel(6, 5, aPixColorA);
140 pWContent->SetPixel(1, 1, aPixColorB);
141 pWContent->SetPixel(1, 5, aPixColorB);
142 pWContent->SetPixel(2, 2, aPixColorB);
143 pWContent->SetPixel(2, 4, aPixColorB);
144 pWContent->SetPixel(3, 3, aPixColorB);
145 pWContent->SetPixel(4, 2, aPixColorB);
146 pWContent->SetPixel(4, 4, aPixColorB);
147 pWContent->SetPixel(5, 1, aPixColorB);
148 pWContent->SetPixel(5, 5, aPixColorB);
150 pWMask->SetPixel(0, 0, aMaskColor);
151 pWMask->SetPixel(0, 2, aMaskColor);
152 pWMask->SetPixel(0, 3, aMaskColor);
153 pWMask->SetPixel(0, 4, aMaskColor);
154 pWMask->SetPixel(0, 6, aMaskColor);
155 pWMask->SetPixel(1, 3, aMaskColor);
156 pWMask->SetPixel(2, 0, aMaskColor);
157 pWMask->SetPixel(2, 6, aMaskColor);
158 pWMask->SetPixel(3, 0, aMaskColor);
159 pWMask->SetPixel(3, 1, aMaskColor);
160 pWMask->SetPixel(3, 5, aMaskColor);
161 pWMask->SetPixel(3, 6, aMaskColor);
162 pWMask->SetPixel(4, 0, aMaskColor);
163 pWMask->SetPixel(4, 6, aMaskColor);
164 pWMask->SetPixel(5, 3, aMaskColor);
165 pWMask->SetPixel(6, 0, aMaskColor);
166 pWMask->SetPixel(6, 2, aMaskColor);
167 pWMask->SetPixel(6, 3, aMaskColor);
168 pWMask->SetPixel(6, 4, aMaskColor);
169 pWMask->SetPixel(6, 6, aMaskColor);
171 aContent.ReleaseAccess(pWContent);
172 aMask.ReleaseAccess(pWMask);
174 if( pRetVal )
175 delete pRetVal;
177 pRetVal = new BitmapEx(aContent, aMask);
180 return *pRetVal;
183 // #i99123#
184 Primitive2DReference createFallbackHitTestPrimitive(const basegfx::B2DHomMatrix& rMatrix)
186 // create PolygonHairlinePrimitive2D
187 basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0)));
188 aUnitOutline.transform(rMatrix);
189 const basegfx::BColor aBlack(0.0, 0.0, 0.0);
190 const Primitive2DReference xReference(new PolygonHairlinePrimitive2D(aUnitOutline, aBlack));
192 // create HitTestPrimitive2D with it
193 const Primitive2DSequence xSequence(&xReference, 1);
194 return Primitive2DReference(new HitTestPrimitive2D(xSequence));
196 } // end of namespace primitive2d
197 } // end of namespace drawinglayer
199 //////////////////////////////////////////////////////////////////////////////
200 // eof