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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_drawinglayer.hxx" 26 27 #include <drawinglayer/attribute/materialattribute3d.hxx> 28 #include <basegfx/color/bcolor.hxx> 29 30 ////////////////////////////////////////////////////////////////////////////// 31 32 namespace drawinglayer 33 { 34 namespace attribute 35 { 36 class ImpMaterialAttribute3D 37 { 38 public: 39 // refcounter 40 sal_uInt32 mnRefCount; 41 42 // materialAttribute3D definitions 43 basegfx::BColor maColor; // object color 44 basegfx::BColor maSpecular; // material specular color 45 basegfx::BColor maEmission; // material emissive color 46 sal_uInt16 mnSpecularIntensity; // material specular intensity [0..128] 47 ImpMaterialAttribute3D(const basegfx::BColor & rColor,const basegfx::BColor & rSpecular,const basegfx::BColor & rEmission,sal_uInt16 nSpecularIntensity)48 ImpMaterialAttribute3D(const basegfx::BColor& rColor, const basegfx::BColor& rSpecular, const basegfx::BColor& rEmission, sal_uInt16 nSpecularIntensity) 49 : mnRefCount(0), 50 maColor(rColor), 51 maSpecular(rSpecular), 52 maEmission(rEmission), 53 mnSpecularIntensity(nSpecularIntensity) 54 { 55 } 56 ImpMaterialAttribute3D(const basegfx::BColor & rColor)57 ImpMaterialAttribute3D(const basegfx::BColor& rColor) 58 : mnRefCount(0), 59 maColor(rColor), 60 maSpecular(1.0, 1.0, 1.0), 61 maEmission(), 62 mnSpecularIntensity(15) 63 { 64 } 65 66 // data read access getColor() const67 const basegfx::BColor& getColor() const { return maColor; } getSpecular() const68 const basegfx::BColor& getSpecular() const { return maSpecular; } getEmission() const69 const basegfx::BColor& getEmission() const { return maEmission; } getSpecularIntensity() const70 sal_uInt16 getSpecularIntensity() const { return mnSpecularIntensity; } 71 operator ==(const ImpMaterialAttribute3D & rCandidate) const72 bool operator==(const ImpMaterialAttribute3D& rCandidate) const 73 { 74 return (getColor() == rCandidate.getColor() 75 && getSpecular() == rCandidate.getSpecular() 76 && getEmission() == rCandidate.getEmission() 77 && getSpecularIntensity() == rCandidate.getSpecularIntensity()); 78 } 79 get_global_default()80 static ImpMaterialAttribute3D* get_global_default() 81 { 82 static ImpMaterialAttribute3D* pDefault = 0; 83 84 if(!pDefault) 85 { 86 pDefault = new ImpMaterialAttribute3D( 87 basegfx::BColor(), 88 basegfx::BColor(), 89 basegfx::BColor(), 90 0); 91 92 // never delete; start with RefCount 1, not 0 93 pDefault->mnRefCount++; 94 } 95 96 return pDefault; 97 } 98 }; 99 MaterialAttribute3D(const basegfx::BColor & rColor,const basegfx::BColor & rSpecular,const basegfx::BColor & rEmission,sal_uInt16 nSpecularIntensity)100 MaterialAttribute3D::MaterialAttribute3D( 101 const basegfx::BColor& rColor, 102 const basegfx::BColor& rSpecular, 103 const basegfx::BColor& rEmission, 104 sal_uInt16 nSpecularIntensity) 105 : mpMaterialAttribute3D(new ImpMaterialAttribute3D( 106 rColor, rSpecular, rEmission, nSpecularIntensity)) 107 { 108 } 109 MaterialAttribute3D(const basegfx::BColor & rColor)110 MaterialAttribute3D::MaterialAttribute3D( 111 const basegfx::BColor& rColor) 112 : mpMaterialAttribute3D(new ImpMaterialAttribute3D(rColor)) 113 { 114 } 115 MaterialAttribute3D()116 MaterialAttribute3D::MaterialAttribute3D() 117 : mpMaterialAttribute3D(ImpMaterialAttribute3D::get_global_default()) 118 { 119 mpMaterialAttribute3D->mnRefCount++; 120 } 121 MaterialAttribute3D(const MaterialAttribute3D & rCandidate)122 MaterialAttribute3D::MaterialAttribute3D(const MaterialAttribute3D& rCandidate) 123 : mpMaterialAttribute3D(rCandidate.mpMaterialAttribute3D) 124 { 125 mpMaterialAttribute3D->mnRefCount++; 126 } 127 ~MaterialAttribute3D()128 MaterialAttribute3D::~MaterialAttribute3D() 129 { 130 if(mpMaterialAttribute3D->mnRefCount) 131 { 132 mpMaterialAttribute3D->mnRefCount--; 133 } 134 else 135 { 136 delete mpMaterialAttribute3D; 137 } 138 } 139 isDefault() const140 bool MaterialAttribute3D::isDefault() const 141 { 142 return mpMaterialAttribute3D == ImpMaterialAttribute3D::get_global_default(); 143 } 144 operator =(const MaterialAttribute3D & rCandidate)145 MaterialAttribute3D& MaterialAttribute3D::operator=(const MaterialAttribute3D& rCandidate) 146 { 147 if(rCandidate.mpMaterialAttribute3D != mpMaterialAttribute3D) 148 { 149 if(mpMaterialAttribute3D->mnRefCount) 150 { 151 mpMaterialAttribute3D->mnRefCount--; 152 } 153 else 154 { 155 delete mpMaterialAttribute3D; 156 } 157 158 mpMaterialAttribute3D = rCandidate.mpMaterialAttribute3D; 159 mpMaterialAttribute3D->mnRefCount++; 160 } 161 162 return *this; 163 } 164 operator ==(const MaterialAttribute3D & rCandidate) const165 bool MaterialAttribute3D::operator==(const MaterialAttribute3D& rCandidate) const 166 { 167 if(rCandidate.mpMaterialAttribute3D == mpMaterialAttribute3D) 168 { 169 return true; 170 } 171 172 if(rCandidate.isDefault() != isDefault()) 173 { 174 return false; 175 } 176 177 return (*rCandidate.mpMaterialAttribute3D == *mpMaterialAttribute3D); 178 } 179 getColor() const180 const basegfx::BColor& MaterialAttribute3D::getColor() const 181 { 182 return mpMaterialAttribute3D->getColor(); 183 } 184 getSpecular() const185 const basegfx::BColor& MaterialAttribute3D::getSpecular() const 186 { 187 return mpMaterialAttribute3D->getSpecular(); 188 } 189 getEmission() const190 const basegfx::BColor& MaterialAttribute3D::getEmission() const 191 { 192 return mpMaterialAttribute3D->getEmission(); 193 } 194 getSpecularIntensity() const195 sal_uInt16 MaterialAttribute3D::getSpecularIntensity() const 196 { 197 return mpMaterialAttribute3D->getSpecularIntensity(); 198 } 199 } // end of namespace attribute 200 } // end of namespace drawinglayer 201 202 ////////////////////////////////////////////////////////////////////////////// 203 // eof 204