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/sdrsceneattribute3d.hxx> 26 27 ////////////////////////////////////////////////////////////////////////////// 28 29 namespace drawinglayer 30 { 31 namespace attribute 32 { 33 class ImpSdrSceneAttribute 34 { 35 public: 36 // refcounter 37 sal_uInt32 mnRefCount; 38 39 // 3D scene attribute definitions 40 double mfDistance; 41 double mfShadowSlant; 42 ::com::sun::star::drawing::ProjectionMode maProjectionMode; 43 ::com::sun::star::drawing::ShadeMode maShadeMode; 44 45 // bitfield 46 unsigned mbTwoSidedLighting : 1; 47 48 public: ImpSdrSceneAttribute(double fDistance,double fShadowSlant,::com::sun::star::drawing::ProjectionMode aProjectionMode,::com::sun::star::drawing::ShadeMode aShadeMode,bool bTwoSidedLighting)49 ImpSdrSceneAttribute( 50 double fDistance, 51 double fShadowSlant, 52 ::com::sun::star::drawing::ProjectionMode aProjectionMode, 53 ::com::sun::star::drawing::ShadeMode aShadeMode, 54 bool bTwoSidedLighting) 55 : mnRefCount(0), 56 mfDistance(fDistance), 57 mfShadowSlant(fShadowSlant), 58 maProjectionMode(aProjectionMode), 59 maShadeMode(aShadeMode), 60 mbTwoSidedLighting(bTwoSidedLighting) 61 { 62 } 63 64 // data read access getDistance() const65 double getDistance() const { return mfDistance; } getShadowSlant() const66 double getShadowSlant() const { return mfShadowSlant; } getProjectionMode() const67 ::com::sun::star::drawing::ProjectionMode getProjectionMode() const { return maProjectionMode; } getShadeMode() const68 ::com::sun::star::drawing::ShadeMode getShadeMode() const { return maShadeMode; } getTwoSidedLighting() const69 bool getTwoSidedLighting() const { return mbTwoSidedLighting; } 70 operator ==(const ImpSdrSceneAttribute & rCandidate) const71 bool operator==(const ImpSdrSceneAttribute& rCandidate) const 72 { 73 return (getDistance() == rCandidate.getDistance() 74 && getShadowSlant() == rCandidate.getShadowSlant() 75 && getProjectionMode() == rCandidate.getProjectionMode() 76 && getShadeMode() == rCandidate.getShadeMode() 77 && getTwoSidedLighting() == rCandidate.getTwoSidedLighting()); 78 } 79 get_global_default()80 static ImpSdrSceneAttribute* get_global_default() 81 { 82 static ImpSdrSceneAttribute* pDefault = 0; 83 84 if(!pDefault) 85 { 86 pDefault = new ImpSdrSceneAttribute( 87 0.0, 0.0, 88 ::com::sun::star::drawing::ProjectionMode_PARALLEL, 89 ::com::sun::star::drawing::ShadeMode_FLAT, 90 false); 91 92 // never delete; start with RefCount 1, not 0 93 pDefault->mnRefCount++; 94 } 95 96 return pDefault; 97 } 98 }; 99 SdrSceneAttribute(double fDistance,double fShadowSlant,::com::sun::star::drawing::ProjectionMode aProjectionMode,::com::sun::star::drawing::ShadeMode aShadeMode,bool bTwoSidedLighting)100 SdrSceneAttribute::SdrSceneAttribute( 101 double fDistance, 102 double fShadowSlant, 103 ::com::sun::star::drawing::ProjectionMode aProjectionMode, 104 ::com::sun::star::drawing::ShadeMode aShadeMode, 105 bool bTwoSidedLighting) 106 : mpSdrSceneAttribute(new ImpSdrSceneAttribute( 107 fDistance, fShadowSlant, aProjectionMode, aShadeMode, bTwoSidedLighting)) 108 { 109 } 110 SdrSceneAttribute()111 SdrSceneAttribute::SdrSceneAttribute() 112 : mpSdrSceneAttribute(ImpSdrSceneAttribute::get_global_default()) 113 { 114 mpSdrSceneAttribute->mnRefCount++; 115 } 116 SdrSceneAttribute(const SdrSceneAttribute & rCandidate)117 SdrSceneAttribute::SdrSceneAttribute(const SdrSceneAttribute& rCandidate) 118 : mpSdrSceneAttribute(rCandidate.mpSdrSceneAttribute) 119 { 120 mpSdrSceneAttribute->mnRefCount++; 121 } 122 ~SdrSceneAttribute()123 SdrSceneAttribute::~SdrSceneAttribute() 124 { 125 if(mpSdrSceneAttribute->mnRefCount) 126 { 127 mpSdrSceneAttribute->mnRefCount--; 128 } 129 else 130 { 131 delete mpSdrSceneAttribute; 132 } 133 } 134 isDefault() const135 bool SdrSceneAttribute::isDefault() const 136 { 137 return mpSdrSceneAttribute == ImpSdrSceneAttribute::get_global_default(); 138 } 139 operator =(const SdrSceneAttribute & rCandidate)140 SdrSceneAttribute& SdrSceneAttribute::operator=(const SdrSceneAttribute& rCandidate) 141 { 142 if(rCandidate.mpSdrSceneAttribute != mpSdrSceneAttribute) 143 { 144 if(mpSdrSceneAttribute->mnRefCount) 145 { 146 mpSdrSceneAttribute->mnRefCount--; 147 } 148 else 149 { 150 delete mpSdrSceneAttribute; 151 } 152 153 mpSdrSceneAttribute = rCandidate.mpSdrSceneAttribute; 154 mpSdrSceneAttribute->mnRefCount++; 155 } 156 157 return *this; 158 } 159 operator ==(const SdrSceneAttribute & rCandidate) const160 bool SdrSceneAttribute::operator==(const SdrSceneAttribute& rCandidate) const 161 { 162 if(rCandidate.mpSdrSceneAttribute == mpSdrSceneAttribute) 163 { 164 return true; 165 } 166 167 if(rCandidate.isDefault() != isDefault()) 168 { 169 return false; 170 } 171 172 return (*rCandidate.mpSdrSceneAttribute == *mpSdrSceneAttribute); 173 } 174 getDistance() const175 double SdrSceneAttribute::getDistance() const 176 { 177 return mpSdrSceneAttribute->getDistance(); 178 } 179 getShadowSlant() const180 double SdrSceneAttribute::getShadowSlant() const 181 { 182 return mpSdrSceneAttribute->getShadowSlant(); 183 } 184 getProjectionMode() const185 ::com::sun::star::drawing::ProjectionMode SdrSceneAttribute::getProjectionMode() const 186 { 187 return mpSdrSceneAttribute->getProjectionMode(); 188 } 189 getShadeMode() const190 ::com::sun::star::drawing::ShadeMode SdrSceneAttribute::getShadeMode() const 191 { 192 return mpSdrSceneAttribute->getShadeMode(); 193 } 194 getTwoSidedLighting() const195 bool SdrSceneAttribute::getTwoSidedLighting() const 196 { 197 return mpSdrSceneAttribute->getTwoSidedLighting(); 198 } 199 200 } // end of namespace attribute 201 } // end of namespace drawinglayer 202 203 ////////////////////////////////////////////////////////////////////////////// 204 // eof 205