xref: /trunk/main/drawinglayer/source/attribute/materialattribute3d.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <drawinglayer/attribute/materialattribute3d.hxx>
32*cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir namespace drawinglayer
37*cdf0e10cSrcweir {
38*cdf0e10cSrcweir     namespace attribute
39*cdf0e10cSrcweir     {
40*cdf0e10cSrcweir         class ImpMaterialAttribute3D
41*cdf0e10cSrcweir         {
42*cdf0e10cSrcweir         public:
43*cdf0e10cSrcweir             // refcounter
44*cdf0e10cSrcweir             sal_uInt32                              mnRefCount;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir             // materialAttribute3D definitions
47*cdf0e10cSrcweir             basegfx::BColor                         maColor;                // object color
48*cdf0e10cSrcweir             basegfx::BColor                         maSpecular;             // material specular color
49*cdf0e10cSrcweir             basegfx::BColor                         maEmission;             // material emissive color
50*cdf0e10cSrcweir             sal_uInt16                              mnSpecularIntensity;    // material specular intensity [0..128]
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir             ImpMaterialAttribute3D(const basegfx::BColor& rColor, const basegfx::BColor& rSpecular, const basegfx::BColor& rEmission, sal_uInt16 nSpecularIntensity)
53*cdf0e10cSrcweir             :   mnRefCount(0),
54*cdf0e10cSrcweir                 maColor(rColor),
55*cdf0e10cSrcweir                 maSpecular(rSpecular),
56*cdf0e10cSrcweir                 maEmission(rEmission),
57*cdf0e10cSrcweir                 mnSpecularIntensity(nSpecularIntensity)
58*cdf0e10cSrcweir             {
59*cdf0e10cSrcweir             }
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir             ImpMaterialAttribute3D(const basegfx::BColor& rColor)
62*cdf0e10cSrcweir             :   mnRefCount(0),
63*cdf0e10cSrcweir                 maColor(rColor),
64*cdf0e10cSrcweir                 maSpecular(1.0, 1.0, 1.0),
65*cdf0e10cSrcweir                 maEmission(),
66*cdf0e10cSrcweir                 mnSpecularIntensity(15)
67*cdf0e10cSrcweir             {
68*cdf0e10cSrcweir             }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir             // data read access
71*cdf0e10cSrcweir             const basegfx::BColor& getColor() const { return maColor; }
72*cdf0e10cSrcweir             const basegfx::BColor& getSpecular() const { return maSpecular; }
73*cdf0e10cSrcweir             const basegfx::BColor& getEmission() const { return maEmission; }
74*cdf0e10cSrcweir             sal_uInt16 getSpecularIntensity() const { return mnSpecularIntensity; }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir             bool operator==(const ImpMaterialAttribute3D& rCandidate) const
77*cdf0e10cSrcweir             {
78*cdf0e10cSrcweir                 return (getColor() == rCandidate.getColor()
79*cdf0e10cSrcweir                     && getSpecular() == rCandidate.getSpecular()
80*cdf0e10cSrcweir                     && getEmission() == rCandidate.getEmission()
81*cdf0e10cSrcweir                     && getSpecularIntensity() == rCandidate.getSpecularIntensity());
82*cdf0e10cSrcweir             }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir             static ImpMaterialAttribute3D* get_global_default()
85*cdf0e10cSrcweir             {
86*cdf0e10cSrcweir                 static ImpMaterialAttribute3D* pDefault = 0;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir                 if(!pDefault)
89*cdf0e10cSrcweir                 {
90*cdf0e10cSrcweir                     pDefault = new ImpMaterialAttribute3D(
91*cdf0e10cSrcweir                         basegfx::BColor(),
92*cdf0e10cSrcweir                         basegfx::BColor(),
93*cdf0e10cSrcweir                         basegfx::BColor(),
94*cdf0e10cSrcweir                         0);
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir                     // never delete; start with RefCount 1, not 0
97*cdf0e10cSrcweir                     pDefault->mnRefCount++;
98*cdf0e10cSrcweir                 }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir                 return pDefault;
101*cdf0e10cSrcweir             }
102*cdf0e10cSrcweir         };
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir         MaterialAttribute3D::MaterialAttribute3D(
105*cdf0e10cSrcweir             const basegfx::BColor& rColor,
106*cdf0e10cSrcweir             const basegfx::BColor& rSpecular,
107*cdf0e10cSrcweir             const basegfx::BColor& rEmission,
108*cdf0e10cSrcweir             sal_uInt16 nSpecularIntensity)
109*cdf0e10cSrcweir         :   mpMaterialAttribute3D(new ImpMaterialAttribute3D(
110*cdf0e10cSrcweir                 rColor, rSpecular, rEmission, nSpecularIntensity))
111*cdf0e10cSrcweir         {
112*cdf0e10cSrcweir         }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir         MaterialAttribute3D::MaterialAttribute3D(
115*cdf0e10cSrcweir             const basegfx::BColor& rColor)
116*cdf0e10cSrcweir         :   mpMaterialAttribute3D(new ImpMaterialAttribute3D(rColor))
117*cdf0e10cSrcweir         {
118*cdf0e10cSrcweir         }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir         MaterialAttribute3D::MaterialAttribute3D()
121*cdf0e10cSrcweir         :   mpMaterialAttribute3D(ImpMaterialAttribute3D::get_global_default())
122*cdf0e10cSrcweir         {
123*cdf0e10cSrcweir             mpMaterialAttribute3D->mnRefCount++;
124*cdf0e10cSrcweir         }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir         MaterialAttribute3D::MaterialAttribute3D(const MaterialAttribute3D& rCandidate)
127*cdf0e10cSrcweir         :   mpMaterialAttribute3D(rCandidate.mpMaterialAttribute3D)
128*cdf0e10cSrcweir         {
129*cdf0e10cSrcweir             mpMaterialAttribute3D->mnRefCount++;
130*cdf0e10cSrcweir         }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir         MaterialAttribute3D::~MaterialAttribute3D()
133*cdf0e10cSrcweir         {
134*cdf0e10cSrcweir             if(mpMaterialAttribute3D->mnRefCount)
135*cdf0e10cSrcweir             {
136*cdf0e10cSrcweir                 mpMaterialAttribute3D->mnRefCount--;
137*cdf0e10cSrcweir             }
138*cdf0e10cSrcweir             else
139*cdf0e10cSrcweir             {
140*cdf0e10cSrcweir                 delete mpMaterialAttribute3D;
141*cdf0e10cSrcweir             }
142*cdf0e10cSrcweir         }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir         bool MaterialAttribute3D::isDefault() const
145*cdf0e10cSrcweir         {
146*cdf0e10cSrcweir             return mpMaterialAttribute3D == ImpMaterialAttribute3D::get_global_default();
147*cdf0e10cSrcweir         }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir         MaterialAttribute3D& MaterialAttribute3D::operator=(const MaterialAttribute3D& rCandidate)
150*cdf0e10cSrcweir         {
151*cdf0e10cSrcweir             if(rCandidate.mpMaterialAttribute3D != mpMaterialAttribute3D)
152*cdf0e10cSrcweir             {
153*cdf0e10cSrcweir                 if(mpMaterialAttribute3D->mnRefCount)
154*cdf0e10cSrcweir                 {
155*cdf0e10cSrcweir                     mpMaterialAttribute3D->mnRefCount--;
156*cdf0e10cSrcweir                 }
157*cdf0e10cSrcweir                 else
158*cdf0e10cSrcweir                 {
159*cdf0e10cSrcweir                     delete mpMaterialAttribute3D;
160*cdf0e10cSrcweir                 }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir                 mpMaterialAttribute3D = rCandidate.mpMaterialAttribute3D;
163*cdf0e10cSrcweir                 mpMaterialAttribute3D->mnRefCount++;
164*cdf0e10cSrcweir             }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir             return *this;
167*cdf0e10cSrcweir         }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir         bool MaterialAttribute3D::operator==(const MaterialAttribute3D& rCandidate) const
170*cdf0e10cSrcweir         {
171*cdf0e10cSrcweir             if(rCandidate.mpMaterialAttribute3D == mpMaterialAttribute3D)
172*cdf0e10cSrcweir             {
173*cdf0e10cSrcweir                 return true;
174*cdf0e10cSrcweir             }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir             if(rCandidate.isDefault() != isDefault())
177*cdf0e10cSrcweir             {
178*cdf0e10cSrcweir                 return false;
179*cdf0e10cSrcweir             }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir             return (*rCandidate.mpMaterialAttribute3D == *mpMaterialAttribute3D);
182*cdf0e10cSrcweir         }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir         const basegfx::BColor& MaterialAttribute3D::getColor() const
185*cdf0e10cSrcweir         {
186*cdf0e10cSrcweir             return mpMaterialAttribute3D->getColor();
187*cdf0e10cSrcweir         }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir         const basegfx::BColor& MaterialAttribute3D::getSpecular() const
190*cdf0e10cSrcweir         {
191*cdf0e10cSrcweir             return mpMaterialAttribute3D->getSpecular();
192*cdf0e10cSrcweir         }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir         const basegfx::BColor& MaterialAttribute3D::getEmission() const
195*cdf0e10cSrcweir         {
196*cdf0e10cSrcweir             return mpMaterialAttribute3D->getEmission();
197*cdf0e10cSrcweir         }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir         sal_uInt16 MaterialAttribute3D::getSpecularIntensity() const
200*cdf0e10cSrcweir         {
201*cdf0e10cSrcweir             return mpMaterialAttribute3D->getSpecularIntensity();
202*cdf0e10cSrcweir         }
203*cdf0e10cSrcweir     } // end of namespace attribute
204*cdf0e10cSrcweir } // end of namespace drawinglayer
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
207*cdf0e10cSrcweir // eof
208