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 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_drawinglayer.hxx" 24 25 #include <drawinglayer/attribute/sdrlightattribute3d.hxx> 26 #include <basegfx/color/bcolor.hxx> 27 #include <basegfx/vector/b3dvector.hxx> 28 29 ////////////////////////////////////////////////////////////////////////////// 30 31 namespace drawinglayer 32 { 33 namespace attribute 34 { 35 class ImpSdr3DLightAttribute 36 { 37 public: 38 // refcounter 39 sal_uInt32 mnRefCount; 40 41 // 3D light attribute definitions 42 basegfx::BColor maColor; 43 basegfx::B3DVector maDirection; 44 45 // bitfield 46 unsigned mbSpecular : 1; 47 ImpSdr3DLightAttribute(const basegfx::BColor & rColor,const basegfx::B3DVector & rDirection,bool bSpecular)48 ImpSdr3DLightAttribute( 49 const basegfx::BColor& rColor, 50 const basegfx::B3DVector& rDirection, 51 bool bSpecular) 52 : mnRefCount(0), 53 maColor(rColor), 54 maDirection(rDirection), 55 mbSpecular(bSpecular) 56 { 57 } 58 59 // data read access getColor() const60 const basegfx::BColor& getColor() const { return maColor; } getDirection() const61 const basegfx::B3DVector& getDirection() const { return maDirection; } getSpecular() const62 bool getSpecular() const { return mbSpecular; } 63 operator ==(const ImpSdr3DLightAttribute & rCandidate) const64 bool operator==(const ImpSdr3DLightAttribute& rCandidate) const 65 { 66 return (getColor() == rCandidate.getColor() 67 && getDirection() == rCandidate.getDirection() 68 && getSpecular() == rCandidate.getSpecular()); 69 } 70 get_global_default()71 static ImpSdr3DLightAttribute* get_global_default() 72 { 73 static ImpSdr3DLightAttribute* pDefault = 0; 74 75 if(!pDefault) 76 { 77 pDefault = new ImpSdr3DLightAttribute( 78 basegfx::BColor(), 79 basegfx::B3DVector(), 80 false); 81 82 // never delete; start with RefCount 1, not 0 83 pDefault->mnRefCount++; 84 } 85 86 return pDefault; 87 } 88 }; 89 Sdr3DLightAttribute(const basegfx::BColor & rColor,const basegfx::B3DVector & rDirection,bool bSpecular)90 Sdr3DLightAttribute::Sdr3DLightAttribute( 91 const basegfx::BColor& rColor, 92 const basegfx::B3DVector& rDirection, 93 bool bSpecular) 94 : mpSdr3DLightAttribute(new ImpSdr3DLightAttribute( 95 rColor, rDirection, bSpecular)) 96 { 97 } 98 Sdr3DLightAttribute()99 Sdr3DLightAttribute::Sdr3DLightAttribute() 100 : mpSdr3DLightAttribute(ImpSdr3DLightAttribute::get_global_default()) 101 { 102 mpSdr3DLightAttribute->mnRefCount++; 103 } 104 Sdr3DLightAttribute(const Sdr3DLightAttribute & rCandidate)105 Sdr3DLightAttribute::Sdr3DLightAttribute(const Sdr3DLightAttribute& rCandidate) 106 : mpSdr3DLightAttribute(rCandidate.mpSdr3DLightAttribute) 107 { 108 mpSdr3DLightAttribute->mnRefCount++; 109 } 110 ~Sdr3DLightAttribute()111 Sdr3DLightAttribute::~Sdr3DLightAttribute() 112 { 113 if(mpSdr3DLightAttribute->mnRefCount) 114 { 115 mpSdr3DLightAttribute->mnRefCount--; 116 } 117 else 118 { 119 delete mpSdr3DLightAttribute; 120 } 121 } 122 isDefault() const123 bool Sdr3DLightAttribute::isDefault() const 124 { 125 return mpSdr3DLightAttribute == ImpSdr3DLightAttribute::get_global_default(); 126 } 127 operator =(const Sdr3DLightAttribute & rCandidate)128 Sdr3DLightAttribute& Sdr3DLightAttribute::operator=(const Sdr3DLightAttribute& rCandidate) 129 { 130 if(rCandidate.mpSdr3DLightAttribute != mpSdr3DLightAttribute) 131 { 132 if(mpSdr3DLightAttribute->mnRefCount) 133 { 134 mpSdr3DLightAttribute->mnRefCount--; 135 } 136 else 137 { 138 delete mpSdr3DLightAttribute; 139 } 140 141 mpSdr3DLightAttribute = rCandidate.mpSdr3DLightAttribute; 142 mpSdr3DLightAttribute->mnRefCount++; 143 } 144 145 return *this; 146 } 147 operator ==(const Sdr3DLightAttribute & rCandidate) const148 bool Sdr3DLightAttribute::operator==(const Sdr3DLightAttribute& rCandidate) const 149 { 150 if(rCandidate.mpSdr3DLightAttribute == mpSdr3DLightAttribute) 151 { 152 return true; 153 } 154 155 if(rCandidate.isDefault() != isDefault()) 156 { 157 return false; 158 } 159 160 return (*rCandidate.mpSdr3DLightAttribute == *mpSdr3DLightAttribute); 161 } 162 getColor() const163 const basegfx::BColor& Sdr3DLightAttribute::getColor() const 164 { 165 return mpSdr3DLightAttribute->getColor(); 166 } 167 getDirection() const168 const basegfx::B3DVector& Sdr3DLightAttribute::getDirection() const 169 { 170 return mpSdr3DLightAttribute->getDirection(); 171 } 172 getSpecular() const173 bool Sdr3DLightAttribute::getSpecular() const 174 { 175 return mpSdr3DLightAttribute->getSpecular(); 176 } 177 178 } // end of namespace attribute 179 } // end of namespace drawinglayer 180 181 ////////////////////////////////////////////////////////////////////////////// 182 // eof 183