1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SVX_DLGCTL3D_HXX
21 #define INCLUDED_SVX_DLGCTL3D_HXX
23 #include <vcl/customweld.hxx>
24 #include <vcl/weld.hxx>
25 #include <svl/itemset.hxx>
26 #include <svx/svxdllapi.h>
27 #include <basegfx/vector/b3dvector.hxx>
36 enum class SvxPreviewObjectType
{ SPHERE
, CUBE
};
38 class SAL_WARN_UNUSED SVX_DLLPUBLIC Svx3DPreviewControl
: public weld::CustomWidgetController
41 std::unique_ptr
<FmFormModel
> mpModel
;
43 std::unique_ptr
<E3dView
> mp3DView
;
46 SvxPreviewObjectType mnObjectType
;
51 Svx3DPreviewControl();
52 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
53 virtual ~Svx3DPreviewControl() override
;
55 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
56 virtual bool MouseButtonDown( const MouseEvent
& rMEvt
) override
;
57 virtual void Resize() override
;
59 virtual void SetObjectType(SvxPreviewObjectType nType
);
60 SvxPreviewObjectType
GetObjectType() const { return mnObjectType
; }
61 SfxItemSet
const & Get3DAttributes() const;
62 virtual void Set3DAttributes(const SfxItemSet
& rAttr
);
65 class SAL_WARN_UNUSED SVX_DLLPUBLIC Svx3DLightControl final
: public Svx3DPreviewControl
67 // Callback for interactive changes
68 Link
<Svx3DLightControl
*,void> maChangeCallback
;
69 Link
<Svx3DLightControl
*,void> maSelectionChangeCallback
;
72 sal_uInt32 maSelectedLight
;
74 // extra objects for light control
75 E3dObject
* mpExpansionObject
;
76 E3dObject
* mpLampBottomObject
;
77 E3dObject
* mpLampShaftObject
;
78 std::vector
< E3dObject
* > maLightObjects
;
80 // 3d rotations of object
85 // interaction parameters
86 Point maActionStartPoint
;
87 double mfSaveActionStartHor
;
88 double mfSaveActionStartVer
;
89 double mfSaveActionStartRotZ
;
91 bool mbMouseMoved
: 1;
92 bool mbMouseCaptured
: 1;
93 bool mbGeometrySelected
: 1;
96 void ConstructLightObjects();
97 void AdaptToSelectedLight();
98 void TrySelection(Point aPosPixel
);
103 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
104 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
105 virtual tools::Rectangle
GetFocusRect() override
;
106 virtual bool MouseButtonDown(const MouseEvent
& rMEvt
) override
;
107 virtual bool MouseMove( const MouseEvent
& rMEvt
) override
;
108 virtual bool MouseButtonUp( const MouseEvent
& rMEvt
) override
;
109 virtual void Resize() override
;
111 virtual void SetObjectType(SvxPreviewObjectType nType
) override
;
113 // register user callback
114 void SetChangeCallback(Link
<Svx3DLightControl
*,void> aNew
) { maChangeCallback
= aNew
; }
115 void SetSelectionChangeCallback(Link
<Svx3DLightControl
*,void> aNew
) { maSelectionChangeCallback
= aNew
; }
118 bool IsSelectionValid();
119 bool IsGeometrySelected() const { return mbGeometrySelected
; }
121 // get/set position of selected lamp in polar coordinates, Hor:[0..360.0[ and Ver:[-90..90] degrees
122 void GetPosition(double& rHor
, double& rVer
);
123 void SetPosition(double fHor
, double fVer
);
125 // get/set rotation of 3D object
126 void SetRotation(double fRotX
, double fRotY
, double fRotZ
);
127 void GetRotation(double& rRotX
, double& rRotY
, double& rRotZ
);
129 void SelectLight(sal_uInt32 nLightNumber
);
130 virtual void Set3DAttributes(const SfxItemSet
& rAttr
) override
;
131 sal_uInt32
GetSelectedLight() const { return maSelectedLight
; }
134 bool GetLightOnOff(sal_uInt32 nNum
) const;
135 Color
GetLightColor(sal_uInt32 nNum
) const;
136 basegfx::B3DVector
GetLightDirection(sal_uInt32 nNum
) const;
139 class SAL_WARN_UNUSED SVX_DLLPUBLIC SvxLightCtl3D
142 Svx3DLightControl
& mrLightControl
;
143 weld::Scale
& mrHorScroller
;
144 weld::Scale
& mrVerScroller
;
145 weld::Button
& mrSwitcher
;
147 // callback for interactive changes
148 Link
<SvxLightCtl3D
*,void> maUserInteractiveChangeCallback
;
149 Link
<SvxLightCtl3D
*,void> maUserSelectionChangeCallback
;
152 SvxLightCtl3D(Svx3DLightControl
& rLightControl
, weld::Scale
& rHori
,
153 weld::Scale
& rVert
, weld::Button
& rButton
);
156 // check the selection for validity
157 void CheckSelection();
159 // bring further settings to the outside world
160 Svx3DLightControl
& GetSvx3DLightControl() { return mrLightControl
; }
162 // register user callback
163 void SetUserInteractiveChangeCallback(Link
<SvxLightCtl3D
*,void> aNew
) { maUserInteractiveChangeCallback
= aNew
; }
164 void SetUserSelectionChangeCallback(Link
<SvxLightCtl3D
*,void> aNew
) { maUserSelectionChangeCallback
= aNew
; }
168 DECL_LINK(InternalInteractiveChange
, Svx3DLightControl
*, void);
169 DECL_LINK(InternalSelectionChange
, Svx3DLightControl
*, void);
170 DECL_LINK(ScrollBarMove
, weld::Scale
&, void);
171 DECL_LINK(ButtonPress
, weld::Button
&, void);
172 DECL_LINK(KeyInput
, const KeyEvent
&, bool);
173 DECL_LINK(FocusIn
, weld::Widget
&, void);
175 // initialize local parameters
178 void move( double fDeltaHor
, double fDeltaVer
);
182 #endif // _SCH_DLGCTL3D_HXX
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */