xref: /trunk/main/svx/source/sdr/primitive2d/sdrprimitivetools.cxx (revision 8cd3382f96de367db86a2b87d61cabbbab28a57e)
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*8cd3382fSmseidel // 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)804e278df9Smseidel         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
944e278df9Smseidel                 Bitmap aContent(Size(9, 9), 24);
954e278df9Smseidel                 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*8cd3382fSmseidel                 pWContent->SetPixel(0, 0, aPixColorA);
107*8cd3382fSmseidel                 pWContent->SetPixel(0, 1, aPixColorA);
108*8cd3382fSmseidel                 pWContent->SetPixel(0, 2, aPixColorA);
109*8cd3382fSmseidel                 pWContent->SetPixel(0, 3, aPixColorA);
110*8cd3382fSmseidel                 pWContent->SetPixel(0, 4, aPixColorA);
111*8cd3382fSmseidel                 pWContent->SetPixel(0, 5, aPixColorA);
112*8cd3382fSmseidel                 pWContent->SetPixel(0, 6, aPixColorA);
113*8cd3382fSmseidel                 pWContent->SetPixel(0, 7, aPixColorA);
114*8cd3382fSmseidel                 pWContent->SetPixel(0, 8, aPixColorA);
115*8cd3382fSmseidel                 pWContent->SetPixel(1, 0, aPixColorA);
116cdf0e10cSrcweir                 pWContent->SetPixel(1, 2, aPixColorA);
117fb9aa39aSmseidel                 pWContent->SetPixel(1, 3, aPixColorA);
118cdf0e10cSrcweir                 pWContent->SetPixel(1, 4, aPixColorA);
1194e278df9Smseidel                 pWContent->SetPixel(1, 5, aPixColorA);
120cdf0e10cSrcweir                 pWContent->SetPixel(1, 6, aPixColorA);
121*8cd3382fSmseidel                 pWContent->SetPixel(1, 8, aPixColorA);
122*8cd3382fSmseidel                 pWContent->SetPixel(2, 0, aPixColorA);
123cdf0e10cSrcweir                 pWContent->SetPixel(2, 1, aPixColorA);
124cdf0e10cSrcweir                 pWContent->SetPixel(2, 3, aPixColorA);
1254e278df9Smseidel                 pWContent->SetPixel(2, 4, aPixColorA);
126cdf0e10cSrcweir                 pWContent->SetPixel(2, 5, aPixColorA);
1274e278df9Smseidel                 pWContent->SetPixel(2, 7, aPixColorA);
128*8cd3382fSmseidel                 pWContent->SetPixel(2, 8, aPixColorA);
129*8cd3382fSmseidel                 pWContent->SetPixel(3, 0, aPixColorA);
130fb9aa39aSmseidel                 pWContent->SetPixel(3, 1, aPixColorA);
131cdf0e10cSrcweir                 pWContent->SetPixel(3, 2, aPixColorA);
132cdf0e10cSrcweir                 pWContent->SetPixel(3, 4, aPixColorA);
133fb9aa39aSmseidel                 pWContent->SetPixel(3, 6, aPixColorA);
1344e278df9Smseidel                 pWContent->SetPixel(3, 7, aPixColorA);
135*8cd3382fSmseidel                 pWContent->SetPixel(3, 8, aPixColorA);
136*8cd3382fSmseidel                 pWContent->SetPixel(4, 0, aPixColorA);
137cdf0e10cSrcweir                 pWContent->SetPixel(4, 1, aPixColorA);
1384e278df9Smseidel                 pWContent->SetPixel(4, 2, aPixColorA);
139cdf0e10cSrcweir                 pWContent->SetPixel(4, 3, aPixColorA);
140cdf0e10cSrcweir                 pWContent->SetPixel(4, 5, aPixColorA);
141fb9aa39aSmseidel                 pWContent->SetPixel(4, 6, aPixColorA);
1424e278df9Smseidel                 pWContent->SetPixel(4, 7, aPixColorA);
143*8cd3382fSmseidel                 pWContent->SetPixel(4, 8, aPixColorA);
144*8cd3382fSmseidel                 pWContent->SetPixel(5, 0, aPixColorA);
1454e278df9Smseidel                 pWContent->SetPixel(5, 1, aPixColorA);
146cdf0e10cSrcweir                 pWContent->SetPixel(5, 2, aPixColorA);
147cdf0e10cSrcweir                 pWContent->SetPixel(5, 4, aPixColorA);
148cdf0e10cSrcweir                 pWContent->SetPixel(5, 6, aPixColorA);
1494e278df9Smseidel                 pWContent->SetPixel(5, 7, aPixColorA);
150*8cd3382fSmseidel                 pWContent->SetPixel(5, 8, aPixColorA);
151*8cd3382fSmseidel                 pWContent->SetPixel(6, 0, aPixColorA);
152cdf0e10cSrcweir                 pWContent->SetPixel(6, 1, aPixColorA);
153fb9aa39aSmseidel                 pWContent->SetPixel(6, 3, aPixColorA);
154fb9aa39aSmseidel                 pWContent->SetPixel(6, 4, aPixColorA);
155cdf0e10cSrcweir                 pWContent->SetPixel(6, 5, aPixColorA);
1564e278df9Smseidel                 pWContent->SetPixel(6, 7, aPixColorA);
157*8cd3382fSmseidel                 pWContent->SetPixel(6, 8, aPixColorA);
158*8cd3382fSmseidel                 pWContent->SetPixel(7, 0, aPixColorA);
1594e278df9Smseidel                 pWContent->SetPixel(7, 2, aPixColorA);
1604e278df9Smseidel                 pWContent->SetPixel(7, 3, aPixColorA);
1614e278df9Smseidel                 pWContent->SetPixel(7, 4, aPixColorA);
1624e278df9Smseidel                 pWContent->SetPixel(7, 5, aPixColorA);
1634e278df9Smseidel                 pWContent->SetPixel(7, 6, aPixColorA);
164*8cd3382fSmseidel                 pWContent->SetPixel(7, 8, aPixColorA);
165*8cd3382fSmseidel                 pWContent->SetPixel(8, 0, aPixColorA);
166*8cd3382fSmseidel                 pWContent->SetPixel(8, 1, aPixColorA);
167*8cd3382fSmseidel                 pWContent->SetPixel(8, 2, aPixColorA);
168*8cd3382fSmseidel                 pWContent->SetPixel(8, 3, aPixColorA);
169*8cd3382fSmseidel                 pWContent->SetPixel(8, 4, aPixColorA);
170*8cd3382fSmseidel                 pWContent->SetPixel(8, 5, aPixColorA);
171*8cd3382fSmseidel                 pWContent->SetPixel(8, 6, aPixColorA);
172*8cd3382fSmseidel                 pWContent->SetPixel(8, 7, aPixColorA);
173*8cd3382fSmseidel                 pWContent->SetPixel(8, 8, aPixColorA);
174cdf0e10cSrcweir 
175cdf0e10cSrcweir                 pWContent->SetPixel(1, 1, aPixColorB);
1764e278df9Smseidel                 pWContent->SetPixel(1, 7, aPixColorB);
177cdf0e10cSrcweir                 pWContent->SetPixel(2, 2, aPixColorB);
1784e278df9Smseidel                 pWContent->SetPixel(2, 6, aPixColorB);
179cdf0e10cSrcweir                 pWContent->SetPixel(3, 3, aPixColorB);
1804e278df9Smseidel                 pWContent->SetPixel(3, 5, aPixColorB);
181cdf0e10cSrcweir                 pWContent->SetPixel(4, 4, aPixColorB);
1824e278df9Smseidel                 pWContent->SetPixel(5, 3, aPixColorB);
183cdf0e10cSrcweir                 pWContent->SetPixel(5, 5, aPixColorB);
1844e278df9Smseidel                 pWContent->SetPixel(6, 2, aPixColorB);
1854e278df9Smseidel                 pWContent->SetPixel(6, 6, aPixColorB);
1864e278df9Smseidel                 pWContent->SetPixel(7, 1, aPixColorB);
1874e278df9Smseidel                 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*8cd3382fSmseidel /* vim: set noet sw=4 ts=4: */
203