1 /************************************************************************* 2 * 3 * OpenOffice.org - a multi-platform office productivity suite 4 * 5 * $RCSfile: sdrattribute3d.cxx,v $ 6 * 7 * $Revision: 1.5 $ 8 * 9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:19 $ 10 * 11 * The Contents of this file are made available subject to 12 * the terms of GNU Lesser General Public License Version 2.1. 13 * 14 * 15 * GNU Lesser General Public License Version 2.1 16 * ============================================= 17 * Copyright 2005 by Sun Microsystems, Inc. 18 * 901 San Antonio Road, Palo Alto, CA 94303, USA 19 * 20 * This library is free software; you can redistribute it and/or 21 * modify it under the terms of the GNU Lesser General Public 22 * License version 2.1, as published by the Free Software Foundation. 23 * 24 * This library is distributed in the hope that it will be useful, 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 * Lesser General Public License for more details. 28 * 29 * You should have received a copy of the GNU Lesser General Public 30 * License along with this library; if not, write to the Free Software 31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 32 * MA 02111-1307 USA 33 * 34 ************************************************************************/ 35 36 // MARKER(update_precomp.py): autogen include statement, do not remove 37 #include "precompiled_drawinglayer.hxx" 38 39 #include <drawinglayer/attribute/sdrlightattribute3d.hxx> 40 #include <basegfx/color/bcolor.hxx> 41 #include <basegfx/vector/b3dvector.hxx> 42 43 ////////////////////////////////////////////////////////////////////////////// 44 45 namespace drawinglayer 46 { 47 namespace attribute 48 { 49 class ImpSdr3DLightAttribute 50 { 51 public: 52 // refcounter 53 sal_uInt32 mnRefCount; 54 55 // 3D light attribute definitions 56 basegfx::BColor maColor; 57 basegfx::B3DVector maDirection; 58 59 // bitfield 60 unsigned mbSpecular : 1; 61 62 ImpSdr3DLightAttribute( 63 const basegfx::BColor& rColor, 64 const basegfx::B3DVector& rDirection, 65 bool bSpecular) 66 : mnRefCount(0), 67 maColor(rColor), 68 maDirection(rDirection), 69 mbSpecular(bSpecular) 70 { 71 } 72 73 // data read access 74 const basegfx::BColor& getColor() const { return maColor; } 75 const basegfx::B3DVector& getDirection() const { return maDirection; } 76 bool getSpecular() const { return mbSpecular; } 77 78 bool operator==(const ImpSdr3DLightAttribute& rCandidate) const 79 { 80 return (getColor() == rCandidate.getColor() 81 && getDirection() == rCandidate.getDirection() 82 && getSpecular() == rCandidate.getSpecular()); 83 } 84 85 static ImpSdr3DLightAttribute* get_global_default() 86 { 87 static ImpSdr3DLightAttribute* pDefault = 0; 88 89 if(!pDefault) 90 { 91 pDefault = new ImpSdr3DLightAttribute( 92 basegfx::BColor(), 93 basegfx::B3DVector(), 94 false); 95 96 // never delete; start with RefCount 1, not 0 97 pDefault->mnRefCount++; 98 } 99 100 return pDefault; 101 } 102 }; 103 104 Sdr3DLightAttribute::Sdr3DLightAttribute( 105 const basegfx::BColor& rColor, 106 const basegfx::B3DVector& rDirection, 107 bool bSpecular) 108 : mpSdr3DLightAttribute(new ImpSdr3DLightAttribute( 109 rColor, rDirection, bSpecular)) 110 { 111 } 112 113 Sdr3DLightAttribute::Sdr3DLightAttribute() 114 : mpSdr3DLightAttribute(ImpSdr3DLightAttribute::get_global_default()) 115 { 116 mpSdr3DLightAttribute->mnRefCount++; 117 } 118 119 Sdr3DLightAttribute::Sdr3DLightAttribute(const Sdr3DLightAttribute& rCandidate) 120 : mpSdr3DLightAttribute(rCandidate.mpSdr3DLightAttribute) 121 { 122 mpSdr3DLightAttribute->mnRefCount++; 123 } 124 125 Sdr3DLightAttribute::~Sdr3DLightAttribute() 126 { 127 if(mpSdr3DLightAttribute->mnRefCount) 128 { 129 mpSdr3DLightAttribute->mnRefCount--; 130 } 131 else 132 { 133 delete mpSdr3DLightAttribute; 134 } 135 } 136 137 bool Sdr3DLightAttribute::isDefault() const 138 { 139 return mpSdr3DLightAttribute == ImpSdr3DLightAttribute::get_global_default(); 140 } 141 142 Sdr3DLightAttribute& Sdr3DLightAttribute::operator=(const Sdr3DLightAttribute& rCandidate) 143 { 144 if(rCandidate.mpSdr3DLightAttribute != mpSdr3DLightAttribute) 145 { 146 if(mpSdr3DLightAttribute->mnRefCount) 147 { 148 mpSdr3DLightAttribute->mnRefCount--; 149 } 150 else 151 { 152 delete mpSdr3DLightAttribute; 153 } 154 155 mpSdr3DLightAttribute = rCandidate.mpSdr3DLightAttribute; 156 mpSdr3DLightAttribute->mnRefCount++; 157 } 158 159 return *this; 160 } 161 162 bool Sdr3DLightAttribute::operator==(const Sdr3DLightAttribute& rCandidate) const 163 { 164 if(rCandidate.mpSdr3DLightAttribute == mpSdr3DLightAttribute) 165 { 166 return true; 167 } 168 169 if(rCandidate.isDefault() != isDefault()) 170 { 171 return false; 172 } 173 174 return (*rCandidate.mpSdr3DLightAttribute == *mpSdr3DLightAttribute); 175 } 176 177 const basegfx::BColor& Sdr3DLightAttribute::getColor() const 178 { 179 return mpSdr3DLightAttribute->getColor(); 180 } 181 182 const basegfx::B3DVector& Sdr3DLightAttribute::getDirection() const 183 { 184 return mpSdr3DLightAttribute->getDirection(); 185 } 186 187 bool Sdr3DLightAttribute::getSpecular() const 188 { 189 return mpSdr3DLightAttribute->getSpecular(); 190 } 191 192 } // end of namespace attribute 193 } // end of namespace drawinglayer 194 195 ////////////////////////////////////////////////////////////////////////////// 196 // eof 197