Branch data 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 : 13972 : 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 : 13944 : 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 : 13944 : mnSpecularIntensity(nSpecularIntensity)
47 : : {
48 : 13944 : }
49 : :
50 : 30 : ImpMaterialAttribute3D(const basegfx::BColor& rColor)
51 : : : mnRefCount(0),
52 : : maColor(rColor),
53 : : maSpecular(1.0, 1.0, 1.0),
54 : : maEmission(),
55 : 30 : mnSpecularIntensity(15)
56 : : {
57 : 30 : }
58 : :
59 : : // data read access
60 : 2206414 : const basegfx::BColor& getColor() const { return maColor; }
61 : 23068 : const basegfx::BColor& getSpecular() const { return maSpecular; }
62 : 23068 : const basegfx::BColor& getEmission() const { return maEmission; }
63 : 23068 : sal_uInt16 getSpecularIntensity() const { return mnSpecularIntensity; }
64 : :
65 : 10983 : bool operator==(const ImpMaterialAttribute3D& rCandidate) const
66 : : {
67 : 10983 : return (getColor() == rCandidate.getColor()
68 : 10983 : && getSpecular() == rCandidate.getSpecular()
69 : 10983 : && getEmission() == rCandidate.getEmission()
70 [ + - ][ + - : 32949 : && getSpecularIntensity() == rCandidate.getSpecularIntensity());
+ - + - ]
71 : : }
72 : :
73 : 21968 : static ImpMaterialAttribute3D* get_global_default()
74 : : {
75 : : static ImpMaterialAttribute3D* pDefault = 0;
76 : :
77 [ + + ]: 21968 : if(!pDefault)
78 : : {
79 : : pDefault = new ImpMaterialAttribute3D(
80 : : basegfx::BColor(),
81 : : basegfx::BColor(),
82 : : basegfx::BColor(),
83 [ + - ]: 2 : 0);
84 : :
85 : : // never delete; start with RefCount 1, not 0
86 : 2 : pDefault->mnRefCount++;
87 : : }
88 : :
89 : 21968 : return pDefault;
90 : : }
91 : : };
92 : :
93 : 13942 : 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 : 13942 : rColor, rSpecular, rEmission, nSpecularIntensity))
100 : : {
101 : 13942 : }
102 : :
103 : 30 : MaterialAttribute3D::MaterialAttribute3D(
104 : : const basegfx::BColor& rColor)
105 : 30 : : mpMaterialAttribute3D(new ImpMaterialAttribute3D(rColor))
106 : : {
107 : 30 : }
108 : :
109 : 2 : MaterialAttribute3D::MaterialAttribute3D()
110 : 2 : : mpMaterialAttribute3D(ImpMaterialAttribute3D::get_global_default())
111 : : {
112 : 2 : mpMaterialAttribute3D->mnRefCount++;
113 : 2 : }
114 : :
115 : 14014 : MaterialAttribute3D::MaterialAttribute3D(const MaterialAttribute3D& rCandidate)
116 : 14014 : : mpMaterialAttribute3D(rCandidate.mpMaterialAttribute3D)
117 : : {
118 : 14014 : mpMaterialAttribute3D->mnRefCount++;
119 : 14014 : }
120 : :
121 : 27986 : MaterialAttribute3D::~MaterialAttribute3D()
122 : : {
123 [ + + ]: 27986 : if(mpMaterialAttribute3D->mnRefCount)
124 : : {
125 : 14014 : mpMaterialAttribute3D->mnRefCount--;
126 : : }
127 : : else
128 : : {
129 [ + - ]: 13972 : delete mpMaterialAttribute3D;
130 : : }
131 : 27986 : }
132 : :
133 : 21966 : bool MaterialAttribute3D::isDefault() const
134 : : {
135 : 21966 : return mpMaterialAttribute3D == ImpMaterialAttribute3D::get_global_default();
136 : : }
137 : :
138 : 142 : MaterialAttribute3D& MaterialAttribute3D::operator=(const MaterialAttribute3D& rCandidate)
139 : : {
140 [ + + ]: 142 : if(rCandidate.mpMaterialAttribute3D != mpMaterialAttribute3D)
141 : : {
142 [ + - ]: 136 : if(mpMaterialAttribute3D->mnRefCount)
143 : : {
144 : 136 : mpMaterialAttribute3D->mnRefCount--;
145 : : }
146 : : else
147 : : {
148 [ # # ]: 0 : delete mpMaterialAttribute3D;
149 : : }
150 : :
151 : 136 : mpMaterialAttribute3D = rCandidate.mpMaterialAttribute3D;
152 : 136 : mpMaterialAttribute3D->mnRefCount++;
153 : : }
154 : :
155 : 142 : return *this;
156 : : }
157 : :
158 : 10983 : bool MaterialAttribute3D::operator==(const MaterialAttribute3D& rCandidate) const
159 : : {
160 [ - + ]: 10983 : if(rCandidate.mpMaterialAttribute3D == mpMaterialAttribute3D)
161 : : {
162 : 0 : return true;
163 : : }
164 : :
165 [ - + ]: 10983 : if(rCandidate.isDefault() != isDefault())
166 : : {
167 : 0 : return false;
168 : : }
169 : :
170 : 10983 : return (*rCandidate.mpMaterialAttribute3D == *mpMaterialAttribute3D);
171 : : }
172 : :
173 : 2184448 : const basegfx::BColor& MaterialAttribute3D::getColor() const
174 : : {
175 : 2184448 : return mpMaterialAttribute3D->getColor();
176 : : }
177 : :
178 : 1102 : const basegfx::BColor& MaterialAttribute3D::getSpecular() const
179 : : {
180 : 1102 : return mpMaterialAttribute3D->getSpecular();
181 : : }
182 : :
183 : 1102 : const basegfx::BColor& MaterialAttribute3D::getEmission() const
184 : : {
185 : 1102 : return mpMaterialAttribute3D->getEmission();
186 : : }
187 : :
188 : 1102 : sal_uInt16 MaterialAttribute3D::getSpecularIntensity() const
189 : : {
190 : 1102 : return mpMaterialAttribute3D->getSpecularIntensity();
191 : : }
192 : : } // end of namespace attribute
193 : : } // end of namespace drawinglayer
194 : :
195 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|