bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / sdr / primitive3d / sdrattributecreator3d.cxx
blob54b335b7a0131e85c30520ef215ef708a5259410
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>
33 namespace drawinglayer
35 namespace primitive2d
37 attribute::Sdr3DObjectAttribute* createNewSdr3DObjectAttribute(const SfxItemSet& rSet)
39 // get NormalsKind
40 ::com::sun::star::drawing::NormalsKind aNormalsKind(::com::sun::star::drawing::NormalsKind_SPECIFIC);
41 const sal_uInt16 nNormalsValue(static_cast<const Svx3DNormalsKindItem&>(rSet.Get(SDRATTR_3DOBJ_NORMALS_KIND)).GetValue());
43 if(1L == nNormalsValue)
45 aNormalsKind = ::com::sun::star::drawing::NormalsKind_FLAT;
47 else if(2L == nNormalsValue)
49 aNormalsKind = ::com::sun::star::drawing::NormalsKind_SPHERE;
52 // get NoermalsInvert flag
53 const bool bInvertNormals(static_cast<const SfxBoolItem&>(rSet.Get(SDRATTR_3DOBJ_NORMALS_INVERT)).GetValue());
55 // get TextureProjectionX
56 ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC);
57 const sal_uInt16 nTextureValueX(static_cast<const Svx3DTextureProjectionXItem&>(rSet.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_X)).GetValue());
59 if(1L == nTextureValueX)
61 aTextureProjectionX = ::com::sun::star::drawing::TextureProjectionMode_PARALLEL;
63 else if(2L == nTextureValueX)
65 aTextureProjectionX = ::com::sun::star::drawing::TextureProjectionMode_SPHERE;
68 // get TextureProjectionY
69 ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC);
70 const sal_uInt16 nTextureValueY(static_cast<const Svx3DTextureProjectionYItem&>(rSet.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_Y)).GetValue());
72 if(1L == nTextureValueY)
74 aTextureProjectionY = ::com::sun::star::drawing::TextureProjectionMode_PARALLEL;
76 else if(2L == nTextureValueY)
78 aTextureProjectionY = ::com::sun::star::drawing::TextureProjectionMode_SPHERE;
81 // get DoubleSided flag
82 const bool bDoubleSided(static_cast<const SfxBoolItem&>(rSet.Get(SDRATTR_3DOBJ_DOUBLE_SIDED)).GetValue());
84 // get Shadow3D flag
85 const bool bShadow3D(static_cast<const SfxBoolItem&>(rSet.Get(SDRATTR_3DOBJ_SHADOW_3D)).GetValue());
87 // get TextureFilter flag
88 const bool bTextureFilter(static_cast<const SfxBoolItem&>(rSet.Get(SDRATTR_3DOBJ_TEXTURE_FILTER)).GetValue());
90 // get texture kind
91 // TextureKind: 1 == Base3DTextureLuminance, 2 == Base3DTextureIntensity, 3 == Base3DTextureColor
92 ::com::sun::star::drawing::TextureKind2 aTextureKind(::com::sun::star::drawing::TextureKind2_LUMINANCE);
93 const sal_uInt16 nTextureKind(static_cast<const Svx3DTextureKindItem&>(rSet.Get(SDRATTR_3DOBJ_TEXTURE_KIND)).GetValue());
95 if(2 == nTextureKind)
97 aTextureKind = ::com::sun::star::drawing::TextureKind2_INTENSITY;
99 else if(3 == nTextureKind)
101 aTextureKind = ::com::sun::star::drawing::TextureKind2_COLOR;
104 // get texture mode
105 // TextureMode: 1 == Base3DTextureReplace, 2 == Base3DTextureModulate, 3 == Base3DTextureBlend
106 ::com::sun::star::drawing::TextureMode aTextureMode(::com::sun::star::drawing::TextureMode_REPLACE);
107 const sal_uInt16 nTextureMode(static_cast<const Svx3DTextureModeItem&>(rSet.Get(SDRATTR_3DOBJ_TEXTURE_MODE)).GetValue());
109 if(2 == nTextureMode)
111 aTextureMode = ::com::sun::star::drawing::TextureMode_MODULATE;
113 else if(3 == nTextureMode)
115 aTextureMode = ::com::sun::star::drawing::TextureMode_BLEND;
118 // get object color
119 const ::basegfx::BColor aObjectColor(static_cast<const XFillColorItem&>(rSet.Get(XATTR_FILLCOLOR)).GetColorValue().getBColor());
121 // get specular color
122 const ::basegfx::BColor aSpecular(static_cast<const SvxColorItem&>(rSet.Get(SDRATTR_3DOBJ_MAT_SPECULAR)).GetValue().getBColor());
124 // get emissive color
125 const ::basegfx::BColor aEmission(static_cast<const SvxColorItem&>(rSet.Get(SDRATTR_3DOBJ_MAT_EMISSION)).GetValue().getBColor());
127 // get specular intensity
128 sal_uInt16 nSpecularIntensity(static_cast<const SfxUInt16Item&>(rSet.Get(SDRATTR_3DOBJ_MAT_SPECULAR_INTENSITY)).GetValue());
130 if(nSpecularIntensity > 128)
132 nSpecularIntensity = 128;
135 // get reduced line geometry
136 const bool bReducedLineGeometry(static_cast<const Svx3DReducedLineGeometryItem&>(rSet.Get(SDRATTR_3DOBJ_REDUCED_LINE_GEOMETRY)).GetValue());
138 // prepare material
139 attribute::MaterialAttribute3D aMaterial(aObjectColor, aSpecular, aEmission, nSpecularIntensity);
141 return new attribute::Sdr3DObjectAttribute(
142 aNormalsKind, aTextureProjectionX, aTextureProjectionY,
143 aTextureKind, aTextureMode, aMaterial,
144 bInvertNormals, bDoubleSided, bShadow3D, bTextureFilter, bReducedLineGeometry);
146 } // end of namespace primitive2d
147 } // end of namespace sdr
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */