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