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