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 : #ifndef INCLUDED_SVX_DLGCTL3D_HXX
21 : #define INCLUDED_SVX_DLGCTL3D_HXX
22 :
23 : #include <vcl/ctrl.hxx>
24 : #include <vcl/scrbar.hxx>
25 : #include <vcl/button.hxx>
26 : #include <svl/itemset.hxx>
27 : #include <svx/svxdllapi.h>
28 : #include <basegfx/vector/b3dvector.hxx>
29 :
30 : class FmFormModel;
31 : class FmFormPage;
32 : class E3dView;
33 : class E3dPolyScene;
34 : class E3dObject;
35 :
36 : enum class SvxPreviewObjectType { SPHERE, CUBE };
37 :
38 : class SVX_DLLPUBLIC SAL_WARN_UNUSED Svx3DPreviewControl : public Control
39 : {
40 : protected:
41 : FmFormModel* mpModel;
42 : FmFormPage* mpFmPage;
43 : E3dView* mp3DView;
44 : E3dPolyScene* mpScene;
45 : E3dObject* mp3DObj;
46 : SvxPreviewObjectType mnObjectType;
47 :
48 : void Construct();
49 :
50 : public:
51 : Svx3DPreviewControl(vcl::Window* pParent, WinBits nStyle = 0);
52 : virtual ~Svx3DPreviewControl();
53 : virtual void dispose() SAL_OVERRIDE;
54 :
55 : virtual void Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect ) SAL_OVERRIDE;
56 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
57 : virtual void Resize() SAL_OVERRIDE;
58 : virtual Size GetOptimalSize() const SAL_OVERRIDE;
59 :
60 : void Reset();
61 : virtual void SetObjectType(SvxPreviewObjectType nType);
62 0 : SvxPreviewObjectType GetObjectType() const { return mnObjectType; }
63 : SfxItemSet Get3DAttributes() const;
64 : virtual void Set3DAttributes(const SfxItemSet& rAttr);
65 : };
66 :
67 0 : class SVX_DLLPUBLIC SAL_WARN_UNUSED Svx3DLightControl : public Svx3DPreviewControl
68 : {
69 : // Callback for interactive changes
70 : Link<> maUserInteractiveChangeCallback;
71 : Link<> maUserSelectionChangeCallback;
72 : Link<> maChangeCallback;
73 : Link<> maSelectionChangeCallback;
74 :
75 : // lights
76 : sal_uInt32 maSelectedLight;
77 :
78 : // extra objects for light control
79 : E3dObject* mpExpansionObject;
80 : E3dObject* mpLampBottomObject;
81 : E3dObject* mpLampShaftObject;
82 : std::vector< E3dObject* > maLightObjects;
83 :
84 : // 3d rotations of object
85 : double mfRotateX;
86 : double mfRotateY;
87 : double mfRotateZ;
88 :
89 : // interaction parameters
90 : Point maActionStartPoint;
91 : sal_Int32 mnInteractionStartDistance;
92 : double mfSaveActionStartHor;
93 : double mfSaveActionStartVer;
94 : double mfSaveActionStartRotZ;
95 :
96 : // bitfield
97 : bool mbMouseMoved : 1;
98 : bool mbGeometrySelected : 1;
99 :
100 : void Construct2();
101 : void ConstructLightObjects();
102 : void AdaptToSelectedLight();
103 : void TrySelection(Point aPosPixel);
104 :
105 : public:
106 : Svx3DLightControl(vcl::Window* pParent, WinBits nStyle = 0);
107 :
108 : virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
109 : virtual void MouseButtonDown(const MouseEvent& rMEvt) SAL_OVERRIDE;
110 : virtual void Tracking( const TrackingEvent& rTEvt ) SAL_OVERRIDE;
111 : virtual void Resize() SAL_OVERRIDE;
112 :
113 : virtual void SetObjectType(SvxPreviewObjectType nType) SAL_OVERRIDE;
114 :
115 : // register user callback
116 : void SetUserInteractiveChangeCallback(Link<> aNew) { maUserInteractiveChangeCallback = aNew; }
117 : void SetUserSelectionChangeCallback(Link<> aNew) { maUserSelectionChangeCallback = aNew; }
118 0 : void SetChangeCallback(Link<> aNew) { maChangeCallback = aNew; }
119 0 : void SetSelectionChangeCallback(Link<> aNew) { maSelectionChangeCallback = aNew; }
120 :
121 : // selection checks
122 : bool IsSelectionValid();
123 0 : bool IsGeometrySelected() { return mbGeometrySelected; }
124 :
125 : // get/set position of selected lamp in polar coordinates, Hor:[0..360.0[ and Ver:[-90..90] degrees
126 : void GetPosition(double& rHor, double& rVer);
127 : void SetPosition(double fHor, double fVer);
128 :
129 : // get/set rotation of 3D object
130 : void SetRotation(double fRotX, double fRotY, double fRotZ);
131 : void GetRotation(double& rRotX, double& rRotY, double& rRotZ);
132 :
133 : void SelectLight(sal_uInt32 nLightNumber);
134 : virtual void Set3DAttributes(const SfxItemSet& rAttr) SAL_OVERRIDE;
135 0 : sal_uInt32 GetSelectedLight() { return maSelectedLight; }
136 :
137 : // light data access
138 : bool GetLightOnOff(sal_uInt32 nNum) const;
139 : Color GetLightColor(sal_uInt32 nNum) const;
140 : basegfx::B3DVector GetLightDirection(sal_uInt32 nNum) const;
141 : };
142 :
143 : class SVX_DLLPUBLIC SAL_WARN_UNUSED SvxLightCtl3D : public Control
144 : {
145 : private:
146 : // local controls
147 : VclPtr<Svx3DLightControl> maLightControl;
148 : VclPtr<ScrollBar> maHorScroller;
149 : VclPtr<ScrollBar> maVerScroller;
150 : VclPtr<PushButton> maSwitcher;
151 :
152 : // callback for interactive changes
153 : Link<> maUserInteractiveChangeCallback;
154 : Link<> maUserSelectionChangeCallback;
155 :
156 : public:
157 : SvxLightCtl3D(vcl::Window* pParent);
158 : virtual ~SvxLightCtl3D();
159 : virtual void dispose() SAL_OVERRIDE;
160 :
161 : // react to size changes
162 : virtual void Resize() SAL_OVERRIDE;
163 : void NewLayout();
164 :
165 : // check the selection for validity
166 : void CheckSelection();
167 :
168 : // bring further settings to the outside world
169 0 : Svx3DLightControl& GetSvx3DLightControl() { return *maLightControl.get(); }
170 :
171 : // register user callback
172 0 : void SetUserInteractiveChangeCallback(Link<> aNew) { maUserInteractiveChangeCallback = aNew; }
173 0 : void SetUserSelectionChangeCallback(Link<> aNew) { maUserSelectionChangeCallback = aNew; }
174 :
175 : virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
176 : virtual void GetFocus() SAL_OVERRIDE;
177 : virtual void LoseFocus() SAL_OVERRIDE;
178 :
179 : virtual Size GetOptimalSize() const SAL_OVERRIDE;
180 :
181 : protected:
182 :
183 : DECL_LINK( InternalInteractiveChange, void*);
184 : DECL_LINK( InternalSelectionChange, void*);
185 : DECL_LINK( ScrollBarMove, void*);
186 : DECL_LINK( ButtonPress, void*);
187 :
188 : // initialize local parameters
189 : void Init();
190 :
191 : void move( double fDeltaHor, double fDeltaVer );
192 : };
193 :
194 : #endif // _SCH_DLGCTL3D_HXX
195 :
196 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|