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 #include "precompiled_svx.hxx"
25 #include <svx/sdr/primitive2d/sdrprimitivetools.hxx>
26 #include <vcl/bmpacc.hxx>
27 #include <osl/mutex.hxx>
28 #include <vcl/lazydelete.hxx>
29 
30 //////////////////////////////////////////////////////////////////////////////
31 // helper methods
32 
33 namespace drawinglayer
34 {
35 	namespace primitive2d
36 	{
37 		BitmapEx createDefaultCross_3x3(const basegfx::BColor& rBColor)
38 		{
39 			static vcl::DeleteOnDeinit< BitmapEx > aRetVal(0);
40 			static basegfx::BColor aColor;
41 			::osl::Mutex m_mutex;
42 
43 			if(!aRetVal.get() || rBColor != aColor)
44 			{
45 				// copy values
46 				aColor = rBColor;
47 
48 				// create bitmap
49 				Bitmap aContent(Size(3, 3), 24);
50 				Bitmap aMask(Size(3, 3), 1);
51 				BitmapWriteAccess* pWContent = aContent.AcquireWriteAccess();
52 				BitmapWriteAccess* pWMask = aMask.AcquireWriteAccess();
53 				OSL_ENSURE(pWContent && pWMask, "No WriteAccess to bitmap (!)");
54 				const Color aVCLColor(aColor);
55 				const BitmapColor aPixColor(aVCLColor);
56 				const BitmapColor aMaskColor(0x01);
57 
58 				// Y,X unusual order (!)
59 				pWContent->SetPixel(0, 1, aPixColor);
60 				pWContent->SetPixel(1, 0, aPixColor);
61 				pWContent->SetPixel(1, 1, aPixColor);
62 				pWContent->SetPixel(1, 2, aPixColor);
63 				pWContent->SetPixel(2, 1, aPixColor);
64 
65 				pWMask->SetPixel(0, 0, aMaskColor);
66 				pWMask->SetPixel(0, 2, aMaskColor);
67 				pWMask->SetPixel(2, 0, aMaskColor);
68 				pWMask->SetPixel(2, 2, aMaskColor);
69 
70 				aContent.ReleaseAccess(pWContent);
71 				aMask.ReleaseAccess(pWMask);
72 
73 				// create and exchange at aRetVal
74 				delete aRetVal.set(new BitmapEx(aContent, aMask));
75 			}
76 
77 			return aRetVal.get() ? *aRetVal.get() : BitmapEx();
78 		}
79 
80 // TODO: Use the bitmap (Glue_Unselected) from markers*.png, so it will be part of the icon theme
81 		BitmapEx createDefaultGluepoint_9x9(const basegfx::BColor& rBColorA, const basegfx::BColor& rBColorB)
82 		{
83 			static vcl::DeleteOnDeinit< BitmapEx > aRetVal(0);
84 			static basegfx::BColor aColorA;
85 			static basegfx::BColor aColorB;
86 			::osl::Mutex m_mutex;
87 
88 			if(!aRetVal.get() || rBColorA != aColorA || rBColorB != aColorB)
89 			{
90 				// copy values
91 				aColorA = rBColorA;
92 				aColorB = rBColorB;
93 
94 				// create bitmap
95 				Bitmap aContent(Size(9, 9), 24);
96 				Bitmap aMask(Size(9, 9), 1);
97 				BitmapWriteAccess* pWContent = aContent.AcquireWriteAccess();
98 				BitmapWriteAccess* pWMask = aMask.AcquireWriteAccess();
99 				OSL_ENSURE(pWContent && pWMask, "No WriteAccess to bitmap (!)");
100 				const Color aColA(aColorA);
101 				const Color aColB(aColorB);
102 				const BitmapColor aPixColorA(aColA);
103 				const BitmapColor aPixColorB(aColB);
104 				const BitmapColor aMaskColor(0x01);
105 
106 				// Y,X unusual order (!)
107 				pWContent->SetPixel(0, 0, aPixColorA);
108 				pWContent->SetPixel(0, 1, aPixColorA);
109 				pWContent->SetPixel(0, 2, aPixColorA);
110 				pWContent->SetPixel(0, 3, aPixColorA);
111 				pWContent->SetPixel(0, 4, aPixColorA);
112 				pWContent->SetPixel(0, 5, aPixColorA);
113 				pWContent->SetPixel(0, 6, aPixColorA);
114 				pWContent->SetPixel(0, 7, aPixColorA);
115 				pWContent->SetPixel(0, 8, aPixColorA);
116 				pWContent->SetPixel(1, 0, aPixColorA);
117 				pWContent->SetPixel(1, 2, aPixColorA);
118 				pWContent->SetPixel(1, 3, aPixColorA);
119 				pWContent->SetPixel(1, 4, aPixColorA);
120 				pWContent->SetPixel(1, 5, aPixColorA);
121 				pWContent->SetPixel(1, 6, aPixColorA);
122 				pWContent->SetPixel(1, 8, aPixColorA);
123 				pWContent->SetPixel(2, 0, aPixColorA);
124 				pWContent->SetPixel(2, 1, aPixColorA);
125 				pWContent->SetPixel(2, 3, aPixColorA);
126 				pWContent->SetPixel(2, 4, aPixColorA);
127 				pWContent->SetPixel(2, 5, aPixColorA);
128 				pWContent->SetPixel(2, 7, aPixColorA);
129 				pWContent->SetPixel(2, 8, aPixColorA);
130 				pWContent->SetPixel(3, 0, aPixColorA);
131 				pWContent->SetPixel(3, 1, aPixColorA);
132 				pWContent->SetPixel(3, 2, aPixColorA);
133 				pWContent->SetPixel(3, 4, aPixColorA);
134 				pWContent->SetPixel(3, 6, aPixColorA);
135 				pWContent->SetPixel(3, 7, aPixColorA);
136 				pWContent->SetPixel(3, 8, aPixColorA);
137 				pWContent->SetPixel(4, 0, aPixColorA);
138 				pWContent->SetPixel(4, 1, aPixColorA);
139 				pWContent->SetPixel(4, 2, aPixColorA);
140 				pWContent->SetPixel(4, 3, aPixColorA);
141 				pWContent->SetPixel(4, 5, aPixColorA);
142 				pWContent->SetPixel(4, 6, aPixColorA);
143 				pWContent->SetPixel(4, 7, aPixColorA);
144 				pWContent->SetPixel(4, 8, aPixColorA);
145 				pWContent->SetPixel(5, 0, aPixColorA);
146 				pWContent->SetPixel(5, 1, aPixColorA);
147 				pWContent->SetPixel(5, 2, aPixColorA);
148 				pWContent->SetPixel(5, 4, aPixColorA);
149 				pWContent->SetPixel(5, 6, aPixColorA);
150 				pWContent->SetPixel(5, 7, aPixColorA);
151 				pWContent->SetPixel(5, 8, aPixColorA);
152 				pWContent->SetPixel(6, 0, aPixColorA);
153 				pWContent->SetPixel(6, 1, aPixColorA);
154 				pWContent->SetPixel(6, 3, aPixColorA);
155 				pWContent->SetPixel(6, 4, aPixColorA);
156 				pWContent->SetPixel(6, 5, aPixColorA);
157 				pWContent->SetPixel(6, 7, aPixColorA);
158 				pWContent->SetPixel(6, 8, aPixColorA);
159 				pWContent->SetPixel(7, 0, aPixColorA);
160 				pWContent->SetPixel(7, 2, aPixColorA);
161 				pWContent->SetPixel(7, 3, aPixColorA);
162 				pWContent->SetPixel(7, 4, aPixColorA);
163 				pWContent->SetPixel(7, 5, aPixColorA);
164 				pWContent->SetPixel(7, 6, aPixColorA);
165 				pWContent->SetPixel(7, 8, aPixColorA);
166 				pWContent->SetPixel(8, 0, aPixColorA);
167 				pWContent->SetPixel(8, 1, aPixColorA);
168 				pWContent->SetPixel(8, 2, aPixColorA);
169 				pWContent->SetPixel(8, 3, aPixColorA);
170 				pWContent->SetPixel(8, 4, aPixColorA);
171 				pWContent->SetPixel(8, 5, aPixColorA);
172 				pWContent->SetPixel(8, 6, aPixColorA);
173 				pWContent->SetPixel(8, 7, aPixColorA);
174 				pWContent->SetPixel(8, 8, aPixColorA);
175 
176 				pWContent->SetPixel(1, 1, aPixColorB);
177 				pWContent->SetPixel(1, 7, aPixColorB);
178 				pWContent->SetPixel(2, 2, aPixColorB);
179 				pWContent->SetPixel(2, 6, aPixColorB);
180 				pWContent->SetPixel(3, 3, aPixColorB);
181 				pWContent->SetPixel(3, 5, aPixColorB);
182 				pWContent->SetPixel(4, 4, aPixColorB);
183 				pWContent->SetPixel(5, 3, aPixColorB);
184 				pWContent->SetPixel(5, 5, aPixColorB);
185 				pWContent->SetPixel(6, 2, aPixColorB);
186 				pWContent->SetPixel(6, 6, aPixColorB);
187 				pWContent->SetPixel(7, 1, aPixColorB);
188 				pWContent->SetPixel(7, 7, aPixColorB);
189 
190 				aContent.ReleaseAccess(pWContent);
191 				aMask.ReleaseAccess(pWMask);
192 
193 				// create and exchange at aRetVal
194 				delete aRetVal.set(new BitmapEx(aContent, aMask));
195 			}
196 
197 			return aRetVal.get() ? *aRetVal.get() : BitmapEx();
198 		}
199 
200 	} // end of namespace primitive2d
201 } // end of namespace drawinglayer
202 
203 //////////////////////////////////////////////////////////////////////////////
204 // eof
205