Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * OpenOffice.org - a multi-platform office productivity suite
5 : : *
6 : : * The Contents of this file are made available subject to
7 : : * the terms of GNU Lesser General Public License Version 2.1.
8 : : *
9 : : *
10 : : * GNU Lesser General Public License Version 2.1
11 : : * =============================================
12 : : * Copyright 2005 by Sun Microsystems, Inc.
13 : : * 901 San Antonio Road, Palo Alto, CA 94303, USA
14 : : *
15 : : * This library is free software; you can redistribute it and/or
16 : : * modify it under the terms of the GNU Lesser General Public
17 : : * License version 2.1, as published by the Free Software Foundation.
18 : : *
19 : : * This library is distributed in the hope that it will be useful,
20 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 : : * Lesser General Public License for more details.
23 : : *
24 : : * You should have received a copy of the GNU Lesser General Public
25 : : * License along with this library; if not, write to the Free Software
26 : : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 : : * MA 02111-1307 USA
28 : : *
29 : : ************************************************************************/
30 : :
31 : : #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
32 : : #include <basegfx/color/bcolor.hxx>
33 : : #include <basegfx/vector/b3dvector.hxx>
34 : :
35 : : //////////////////////////////////////////////////////////////////////////////
36 : :
37 : : namespace drawinglayer
38 : : {
39 : : namespace attribute
40 : : {
41 : 9 : class ImpSdr3DLightAttribute
42 : : {
43 : : public:
44 : : // refcounter
45 : : sal_uInt32 mnRefCount;
46 : :
47 : : // 3D light attribute definitions
48 : : basegfx::BColor maColor;
49 : : basegfx::B3DVector maDirection;
50 : :
51 : : // bitfield
52 : : unsigned mbSpecular : 1;
53 : :
54 : 9 : ImpSdr3DLightAttribute(
55 : : const basegfx::BColor& rColor,
56 : : const basegfx::B3DVector& rDirection,
57 : : bool bSpecular)
58 : : : mnRefCount(0),
59 : : maColor(rColor),
60 : : maDirection(rDirection),
61 : 9 : mbSpecular(bSpecular)
62 : : {
63 : 9 : }
64 : :
65 : : // data read access
66 : 614 : const basegfx::BColor& getColor() const { return maColor; }
67 : 764 : const basegfx::B3DVector& getDirection() const { return maDirection; }
68 : 614 : bool getSpecular() const { return mbSpecular; }
69 : :
70 : 0 : bool operator==(const ImpSdr3DLightAttribute& rCandidate) const
71 : : {
72 : 0 : return (getColor() == rCandidate.getColor()
73 : 0 : && getDirection() == rCandidate.getDirection()
74 [ # # ]: 0 : && getSpecular() == rCandidate.getSpecular());
[ # # # # ]
75 : : }
76 : :
77 : 0 : static ImpSdr3DLightAttribute* get_global_default()
78 : : {
79 : : static ImpSdr3DLightAttribute* pDefault = 0;
80 : :
81 [ # # ]: 0 : if(!pDefault)
82 : : {
83 : : pDefault = new ImpSdr3DLightAttribute(
84 : : basegfx::BColor(),
85 : : basegfx::B3DVector(),
86 [ # # ]: 0 : false);
87 : :
88 : : // never delete; start with RefCount 1, not 0
89 : 0 : pDefault->mnRefCount++;
90 : : }
91 : :
92 : 0 : return pDefault;
93 : : }
94 : : };
95 : :
96 : 9 : Sdr3DLightAttribute::Sdr3DLightAttribute(
97 : : const basegfx::BColor& rColor,
98 : : const basegfx::B3DVector& rDirection,
99 : : bool bSpecular)
100 : : : mpSdr3DLightAttribute(new ImpSdr3DLightAttribute(
101 : 9 : rColor, rDirection, bSpecular))
102 : : {
103 : 9 : }
104 : :
105 : 18 : Sdr3DLightAttribute::Sdr3DLightAttribute(const Sdr3DLightAttribute& rCandidate)
106 : 18 : : mpSdr3DLightAttribute(rCandidate.mpSdr3DLightAttribute)
107 : : {
108 : 18 : mpSdr3DLightAttribute->mnRefCount++;
109 : 18 : }
110 : :
111 : 27 : Sdr3DLightAttribute::~Sdr3DLightAttribute()
112 : : {
113 [ + + ]: 27 : if(mpSdr3DLightAttribute->mnRefCount)
114 : : {
115 : 18 : mpSdr3DLightAttribute->mnRefCount--;
116 : : }
117 : : else
118 : : {
119 [ + - ]: 9 : delete mpSdr3DLightAttribute;
120 : : }
121 : 27 : }
122 : :
123 : 0 : bool Sdr3DLightAttribute::isDefault() const
124 : : {
125 : 0 : return mpSdr3DLightAttribute == ImpSdr3DLightAttribute::get_global_default();
126 : : }
127 : :
128 : 0 : Sdr3DLightAttribute& Sdr3DLightAttribute::operator=(const Sdr3DLightAttribute& rCandidate)
129 : : {
130 [ # # ]: 0 : if(rCandidate.mpSdr3DLightAttribute != mpSdr3DLightAttribute)
131 : : {
132 [ # # ]: 0 : if(mpSdr3DLightAttribute->mnRefCount)
133 : : {
134 : 0 : mpSdr3DLightAttribute->mnRefCount--;
135 : : }
136 : : else
137 : : {
138 [ # # ]: 0 : delete mpSdr3DLightAttribute;
139 : : }
140 : :
141 : 0 : mpSdr3DLightAttribute = rCandidate.mpSdr3DLightAttribute;
142 : 0 : mpSdr3DLightAttribute->mnRefCount++;
143 : : }
144 : :
145 : 0 : return *this;
146 : : }
147 : :
148 : 0 : bool Sdr3DLightAttribute::operator==(const Sdr3DLightAttribute& rCandidate) const
149 : : {
150 [ # # ]: 0 : if(rCandidate.mpSdr3DLightAttribute == mpSdr3DLightAttribute)
151 : : {
152 : 0 : return true;
153 : : }
154 : :
155 [ # # ]: 0 : if(rCandidate.isDefault() != isDefault())
156 : : {
157 : 0 : return false;
158 : : }
159 : :
160 : 0 : return (*rCandidate.mpSdr3DLightAttribute == *mpSdr3DLightAttribute);
161 : : }
162 : :
163 : 614 : const basegfx::BColor& Sdr3DLightAttribute::getColor() const
164 : : {
165 : 614 : return mpSdr3DLightAttribute->getColor();
166 : : }
167 : :
168 : 764 : const basegfx::B3DVector& Sdr3DLightAttribute::getDirection() const
169 : : {
170 : 764 : return mpSdr3DLightAttribute->getDirection();
171 : : }
172 : :
173 : 614 : bool Sdr3DLightAttribute::getSpecular() const
174 : : {
175 : 614 : return mpSdr3DLightAttribute->getSpecular();
176 : : }
177 : :
178 : : } // end of namespace attribute
179 : : } // end of namespace drawinglayer
180 : :
181 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|