diff options
Diffstat (limited to 'drawinglayer/source/attribute/materialattribute3d.cxx')
-rw-r--r-- | drawinglayer/source/attribute/materialattribute3d.cxx | 93 |
1 files changed, 58 insertions, 35 deletions
diff --git a/drawinglayer/source/attribute/materialattribute3d.cxx b/drawinglayer/source/attribute/materialattribute3d.cxx index 10dee5ec4ce9..4dbb152130ff 100644 --- a/drawinglayer/source/attribute/materialattribute3d.cxx +++ b/drawinglayer/source/attribute/materialattribute3d.cxx @@ -40,74 +40,87 @@ namespace drawinglayer class ImpMaterialAttribute3D { public: + // refcounter + sal_uInt32 mnRefCount; + // materialAttribute3D definitions basegfx::BColor maColor; // object color basegfx::BColor maSpecular; // material specular color basegfx::BColor maEmission; // material emissive color - sal_uInt16 mnSpecularIntensity; // material specular intensity [0..128] - - // refcounter - sal_uInt32 mnRefCount; + sal_uInt16 mnSpecularIntensity; // material specular intensity [0..128] ImpMaterialAttribute3D(const basegfx::BColor& rColor, const basegfx::BColor& rSpecular, const basegfx::BColor& rEmission, sal_uInt16 nSpecularIntensity) - : maColor(rColor), + : mnRefCount(0), + maColor(rColor), maSpecular(rSpecular), maEmission(rEmission), - mnSpecularIntensity(nSpecularIntensity), - mnRefCount(0L) + mnSpecularIntensity(nSpecularIntensity) { } ImpMaterialAttribute3D(const basegfx::BColor& rColor) - : maColor(rColor), + : mnRefCount(0), + maColor(rColor), maSpecular(1.0, 1.0, 1.0), maEmission(), - mnSpecularIntensity(15), - mnRefCount(0L) + mnSpecularIntensity(15) { } - ImpMaterialAttribute3D() - : mnSpecularIntensity(0), - mnRefCount(0L) - { - } + // data read access + const basegfx::BColor& getColor() const { return maColor; } + const basegfx::BColor& getSpecular() const { return maSpecular; } + const basegfx::BColor& getEmission() const { return maEmission; } + sal_uInt16 getSpecularIntensity() const { return mnSpecularIntensity; } bool operator==(const ImpMaterialAttribute3D& rCandidate) const { - return (maColor == rCandidate.maColor - && maSpecular == rCandidate.maSpecular - && maEmission == rCandidate.maEmission - && mnSpecularIntensity == rCandidate.mnSpecularIntensity); + return (getColor() == rCandidate.getColor() + && getSpecular() == rCandidate.getSpecular() + && getEmission() == rCandidate.getEmission() + && getSpecularIntensity() == rCandidate.getSpecularIntensity()); } - const basegfx::BColor& getColor() const { return maColor; } - const basegfx::BColor& getSpecular() const { return maSpecular; } - const basegfx::BColor& getEmission() const { return maEmission; } - sal_uInt16 getSpecularIntensity() const { return mnSpecularIntensity; } - }; - } // end of anonymous namespace -} // end of namespace drawinglayer + static ImpMaterialAttribute3D* get_global_default() + { + static ImpMaterialAttribute3D* pDefault = 0; -////////////////////////////////////////////////////////////////////////////// + if(!pDefault) + { + pDefault = new ImpMaterialAttribute3D( + basegfx::BColor(), + basegfx::BColor(), + basegfx::BColor(), + 0); + + // never delete; start with RefCount 1, not 0 + pDefault->mnRefCount++; + } -namespace drawinglayer -{ - namespace attribute - { - MaterialAttribute3D::MaterialAttribute3D(const basegfx::BColor& rColor, const basegfx::BColor& rSpecular, const basegfx::BColor& rEmission, sal_uInt16 nSpecularIntensity) - : mpMaterialAttribute3D(new ImpMaterialAttribute3D(rColor, rSpecular, rEmission, nSpecularIntensity)) + return pDefault; + } + }; + + MaterialAttribute3D::MaterialAttribute3D( + const basegfx::BColor& rColor, + const basegfx::BColor& rSpecular, + const basegfx::BColor& rEmission, + sal_uInt16 nSpecularIntensity) + : mpMaterialAttribute3D(new ImpMaterialAttribute3D( + rColor, rSpecular, rEmission, nSpecularIntensity)) { } - MaterialAttribute3D::MaterialAttribute3D(const basegfx::BColor& rColor) + MaterialAttribute3D::MaterialAttribute3D( + const basegfx::BColor& rColor) : mpMaterialAttribute3D(new ImpMaterialAttribute3D(rColor)) { } MaterialAttribute3D::MaterialAttribute3D() - : mpMaterialAttribute3D(new ImpMaterialAttribute3D()) + : mpMaterialAttribute3D(ImpMaterialAttribute3D::get_global_default()) { + mpMaterialAttribute3D->mnRefCount++; } MaterialAttribute3D::MaterialAttribute3D(const MaterialAttribute3D& rCandidate) @@ -128,6 +141,11 @@ namespace drawinglayer } } + bool MaterialAttribute3D::isDefault() const + { + return mpMaterialAttribute3D == ImpMaterialAttribute3D::get_global_default(); + } + MaterialAttribute3D& MaterialAttribute3D::operator=(const MaterialAttribute3D& rCandidate) { if(rCandidate.mpMaterialAttribute3D != mpMaterialAttribute3D) @@ -155,6 +173,11 @@ namespace drawinglayer return true; } + if(rCandidate.isDefault() != isDefault()) + { + return false; + } + return (*rCandidate.mpMaterialAttribute3D == *mpMaterialAttribute3D); } |