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 <vcl/customweld.hxx>
27 #include <vcl/weld.hxx>
28 #include <svl/itemset.hxx>
29 #include <svx/svxdllapi.h>
30 #include <basegfx/vector/b3dvector.hxx>
31 #include <memory>
32 
33 class FmFormModel;
34 class FmFormPage;
35 class E3dView;
36 class E3dObject;
37 class E3dScene;
38 
39 enum class SvxPreviewObjectType { SPHERE, CUBE };
40 
41 class SAL_WARN_UNUSED Svx3DPreviewControl : public Control
42 {
43 protected:
44     std::unique_ptr<FmFormModel> mpModel;
45     FmFormPage*             mpFmPage;
46     std::unique_ptr<E3dView> mp3DView;
47     E3dScene*               mpScene;
48     E3dObject*              mp3DObj;
49     SvxPreviewObjectType    mnObjectType;
50 
51     void Construct();
52 
53 public:
54     Svx3DPreviewControl(vcl::Window* pParent, WinBits nStyle = 0);
55     virtual ~Svx3DPreviewControl() override;
56     virtual void dispose() override;
57 
58     virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
59     virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
60     virtual void Resize() override;
61     virtual Size GetOptimalSize() const override;
62 
63     virtual void SetObjectType(SvxPreviewObjectType nType);
GetObjectType() const64     SvxPreviewObjectType GetObjectType() const { return mnObjectType; }
65     SfxItemSet const & Get3DAttributes() const;
66     virtual void Set3DAttributes(const SfxItemSet& rAttr);
67 };
68 
69 class SAL_WARN_UNUSED SVX_DLLPUBLIC PreviewControl3D : public weld::CustomWidgetController
70 {
71 protected:
72     std::unique_ptr<FmFormModel> mpModel;
73     FmFormPage*             mpFmPage;
74     std::unique_ptr<E3dView> mp3DView;
75     E3dScene*               mpScene;
76     E3dObject*              mp3DObj;
77     SvxPreviewObjectType    mnObjectType;
78 
79     void Construct();
80 
81 public:
82     PreviewControl3D();
83     virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
84     virtual ~PreviewControl3D() override;
85 
86     virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
87     virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
88     virtual void Resize() override;
89 
90     virtual void SetObjectType(SvxPreviewObjectType nType);
GetObjectType() const91     SvxPreviewObjectType GetObjectType() const { return mnObjectType; }
92     SfxItemSet const & Get3DAttributes() const;
93     virtual void Set3DAttributes(const SfxItemSet& rAttr);
94 };
95 
96 
97 class SAL_WARN_UNUSED Svx3DLightControl final : public Svx3DPreviewControl
98 {
99     // Callback for interactive changes
100     Link<Svx3DLightControl*,void>  maChangeCallback;
101     Link<Svx3DLightControl*,void>  maSelectionChangeCallback;
102 
103     // lights
104     sal_uInt32                  maSelectedLight;
105 
106     // extra objects for light control
107     E3dObject*                  mpExpansionObject;
108     E3dObject*                  mpLampBottomObject;
109     E3dObject*                  mpLampShaftObject;
110     std::vector< E3dObject* >   maLightObjects;
111 
112     // 3d rotations of object
113     double                      mfRotateX;
114     double                      mfRotateY;
115     double                      mfRotateZ;
116 
117     // interaction parameters
118     Point                       maActionStartPoint;
119     double                      mfSaveActionStartHor;
120     double                      mfSaveActionStartVer;
121     double                      mfSaveActionStartRotZ;
122 
123     bool                        mbMouseMoved : 1;
124     bool                        mbGeometrySelected : 1;
125 
126     void Construct2();
127     void ConstructLightObjects();
128     void AdaptToSelectedLight();
129     void TrySelection(Point aPosPixel);
130 
131 public:
132     Svx3DLightControl(vcl::Window* pParent, WinBits nStyle);
133 
134     virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
135     virtual void MouseButtonDown(const MouseEvent& rMEvt) override;
136     virtual void Tracking( const TrackingEvent& rTEvt ) override;
137     virtual void Resize() override;
138 
139     virtual void SetObjectType(SvxPreviewObjectType nType) override;
140 
141     // register user callback
SetChangeCallback(Link<Svx3DLightControl *,void> aNew)142     void SetChangeCallback(Link<Svx3DLightControl*,void> aNew) { maChangeCallback = aNew; }
SetSelectionChangeCallback(Link<Svx3DLightControl *,void> aNew)143     void SetSelectionChangeCallback(Link<Svx3DLightControl*,void> aNew) { maSelectionChangeCallback = aNew; }
144 
145     // selection checks
146     bool IsSelectionValid();
IsGeometrySelected() const147     bool IsGeometrySelected() const { return mbGeometrySelected; }
148 
149     // get/set position of selected lamp in polar coordinates, Hor:[0..360.0[ and Ver:[-90..90] degrees
150     void GetPosition(double& rHor, double& rVer);
151     void SetPosition(double fHor, double fVer);
152 
153     // get/set rotation of 3D object
154     void SetRotation(double fRotX, double fRotY, double fRotZ);
155     void GetRotation(double& rRotX, double& rRotY, double& rRotZ);
156 
157     void SelectLight(sal_uInt32 nLightNumber);
158     virtual void Set3DAttributes(const SfxItemSet& rAttr) override;
GetSelectedLight() const159     sal_uInt32 GetSelectedLight() const { return maSelectedLight; }
160 
161     // light data access
162     bool GetLightOnOff(sal_uInt32 nNum) const;
163     Color GetLightColor(sal_uInt32 nNum) const;
164     basegfx::B3DVector GetLightDirection(sal_uInt32 nNum) const;
165 };
166 
167 class SAL_WARN_UNUSED SVX_DLLPUBLIC LightControl3D final : public PreviewControl3D
168 {
169     // Callback for interactive changes
170     Link<LightControl3D*,void>  maChangeCallback;
171     Link<LightControl3D*,void>  maSelectionChangeCallback;
172 
173     // lights
174     sal_uInt32                  maSelectedLight;
175 
176     // extra objects for light control
177     E3dObject*                  mpExpansionObject;
178     E3dObject*                  mpLampBottomObject;
179     E3dObject*                  mpLampShaftObject;
180     std::vector< E3dObject* >   maLightObjects;
181 
182     // 3d rotations of object
183     double                      mfRotateX;
184     double                      mfRotateY;
185     double                      mfRotateZ;
186 
187     // interaction parameters
188     Point                       maActionStartPoint;
189     double                      mfSaveActionStartHor;
190     double                      mfSaveActionStartVer;
191     double                      mfSaveActionStartRotZ;
192 
193     bool                        mbMouseMoved : 1;
194     bool                        mbMouseCaptured : 1;
195     bool                        mbGeometrySelected : 1;
196 
197     void Construct2();
198     void ConstructLightObjects();
199     void AdaptToSelectedLight();
200     void TrySelection(Point aPosPixel);
201 
202 public:
203     LightControl3D();
204 
205     virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
206     virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
207     virtual tools::Rectangle GetFocusRect() override;
208     virtual bool MouseButtonDown(const MouseEvent& rMEvt) override;
209     virtual bool MouseMove( const MouseEvent& rMEvt ) override;
210     virtual bool MouseButtonUp( const MouseEvent& rMEvt ) override;
211     virtual void Resize() override;
212 
213     virtual void SetObjectType(SvxPreviewObjectType nType) override;
214 
215     // register user callback
SetChangeCallback(Link<LightControl3D *,void> aNew)216     void SetChangeCallback(Link<LightControl3D*,void> aNew) { maChangeCallback = aNew; }
SetSelectionChangeCallback(Link<LightControl3D *,void> aNew)217     void SetSelectionChangeCallback(Link<LightControl3D*,void> aNew) { maSelectionChangeCallback = aNew; }
218 
219     // selection checks
220     bool IsSelectionValid();
IsGeometrySelected() const221     bool IsGeometrySelected() const { return mbGeometrySelected; }
222 
223     // get/set position of selected lamp in polar coordinates, Hor:[0..360.0[ and Ver:[-90..90] degrees
224     void GetPosition(double& rHor, double& rVer);
225     void SetPosition(double fHor, double fVer);
226 
227     // get/set rotation of 3D object
228     void SetRotation(double fRotX, double fRotY, double fRotZ);
229     void GetRotation(double& rRotX, double& rRotY, double& rRotZ);
230 
231     void SelectLight(sal_uInt32 nLightNumber);
232     virtual void Set3DAttributes(const SfxItemSet& rAttr) override;
GetSelectedLight() const233     sal_uInt32 GetSelectedLight() const { return maSelectedLight; }
234 
235     // light data access
236     bool GetLightOnOff(sal_uInt32 nNum) const;
237     Color GetLightColor(sal_uInt32 nNum) const;
238     basegfx::B3DVector GetLightDirection(sal_uInt32 nNum) const;
239 };
240 
241 class SAL_WARN_UNUSED SvxLightCtl3D final : public Control
242 {
243     // local controls
244     VclPtr<Svx3DLightControl>  maLightControl;
245     VclPtr<ScrollBar>          maHorScroller;
246     VclPtr<ScrollBar>          maVerScroller;
247     VclPtr<PushButton>         maSwitcher;
248 
249     // callback for interactive changes
250     Link<SvxLightCtl3D*,void>  maUserSelectionChangeCallback;
251 
252 public:
253     SvxLightCtl3D(vcl::Window* pParent);
254     virtual ~SvxLightCtl3D() override;
255     virtual void dispose() override;
256 
257     // react to size changes
258     virtual void Resize() override;
259     void NewLayout();
260 
261     // check the selection for validity
262     void CheckSelection();
263 
264     // bring further settings to the outside world
GetSvx3DLightControl()265     Svx3DLightControl& GetSvx3DLightControl() { return *maLightControl; }
266 
267     // register user callback
SetUserSelectionChangeCallback(Link<SvxLightCtl3D *,void> aNew)268     void SetUserSelectionChangeCallback(Link<SvxLightCtl3D*,void> aNew) { maUserSelectionChangeCallback = aNew; }
269 
270     virtual void KeyInput( const KeyEvent& rKEvt ) override;
271     virtual void GetFocus() override;
272     virtual void LoseFocus() override;
273 
274     virtual Size GetOptimalSize() const override;
275 
276 private:
277 
278     DECL_LINK( InternalInteractiveChange, Svx3DLightControl*, void);
279     DECL_LINK( InternalSelectionChange, Svx3DLightControl*, void);
280     DECL_LINK( ScrollBarMove, ScrollBar*, void);
281     DECL_LINK( ButtonPress, Button*, void);
282 
283     // initialize local parameters
284     void Init();
285 
286     void move( double fDeltaHor, double fDeltaVer );
287 };
288 
289 class SAL_WARN_UNUSED SVX_DLLPUBLIC LightCtl3D
290 {
291     // local controls
292     LightControl3D& mrLightControl;
293     weld::Scale& mrHorScroller;
294     weld::Scale& mrVerScroller;
295     weld::Button& mrSwitcher;
296 
297     // callback for interactive changes
298     Link<LightCtl3D*,void>  maUserInteractiveChangeCallback;
299     Link<LightCtl3D*,void>  maUserSelectionChangeCallback;
300 
301 public:
302     LightCtl3D(LightControl3D& rLightControl, weld::Scale& rHori,
303                weld::Scale& rVert, weld::Button& rButton);
304     ~LightCtl3D();
305 
306     // check the selection for validity
307     void CheckSelection();
308 
309     // bring further settings to the outside world
GetSvx3DLightControl()310     LightControl3D& GetSvx3DLightControl() { return mrLightControl; }
311 
312     // register user callback
SetUserInteractiveChangeCallback(Link<LightCtl3D *,void> aNew)313     void SetUserInteractiveChangeCallback(Link<LightCtl3D*,void> aNew) { maUserInteractiveChangeCallback = aNew; }
SetUserSelectionChangeCallback(Link<LightCtl3D *,void> aNew)314     void SetUserSelectionChangeCallback(Link<LightCtl3D*,void> aNew) { maUserSelectionChangeCallback = aNew; }
315 
316 private:
317 
318     DECL_LINK(InternalInteractiveChange, LightControl3D*, void);
319     DECL_LINK(InternalSelectionChange, LightControl3D*, void);
320     DECL_LINK(ScrollBarMove, weld::Scale&, void);
321     DECL_LINK(ButtonPress, weld::Button&, void);
322     DECL_LINK(KeyInput, const KeyEvent&, bool);
323     DECL_LINK(FocusIn, weld::Widget&, void);
324 
325     // initialize local parameters
326     void Init();
327 
328     void move( double fDeltaHor, double fDeltaVer );
329 };
330 
331 
332 #endif // _SCH_DLGCTL3D_HXX
333 
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
335