1*4bfbcde8SAndrew Rist /**************************************************************
2*4bfbcde8SAndrew Rist  *
3*4bfbcde8SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*4bfbcde8SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*4bfbcde8SAndrew Rist  * distributed with this work for additional information
6*4bfbcde8SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*4bfbcde8SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*4bfbcde8SAndrew Rist  * "License"); you may not use this file except in compliance
9*4bfbcde8SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*4bfbcde8SAndrew Rist  *
11*4bfbcde8SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*4bfbcde8SAndrew Rist  *
13*4bfbcde8SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*4bfbcde8SAndrew Rist  * software distributed under the License is distributed on an
15*4bfbcde8SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*4bfbcde8SAndrew Rist  * KIND, either express or implied.  See the License for the
17*4bfbcde8SAndrew Rist  * specific language governing permissions and limitations
18*4bfbcde8SAndrew Rist  * under the License.
19*4bfbcde8SAndrew Rist  *
20*4bfbcde8SAndrew Rist  *************************************************************/
21cdf0e10cSrcweir 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
26cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx>
27cdf0e10cSrcweir #include <basegfx/vector/b3dvector.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
30cdf0e10cSrcweir 
31cdf0e10cSrcweir namespace drawinglayer
32cdf0e10cSrcweir {
33cdf0e10cSrcweir 	namespace attribute
34cdf0e10cSrcweir 	{
35cdf0e10cSrcweir 		class ImpSdr3DLightAttribute
36cdf0e10cSrcweir 		{
37cdf0e10cSrcweir 		public:
38cdf0e10cSrcweir 			// refcounter
39cdf0e10cSrcweir 			sal_uInt32								mnRefCount;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 			// 3D light attribute definitions
42cdf0e10cSrcweir 			basegfx::BColor							maColor;
43cdf0e10cSrcweir 			basegfx::B3DVector						maDirection;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 			// bitfield
46cdf0e10cSrcweir 			unsigned								mbSpecular : 1;
47cdf0e10cSrcweir 
ImpSdr3DLightAttribute(const basegfx::BColor & rColor,const basegfx::B3DVector & rDirection,bool bSpecular)48cdf0e10cSrcweir 			ImpSdr3DLightAttribute(
49cdf0e10cSrcweir 			    const basegfx::BColor& rColor,
50cdf0e10cSrcweir 			    const basegfx::B3DVector& rDirection,
51cdf0e10cSrcweir 			    bool bSpecular)
52cdf0e10cSrcweir 			:	mnRefCount(0),
53cdf0e10cSrcweir 		    	maColor(rColor),
54cdf0e10cSrcweir 			    maDirection(rDirection),
55cdf0e10cSrcweir 			    mbSpecular(bSpecular)
56cdf0e10cSrcweir 		    {
57cdf0e10cSrcweir 		    }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 			// data read access
getColor() const60cdf0e10cSrcweir 			const basegfx::BColor& getColor() const { return maColor; }
getDirection() const61cdf0e10cSrcweir 			const basegfx::B3DVector& getDirection() const { return maDirection; }
getSpecular() const62cdf0e10cSrcweir 			bool getSpecular() const { return mbSpecular; }
63cdf0e10cSrcweir 
operator ==(const ImpSdr3DLightAttribute & rCandidate) const64cdf0e10cSrcweir 			bool operator==(const ImpSdr3DLightAttribute& rCandidate) const
65cdf0e10cSrcweir             {
66cdf0e10cSrcweir 			    return (getColor() == rCandidate.getColor()
67cdf0e10cSrcweir 				    && getDirection() == rCandidate.getDirection()
68cdf0e10cSrcweir 				    && getSpecular() == rCandidate.getSpecular());
69cdf0e10cSrcweir             }
70cdf0e10cSrcweir 
get_global_default()71cdf0e10cSrcweir             static ImpSdr3DLightAttribute* get_global_default()
72cdf0e10cSrcweir             {
73cdf0e10cSrcweir                 static ImpSdr3DLightAttribute* pDefault = 0;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir                 if(!pDefault)
76cdf0e10cSrcweir                 {
77cdf0e10cSrcweir                     pDefault = new ImpSdr3DLightAttribute(
78cdf0e10cSrcweir 			            basegfx::BColor(),
79cdf0e10cSrcweir 			            basegfx::B3DVector(),
80cdf0e10cSrcweir 			            false);
81cdf0e10cSrcweir 
82cdf0e10cSrcweir                     // never delete; start with RefCount 1, not 0
83cdf0e10cSrcweir     			    pDefault->mnRefCount++;
84cdf0e10cSrcweir                 }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir                 return pDefault;
87cdf0e10cSrcweir             }
88cdf0e10cSrcweir 		};
89cdf0e10cSrcweir 
Sdr3DLightAttribute(const basegfx::BColor & rColor,const basegfx::B3DVector & rDirection,bool bSpecular)90cdf0e10cSrcweir         Sdr3DLightAttribute::Sdr3DLightAttribute(
91cdf0e10cSrcweir 			const basegfx::BColor& rColor,
92cdf0e10cSrcweir 			const basegfx::B3DVector& rDirection,
93cdf0e10cSrcweir 			bool bSpecular)
94cdf0e10cSrcweir 		:	mpSdr3DLightAttribute(new ImpSdr3DLightAttribute(
95cdf0e10cSrcweir                 rColor, rDirection, bSpecular))
96cdf0e10cSrcweir 		{
97cdf0e10cSrcweir 		}
98cdf0e10cSrcweir 
Sdr3DLightAttribute()99cdf0e10cSrcweir 		Sdr3DLightAttribute::Sdr3DLightAttribute()
100cdf0e10cSrcweir         :	mpSdr3DLightAttribute(ImpSdr3DLightAttribute::get_global_default())
101cdf0e10cSrcweir 		{
102cdf0e10cSrcweir 			mpSdr3DLightAttribute->mnRefCount++;
103cdf0e10cSrcweir 		}
104cdf0e10cSrcweir 
Sdr3DLightAttribute(const Sdr3DLightAttribute & rCandidate)105cdf0e10cSrcweir         Sdr3DLightAttribute::Sdr3DLightAttribute(const Sdr3DLightAttribute& rCandidate)
106cdf0e10cSrcweir 		:	mpSdr3DLightAttribute(rCandidate.mpSdr3DLightAttribute)
107cdf0e10cSrcweir 		{
108cdf0e10cSrcweir 			mpSdr3DLightAttribute->mnRefCount++;
109cdf0e10cSrcweir 		}
110cdf0e10cSrcweir 
~Sdr3DLightAttribute()111cdf0e10cSrcweir 		Sdr3DLightAttribute::~Sdr3DLightAttribute()
112cdf0e10cSrcweir 		{
113cdf0e10cSrcweir 			if(mpSdr3DLightAttribute->mnRefCount)
114cdf0e10cSrcweir 			{
115cdf0e10cSrcweir 				mpSdr3DLightAttribute->mnRefCount--;
116cdf0e10cSrcweir 			}
117cdf0e10cSrcweir 			else
118cdf0e10cSrcweir 			{
119cdf0e10cSrcweir 				delete mpSdr3DLightAttribute;
120cdf0e10cSrcweir 			}
121cdf0e10cSrcweir 		}
122cdf0e10cSrcweir 
isDefault() const123cdf0e10cSrcweir         bool Sdr3DLightAttribute::isDefault() const
124cdf0e10cSrcweir         {
125cdf0e10cSrcweir             return mpSdr3DLightAttribute == ImpSdr3DLightAttribute::get_global_default();
126cdf0e10cSrcweir         }
127cdf0e10cSrcweir 
operator =(const Sdr3DLightAttribute & rCandidate)128cdf0e10cSrcweir         Sdr3DLightAttribute& Sdr3DLightAttribute::operator=(const Sdr3DLightAttribute& rCandidate)
129cdf0e10cSrcweir 		{
130cdf0e10cSrcweir 			if(rCandidate.mpSdr3DLightAttribute != mpSdr3DLightAttribute)
131cdf0e10cSrcweir 			{
132cdf0e10cSrcweir 				if(mpSdr3DLightAttribute->mnRefCount)
133cdf0e10cSrcweir 				{
134cdf0e10cSrcweir 					mpSdr3DLightAttribute->mnRefCount--;
135cdf0e10cSrcweir 				}
136cdf0e10cSrcweir 				else
137cdf0e10cSrcweir 				{
138cdf0e10cSrcweir 					delete mpSdr3DLightAttribute;
139cdf0e10cSrcweir 				}
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 				mpSdr3DLightAttribute = rCandidate.mpSdr3DLightAttribute;
142cdf0e10cSrcweir 				mpSdr3DLightAttribute->mnRefCount++;
143cdf0e10cSrcweir 			}
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 			return *this;
146cdf0e10cSrcweir 		}
147cdf0e10cSrcweir 
operator ==(const Sdr3DLightAttribute & rCandidate) const148cdf0e10cSrcweir 		bool Sdr3DLightAttribute::operator==(const Sdr3DLightAttribute& rCandidate) const
149cdf0e10cSrcweir 		{
150cdf0e10cSrcweir 			if(rCandidate.mpSdr3DLightAttribute == mpSdr3DLightAttribute)
151cdf0e10cSrcweir 			{
152cdf0e10cSrcweir 				return true;
153cdf0e10cSrcweir 			}
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 			if(rCandidate.isDefault() != isDefault())
156cdf0e10cSrcweir 			{
157cdf0e10cSrcweir 				return false;
158cdf0e10cSrcweir 			}
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 			return (*rCandidate.mpSdr3DLightAttribute == *mpSdr3DLightAttribute);
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 
getColor() const163cdf0e10cSrcweir 		const basegfx::BColor& Sdr3DLightAttribute::getColor() const
164cdf0e10cSrcweir         {
165cdf0e10cSrcweir             return mpSdr3DLightAttribute->getColor();
166cdf0e10cSrcweir         }
167cdf0e10cSrcweir 
getDirection() const168cdf0e10cSrcweir 		const basegfx::B3DVector& Sdr3DLightAttribute::getDirection() const
169cdf0e10cSrcweir         {
170cdf0e10cSrcweir             return mpSdr3DLightAttribute->getDirection();
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir 
getSpecular() const173cdf0e10cSrcweir 		bool Sdr3DLightAttribute::getSpecular() const
174cdf0e10cSrcweir         {
175cdf0e10cSrcweir             return mpSdr3DLightAttribute->getSpecular();
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 	} // end of namespace attribute
179cdf0e10cSrcweir } // end of namespace drawinglayer
180cdf0e10cSrcweir 
181cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
182cdf0e10cSrcweir // eof
183