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 <svx/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>
30 :
31 : //////////////////////////////////////////////////////////////////////////////
32 :
33 : namespace drawinglayer
34 : {
35 : namespace primitive2d
36 : {
37 0 : attribute::Sdr3DObjectAttribute* createNewSdr3DObjectAttribute(const SfxItemSet& rSet)
38 : {
39 : // get NormalsKind
40 0 : ::com::sun::star::drawing::NormalsKind aNormalsKind(::com::sun::star::drawing::NormalsKind_SPECIFIC);
41 0 : const sal_uInt16 nNormalsValue(((const Svx3DNormalsKindItem&)rSet.Get(SDRATTR_3DOBJ_NORMALS_KIND)).GetValue());
42 :
43 0 : if(1L == nNormalsValue)
44 : {
45 0 : aNormalsKind = ::com::sun::star::drawing::NormalsKind_FLAT;
46 : }
47 0 : else if(2L == nNormalsValue)
48 : {
49 0 : aNormalsKind = ::com::sun::star::drawing::NormalsKind_SPHERE;
50 : }
51 :
52 : // get NoermalsInvert flag
53 0 : const bool bInvertNormals(((const Svx3DNormalsInvertItem&)rSet.Get(SDRATTR_3DOBJ_NORMALS_INVERT)).GetValue());
54 :
55 : // get TextureProjectionX
56 0 : ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC);
57 0 : const sal_uInt16 nTextureValueX(((const Svx3DTextureProjectionXItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_X)).GetValue());
58 :
59 0 : if(1L == nTextureValueX)
60 : {
61 0 : aTextureProjectionX = ::com::sun::star::drawing::TextureProjectionMode_PARALLEL;
62 : }
63 0 : else if(2L == nTextureValueX)
64 : {
65 0 : aTextureProjectionX = ::com::sun::star::drawing::TextureProjectionMode_SPHERE;
66 : }
67 :
68 : // get TextureProjectionY
69 0 : ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC);
70 0 : const sal_uInt16 nTextureValueY(((const Svx3DTextureProjectionYItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_Y)).GetValue());
71 :
72 0 : if(1L == nTextureValueY)
73 : {
74 0 : aTextureProjectionY = ::com::sun::star::drawing::TextureProjectionMode_PARALLEL;
75 : }
76 0 : else if(2L == nTextureValueY)
77 : {
78 0 : aTextureProjectionY = ::com::sun::star::drawing::TextureProjectionMode_SPHERE;
79 : }
80 :
81 : // get DoubleSided flag
82 0 : const bool bDoubleSided(((const Svx3DDoubleSidedItem&)rSet.Get(SDRATTR_3DOBJ_DOUBLE_SIDED)).GetValue());
83 :
84 : // get Shadow3D flag
85 0 : const bool bShadow3D(((const Svx3DShadow3DItem&)rSet.Get(SDRATTR_3DOBJ_SHADOW_3D)).GetValue());
86 :
87 : // get TextureFilter flag
88 0 : const bool bTextureFilter(((const Svx3DTextureFilterItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_FILTER)).GetValue());
89 :
90 : // get texture kind
91 : // TextureKind: 1 == Base3DTextureLuminance, 2 == Base3DTextureIntensity, 3 == Base3DTextureColor
92 0 : ::com::sun::star::drawing::TextureKind2 aTextureKind(::com::sun::star::drawing::TextureKind2_LUMINANCE);
93 0 : const sal_uInt16 nTextureKind(((const Svx3DTextureKindItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_KIND)).GetValue());
94 :
95 0 : if(2 == nTextureKind)
96 : {
97 0 : aTextureKind = ::com::sun::star::drawing::TextureKind2_INTENSITY;
98 : }
99 0 : else if(3 == nTextureKind)
100 : {
101 0 : aTextureKind = ::com::sun::star::drawing::TextureKind2_COLOR;
102 : }
103 :
104 : // get texture mode
105 : // TextureMode: 1 == Base3DTextureReplace, 2 == Base3DTextureModulate, 3 == Base3DTextureBlend
106 0 : ::com::sun::star::drawing::TextureMode aTextureMode(::com::sun::star::drawing::TextureMode_REPLACE);
107 0 : const sal_uInt16 nTextureMode(((const Svx3DTextureModeItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_MODE)).GetValue());
108 :
109 0 : if(2 == nTextureMode)
110 : {
111 0 : aTextureMode = ::com::sun::star::drawing::TextureMode_MODULATE;
112 : }
113 0 : else if(3 == nTextureMode)
114 : {
115 0 : aTextureMode = ::com::sun::star::drawing::TextureMode_BLEND;
116 : }
117 :
118 : // get object color
119 0 : const ::basegfx::BColor aObjectColor(((const XFillColorItem&)rSet.Get(XATTR_FILLCOLOR)).GetColorValue().getBColor());
120 :
121 : // get specular color
122 0 : const ::basegfx::BColor aSpecular(((const Svx3DMaterialSpecularItem&)rSet.Get(SDRATTR_3DOBJ_MAT_SPECULAR)).GetValue().getBColor());
123 :
124 : // get emissive color
125 0 : const ::basegfx::BColor aEmission(((const Svx3DMaterialEmissionItem&)rSet.Get(SDRATTR_3DOBJ_MAT_EMISSION)).GetValue().getBColor());
126 :
127 : // get specular intensity
128 0 : sal_uInt16 nSpecularIntensity(((const Svx3DMaterialSpecularIntensityItem&)rSet.Get(SDRATTR_3DOBJ_MAT_SPECULAR_INTENSITY)).GetValue());
129 :
130 0 : if(nSpecularIntensity > 128)
131 : {
132 0 : nSpecularIntensity = 128;
133 : }
134 :
135 : // get reduced line geometry
136 0 : const bool bReducedLineGeometry(((const Svx3DReducedLineGeometryItem&)rSet.Get(SDRATTR_3DOBJ_REDUCED_LINE_GEOMETRY)).GetValue());
137 :
138 : // prepare material
139 0 : attribute::MaterialAttribute3D aMaterial(aObjectColor, aSpecular, aEmission, nSpecularIntensity);
140 :
141 : return new attribute::Sdr3DObjectAttribute(
142 : aNormalsKind, aTextureProjectionX, aTextureProjectionY,
143 : aTextureKind, aTextureMode, aMaterial,
144 0 : bInvertNormals, bDoubleSided, bShadow3D, bTextureFilter, bReducedLineGeometry);
145 : }
146 : } // end of namespace primitive2d
147 : } // end of namespace sdr
148 :
149 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|