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: Move this bitmap to markers*.png, so it will be part of the icon theme 81 BitmapEx createDefaultGluepoint_7x7(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(7, 7), 24); 96 Bitmap aMask(Size(7, 7), 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(1, 0, aPixColorA); 115 pWContent->SetPixel(1, 2, aPixColorA); 116 pWContent->SetPixel(1, 3, aPixColorA); 117 pWContent->SetPixel(1, 4, aPixColorA); 118 pWContent->SetPixel(1, 6, aPixColorA); 119 pWContent->SetPixel(2, 0, aPixColorA); 120 pWContent->SetPixel(2, 1, aPixColorA); 121 pWContent->SetPixel(2, 3, aPixColorA); 122 pWContent->SetPixel(2, 5, aPixColorA); 123 pWContent->SetPixel(2, 6, aPixColorA); 124 pWContent->SetPixel(3, 0, aPixColorA); 125 pWContent->SetPixel(3, 1, aPixColorA); 126 pWContent->SetPixel(3, 2, aPixColorA); 127 pWContent->SetPixel(3, 4, aPixColorA); 128 pWContent->SetPixel(3, 5, aPixColorA); 129 pWContent->SetPixel(3, 6, aPixColorA); 130 pWContent->SetPixel(4, 0, aPixColorA); 131 pWContent->SetPixel(4, 1, aPixColorA); 132 pWContent->SetPixel(4, 3, aPixColorA); 133 pWContent->SetPixel(4, 5, aPixColorA); 134 pWContent->SetPixel(4, 6, aPixColorA); 135 pWContent->SetPixel(5, 0, aPixColorA); 136 pWContent->SetPixel(5, 2, aPixColorA); 137 pWContent->SetPixel(5, 3, aPixColorA); 138 pWContent->SetPixel(5, 4, aPixColorA); 139 pWContent->SetPixel(5, 6, aPixColorA); 140 pWContent->SetPixel(6, 0, aPixColorA); 141 pWContent->SetPixel(6, 1, aPixColorA); 142 pWContent->SetPixel(6, 2, aPixColorA); 143 pWContent->SetPixel(6, 3, aPixColorA); 144 pWContent->SetPixel(6, 4, aPixColorA); 145 pWContent->SetPixel(6, 5, aPixColorA); 146 pWContent->SetPixel(6, 6, aPixColorA); 147 148 pWContent->SetPixel(1, 1, aPixColorB); 149 pWContent->SetPixel(1, 5, aPixColorB); 150 pWContent->SetPixel(2, 2, aPixColorB); 151 pWContent->SetPixel(2, 4, aPixColorB); 152 pWContent->SetPixel(3, 3, aPixColorB); 153 pWContent->SetPixel(4, 2, aPixColorB); 154 pWContent->SetPixel(4, 4, aPixColorB); 155 pWContent->SetPixel(5, 1, aPixColorB); 156 pWContent->SetPixel(5, 5, aPixColorB); 157 158 aContent.ReleaseAccess(pWContent); 159 aMask.ReleaseAccess(pWMask); 160 161 // create and exchange at aRetVal 162 delete aRetVal.set(new BitmapEx(aContent, aMask)); 163 } 164 165 return aRetVal.get() ? *aRetVal.get() : BitmapEx(); 166 } 167 168 } // end of namespace primitive2d 169 } // end of namespace drawinglayer 170 171 ////////////////////////////////////////////////////////////////////////////// 172 // eof 173