xref: /AOO41X/main/svx/source/sdr/primitive2d/sdrprimitivetools.cxx (revision 330b556ef3b61775790d8c8a17a4c7863e4a22ad)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_svx.hxx"
25cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrprimitivetools.hxx>
26cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
27cdf0e10cSrcweir #include <osl/mutex.hxx>
28cdf0e10cSrcweir #include <vcl/lazydelete.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir // helper methods
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace drawinglayer
33cdf0e10cSrcweir {
34cdf0e10cSrcweir 	namespace primitive2d
35cdf0e10cSrcweir 	{
createDefaultCross_3x3(const basegfx::BColor & rBColor)36cdf0e10cSrcweir 		BitmapEx createDefaultCross_3x3(const basegfx::BColor& rBColor)
37cdf0e10cSrcweir 		{
38cdf0e10cSrcweir 			static vcl::DeleteOnDeinit< BitmapEx > aRetVal(0);
39cdf0e10cSrcweir 			static basegfx::BColor aColor;
40cdf0e10cSrcweir 			::osl::Mutex m_mutex;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 			if(!aRetVal.get() || rBColor != aColor)
43cdf0e10cSrcweir 			{
44cdf0e10cSrcweir 				// copy values
45cdf0e10cSrcweir 				aColor = rBColor;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 				// create bitmap
48cdf0e10cSrcweir 				Bitmap aContent(Size(3, 3), 24);
49cdf0e10cSrcweir 				Bitmap aMask(Size(3, 3), 1);
50cdf0e10cSrcweir 				BitmapWriteAccess* pWContent = aContent.AcquireWriteAccess();
51cdf0e10cSrcweir 				BitmapWriteAccess* pWMask = aMask.AcquireWriteAccess();
52cdf0e10cSrcweir 				OSL_ENSURE(pWContent && pWMask, "No WriteAccess to bitmap (!)");
53cdf0e10cSrcweir 				const Color aVCLColor(aColor);
54cdf0e10cSrcweir 				const BitmapColor aPixColor(aVCLColor);
55cdf0e10cSrcweir 				const BitmapColor aMaskColor(0x01);
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 				// Y,X unusual order (!)
58cdf0e10cSrcweir 				pWContent->SetPixel(0, 1, aPixColor);
59cdf0e10cSrcweir 				pWContent->SetPixel(1, 0, aPixColor);
60cdf0e10cSrcweir 				pWContent->SetPixel(1, 1, aPixColor);
61cdf0e10cSrcweir 				pWContent->SetPixel(1, 2, aPixColor);
62cdf0e10cSrcweir 				pWContent->SetPixel(2, 1, aPixColor);
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 				pWMask->SetPixel(0, 0, aMaskColor);
65cdf0e10cSrcweir 				pWMask->SetPixel(0, 2, aMaskColor);
66cdf0e10cSrcweir 				pWMask->SetPixel(2, 0, aMaskColor);
67cdf0e10cSrcweir 				pWMask->SetPixel(2, 2, aMaskColor);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 				aContent.ReleaseAccess(pWContent);
70cdf0e10cSrcweir 				aMask.ReleaseAccess(pWMask);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 				// create and exchange at aRetVal
73cdf0e10cSrcweir 				delete aRetVal.set(new BitmapEx(aContent, aMask));
74cdf0e10cSrcweir 			}
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 			return aRetVal.get() ? *aRetVal.get() : BitmapEx();
77cdf0e10cSrcweir 		}
78cdf0e10cSrcweir 
79*330b556eSmseidel // TODO: Use the bitmap (Glue_Unselected) from markers*.png instead, so it will be part of the icon theme
createDefaultGluepoint_9x9(const basegfx::BColor & rBColorA,const basegfx::BColor & rBColorB)80b5697104Smseidel 		BitmapEx createDefaultGluepoint_9x9(const basegfx::BColor& rBColorA, const basegfx::BColor& rBColorB)
81cdf0e10cSrcweir 		{
82cdf0e10cSrcweir 			static vcl::DeleteOnDeinit< BitmapEx > aRetVal(0);
83cdf0e10cSrcweir 			static basegfx::BColor aColorA;
84cdf0e10cSrcweir 			static basegfx::BColor aColorB;
85cdf0e10cSrcweir 			::osl::Mutex m_mutex;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 			if(!aRetVal.get() || rBColorA != aColorA || rBColorB != aColorB)
88cdf0e10cSrcweir 			{
89cdf0e10cSrcweir 				// copy values
90cdf0e10cSrcweir 				aColorA = rBColorA;
91cdf0e10cSrcweir 				aColorB = rBColorB;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 				// create bitmap
94b5697104Smseidel 				Bitmap aContent(Size(9, 9), 24);
95b5697104Smseidel 				Bitmap aMask(Size(9, 9), 1);
96cdf0e10cSrcweir 				BitmapWriteAccess* pWContent = aContent.AcquireWriteAccess();
97cdf0e10cSrcweir 				BitmapWriteAccess* pWMask = aMask.AcquireWriteAccess();
98cdf0e10cSrcweir 				OSL_ENSURE(pWContent && pWMask, "No WriteAccess to bitmap (!)");
99cdf0e10cSrcweir 				const Color aColA(aColorA);
100cdf0e10cSrcweir 				const Color aColB(aColorB);
101cdf0e10cSrcweir 				const BitmapColor aPixColorA(aColA);
102cdf0e10cSrcweir 				const BitmapColor aPixColorB(aColB);
103cdf0e10cSrcweir 				const BitmapColor aMaskColor(0x01);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 				// Y,X unusual order (!)
106*330b556eSmseidel 				pWContent->SetPixel(0, 0, aPixColorA);
107*330b556eSmseidel 				pWContent->SetPixel(0, 1, aPixColorA);
108*330b556eSmseidel 				pWContent->SetPixel(0, 2, aPixColorA);
109*330b556eSmseidel 				pWContent->SetPixel(0, 3, aPixColorA);
110*330b556eSmseidel 				pWContent->SetPixel(0, 4, aPixColorA);
111*330b556eSmseidel 				pWContent->SetPixel(0, 5, aPixColorA);
112*330b556eSmseidel 				pWContent->SetPixel(0, 6, aPixColorA);
113*330b556eSmseidel 				pWContent->SetPixel(0, 7, aPixColorA);
114*330b556eSmseidel 				pWContent->SetPixel(0, 8, aPixColorA);
115*330b556eSmseidel 				pWContent->SetPixel(1, 0, aPixColorA);
116cdf0e10cSrcweir 				pWContent->SetPixel(1, 2, aPixColorA);
117b593925bSmseidel 				pWContent->SetPixel(1, 3, aPixColorA);
118cdf0e10cSrcweir 				pWContent->SetPixel(1, 4, aPixColorA);
119b5697104Smseidel 				pWContent->SetPixel(1, 5, aPixColorA);
120cdf0e10cSrcweir 				pWContent->SetPixel(1, 6, aPixColorA);
121*330b556eSmseidel 				pWContent->SetPixel(1, 8, aPixColorA);
122*330b556eSmseidel 				pWContent->SetPixel(2, 0, aPixColorA);
123cdf0e10cSrcweir 				pWContent->SetPixel(2, 1, aPixColorA);
124cdf0e10cSrcweir 				pWContent->SetPixel(2, 3, aPixColorA);
125b5697104Smseidel 				pWContent->SetPixel(2, 4, aPixColorA);
126cdf0e10cSrcweir 				pWContent->SetPixel(2, 5, aPixColorA);
127b5697104Smseidel 				pWContent->SetPixel(2, 7, aPixColorA);
128*330b556eSmseidel 				pWContent->SetPixel(2, 8, aPixColorA);
129*330b556eSmseidel 				pWContent->SetPixel(3, 0, aPixColorA);
130b593925bSmseidel 				pWContent->SetPixel(3, 1, aPixColorA);
131cdf0e10cSrcweir 				pWContent->SetPixel(3, 2, aPixColorA);
132cdf0e10cSrcweir 				pWContent->SetPixel(3, 4, aPixColorA);
133b593925bSmseidel 				pWContent->SetPixel(3, 6, aPixColorA);
134b5697104Smseidel 				pWContent->SetPixel(3, 7, aPixColorA);
135*330b556eSmseidel 				pWContent->SetPixel(3, 8, aPixColorA);
136*330b556eSmseidel 				pWContent->SetPixel(4, 0, aPixColorA);
137cdf0e10cSrcweir 				pWContent->SetPixel(4, 1, aPixColorA);
138b5697104Smseidel 				pWContent->SetPixel(4, 2, aPixColorA);
139cdf0e10cSrcweir 				pWContent->SetPixel(4, 3, aPixColorA);
140cdf0e10cSrcweir 				pWContent->SetPixel(4, 5, aPixColorA);
141b593925bSmseidel 				pWContent->SetPixel(4, 6, aPixColorA);
142b5697104Smseidel 				pWContent->SetPixel(4, 7, aPixColorA);
143*330b556eSmseidel 				pWContent->SetPixel(4, 8, aPixColorA);
144*330b556eSmseidel 				pWContent->SetPixel(5, 0, aPixColorA);
145b5697104Smseidel 				pWContent->SetPixel(5, 1, aPixColorA);
146cdf0e10cSrcweir 				pWContent->SetPixel(5, 2, aPixColorA);
147cdf0e10cSrcweir 				pWContent->SetPixel(5, 4, aPixColorA);
148cdf0e10cSrcweir 				pWContent->SetPixel(5, 6, aPixColorA);
149b5697104Smseidel 				pWContent->SetPixel(5, 7, aPixColorA);
150*330b556eSmseidel 				pWContent->SetPixel(5, 8, aPixColorA);
151*330b556eSmseidel 				pWContent->SetPixel(6, 0, aPixColorA);
152cdf0e10cSrcweir 				pWContent->SetPixel(6, 1, aPixColorA);
153b593925bSmseidel 				pWContent->SetPixel(6, 3, aPixColorA);
154b593925bSmseidel 				pWContent->SetPixel(6, 4, aPixColorA);
155cdf0e10cSrcweir 				pWContent->SetPixel(6, 5, aPixColorA);
156b5697104Smseidel 				pWContent->SetPixel(6, 7, aPixColorA);
157*330b556eSmseidel 				pWContent->SetPixel(6, 8, aPixColorA);
158*330b556eSmseidel 				pWContent->SetPixel(7, 0, aPixColorA);
159b5697104Smseidel 				pWContent->SetPixel(7, 2, aPixColorA);
160b5697104Smseidel 				pWContent->SetPixel(7, 3, aPixColorA);
161b5697104Smseidel 				pWContent->SetPixel(7, 4, aPixColorA);
162b5697104Smseidel 				pWContent->SetPixel(7, 5, aPixColorA);
163b5697104Smseidel 				pWContent->SetPixel(7, 6, aPixColorA);
164*330b556eSmseidel 				pWContent->SetPixel(7, 8, aPixColorA);
165*330b556eSmseidel 				pWContent->SetPixel(8, 0, aPixColorA);
166*330b556eSmseidel 				pWContent->SetPixel(8, 1, aPixColorA);
167*330b556eSmseidel 				pWContent->SetPixel(8, 2, aPixColorA);
168*330b556eSmseidel 				pWContent->SetPixel(8, 3, aPixColorA);
169*330b556eSmseidel 				pWContent->SetPixel(8, 4, aPixColorA);
170*330b556eSmseidel 				pWContent->SetPixel(8, 5, aPixColorA);
171*330b556eSmseidel 				pWContent->SetPixel(8, 6, aPixColorA);
172*330b556eSmseidel 				pWContent->SetPixel(8, 7, aPixColorA);
173*330b556eSmseidel 				pWContent->SetPixel(8, 8, aPixColorA);
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 				pWContent->SetPixel(1, 1, aPixColorB);
176b5697104Smseidel 				pWContent->SetPixel(1, 7, aPixColorB);
177cdf0e10cSrcweir 				pWContent->SetPixel(2, 2, aPixColorB);
178b5697104Smseidel 				pWContent->SetPixel(2, 6, aPixColorB);
179cdf0e10cSrcweir 				pWContent->SetPixel(3, 3, aPixColorB);
180b5697104Smseidel 				pWContent->SetPixel(3, 5, aPixColorB);
181cdf0e10cSrcweir 				pWContent->SetPixel(4, 4, aPixColorB);
182b5697104Smseidel 				pWContent->SetPixel(5, 3, aPixColorB);
183cdf0e10cSrcweir 				pWContent->SetPixel(5, 5, aPixColorB);
184b5697104Smseidel 				pWContent->SetPixel(6, 2, aPixColorB);
185b5697104Smseidel 				pWContent->SetPixel(6, 6, aPixColorB);
186b5697104Smseidel 				pWContent->SetPixel(7, 1, aPixColorB);
187b5697104Smseidel 				pWContent->SetPixel(7, 7, aPixColorB);
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 				aContent.ReleaseAccess(pWContent);
190cdf0e10cSrcweir 				aMask.ReleaseAccess(pWMask);
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 				// create and exchange at aRetVal
193cdf0e10cSrcweir 				delete aRetVal.set(new BitmapEx(aContent, aMask));
194cdf0e10cSrcweir 			}
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 			return aRetVal.get() ? *aRetVal.get() : BitmapEx();
197cdf0e10cSrcweir 		}
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 	} // end of namespace primitive2d
200cdf0e10cSrcweir } // end of namespace drawinglayer
201cdf0e10cSrcweir 
202*330b556eSmseidel /* vim: set noet sw=4 ts=4: */
203