Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / sdr / primitive3d / sdrattributecreator3d.cxx
blob6bf8f8c6e2e09aa98911a75d16f3312cbe76227d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sdr/primitive3d/sdrattributecreator3d.hxx>
21 #include <svx/svx3ditems.hxx>
22 #include <svl/itemset.hxx>
23 #include <com/sun/star/drawing/NormalsKind.hpp>
24 #include <com/sun/star/drawing/TextureProjectionMode.hpp>
25 #include <com/sun/star/drawing/TextureKind2.hpp>
26 #include <com/sun/star/drawing/TextureMode.hpp>
27 #include <svx/xflclit.hxx>
28 #include <drawinglayer/attribute/materialattribute3d.hxx>
29 #include <drawinglayer/attribute/sdrobjectattribute3d.hxx>
32 namespace drawinglayer::primitive2d
34 attribute::Sdr3DObjectAttribute createNewSdr3DObjectAttribute(const SfxItemSet& rSet)
36 // get NormalsKind
37 css::drawing::NormalsKind aNormalsKind(css::drawing::NormalsKind_SPECIFIC);
38 const sal_uInt16 nNormalsValue(rSet.Get(SDRATTR_3DOBJ_NORMALS_KIND).GetValue());
40 if(1 == nNormalsValue)
42 aNormalsKind = css::drawing::NormalsKind_FLAT;
44 else if(2 == nNormalsValue)
46 aNormalsKind = css::drawing::NormalsKind_SPHERE;
49 // get NormalsInvert flag
50 const bool bInvertNormals(rSet.Get(SDRATTR_3DOBJ_NORMALS_INVERT).GetValue());
52 // get TextureProjectionX
53 css::drawing::TextureProjectionMode aTextureProjectionX(css::drawing::TextureProjectionMode_OBJECTSPECIFIC);
54 const sal_uInt16 nTextureValueX(rSet.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_X).GetValue());
56 if(1 == nTextureValueX)
58 aTextureProjectionX = css::drawing::TextureProjectionMode_PARALLEL;
60 else if(2 == nTextureValueX)
62 aTextureProjectionX = css::drawing::TextureProjectionMode_SPHERE;
65 // get TextureProjectionY
66 css::drawing::TextureProjectionMode aTextureProjectionY(css::drawing::TextureProjectionMode_OBJECTSPECIFIC);
67 const sal_uInt16 nTextureValueY(rSet.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_Y).GetValue());
69 if(1 == nTextureValueY)
71 aTextureProjectionY = css::drawing::TextureProjectionMode_PARALLEL;
73 else if(2 == nTextureValueY)
75 aTextureProjectionY = css::drawing::TextureProjectionMode_SPHERE;
78 // get DoubleSided flag
79 const bool bDoubleSided(rSet.Get(SDRATTR_3DOBJ_DOUBLE_SIDED).GetValue());
81 // get Shadow3D flag
82 const bool bShadow3D(rSet.Get(SDRATTR_3DOBJ_SHADOW_3D).GetValue());
84 // get TextureFilter flag
85 const bool bTextureFilter(rSet.Get(SDRATTR_3DOBJ_TEXTURE_FILTER).GetValue());
87 // get texture kind
88 // TextureKind: 1 == Base3DTextureLuminance, 2 == Base3DTextureIntensity, 3 == Base3DTextureColor
89 css::drawing::TextureKind2 aTextureKind(css::drawing::TextureKind2_LUMINANCE);
90 const sal_uInt16 nTextureKind(rSet.Get(SDRATTR_3DOBJ_TEXTURE_KIND).GetValue());
92 if(2 == nTextureKind)
94 aTextureKind = css::drawing::TextureKind2_INTENSITY;
96 else if(3 == nTextureKind)
98 aTextureKind = css::drawing::TextureKind2_COLOR;
101 // get texture mode
102 // TextureMode: 1 == Base3DTextureReplace, 2 == Base3DTextureModulate, 3 == Base3DTextureBlend
103 css::drawing::TextureMode aTextureMode(css::drawing::TextureMode_REPLACE);
104 const sal_uInt16 nTextureMode(rSet.Get(SDRATTR_3DOBJ_TEXTURE_MODE).GetValue());
106 if(2 == nTextureMode)
108 aTextureMode = css::drawing::TextureMode_MODULATE;
110 else if(3 == nTextureMode)
112 aTextureMode = css::drawing::TextureMode_BLEND;
115 // get object color
116 const ::basegfx::BColor aObjectColor(rSet.Get(XATTR_FILLCOLOR).GetColorValue().getBColor());
118 // get specular color
119 const ::basegfx::BColor aSpecular(rSet.Get(SDRATTR_3DOBJ_MAT_SPECULAR).GetValue().getBColor());
121 // get emissive color
122 const ::basegfx::BColor aEmission(rSet.Get(SDRATTR_3DOBJ_MAT_EMISSION).GetValue().getBColor());
124 // get specular intensity
125 sal_uInt16 nSpecularIntensity(rSet.Get(SDRATTR_3DOBJ_MAT_SPECULAR_INTENSITY).GetValue());
127 if(nSpecularIntensity > 128)
129 nSpecularIntensity = 128;
132 // get reduced line geometry
133 const bool bReducedLineGeometry(rSet.Get(SDRATTR_3DOBJ_REDUCED_LINE_GEOMETRY).GetValue());
135 // prepare material
136 attribute::MaterialAttribute3D aMaterial(aObjectColor, aSpecular, aEmission, nSpecularIntensity);
138 return attribute::Sdr3DObjectAttribute(
139 aNormalsKind, aTextureProjectionX, aTextureProjectionY,
140 aTextureKind, aTextureMode, aMaterial,
141 bInvertNormals, bDoubleSided, bShadow3D, bTextureFilter, bReducedLineGeometry);
143 } // end of namespace
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */