1*464702f4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*464702f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*464702f4SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*464702f4SAndrew Rist * distributed with this work for additional information 6*464702f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*464702f4SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*464702f4SAndrew Rist * "License"); you may not use this file except in compliance 9*464702f4SAndrew Rist * with the License. You may obtain a copy of the License at 10*464702f4SAndrew Rist * 11*464702f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*464702f4SAndrew Rist * 13*464702f4SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*464702f4SAndrew Rist * software distributed under the License is distributed on an 15*464702f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*464702f4SAndrew Rist * KIND, either express or implied. See the License for the 17*464702f4SAndrew Rist * specific language governing permissions and limitations 18*464702f4SAndrew Rist * under the License. 19*464702f4SAndrew Rist * 20*464702f4SAndrew Rist *************************************************************/ 21*464702f4SAndrew Rist 22*464702f4SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <drawinglayer/attribute/materialattribute3d.hxx> 28cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 31cdf0e10cSrcweir 32cdf0e10cSrcweir namespace drawinglayer 33cdf0e10cSrcweir { 34cdf0e10cSrcweir namespace attribute 35cdf0e10cSrcweir { 36cdf0e10cSrcweir class ImpMaterialAttribute3D 37cdf0e10cSrcweir { 38cdf0e10cSrcweir public: 39cdf0e10cSrcweir // refcounter 40cdf0e10cSrcweir sal_uInt32 mnRefCount; 41cdf0e10cSrcweir 42cdf0e10cSrcweir // materialAttribute3D definitions 43cdf0e10cSrcweir basegfx::BColor maColor; // object color 44cdf0e10cSrcweir basegfx::BColor maSpecular; // material specular color 45cdf0e10cSrcweir basegfx::BColor maEmission; // material emissive color 46cdf0e10cSrcweir sal_uInt16 mnSpecularIntensity; // material specular intensity [0..128] 47cdf0e10cSrcweir ImpMaterialAttribute3D(const basegfx::BColor & rColor,const basegfx::BColor & rSpecular,const basegfx::BColor & rEmission,sal_uInt16 nSpecularIntensity)48cdf0e10cSrcweir ImpMaterialAttribute3D(const basegfx::BColor& rColor, const basegfx::BColor& rSpecular, const basegfx::BColor& rEmission, sal_uInt16 nSpecularIntensity) 49cdf0e10cSrcweir : mnRefCount(0), 50cdf0e10cSrcweir maColor(rColor), 51cdf0e10cSrcweir maSpecular(rSpecular), 52cdf0e10cSrcweir maEmission(rEmission), 53cdf0e10cSrcweir mnSpecularIntensity(nSpecularIntensity) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir } 56cdf0e10cSrcweir ImpMaterialAttribute3D(const basegfx::BColor & rColor)57cdf0e10cSrcweir ImpMaterialAttribute3D(const basegfx::BColor& rColor) 58cdf0e10cSrcweir : mnRefCount(0), 59cdf0e10cSrcweir maColor(rColor), 60cdf0e10cSrcweir maSpecular(1.0, 1.0, 1.0), 61cdf0e10cSrcweir maEmission(), 62cdf0e10cSrcweir mnSpecularIntensity(15) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir // data read access getColor() const67cdf0e10cSrcweir const basegfx::BColor& getColor() const { return maColor; } getSpecular() const68cdf0e10cSrcweir const basegfx::BColor& getSpecular() const { return maSpecular; } getEmission() const69cdf0e10cSrcweir const basegfx::BColor& getEmission() const { return maEmission; } getSpecularIntensity() const70cdf0e10cSrcweir sal_uInt16 getSpecularIntensity() const { return mnSpecularIntensity; } 71cdf0e10cSrcweir operator ==(const ImpMaterialAttribute3D & rCandidate) const72cdf0e10cSrcweir bool operator==(const ImpMaterialAttribute3D& rCandidate) const 73cdf0e10cSrcweir { 74cdf0e10cSrcweir return (getColor() == rCandidate.getColor() 75cdf0e10cSrcweir && getSpecular() == rCandidate.getSpecular() 76cdf0e10cSrcweir && getEmission() == rCandidate.getEmission() 77cdf0e10cSrcweir && getSpecularIntensity() == rCandidate.getSpecularIntensity()); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir get_global_default()80cdf0e10cSrcweir static ImpMaterialAttribute3D* get_global_default() 81cdf0e10cSrcweir { 82cdf0e10cSrcweir static ImpMaterialAttribute3D* pDefault = 0; 83cdf0e10cSrcweir 84cdf0e10cSrcweir if(!pDefault) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir pDefault = new ImpMaterialAttribute3D( 87cdf0e10cSrcweir basegfx::BColor(), 88cdf0e10cSrcweir basegfx::BColor(), 89cdf0e10cSrcweir basegfx::BColor(), 90cdf0e10cSrcweir 0); 91cdf0e10cSrcweir 92cdf0e10cSrcweir // never delete; start with RefCount 1, not 0 93cdf0e10cSrcweir pDefault->mnRefCount++; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir return pDefault; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir }; 99cdf0e10cSrcweir MaterialAttribute3D(const basegfx::BColor & rColor,const basegfx::BColor & rSpecular,const basegfx::BColor & rEmission,sal_uInt16 nSpecularIntensity)100cdf0e10cSrcweir MaterialAttribute3D::MaterialAttribute3D( 101cdf0e10cSrcweir const basegfx::BColor& rColor, 102cdf0e10cSrcweir const basegfx::BColor& rSpecular, 103cdf0e10cSrcweir const basegfx::BColor& rEmission, 104cdf0e10cSrcweir sal_uInt16 nSpecularIntensity) 105cdf0e10cSrcweir : mpMaterialAttribute3D(new ImpMaterialAttribute3D( 106cdf0e10cSrcweir rColor, rSpecular, rEmission, nSpecularIntensity)) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir } 109cdf0e10cSrcweir MaterialAttribute3D(const basegfx::BColor & rColor)110cdf0e10cSrcweir MaterialAttribute3D::MaterialAttribute3D( 111cdf0e10cSrcweir const basegfx::BColor& rColor) 112cdf0e10cSrcweir : mpMaterialAttribute3D(new ImpMaterialAttribute3D(rColor)) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir } 115cdf0e10cSrcweir MaterialAttribute3D()116cdf0e10cSrcweir MaterialAttribute3D::MaterialAttribute3D() 117cdf0e10cSrcweir : mpMaterialAttribute3D(ImpMaterialAttribute3D::get_global_default()) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir mpMaterialAttribute3D->mnRefCount++; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir MaterialAttribute3D(const MaterialAttribute3D & rCandidate)122cdf0e10cSrcweir MaterialAttribute3D::MaterialAttribute3D(const MaterialAttribute3D& rCandidate) 123cdf0e10cSrcweir : mpMaterialAttribute3D(rCandidate.mpMaterialAttribute3D) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir mpMaterialAttribute3D->mnRefCount++; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir ~MaterialAttribute3D()128cdf0e10cSrcweir MaterialAttribute3D::~MaterialAttribute3D() 129cdf0e10cSrcweir { 130cdf0e10cSrcweir if(mpMaterialAttribute3D->mnRefCount) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir mpMaterialAttribute3D->mnRefCount--; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir else 135cdf0e10cSrcweir { 136cdf0e10cSrcweir delete mpMaterialAttribute3D; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } 139cdf0e10cSrcweir isDefault() const140cdf0e10cSrcweir bool MaterialAttribute3D::isDefault() const 141cdf0e10cSrcweir { 142cdf0e10cSrcweir return mpMaterialAttribute3D == ImpMaterialAttribute3D::get_global_default(); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir operator =(const MaterialAttribute3D & rCandidate)145cdf0e10cSrcweir MaterialAttribute3D& MaterialAttribute3D::operator=(const MaterialAttribute3D& rCandidate) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir if(rCandidate.mpMaterialAttribute3D != mpMaterialAttribute3D) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir if(mpMaterialAttribute3D->mnRefCount) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir mpMaterialAttribute3D->mnRefCount--; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir else 154cdf0e10cSrcweir { 155cdf0e10cSrcweir delete mpMaterialAttribute3D; 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir mpMaterialAttribute3D = rCandidate.mpMaterialAttribute3D; 159cdf0e10cSrcweir mpMaterialAttribute3D->mnRefCount++; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir return *this; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir operator ==(const MaterialAttribute3D & rCandidate) const165cdf0e10cSrcweir bool MaterialAttribute3D::operator==(const MaterialAttribute3D& rCandidate) const 166cdf0e10cSrcweir { 167cdf0e10cSrcweir if(rCandidate.mpMaterialAttribute3D == mpMaterialAttribute3D) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir return true; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir if(rCandidate.isDefault() != isDefault()) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir return false; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir return (*rCandidate.mpMaterialAttribute3D == *mpMaterialAttribute3D); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir getColor() const180cdf0e10cSrcweir const basegfx::BColor& MaterialAttribute3D::getColor() const 181cdf0e10cSrcweir { 182cdf0e10cSrcweir return mpMaterialAttribute3D->getColor(); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir getSpecular() const185cdf0e10cSrcweir const basegfx::BColor& MaterialAttribute3D::getSpecular() const 186cdf0e10cSrcweir { 187cdf0e10cSrcweir return mpMaterialAttribute3D->getSpecular(); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir getEmission() const190cdf0e10cSrcweir const basegfx::BColor& MaterialAttribute3D::getEmission() const 191cdf0e10cSrcweir { 192cdf0e10cSrcweir return mpMaterialAttribute3D->getEmission(); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir getSpecularIntensity() const195cdf0e10cSrcweir sal_uInt16 MaterialAttribute3D::getSpecularIntensity() const 196cdf0e10cSrcweir { 197cdf0e10cSrcweir return mpMaterialAttribute3D->getSpecularIntensity(); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir } // end of namespace attribute 200cdf0e10cSrcweir } // end of namespace drawinglayer 201cdf0e10cSrcweir 202cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 203cdf0e10cSrcweir // eof 204