xref: /AOO41X/main/svx/source/sdr/primitive2d/sdrprimitivetools.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew 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 //////////////////////////////////////////////////////////////////////////////
31cdf0e10cSrcweir // helper methods
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace drawinglayer
34cdf0e10cSrcweir {
35cdf0e10cSrcweir 	namespace primitive2d
36cdf0e10cSrcweir 	{
37cdf0e10cSrcweir 		BitmapEx createDefaultCross_3x3(const basegfx::BColor& rBColor)
38cdf0e10cSrcweir 		{
39cdf0e10cSrcweir 			static vcl::DeleteOnDeinit< BitmapEx > aRetVal(0);
40cdf0e10cSrcweir 			static basegfx::BColor aColor;
41cdf0e10cSrcweir 		    ::osl::Mutex m_mutex;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 			if(!aRetVal.get() || rBColor != aColor)
44cdf0e10cSrcweir 			{
45cdf0e10cSrcweir 				// copy values
46cdf0e10cSrcweir 				aColor = rBColor;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 				// create bitmap
49cdf0e10cSrcweir 				Bitmap aContent(Size(3, 3), 24);
50cdf0e10cSrcweir 				Bitmap aMask(Size(3, 3), 1);
51cdf0e10cSrcweir 				BitmapWriteAccess* pWContent = aContent.AcquireWriteAccess();
52cdf0e10cSrcweir 				BitmapWriteAccess* pWMask = aMask.AcquireWriteAccess();
53cdf0e10cSrcweir 				OSL_ENSURE(pWContent && pWMask, "No WriteAccess to bitmap (!)");
54cdf0e10cSrcweir 				const Color aVCLColor(aColor);
55cdf0e10cSrcweir 				const BitmapColor aPixColor(aVCLColor);
56cdf0e10cSrcweir 				const BitmapColor aMaskColor(0x01);
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 				// Y,X unusual order (!)
59cdf0e10cSrcweir 				pWContent->SetPixel(0, 1, aPixColor);
60cdf0e10cSrcweir 				pWContent->SetPixel(1, 0, aPixColor);
61cdf0e10cSrcweir 				pWContent->SetPixel(1, 1, aPixColor);
62cdf0e10cSrcweir 				pWContent->SetPixel(1, 2, aPixColor);
63cdf0e10cSrcweir 				pWContent->SetPixel(2, 1, aPixColor);
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 				pWMask->SetPixel(0, 0, aMaskColor);
66cdf0e10cSrcweir 				pWMask->SetPixel(0, 2, aMaskColor);
67cdf0e10cSrcweir 				pWMask->SetPixel(2, 0, aMaskColor);
68cdf0e10cSrcweir 				pWMask->SetPixel(2, 2, aMaskColor);
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 				aContent.ReleaseAccess(pWContent);
71cdf0e10cSrcweir 				aMask.ReleaseAccess(pWMask);
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 				// create and exchange at aRetVal
74cdf0e10cSrcweir 				delete aRetVal.set(new BitmapEx(aContent, aMask));
75cdf0e10cSrcweir 			}
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 			return aRetVal.get() ? *aRetVal.get() : BitmapEx();
78cdf0e10cSrcweir 		}
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 		BitmapEx createDefaultGluepoint_7x7(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
94cdf0e10cSrcweir 				Bitmap aContent(Size(7, 7), 24);
95cdf0e10cSrcweir 				Bitmap aMask(Size(7, 7), 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 (!)
106cdf0e10cSrcweir 				pWContent->SetPixel(0, 1, aPixColorA);
107cdf0e10cSrcweir 				pWContent->SetPixel(0, 5, aPixColorA);
108cdf0e10cSrcweir 				pWContent->SetPixel(1, 0, aPixColorA);
109cdf0e10cSrcweir 				pWContent->SetPixel(1, 2, aPixColorA);
110cdf0e10cSrcweir 				pWContent->SetPixel(1, 4, aPixColorA);
111cdf0e10cSrcweir 				pWContent->SetPixel(1, 6, aPixColorA);
112cdf0e10cSrcweir 				pWContent->SetPixel(2, 1, aPixColorA);
113cdf0e10cSrcweir 				pWContent->SetPixel(2, 3, aPixColorA);
114cdf0e10cSrcweir 				pWContent->SetPixel(2, 5, aPixColorA);
115cdf0e10cSrcweir 				pWContent->SetPixel(3, 2, aPixColorA);
116cdf0e10cSrcweir 				pWContent->SetPixel(3, 4, aPixColorA);
117cdf0e10cSrcweir 				pWContent->SetPixel(4, 1, aPixColorA);
118cdf0e10cSrcweir 				pWContent->SetPixel(4, 3, aPixColorA);
119cdf0e10cSrcweir 				pWContent->SetPixel(4, 5, aPixColorA);
120cdf0e10cSrcweir 				pWContent->SetPixel(5, 0, aPixColorA);
121cdf0e10cSrcweir 				pWContent->SetPixel(5, 2, aPixColorA);
122cdf0e10cSrcweir 				pWContent->SetPixel(5, 4, aPixColorA);
123cdf0e10cSrcweir 				pWContent->SetPixel(5, 6, aPixColorA);
124cdf0e10cSrcweir 				pWContent->SetPixel(6, 1, aPixColorA);
125cdf0e10cSrcweir 				pWContent->SetPixel(6, 5, aPixColorA);
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 				pWContent->SetPixel(1, 1, aPixColorB);
128cdf0e10cSrcweir 				pWContent->SetPixel(1, 5, aPixColorB);
129cdf0e10cSrcweir 				pWContent->SetPixel(2, 2, aPixColorB);
130cdf0e10cSrcweir 				pWContent->SetPixel(2, 4, aPixColorB);
131cdf0e10cSrcweir 				pWContent->SetPixel(3, 3, aPixColorB);
132cdf0e10cSrcweir 				pWContent->SetPixel(4, 2, aPixColorB);
133cdf0e10cSrcweir 				pWContent->SetPixel(4, 4, aPixColorB);
134cdf0e10cSrcweir 				pWContent->SetPixel(5, 1, aPixColorB);
135cdf0e10cSrcweir 				pWContent->SetPixel(5, 5, aPixColorB);
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 				pWMask->SetPixel(0, 0, aMaskColor);
138cdf0e10cSrcweir 				pWMask->SetPixel(0, 2, aMaskColor);
139cdf0e10cSrcweir 				pWMask->SetPixel(0, 3, aMaskColor);
140cdf0e10cSrcweir 				pWMask->SetPixel(0, 4, aMaskColor);
141cdf0e10cSrcweir 				pWMask->SetPixel(0, 6, aMaskColor);
142cdf0e10cSrcweir 				pWMask->SetPixel(1, 3, aMaskColor);
143cdf0e10cSrcweir 				pWMask->SetPixel(2, 0, aMaskColor);
144cdf0e10cSrcweir 				pWMask->SetPixel(2, 6, aMaskColor);
145cdf0e10cSrcweir 				pWMask->SetPixel(3, 0, aMaskColor);
146cdf0e10cSrcweir 				pWMask->SetPixel(3, 1, aMaskColor);
147cdf0e10cSrcweir 				pWMask->SetPixel(3, 5, aMaskColor);
148cdf0e10cSrcweir 				pWMask->SetPixel(3, 6, aMaskColor);
149cdf0e10cSrcweir 				pWMask->SetPixel(4, 0, aMaskColor);
150cdf0e10cSrcweir 				pWMask->SetPixel(4, 6, aMaskColor);
151cdf0e10cSrcweir 				pWMask->SetPixel(5, 3, aMaskColor);
152cdf0e10cSrcweir 				pWMask->SetPixel(6, 0, aMaskColor);
153cdf0e10cSrcweir 				pWMask->SetPixel(6, 2, aMaskColor);
154cdf0e10cSrcweir 				pWMask->SetPixel(6, 3, aMaskColor);
155cdf0e10cSrcweir 				pWMask->SetPixel(6, 4, aMaskColor);
156cdf0e10cSrcweir 				pWMask->SetPixel(6, 6, aMaskColor);
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 				aContent.ReleaseAccess(pWContent);
159cdf0e10cSrcweir 				aMask.ReleaseAccess(pWMask);
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 				// create and exchange at aRetVal
162cdf0e10cSrcweir 				delete aRetVal.set(new BitmapEx(aContent, aMask));
163cdf0e10cSrcweir 			}
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 			return aRetVal.get() ? *aRetVal.get() : BitmapEx();
166cdf0e10cSrcweir 		}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	} // end of namespace primitive2d
169cdf0e10cSrcweir } // end of namespace drawinglayer
170cdf0e10cSrcweir 
171cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
172cdf0e10cSrcweir // eof
173