xref: /trunk/main/svx/source/sdr/primitive2d/sdrprimitivetools.cxx (revision 4b8033380f80e13c9dd42556d58e106a405f8290)
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(1, 2, aPixColorA);
108                 pWContent->SetPixel(1, 3, aPixColorA);
109                 pWContent->SetPixel(1, 4, aPixColorA);
110                 pWContent->SetPixel(1, 5, aPixColorA);
111                 pWContent->SetPixel(1, 6, aPixColorA);
112                 pWContent->SetPixel(2, 1, aPixColorA);
113                 pWContent->SetPixel(2, 3, aPixColorA);
114                 pWContent->SetPixel(2, 4, aPixColorA);
115                 pWContent->SetPixel(2, 5, aPixColorA);
116                 pWContent->SetPixel(2, 7, aPixColorA);
117                 pWContent->SetPixel(3, 1, aPixColorA);
118                 pWContent->SetPixel(3, 2, aPixColorA);
119                 pWContent->SetPixel(3, 4, aPixColorA);
120                 pWContent->SetPixel(3, 6, aPixColorA);
121                 pWContent->SetPixel(3, 7, aPixColorA);
122                 pWContent->SetPixel(4, 1, aPixColorA);
123                 pWContent->SetPixel(4, 2, aPixColorA);
124                 pWContent->SetPixel(4, 3, aPixColorA);
125                 pWContent->SetPixel(4, 5, aPixColorA);
126                 pWContent->SetPixel(4, 6, aPixColorA);
127                 pWContent->SetPixel(4, 7, aPixColorA);
128                 pWContent->SetPixel(5, 1, aPixColorA);
129                 pWContent->SetPixel(5, 2, aPixColorA);
130                 pWContent->SetPixel(5, 4, aPixColorA);
131                 pWContent->SetPixel(5, 6, aPixColorA);
132                 pWContent->SetPixel(5, 7, aPixColorA);
133                 pWContent->SetPixel(6, 1, aPixColorA);
134                 pWContent->SetPixel(6, 3, aPixColorA);
135                 pWContent->SetPixel(6, 4, aPixColorA);
136                 pWContent->SetPixel(6, 5, aPixColorA);
137                 pWContent->SetPixel(6, 7, aPixColorA);
138                 pWContent->SetPixel(7, 2, aPixColorA);
139                 pWContent->SetPixel(7, 3, aPixColorA);
140                 pWContent->SetPixel(7, 4, aPixColorA);
141                 pWContent->SetPixel(7, 5, aPixColorA);
142                 pWContent->SetPixel(7, 6, aPixColorA);
143 
144                 pWContent->SetPixel(1, 1, aPixColorB);
145                 pWContent->SetPixel(1, 7, aPixColorB);
146                 pWContent->SetPixel(2, 2, aPixColorB);
147                 pWContent->SetPixel(2, 6, aPixColorB);
148                 pWContent->SetPixel(3, 3, aPixColorB);
149                 pWContent->SetPixel(3, 5, aPixColorB);
150                 pWContent->SetPixel(4, 4, aPixColorB);
151                 pWContent->SetPixel(5, 3, aPixColorB);
152                 pWContent->SetPixel(5, 5, aPixColorB);
153                 pWContent->SetPixel(6, 2, aPixColorB);
154                 pWContent->SetPixel(6, 6, aPixColorB);
155                 pWContent->SetPixel(7, 1, aPixColorB);
156                 pWContent->SetPixel(7, 7, aPixColorB);
157 
158                 pWMask->SetPixel(0, 0, aMaskColor);
159                 pWMask->SetPixel(0, 1, aMaskColor);
160                 pWMask->SetPixel(0, 2, aMaskColor);
161                 pWMask->SetPixel(0, 3, aMaskColor);
162                 pWMask->SetPixel(0, 4, aMaskColor);
163                 pWMask->SetPixel(0, 5, aMaskColor);
164                 pWMask->SetPixel(0, 6, aMaskColor);
165                 pWMask->SetPixel(0, 7, aMaskColor);
166                 pWMask->SetPixel(0, 8, aMaskColor);
167                 pWMask->SetPixel(1, 0, aMaskColor);
168                 pWMask->SetPixel(1, 8, aMaskColor);
169                 pWMask->SetPixel(2, 0, aMaskColor);
170                 pWMask->SetPixel(2, 8, aMaskColor);
171                 pWMask->SetPixel(3, 0, aMaskColor);
172                 pWMask->SetPixel(3, 8, aMaskColor);
173                 pWMask->SetPixel(4, 0, aMaskColor);
174                 pWMask->SetPixel(4, 8, aMaskColor);
175                 pWMask->SetPixel(5, 0, aMaskColor);
176                 pWMask->SetPixel(5, 8, aMaskColor);
177                 pWMask->SetPixel(6, 0, aMaskColor);
178                 pWMask->SetPixel(6, 8, aMaskColor);
179                 pWMask->SetPixel(7, 0, aMaskColor);
180                 pWMask->SetPixel(7, 8, aMaskColor);
181                 pWMask->SetPixel(8, 0, aMaskColor);
182                 pWMask->SetPixel(8, 1, aMaskColor);
183                 pWMask->SetPixel(8, 2, aMaskColor);
184                 pWMask->SetPixel(8, 3, aMaskColor);
185                 pWMask->SetPixel(8, 4, aMaskColor);
186                 pWMask->SetPixel(8, 5, aMaskColor);
187                 pWMask->SetPixel(8, 6, aMaskColor);
188                 pWMask->SetPixel(8, 7, aMaskColor);
189                 pWMask->SetPixel(8, 8, aMaskColor);
190 
191 
192                 aContent.ReleaseAccess(pWContent);
193                 aMask.ReleaseAccess(pWMask);
194 
195                 // create and exchange at aRetVal
196                 delete aRetVal.set(new BitmapEx(aContent, aMask));
197             }
198 
199             return aRetVal.get() ? *aRetVal.get() : BitmapEx();
200         }
201 
202     } // end of namespace primitive2d
203 } // end of namespace drawinglayer
204 
205 //////////////////////////////////////////////////////////////////////////////
206 // eof
207