Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <drawinglayer/attribute/materialattribute3d.hxx>
21 : #include <basegfx/color/bcolor.hxx>
22 :
23 : //////////////////////////////////////////////////////////////////////////////
24 :
25 : namespace drawinglayer
26 : {
27 : namespace attribute
28 : {
29 0 : class ImpMaterialAttribute3D
30 : {
31 : public:
32 : // refcounter
33 : sal_uInt32 mnRefCount;
34 :
35 : // materialAttribute3D definitions
36 : basegfx::BColor maColor; // object color
37 : basegfx::BColor maSpecular; // material specular color
38 : basegfx::BColor maEmission; // material emissive color
39 : sal_uInt16 mnSpecularIntensity; // material specular intensity [0..128]
40 :
41 0 : ImpMaterialAttribute3D(const basegfx::BColor& rColor, const basegfx::BColor& rSpecular, const basegfx::BColor& rEmission, sal_uInt16 nSpecularIntensity)
42 : : mnRefCount(0),
43 : maColor(rColor),
44 : maSpecular(rSpecular),
45 : maEmission(rEmission),
46 0 : mnSpecularIntensity(nSpecularIntensity)
47 : {
48 0 : }
49 :
50 0 : ImpMaterialAttribute3D(const basegfx::BColor& rColor)
51 : : mnRefCount(0),
52 : maColor(rColor),
53 : maSpecular(1.0, 1.0, 1.0),
54 : maEmission(),
55 0 : mnSpecularIntensity(15)
56 : {
57 0 : }
58 :
59 : // data read access
60 0 : const basegfx::BColor& getColor() const { return maColor; }
61 0 : const basegfx::BColor& getSpecular() const { return maSpecular; }
62 0 : const basegfx::BColor& getEmission() const { return maEmission; }
63 0 : sal_uInt16 getSpecularIntensity() const { return mnSpecularIntensity; }
64 :
65 0 : bool operator==(const ImpMaterialAttribute3D& rCandidate) const
66 : {
67 0 : return (getColor() == rCandidate.getColor()
68 0 : && getSpecular() == rCandidate.getSpecular()
69 0 : && getEmission() == rCandidate.getEmission()
70 0 : && getSpecularIntensity() == rCandidate.getSpecularIntensity());
71 : }
72 :
73 0 : static ImpMaterialAttribute3D* get_global_default()
74 : {
75 : static ImpMaterialAttribute3D* pDefault = 0;
76 :
77 0 : if(!pDefault)
78 : {
79 : pDefault = new ImpMaterialAttribute3D(
80 : basegfx::BColor(),
81 : basegfx::BColor(),
82 : basegfx::BColor(),
83 0 : 0);
84 :
85 : // never delete; start with RefCount 1, not 0
86 0 : pDefault->mnRefCount++;
87 : }
88 :
89 0 : return pDefault;
90 : }
91 : };
92 :
93 0 : MaterialAttribute3D::MaterialAttribute3D(
94 : const basegfx::BColor& rColor,
95 : const basegfx::BColor& rSpecular,
96 : const basegfx::BColor& rEmission,
97 : sal_uInt16 nSpecularIntensity)
98 : : mpMaterialAttribute3D(new ImpMaterialAttribute3D(
99 0 : rColor, rSpecular, rEmission, nSpecularIntensity))
100 : {
101 0 : }
102 :
103 0 : MaterialAttribute3D::MaterialAttribute3D(
104 : const basegfx::BColor& rColor)
105 0 : : mpMaterialAttribute3D(new ImpMaterialAttribute3D(rColor))
106 : {
107 0 : }
108 :
109 0 : MaterialAttribute3D::MaterialAttribute3D()
110 0 : : mpMaterialAttribute3D(ImpMaterialAttribute3D::get_global_default())
111 : {
112 0 : mpMaterialAttribute3D->mnRefCount++;
113 0 : }
114 :
115 0 : MaterialAttribute3D::MaterialAttribute3D(const MaterialAttribute3D& rCandidate)
116 0 : : mpMaterialAttribute3D(rCandidate.mpMaterialAttribute3D)
117 : {
118 0 : mpMaterialAttribute3D->mnRefCount++;
119 0 : }
120 :
121 0 : MaterialAttribute3D::~MaterialAttribute3D()
122 : {
123 0 : if(mpMaterialAttribute3D->mnRefCount)
124 : {
125 0 : mpMaterialAttribute3D->mnRefCount--;
126 : }
127 : else
128 : {
129 0 : delete mpMaterialAttribute3D;
130 : }
131 0 : }
132 :
133 0 : bool MaterialAttribute3D::isDefault() const
134 : {
135 0 : return mpMaterialAttribute3D == ImpMaterialAttribute3D::get_global_default();
136 : }
137 :
138 0 : MaterialAttribute3D& MaterialAttribute3D::operator=(const MaterialAttribute3D& rCandidate)
139 : {
140 0 : if(rCandidate.mpMaterialAttribute3D != mpMaterialAttribute3D)
141 : {
142 0 : if(mpMaterialAttribute3D->mnRefCount)
143 : {
144 0 : mpMaterialAttribute3D->mnRefCount--;
145 : }
146 : else
147 : {
148 0 : delete mpMaterialAttribute3D;
149 : }
150 :
151 0 : mpMaterialAttribute3D = rCandidate.mpMaterialAttribute3D;
152 0 : mpMaterialAttribute3D->mnRefCount++;
153 : }
154 :
155 0 : return *this;
156 : }
157 :
158 0 : bool MaterialAttribute3D::operator==(const MaterialAttribute3D& rCandidate) const
159 : {
160 0 : if(rCandidate.mpMaterialAttribute3D == mpMaterialAttribute3D)
161 : {
162 0 : return true;
163 : }
164 :
165 0 : if(rCandidate.isDefault() != isDefault())
166 : {
167 0 : return false;
168 : }
169 :
170 0 : return (*rCandidate.mpMaterialAttribute3D == *mpMaterialAttribute3D);
171 : }
172 :
173 0 : const basegfx::BColor& MaterialAttribute3D::getColor() const
174 : {
175 0 : return mpMaterialAttribute3D->getColor();
176 : }
177 :
178 0 : const basegfx::BColor& MaterialAttribute3D::getSpecular() const
179 : {
180 0 : return mpMaterialAttribute3D->getSpecular();
181 : }
182 :
183 0 : const basegfx::BColor& MaterialAttribute3D::getEmission() const
184 : {
185 0 : return mpMaterialAttribute3D->getEmission();
186 : }
187 :
188 0 : sal_uInt16 MaterialAttribute3D::getSpecularIntensity() const
189 : {
190 0 : return mpMaterialAttribute3D->getSpecularIntensity();
191 : }
192 : } // end of namespace attribute
193 : } // end of namespace drawinglayer
194 :
195 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|