/src/libreoffice/svx/source/dialog/dlgctl3d.cxx
Line | Count | Source (jump to first uncovered line) |
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 | | |
21 | | #include <svx/dlgctl3d.hxx> |
22 | | #include <svx/strings.hrc> |
23 | | #include <svx/view3d.hxx> |
24 | | #include <svx/fmmodel.hxx> |
25 | | #include <svl/itempool.hxx> |
26 | | #include <svx/fmpage.hxx> |
27 | | #include <svx/sphere3d.hxx> |
28 | | #include <svx/cube3d.hxx> |
29 | | #include <svx/scene3d.hxx> |
30 | | #include <vcl/svapp.hxx> |
31 | | #include <svx/helperhittest3d.hxx> |
32 | | #include <basegfx/polygon/b2dpolygontools.hxx> |
33 | | #include <polygn3d.hxx> |
34 | | #include <svx/xfillit0.hxx> |
35 | | #include <svx/xflclit.hxx> |
36 | | #include <svx/xlineit0.hxx> |
37 | | #include <svx/xlnclit.hxx> |
38 | | #include <svx/xlnwtit.hxx> |
39 | | #include <helpids.h> |
40 | | #include <svx/dialmgr.hxx> |
41 | | #include <tools/helpers.hxx> |
42 | | #include <vcl/settings.hxx> |
43 | | |
44 | | using namespace com::sun::star; |
45 | | |
46 | | Svx3DPreviewControl::Svx3DPreviewControl() |
47 | 0 | : mnObjectType(SvxPreviewObjectType::SPHERE) |
48 | 0 | { |
49 | 0 | } |
50 | | |
51 | | void Svx3DPreviewControl::SetDrawingArea(weld::DrawingArea* pDrawingArea) |
52 | 0 | { |
53 | 0 | Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(80, 100), MapMode(MapUnit::MapAppFont))); |
54 | 0 | pDrawingArea->set_size_request(aSize.Width(), aSize.Height()); |
55 | 0 | CustomWidgetController::SetDrawingArea(pDrawingArea); |
56 | 0 | SetOutputSizePixel(aSize); |
57 | |
|
58 | 0 | Construct(); |
59 | 0 | } |
60 | | |
61 | | void Svx3DPreviewControl::ClearPageView() |
62 | 0 | { |
63 | 0 | mp3DView->ClearPageView(); |
64 | 0 | } |
65 | | |
66 | | Svx3DPreviewControl::~Svx3DPreviewControl() |
67 | 0 | { |
68 | 0 | mp3DObj.clear(); |
69 | 0 | mxFmPage.clear(); |
70 | 0 | mpScene.clear(); |
71 | 0 | mp3DView.reset(); |
72 | 0 | mpModel.reset(); |
73 | 0 | } |
74 | | |
75 | | void Svx3DPreviewControl::Construct() |
76 | 0 | { |
77 | | // Do never mirror the preview window. This explicitly includes right |
78 | | // to left writing environments. |
79 | 0 | EnableRTL (false); |
80 | 0 | OutputDevice& rDevice = GetDrawingArea()->get_ref_device(); |
81 | 0 | rDevice.SetMapMode(MapMode(MapUnit::Map100thMM)); |
82 | | |
83 | | // Model |
84 | 0 | mpModel.reset(new FmFormModel()); |
85 | | |
86 | | // Page |
87 | 0 | mxFmPage = new FmFormPage( *mpModel ); |
88 | 0 | mpModel->InsertPage( mxFmPage.get(), 0 ); |
89 | | |
90 | | // 3D View |
91 | 0 | mp3DView.reset(new E3dView(*mpModel, &rDevice)); |
92 | 0 | mp3DView->SetBufferedOutputAllowed(true); |
93 | 0 | mp3DView->SetBufferedOverlayAllowed(true); |
94 | | |
95 | | // 3D Scene |
96 | 0 | mpScene = new E3dScene(*mpModel); |
97 | | |
98 | | // initially create object |
99 | 0 | SetObjectType(SvxPreviewObjectType::SPHERE); |
100 | | |
101 | | // camera and perspective |
102 | 0 | Camera3D rCamera = mpScene->GetCamera(); |
103 | 0 | const basegfx::B3DRange& rVolume = mpScene->GetBoundVolume(); |
104 | 0 | double fW = rVolume.getWidth(); |
105 | 0 | double fH = rVolume.getHeight(); |
106 | 0 | double fCamZ = rVolume.getMaxZ() + ((fW + fH) / 2.0); |
107 | |
|
108 | 0 | rCamera.SetAutoAdjustProjection(false); |
109 | 0 | rCamera.SetViewWindow(- fW / 2, - fH / 2, fW, fH); |
110 | 0 | basegfx::B3DPoint aLookAt; |
111 | 0 | double fDefaultCamPosZ = mp3DView->GetDefaultCamPosZ(); |
112 | 0 | basegfx::B3DPoint aCamPos(0.0, 0.0, fCamZ < fDefaultCamPosZ ? fDefaultCamPosZ : fCamZ); |
113 | 0 | rCamera.SetPosAndLookAt(aCamPos, aLookAt); |
114 | 0 | double fDefaultCamFocal = mp3DView->GetDefaultCamFocal(); |
115 | 0 | rCamera.SetFocalLength(fDefaultCamFocal); |
116 | |
|
117 | 0 | mpScene->SetCamera( rCamera ); |
118 | 0 | mxFmPage->InsertObject( mpScene.get() ); |
119 | |
|
120 | 0 | basegfx::B3DHomMatrix aRotation; |
121 | 0 | aRotation.rotate(basegfx::deg2rad( 25 ), 0.0, 0.0); |
122 | 0 | aRotation.rotate(0.0, basegfx::deg2rad( 40 ), 0.0); |
123 | 0 | mpScene->SetTransform(aRotation * mpScene->GetTransform()); |
124 | | |
125 | | // invalidate SnapRects of objects |
126 | 0 | mpScene->SetBoundAndSnapRectsDirty(); |
127 | |
|
128 | 0 | SfxItemSetFixed<XATTR_LINESTYLE, XATTR_LINESTYLE, |
129 | 0 | XATTR_FILL_FIRST, XATTR_FILLBITMAP> aSet( mpModel->GetItemPool() ); |
130 | 0 | aSet.Put( XLineStyleItem( drawing::LineStyle_NONE ) ); |
131 | 0 | aSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) ); |
132 | 0 | aSet.Put( XFillColorItem( u""_ustr, COL_WHITE ) ); |
133 | |
|
134 | 0 | mpScene->SetMergedItemSet(aSet); |
135 | | |
136 | | // PageView |
137 | 0 | SdrPageView* pPageView = mp3DView->ShowSdrPage( mxFmPage.get() ); |
138 | 0 | mp3DView->hideMarkHandles(); |
139 | | |
140 | | // mark scene |
141 | 0 | mp3DView->MarkObj( mpScene.get(), pPageView ); |
142 | 0 | } |
143 | | |
144 | | void Svx3DPreviewControl::Resize() |
145 | 0 | { |
146 | | // size of page |
147 | 0 | Size aSize(GetOutputSizePixel()); |
148 | 0 | aSize = GetDrawingArea()->get_ref_device().PixelToLogic(aSize); |
149 | 0 | mxFmPage->SetSize(aSize); |
150 | | |
151 | | // set size |
152 | 0 | Size aObjSize( aSize.Width()*5/6, aSize.Height()*5/6 ); |
153 | 0 | Point aObjPoint( (aSize.Width() - aObjSize.Width()) / 2, |
154 | 0 | (aSize.Height() - aObjSize.Height()) / 2); |
155 | 0 | tools::Rectangle aRect( aObjPoint, aObjSize); |
156 | 0 | mpScene->SetSnapRect( aRect ); |
157 | 0 | } |
158 | | |
159 | | void Svx3DPreviewControl::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) |
160 | 0 | { |
161 | 0 | mp3DView->CompleteRedraw(&rRenderContext, vcl::Region(rRect)); |
162 | 0 | } |
163 | | |
164 | | bool Svx3DPreviewControl::MouseButtonDown(const MouseEvent& rMEvt) |
165 | 0 | { |
166 | 0 | if (rMEvt.IsShift() && rMEvt.IsMod1()) |
167 | 0 | { |
168 | 0 | if(SvxPreviewObjectType::SPHERE == GetObjectType()) |
169 | 0 | { |
170 | 0 | SetObjectType(SvxPreviewObjectType::CUBE); |
171 | 0 | } |
172 | 0 | else |
173 | 0 | { |
174 | 0 | SetObjectType(SvxPreviewObjectType::SPHERE); |
175 | 0 | } |
176 | 0 | } |
177 | 0 | return false; |
178 | 0 | } |
179 | | |
180 | | void Svx3DPreviewControl::SetObjectType(SvxPreviewObjectType nType) |
181 | 0 | { |
182 | 0 | if(mnObjectType == nType && mp3DObj) |
183 | 0 | return; |
184 | | |
185 | 0 | SfxItemSetFixed<SDRATTR_START, SDRATTR_END> aSet(mpModel->GetItemPool()); |
186 | 0 | mnObjectType = nType; |
187 | |
|
188 | 0 | if( mp3DObj ) |
189 | 0 | { |
190 | 0 | aSet.Put(mp3DObj->GetMergedItemSet()); |
191 | 0 | mpScene->RemoveObject( mp3DObj->GetOrdNum() ); |
192 | 0 | mp3DObj.clear(); |
193 | 0 | } |
194 | |
|
195 | 0 | switch( nType ) |
196 | 0 | { |
197 | 0 | case SvxPreviewObjectType::SPHERE: |
198 | 0 | { |
199 | 0 | mp3DObj = new E3dSphereObj( |
200 | 0 | *mpModel, |
201 | 0 | mp3DView->Get3DDefaultAttributes(), |
202 | 0 | basegfx::B3DPoint( 0, 0, 0 ), |
203 | 0 | basegfx::B3DVector( 5000, 5000, 5000 )); |
204 | 0 | } |
205 | 0 | break; |
206 | | |
207 | 0 | case SvxPreviewObjectType::CUBE: |
208 | 0 | { |
209 | 0 | mp3DObj = new E3dCubeObj( |
210 | 0 | *mpModel, |
211 | 0 | mp3DView->Get3DDefaultAttributes(), |
212 | 0 | basegfx::B3DPoint( -2500, -2500, -2500 ), |
213 | 0 | basegfx::B3DVector( 5000, 5000, 5000 )); |
214 | 0 | } |
215 | 0 | break; |
216 | 0 | } |
217 | | |
218 | 0 | if (mp3DObj) |
219 | 0 | { |
220 | 0 | mpScene->InsertObject( mp3DObj.get() ); |
221 | 0 | mp3DObj->SetMergedItemSet(aSet); |
222 | 0 | } |
223 | |
|
224 | 0 | Invalidate(); |
225 | 0 | } |
226 | | |
227 | | SfxItemSet const & Svx3DPreviewControl::Get3DAttributes() const |
228 | 0 | { |
229 | 0 | return mp3DObj->GetMergedItemSet(); |
230 | 0 | } |
231 | | |
232 | | void Svx3DPreviewControl::Set3DAttributes( const SfxItemSet& rAttr ) |
233 | 0 | { |
234 | 0 | mp3DObj->SetMergedItemSet(rAttr, true); |
235 | 0 | Resize(); |
236 | 0 | Invalidate(); |
237 | 0 | } |
238 | | |
239 | 0 | #define RADIUS_LAMP_PREVIEW_SIZE (4500.0) |
240 | 0 | #define RADIUS_LAMP_SMALL (600.0) |
241 | 0 | #define RADIUS_LAMP_BIG (1000.0) |
242 | 0 | #define NO_LIGHT_SELECTED (0xffffffff) |
243 | 0 | #define MAX_NUMBER_LIGHTS (8) |
244 | | |
245 | | const sal_Int32 g_nInteractionStartDistance = 5 * 5 * 2; |
246 | | |
247 | | Svx3DLightControl::Svx3DLightControl() |
248 | 0 | : maSelectedLight(NO_LIGHT_SELECTED), |
249 | 0 | maLightObjects(MAX_NUMBER_LIGHTS, nullptr), |
250 | 0 | mfRotateX(-20.0), |
251 | 0 | mfRotateY(45.0), |
252 | 0 | mfRotateZ(0.0), |
253 | 0 | mfSaveActionStartHor(0.0), |
254 | 0 | mfSaveActionStartVer(0.0), |
255 | 0 | mfSaveActionStartRotZ(0.0), |
256 | 0 | mbMouseMoved(false), |
257 | 0 | mbMouseCaptured(false), |
258 | 0 | mbGeometrySelected(false) |
259 | 0 | { |
260 | 0 | } |
261 | | |
262 | | void Svx3DLightControl::SetDrawingArea(weld::DrawingArea* pDrawingArea) |
263 | 0 | { |
264 | 0 | Svx3DPreviewControl::SetDrawingArea(pDrawingArea); |
265 | 0 | Construct2(); |
266 | 0 | } |
267 | | |
268 | | void Svx3DLightControl::Construct2() |
269 | 0 | { |
270 | 0 | { |
271 | | // hide all page stuff, use control background (normally gray) |
272 | 0 | const Color aDialogColor(Application::GetSettings().GetStyleSettings().GetDialogColor()); |
273 | 0 | mp3DView->SetPageVisible(false); |
274 | 0 | mp3DView->SetApplicationBackgroundColor(aDialogColor); |
275 | 0 | mp3DView->SetApplicationDocumentColor(aDialogColor); |
276 | 0 | } |
277 | |
|
278 | 0 | { |
279 | | // create invisible expansion object |
280 | 0 | const double fMaxExpansion(RADIUS_LAMP_BIG + RADIUS_LAMP_PREVIEW_SIZE); |
281 | 0 | mpExpansionObject = new E3dCubeObj( |
282 | 0 | *mpModel, |
283 | 0 | mp3DView->Get3DDefaultAttributes(), |
284 | 0 | basegfx::B3DPoint(-fMaxExpansion, -fMaxExpansion, -fMaxExpansion), |
285 | 0 | basegfx::B3DVector(2.0 * fMaxExpansion, 2.0 * fMaxExpansion, 2.0 * fMaxExpansion)); |
286 | 0 | mpScene->InsertObject( mpExpansionObject.get() ); |
287 | 0 | SfxItemSet aSet(mpModel->GetItemPool()); |
288 | 0 | aSet.Put( XLineStyleItem( drawing::LineStyle_NONE ) ); |
289 | 0 | aSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) ); |
290 | 0 | mpExpansionObject->SetMergedItemSet(aSet); |
291 | 0 | } |
292 | |
|
293 | 0 | { |
294 | | // create lamp control object (Yellow lined object) |
295 | | // base circle |
296 | 0 | const basegfx::B2DPolygon a2DCircle(basegfx::utils::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), RADIUS_LAMP_PREVIEW_SIZE)); |
297 | 0 | basegfx::B3DPolygon a3DCircle(basegfx::utils::createB3DPolygonFromB2DPolygon(a2DCircle)); |
298 | 0 | basegfx::B3DHomMatrix aTransform; |
299 | |
|
300 | 0 | aTransform.rotate(M_PI_2, 0.0, 0.0); |
301 | 0 | aTransform.translate(0.0, -RADIUS_LAMP_PREVIEW_SIZE, 0.0); |
302 | 0 | a3DCircle.transform(aTransform); |
303 | | |
304 | | // create object for it |
305 | 0 | mpLampBottomObject = new E3dPolygonObj( |
306 | 0 | *mpModel, |
307 | 0 | basegfx::B3DPolyPolygon(a3DCircle)); |
308 | 0 | mpScene->InsertObject( mpLampBottomObject.get() ); |
309 | | |
310 | | // half circle with stand |
311 | 0 | basegfx::B2DPolygon a2DHalfCircle; |
312 | 0 | a2DHalfCircle.append(basegfx::B2DPoint(RADIUS_LAMP_PREVIEW_SIZE, 0.0)); |
313 | 0 | a2DHalfCircle.append(basegfx::B2DPoint(RADIUS_LAMP_PREVIEW_SIZE, -RADIUS_LAMP_PREVIEW_SIZE)); |
314 | 0 | a2DHalfCircle.append(basegfx::utils::createPolygonFromEllipseSegment( |
315 | 0 | basegfx::B2DPoint(0.0, 0.0), RADIUS_LAMP_PREVIEW_SIZE, RADIUS_LAMP_PREVIEW_SIZE, 2 * M_PI - M_PI_2, M_PI_2)); |
316 | 0 | basegfx::B3DPolygon a3DHalfCircle(basegfx::utils::createB3DPolygonFromB2DPolygon(a2DHalfCircle)); |
317 | | |
318 | | // create object for it |
319 | 0 | mpLampShaftObject = new E3dPolygonObj( |
320 | 0 | *mpModel, |
321 | 0 | basegfx::B3DPolyPolygon(a3DHalfCircle)); |
322 | 0 | mpScene->InsertObject( mpLampShaftObject.get() ); |
323 | | |
324 | | // initially invisible |
325 | 0 | SfxItemSet aSet(mpModel->GetItemPool()); |
326 | 0 | aSet.Put( XLineStyleItem( drawing::LineStyle_NONE ) ); |
327 | 0 | aSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) ); |
328 | |
|
329 | 0 | mpLampBottomObject->SetMergedItemSet(aSet); |
330 | 0 | mpLampShaftObject->SetMergedItemSet(aSet); |
331 | 0 | } |
332 | |
|
333 | 0 | { |
334 | | // change camera settings |
335 | 0 | Camera3D rCamera = mpScene->GetCamera(); |
336 | 0 | const basegfx::B3DRange& rVolume = mpScene->GetBoundVolume(); |
337 | 0 | double fW = rVolume.getWidth(); |
338 | 0 | double fH = rVolume.getHeight(); |
339 | 0 | double fCamZ = rVolume.getMaxZ() + ((fW + fH) / 2.0); |
340 | |
|
341 | 0 | rCamera.SetAutoAdjustProjection(false); |
342 | 0 | rCamera.SetViewWindow(- fW / 2, - fH / 2, fW, fH); |
343 | 0 | basegfx::B3DPoint aLookAt; |
344 | 0 | double fDefaultCamPosZ = mp3DView->GetDefaultCamPosZ(); |
345 | 0 | basegfx::B3DPoint aCamPos(0.0, 0.0, fCamZ < fDefaultCamPosZ ? fDefaultCamPosZ : fCamZ); |
346 | 0 | rCamera.SetPosAndLookAt(aCamPos, aLookAt); |
347 | 0 | double fDefaultCamFocal = mp3DView->GetDefaultCamFocal(); |
348 | 0 | rCamera.SetFocalLength(fDefaultCamFocal); |
349 | |
|
350 | 0 | mpScene->SetCamera( rCamera ); |
351 | |
|
352 | 0 | basegfx::B3DHomMatrix aNeutral; |
353 | 0 | mpScene->SetTransform(aNeutral); |
354 | 0 | } |
355 | | |
356 | | // invalidate SnapRects of objects |
357 | 0 | mpScene->SetBoundAndSnapRectsDirty(); |
358 | 0 | } |
359 | | |
360 | | void Svx3DLightControl::ConstructLightObjects() |
361 | 0 | { |
362 | 0 | for(sal_uInt32 a(0); a < MAX_NUMBER_LIGHTS; a++) |
363 | 0 | { |
364 | | // get rid of possible existing light object |
365 | 0 | if(maLightObjects[a]) |
366 | 0 | { |
367 | 0 | mpScene->RemoveObject(maLightObjects[a]->GetOrdNum()); |
368 | 0 | maLightObjects[a] = nullptr; |
369 | 0 | } |
370 | |
|
371 | 0 | if(GetLightOnOff(a)) |
372 | 0 | { |
373 | 0 | const bool bIsSelectedLight(a == maSelectedLight); |
374 | 0 | basegfx::B3DVector aDirection(GetLightDirection(a)); |
375 | 0 | aDirection.normalize(); |
376 | 0 | aDirection *= RADIUS_LAMP_PREVIEW_SIZE; |
377 | |
|
378 | 0 | const double fLampSize(bIsSelectedLight ? RADIUS_LAMP_BIG : RADIUS_LAMP_SMALL); |
379 | 0 | rtl::Reference<E3dObject> pNewLight = new E3dSphereObj( |
380 | 0 | *mpModel, |
381 | 0 | mp3DView->Get3DDefaultAttributes(), |
382 | 0 | basegfx::B3DPoint( 0, 0, 0 ), |
383 | 0 | basegfx::B3DVector( fLampSize, fLampSize, fLampSize)); |
384 | 0 | mpScene->InsertObject(pNewLight.get()); |
385 | |
|
386 | 0 | basegfx::B3DHomMatrix aTransform; |
387 | 0 | aTransform.translate(aDirection.getX(), aDirection.getY(), aDirection.getZ()); |
388 | 0 | pNewLight->SetTransform(aTransform); |
389 | |
|
390 | 0 | SfxItemSet aSet(mpModel->GetItemPool()); |
391 | 0 | aSet.Put( XLineStyleItem( drawing::LineStyle_NONE ) ); |
392 | 0 | aSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) ); |
393 | 0 | aSet.Put( XFillColorItem(OUString(), GetLightColor(a))); |
394 | 0 | pNewLight->SetMergedItemSet(aSet); |
395 | |
|
396 | 0 | maLightObjects[a] = pNewLight.get(); |
397 | 0 | } |
398 | 0 | } |
399 | 0 | } |
400 | | |
401 | | void Svx3DLightControl::AdaptToSelectedLight() |
402 | 0 | { |
403 | 0 | if(NO_LIGHT_SELECTED == maSelectedLight) |
404 | 0 | { |
405 | | // make mpLampBottomObject/mpLampShaftObject invisible |
406 | 0 | SfxItemSet aSet(mpModel->GetItemPool()); |
407 | 0 | aSet.Put( XLineStyleItem( drawing::LineStyle_NONE ) ); |
408 | 0 | aSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) ); |
409 | 0 | mpLampBottomObject->SetMergedItemSet(aSet); |
410 | 0 | mpLampShaftObject->SetMergedItemSet(aSet); |
411 | 0 | } |
412 | 0 | else |
413 | 0 | { |
414 | 0 | basegfx::B3DVector aDirection(GetLightDirection(maSelectedLight)); |
415 | 0 | aDirection.normalize(); |
416 | | |
417 | | // make mpLampBottomObject/mpLampShaftObject visible (yellow hairline) |
418 | 0 | SfxItemSet aSet(mpModel->GetItemPool()); |
419 | 0 | aSet.Put( XLineStyleItem( drawing::LineStyle_SOLID ) ); |
420 | 0 | aSet.Put( XLineColorItem(OUString(), COL_YELLOW)); |
421 | 0 | aSet.Put( XLineWidthItem(0)); |
422 | 0 | aSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) ); |
423 | 0 | mpLampBottomObject->SetMergedItemSet(aSet); |
424 | 0 | mpLampShaftObject->SetMergedItemSet(aSet); |
425 | | |
426 | | // adapt transformation of mpLampShaftObject |
427 | 0 | basegfx::B3DHomMatrix aTransform; |
428 | 0 | double fRotateY(0.0); |
429 | |
|
430 | 0 | if(!basegfx::fTools::equalZero(aDirection.getZ()) || !basegfx::fTools::equalZero(aDirection.getX())) |
431 | 0 | { |
432 | 0 | fRotateY = atan2(-aDirection.getZ(), aDirection.getX()); |
433 | 0 | } |
434 | |
|
435 | 0 | aTransform.rotate(0.0, fRotateY, 0.0); |
436 | 0 | mpLampShaftObject->SetTransform(aTransform); |
437 | | |
438 | | // adapt transformation of selected light |
439 | 0 | E3dObject* pSelectedLight = maLightObjects[sal_Int32(maSelectedLight)]; |
440 | |
|
441 | 0 | if(pSelectedLight) |
442 | 0 | { |
443 | 0 | aTransform.identity(); |
444 | 0 | aTransform.translate( |
445 | 0 | aDirection.getX() * RADIUS_LAMP_PREVIEW_SIZE, |
446 | 0 | aDirection.getY() * RADIUS_LAMP_PREVIEW_SIZE, |
447 | 0 | aDirection.getZ() * RADIUS_LAMP_PREVIEW_SIZE); |
448 | 0 | pSelectedLight->SetTransform(aTransform); |
449 | 0 | } |
450 | 0 | } |
451 | 0 | } |
452 | | |
453 | | void Svx3DLightControl::TrySelection(Point aPosPixel) |
454 | 0 | { |
455 | 0 | if(!mpScene) |
456 | 0 | return; |
457 | | |
458 | 0 | const Point aPosLogic(GetDrawingArea()->get_ref_device().PixelToLogic(aPosPixel)); |
459 | 0 | const basegfx::B2DPoint aPoint(aPosLogic.X(), aPosLogic.Y()); |
460 | 0 | std::vector< const E3dCompoundObject* > aResult; |
461 | 0 | getAllHit3DObjectsSortedFrontToBack(aPoint, *mpScene, aResult); |
462 | |
|
463 | 0 | if(aResult.empty()) |
464 | 0 | return; |
465 | | |
466 | | // exclude expansion object which will be part of |
467 | | // the hits. It's invisible, but for HitTest, it's included |
468 | 0 | const E3dCompoundObject* pResult = nullptr; |
469 | |
|
470 | 0 | for(auto const & b: aResult) |
471 | 0 | { |
472 | 0 | if(b && b != mpExpansionObject.get()) |
473 | 0 | { |
474 | 0 | pResult = b; |
475 | 0 | break; |
476 | 0 | } |
477 | 0 | } |
478 | |
|
479 | 0 | if(pResult == mp3DObj.get()) |
480 | 0 | { |
481 | 0 | if(!mbGeometrySelected) |
482 | 0 | { |
483 | 0 | mbGeometrySelected = true; |
484 | 0 | maSelectedLight = NO_LIGHT_SELECTED; |
485 | 0 | ConstructLightObjects(); |
486 | 0 | AdaptToSelectedLight(); |
487 | 0 | Invalidate(); |
488 | |
|
489 | 0 | if(maSelectionChangeCallback.IsSet()) |
490 | 0 | { |
491 | 0 | maSelectionChangeCallback.Call(this); |
492 | 0 | } |
493 | 0 | } |
494 | 0 | } |
495 | 0 | else |
496 | 0 | { |
497 | 0 | sal_uInt32 aNewSelectedLight(NO_LIGHT_SELECTED); |
498 | |
|
499 | 0 | for(sal_uInt32 a(0); a < MAX_NUMBER_LIGHTS; a++) |
500 | 0 | { |
501 | 0 | if(maLightObjects[a] && maLightObjects[a] == pResult) |
502 | 0 | { |
503 | 0 | aNewSelectedLight = a; |
504 | 0 | } |
505 | 0 | } |
506 | |
|
507 | 0 | if(aNewSelectedLight != maSelectedLight) |
508 | 0 | { |
509 | 0 | SelectLight(aNewSelectedLight); |
510 | |
|
511 | 0 | if(maSelectionChangeCallback.IsSet()) |
512 | 0 | { |
513 | 0 | maSelectionChangeCallback.Call(this); |
514 | 0 | } |
515 | 0 | } |
516 | 0 | } |
517 | 0 | } |
518 | | |
519 | | void Svx3DLightControl::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) |
520 | 0 | { |
521 | 0 | Svx3DPreviewControl::Paint(rRenderContext, rRect); |
522 | 0 | } |
523 | | |
524 | | tools::Rectangle Svx3DLightControl::GetFocusRect() |
525 | 0 | { |
526 | 0 | if (!HasFocus()) |
527 | 0 | return tools::Rectangle(); |
528 | 0 | Size aFocusSize = GetOutputSizePixel(); |
529 | 0 | aFocusSize.AdjustWidth( -4 ); |
530 | 0 | aFocusSize.AdjustHeight( -4 ); |
531 | 0 | return tools::Rectangle(Point(2, 2), aFocusSize); |
532 | 0 | } |
533 | | |
534 | | bool Svx3DLightControl::MouseButtonDown( const MouseEvent& rMEvt ) |
535 | 0 | { |
536 | 0 | bool bCallParent(true); |
537 | | |
538 | | // switch state |
539 | 0 | if(rMEvt.IsLeft()) |
540 | 0 | { |
541 | 0 | if(IsSelectionValid() || mbGeometrySelected) |
542 | 0 | { |
543 | 0 | mbMouseMoved = false; |
544 | 0 | bCallParent = false; |
545 | 0 | maActionStartPoint = rMEvt.GetPosPixel(); |
546 | 0 | CaptureMouse(); |
547 | 0 | mbMouseCaptured = true; |
548 | 0 | } |
549 | 0 | else |
550 | 0 | { |
551 | | // Single click without moving much trying to do a selection |
552 | 0 | TrySelection(rMEvt.GetPosPixel()); |
553 | 0 | bCallParent = false; |
554 | 0 | } |
555 | 0 | } |
556 | | |
557 | | // call parent |
558 | 0 | if (bCallParent) |
559 | 0 | return Svx3DPreviewControl::MouseButtonDown(rMEvt); |
560 | 0 | return true; |
561 | 0 | } |
562 | | |
563 | | bool Svx3DLightControl::MouseMove(const MouseEvent& rMEvt) |
564 | 0 | { |
565 | 0 | if (!mbMouseCaptured) |
566 | 0 | return false; |
567 | | |
568 | 0 | Point aDeltaPos = rMEvt.GetPosPixel() - maActionStartPoint; |
569 | |
|
570 | 0 | if(!mbMouseMoved) |
571 | 0 | { |
572 | 0 | if(sal_Int32(aDeltaPos.X() * aDeltaPos.X() + aDeltaPos.Y() * aDeltaPos.Y()) > g_nInteractionStartDistance) |
573 | 0 | { |
574 | 0 | if(mbGeometrySelected) |
575 | 0 | { |
576 | 0 | GetRotation(mfSaveActionStartVer, mfSaveActionStartHor, mfSaveActionStartRotZ); |
577 | 0 | } |
578 | 0 | else |
579 | 0 | { |
580 | | // interaction start, save values |
581 | 0 | GetPosition(mfSaveActionStartHor, mfSaveActionStartVer); |
582 | 0 | } |
583 | |
|
584 | 0 | mbMouseMoved = true; |
585 | 0 | } |
586 | 0 | } |
587 | |
|
588 | 0 | if(mbMouseMoved) |
589 | 0 | { |
590 | 0 | if(mbGeometrySelected) |
591 | 0 | { |
592 | 0 | double fNewRotX = mfSaveActionStartVer - basegfx::deg2rad(aDeltaPos.Y()); |
593 | 0 | double fNewRotY = mfSaveActionStartHor + basegfx::deg2rad(aDeltaPos.X()); |
594 | | |
595 | | // cut horizontal |
596 | 0 | while(fNewRotY < 0.0) |
597 | 0 | { |
598 | 0 | fNewRotY += 2 * M_PI; |
599 | 0 | } |
600 | |
|
601 | 0 | while(fNewRotY >= 2 * M_PI) |
602 | 0 | { |
603 | 0 | fNewRotY -= 2 * M_PI; |
604 | 0 | } |
605 | | |
606 | | // cut vertical |
607 | 0 | if(fNewRotX < -M_PI_2) |
608 | 0 | { |
609 | 0 | fNewRotX = -M_PI_2; |
610 | 0 | } |
611 | |
|
612 | 0 | if(fNewRotX > M_PI_2) |
613 | 0 | { |
614 | 0 | fNewRotX = M_PI_2; |
615 | 0 | } |
616 | |
|
617 | 0 | SetRotation(fNewRotX, fNewRotY, mfSaveActionStartRotZ); |
618 | |
|
619 | 0 | if(maChangeCallback.IsSet()) |
620 | 0 | { |
621 | 0 | maChangeCallback.Call(this); |
622 | 0 | } |
623 | 0 | } |
624 | 0 | else |
625 | 0 | { |
626 | | // interaction in progress |
627 | 0 | double fNewPosHor = mfSaveActionStartHor + static_cast<double>(aDeltaPos.X()); |
628 | 0 | double fNewPosVer = mfSaveActionStartVer - static_cast<double>(aDeltaPos.Y()); |
629 | | |
630 | | // cut horizontal |
631 | 0 | fNewPosHor = NormAngle360(fNewPosHor); |
632 | | |
633 | | // cut vertical |
634 | 0 | if(fNewPosVer < -90.0) |
635 | 0 | { |
636 | 0 | fNewPosVer = -90.0; |
637 | 0 | } |
638 | |
|
639 | 0 | if(fNewPosVer > 90.0) |
640 | 0 | { |
641 | 0 | fNewPosVer = 90.0; |
642 | 0 | } |
643 | |
|
644 | 0 | SetPosition(fNewPosHor, fNewPosVer); |
645 | |
|
646 | 0 | if(maChangeCallback.IsSet()) |
647 | 0 | { |
648 | 0 | maChangeCallback.Call(this); |
649 | 0 | } |
650 | 0 | } |
651 | 0 | } |
652 | 0 | return true; |
653 | 0 | } |
654 | | |
655 | | bool Svx3DLightControl::MouseButtonUp(const MouseEvent& rMEvt) |
656 | 0 | { |
657 | 0 | if (!mbMouseCaptured) |
658 | 0 | return false; |
659 | 0 | ReleaseMouse(); |
660 | 0 | mbMouseCaptured = false; |
661 | |
|
662 | 0 | if (mbMouseMoved) |
663 | 0 | { |
664 | | // was change interactively |
665 | 0 | } |
666 | 0 | else |
667 | 0 | { |
668 | | // simple click without much movement, try selection |
669 | 0 | TrySelection(rMEvt.GetPosPixel()); |
670 | 0 | } |
671 | |
|
672 | 0 | return true; |
673 | 0 | } |
674 | | |
675 | | void Svx3DLightControl::Resize() |
676 | 0 | { |
677 | | // set size of page |
678 | 0 | const Size aSize(GetDrawingArea()->get_ref_device().PixelToLogic(GetOutputSizePixel())); |
679 | 0 | mxFmPage->SetSize(aSize); |
680 | | |
681 | | // set position and size of scene |
682 | 0 | mpScene->SetSnapRect(tools::Rectangle(Point(0, 0), aSize)); |
683 | 0 | } |
684 | | |
685 | | void Svx3DLightControl::SetObjectType(SvxPreviewObjectType nType) |
686 | 0 | { |
687 | | // call parent |
688 | 0 | Svx3DPreviewControl::SetObjectType(nType); |
689 | | |
690 | | // apply object rotation |
691 | 0 | if(mp3DObj) |
692 | 0 | { |
693 | 0 | basegfx::B3DHomMatrix aObjectRotation; |
694 | 0 | aObjectRotation.rotate(mfRotateX, mfRotateY, mfRotateZ); |
695 | 0 | mp3DObj->SetTransform(aObjectRotation); |
696 | 0 | } |
697 | 0 | } |
698 | | |
699 | | bool Svx3DLightControl::IsSelectionValid() |
700 | 0 | { |
701 | 0 | return (NO_LIGHT_SELECTED != maSelectedLight) && GetLightOnOff(maSelectedLight); |
702 | 0 | } |
703 | | |
704 | | void Svx3DLightControl::GetPosition(double& rHor, double& rVer) |
705 | 0 | { |
706 | 0 | if(IsSelectionValid()) |
707 | 0 | { |
708 | 0 | basegfx::B3DVector aDirection(GetLightDirection(maSelectedLight)); |
709 | 0 | aDirection.normalize(); |
710 | 0 | rHor = basegfx::rad2deg(atan2(-aDirection.getX(), -aDirection.getZ()) + M_PI); // 0..360.0 |
711 | 0 | rVer = basegfx::rad2deg(atan2(aDirection.getY(), aDirection.getXZLength())); // -90.0..90.0 |
712 | 0 | } |
713 | 0 | if(IsGeometrySelected()) |
714 | 0 | { |
715 | 0 | rHor = basegfx::rad2deg(mfRotateY); // 0..360.0 |
716 | 0 | rVer = basegfx::rad2deg(mfRotateX); // -90.0..90.0 |
717 | 0 | } |
718 | 0 | } |
719 | | |
720 | | void Svx3DLightControl::SetPosition(double fHor, double fVer) |
721 | 0 | { |
722 | 0 | if(IsSelectionValid()) |
723 | 0 | { |
724 | | // set selected light's direction |
725 | 0 | fHor = basegfx::deg2rad(fHor) - M_PI; // -PI..PI |
726 | 0 | fVer = basegfx::deg2rad(fVer); // -PI2..PI2 |
727 | 0 | basegfx::B3DVector aDirection(cos(fVer) * -sin(fHor), sin(fVer), cos(fVer) * -cos(fHor)); |
728 | 0 | aDirection.normalize(); |
729 | |
|
730 | 0 | if(!aDirection.equal(GetLightDirection(maSelectedLight))) |
731 | 0 | { |
732 | | // set changed light direction at SdrScene |
733 | 0 | SfxItemSet aSet(mpModel->GetItemPool()); |
734 | |
|
735 | 0 | switch(maSelectedLight) |
736 | 0 | { |
737 | 0 | case 0: aSet.Put(makeSvx3DLightDirection1Item(aDirection)); break; |
738 | 0 | case 1: aSet.Put(makeSvx3DLightDirection2Item(aDirection)); break; |
739 | 0 | case 2: aSet.Put(makeSvx3DLightDirection3Item(aDirection)); break; |
740 | 0 | case 3: aSet.Put(makeSvx3DLightDirection4Item(aDirection)); break; |
741 | 0 | case 4: aSet.Put(makeSvx3DLightDirection5Item(aDirection)); break; |
742 | 0 | case 5: aSet.Put(makeSvx3DLightDirection6Item(aDirection)); break; |
743 | 0 | case 6: aSet.Put(makeSvx3DLightDirection7Item(aDirection)); break; |
744 | 0 | default: |
745 | 0 | case 7: aSet.Put(makeSvx3DLightDirection8Item(aDirection)); break; |
746 | 0 | } |
747 | | |
748 | 0 | mpScene->SetMergedItemSet(aSet); |
749 | | |
750 | | // correct 3D light's and LampFrame's geometries |
751 | 0 | AdaptToSelectedLight(); |
752 | 0 | Invalidate(); |
753 | 0 | } |
754 | 0 | } |
755 | 0 | if(!IsGeometrySelected()) |
756 | 0 | return; |
757 | | |
758 | 0 | if(mfRotateX == fVer && mfRotateY == fHor) |
759 | 0 | return; |
760 | | |
761 | 0 | mfRotateX = basegfx::deg2rad(fVer); |
762 | 0 | mfRotateY = basegfx::deg2rad(fHor); |
763 | |
|
764 | 0 | if(mp3DObj) |
765 | 0 | { |
766 | 0 | basegfx::B3DHomMatrix aObjectRotation; |
767 | 0 | aObjectRotation.rotate(mfRotateX, mfRotateY, mfRotateZ); |
768 | 0 | mp3DObj->SetTransform(aObjectRotation); |
769 | |
|
770 | 0 | Invalidate(); |
771 | 0 | } |
772 | 0 | } |
773 | | |
774 | | void Svx3DLightControl::SetRotation(double fRotX, double fRotY, double fRotZ) |
775 | 0 | { |
776 | 0 | if(!IsGeometrySelected()) |
777 | 0 | return; |
778 | | |
779 | 0 | if(fRotX == mfRotateX && fRotY == mfRotateY && fRotZ == mfRotateZ) |
780 | 0 | return; |
781 | | |
782 | 0 | mfRotateX = fRotX; |
783 | 0 | mfRotateY = fRotY; |
784 | 0 | mfRotateZ = fRotZ; |
785 | |
|
786 | 0 | if(mp3DObj) |
787 | 0 | { |
788 | 0 | basegfx::B3DHomMatrix aObjectRotation; |
789 | 0 | aObjectRotation.rotate(mfRotateX, mfRotateY, mfRotateZ); |
790 | 0 | mp3DObj->SetTransform(aObjectRotation); |
791 | |
|
792 | 0 | Invalidate(); |
793 | 0 | } |
794 | 0 | } |
795 | | |
796 | | void Svx3DLightControl::GetRotation(double& rRotX, double& rRotY, double& rRotZ) |
797 | 0 | { |
798 | 0 | rRotX = mfRotateX; |
799 | 0 | rRotY = mfRotateY; |
800 | 0 | rRotZ = mfRotateZ; |
801 | 0 | } |
802 | | |
803 | | void Svx3DLightControl::Set3DAttributes( const SfxItemSet& rAttr ) |
804 | 0 | { |
805 | | // call parent |
806 | 0 | Svx3DPreviewControl::Set3DAttributes(rAttr); |
807 | |
|
808 | 0 | if(maSelectedLight != NO_LIGHT_SELECTED && !GetLightOnOff(maSelectedLight)) |
809 | 0 | { |
810 | | // selected light is no more active, select new one |
811 | 0 | maSelectedLight = NO_LIGHT_SELECTED; |
812 | 0 | } |
813 | | |
814 | | // local updates |
815 | 0 | ConstructLightObjects(); |
816 | 0 | AdaptToSelectedLight(); |
817 | 0 | Invalidate(); |
818 | 0 | } |
819 | | |
820 | | void Svx3DLightControl::SelectLight(sal_uInt32 nLightNumber) |
821 | 0 | { |
822 | 0 | if(nLightNumber > 7) |
823 | 0 | { |
824 | 0 | nLightNumber = NO_LIGHT_SELECTED; |
825 | 0 | } |
826 | |
|
827 | 0 | if(NO_LIGHT_SELECTED != nLightNumber) |
828 | 0 | { |
829 | 0 | if(!GetLightOnOff(nLightNumber)) |
830 | 0 | { |
831 | 0 | nLightNumber = NO_LIGHT_SELECTED; |
832 | 0 | } |
833 | 0 | } |
834 | |
|
835 | 0 | if(nLightNumber != maSelectedLight) |
836 | 0 | { |
837 | 0 | maSelectedLight = nLightNumber; |
838 | 0 | mbGeometrySelected = false; |
839 | 0 | ConstructLightObjects(); |
840 | 0 | AdaptToSelectedLight(); |
841 | 0 | Invalidate(); |
842 | 0 | } |
843 | 0 | } |
844 | | |
845 | | bool Svx3DLightControl::GetLightOnOff(sal_uInt32 nNum) const |
846 | 0 | { |
847 | 0 | if(nNum <= 7) |
848 | 0 | { |
849 | 0 | const SfxItemSet aLightItemSet(Get3DAttributes()); |
850 | |
|
851 | 0 | switch(nNum) |
852 | 0 | { |
853 | 0 | case 0 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_1).GetValue(); |
854 | 0 | case 1 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_2).GetValue(); |
855 | 0 | case 2 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_3).GetValue(); |
856 | 0 | case 3 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_4).GetValue(); |
857 | 0 | case 4 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_5).GetValue(); |
858 | 0 | case 5 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_6).GetValue(); |
859 | 0 | case 6 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_7).GetValue(); |
860 | 0 | case 7 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTON_8).GetValue(); |
861 | 0 | } |
862 | 0 | } |
863 | | |
864 | 0 | return false; |
865 | 0 | } |
866 | | |
867 | | Color Svx3DLightControl::GetLightColor(sal_uInt32 nNum) const |
868 | 0 | { |
869 | 0 | if(nNum <= 7) |
870 | 0 | { |
871 | 0 | const SfxItemSet aLightItemSet(Get3DAttributes()); |
872 | |
|
873 | 0 | switch(nNum) |
874 | 0 | { |
875 | 0 | case 0 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_1).GetValue(); |
876 | 0 | case 1 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_2).GetValue(); |
877 | 0 | case 2 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_3).GetValue(); |
878 | 0 | case 3 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_4).GetValue(); |
879 | 0 | case 4 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_5).GetValue(); |
880 | 0 | case 5 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_6).GetValue(); |
881 | 0 | case 6 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_7).GetValue(); |
882 | 0 | case 7 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_8).GetValue(); |
883 | 0 | } |
884 | 0 | } |
885 | | |
886 | 0 | return COL_BLACK; |
887 | 0 | } |
888 | | |
889 | | basegfx::B3DVector Svx3DLightControl::GetLightDirection(sal_uInt32 nNum) const |
890 | 0 | { |
891 | 0 | if(nNum <= 7) |
892 | 0 | { |
893 | 0 | const SfxItemSet aLightItemSet(Get3DAttributes()); |
894 | |
|
895 | 0 | switch(nNum) |
896 | 0 | { |
897 | 0 | case 0 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_1).GetValue(); |
898 | 0 | case 1 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_2).GetValue(); |
899 | 0 | case 2 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_3).GetValue(); |
900 | 0 | case 3 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_4).GetValue(); |
901 | 0 | case 4 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_5).GetValue(); |
902 | 0 | case 5 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_6).GetValue(); |
903 | 0 | case 6 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_7).GetValue(); |
904 | 0 | case 7 : return aLightItemSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_8).GetValue(); |
905 | 0 | } |
906 | 0 | } |
907 | | |
908 | 0 | return basegfx::B3DVector(); |
909 | 0 | } |
910 | | |
911 | | SvxLightCtl3D::SvxLightCtl3D(Svx3DLightControl& rLightControl, weld::Scale& rHori, |
912 | | weld::Scale& rVert, weld::Button& rSwitcher) |
913 | 0 | : mrLightControl(rLightControl) |
914 | 0 | , mrHorScroller(rHori) |
915 | 0 | , mrVerScroller(rVert) |
916 | 0 | , mrSwitcher(rSwitcher) |
917 | 0 | { |
918 | | // init members |
919 | 0 | Init(); |
920 | 0 | } |
921 | | |
922 | | void SvxLightCtl3D::Init() |
923 | 0 | { |
924 | 0 | Size aSize(mrLightControl.GetDrawingArea()->get_ref_device().LogicToPixel(Size(80, 100), MapMode(MapUnit::MapAppFont))); |
925 | 0 | mrLightControl.set_size_request(aSize.Width(), aSize.Height()); |
926 | | |
927 | | // #i58240# set HelpIDs for scrollbars and switcher |
928 | 0 | mrHorScroller.set_help_id(HID_CTRL3D_HSCROLL); |
929 | 0 | mrVerScroller.set_help_id(HID_CTRL3D_VSCROLL); |
930 | 0 | mrSwitcher.set_help_id(HID_CTRL3D_SWITCHER); |
931 | 0 | mrSwitcher.set_accessible_name(SvxResId(STR_SWITCH)); |
932 | | |
933 | | // Light preview |
934 | 0 | mrLightControl.Show(); |
935 | 0 | mrLightControl.SetChangeCallback( LINK(this, SvxLightCtl3D, InternalInteractiveChange) ); |
936 | 0 | mrLightControl.SetSelectionChangeCallback( LINK(this, SvxLightCtl3D, InternalSelectionChange) ); |
937 | | |
938 | | // Horiz Scrollbar |
939 | 0 | mrHorScroller.show(); |
940 | 0 | mrHorScroller.set_range(0, 36000); |
941 | 0 | mrHorScroller.connect_value_changed( LINK(this, SvxLightCtl3D, ScrollBarMove) ); |
942 | | |
943 | | // Vert Scrollbar |
944 | 0 | mrVerScroller.show(); |
945 | 0 | mrVerScroller.set_range(0, 18000); |
946 | 0 | mrVerScroller.connect_value_changed( LINK(this, SvxLightCtl3D, ScrollBarMove) ); |
947 | | |
948 | | // Switch Button |
949 | 0 | mrSwitcher.show(); |
950 | 0 | mrSwitcher.connect_clicked( LINK(this, SvxLightCtl3D, ButtonPress) ); |
951 | |
|
952 | 0 | weld::DrawingArea* pArea = mrLightControl.GetDrawingArea(); |
953 | 0 | pArea->connect_key_press(Link<const KeyEvent&, bool>()); //acknowledge we first remove the old one |
954 | 0 | pArea->connect_key_press(LINK(this, SvxLightCtl3D, KeyInput)); |
955 | |
|
956 | 0 | pArea->connect_focus_in(Link<weld::Widget&, void>()); //acknowledge we first remove the old one |
957 | 0 | pArea->connect_focus_in(LINK(this, SvxLightCtl3D, FocusIn)); |
958 | | |
959 | | // check selection |
960 | 0 | CheckSelection(); |
961 | 0 | } |
962 | | |
963 | | void SvxLightCtl3D::CheckSelection() |
964 | 0 | { |
965 | 0 | const bool bSelectionValid(mrLightControl.IsSelectionValid() || mrLightControl.IsGeometrySelected()); |
966 | 0 | mrHorScroller.set_sensitive(bSelectionValid); |
967 | 0 | mrVerScroller.set_sensitive(bSelectionValid); |
968 | |
|
969 | 0 | if (bSelectionValid) |
970 | 0 | { |
971 | 0 | double fHor(0.0), fVer(0.0); |
972 | 0 | mrLightControl.GetPosition(fHor, fVer); |
973 | 0 | mrHorScroller.set_value( sal_Int32(fHor * 100.0) ); |
974 | 0 | mrVerScroller.set_value( 18000 - sal_Int32((fVer + 90.0) * 100.0) ); |
975 | 0 | } |
976 | 0 | } |
977 | | |
978 | | void SvxLightCtl3D::move( double fDeltaHor, double fDeltaVer ) |
979 | 0 | { |
980 | 0 | double fHor(0.0), fVer(0.0); |
981 | |
|
982 | 0 | mrLightControl.GetPosition(fHor, fVer); |
983 | 0 | fHor += fDeltaHor; |
984 | 0 | fVer += fDeltaVer; |
985 | |
|
986 | 0 | if( fVer > 90.0 ) |
987 | 0 | return; |
988 | | |
989 | 0 | if ( fVer < -90.0 ) |
990 | 0 | return; |
991 | | |
992 | 0 | mrLightControl.SetPosition(fHor, fVer); |
993 | 0 | mrHorScroller.set_value( sal_Int32(fHor * 100.0) ); |
994 | 0 | mrVerScroller.set_value( 18000 - sal_Int32((fVer + 90.0) * 100.0) ); |
995 | |
|
996 | 0 | if(maUserInteractiveChangeCallback.IsSet()) |
997 | 0 | { |
998 | 0 | maUserInteractiveChangeCallback.Call(this); |
999 | 0 | } |
1000 | 0 | } |
1001 | | |
1002 | | IMPL_LINK(SvxLightCtl3D, KeyInput, const KeyEvent&, rKEvt, bool) |
1003 | 0 | { |
1004 | 0 | const vcl::KeyCode aCode(rKEvt.GetKeyCode()); |
1005 | |
|
1006 | 0 | if (aCode.GetModifier()) |
1007 | 0 | return false; |
1008 | | |
1009 | 0 | bool bHandled = true; |
1010 | |
|
1011 | 0 | switch ( aCode.GetCode() ) |
1012 | 0 | { |
1013 | 0 | case KEY_SPACE: |
1014 | 0 | { |
1015 | 0 | break; |
1016 | 0 | } |
1017 | 0 | case KEY_LEFT: |
1018 | 0 | { |
1019 | 0 | move( -4.0, 0.0 ); // #i58242# changed move direction in X |
1020 | 0 | break; |
1021 | 0 | } |
1022 | 0 | case KEY_RIGHT: |
1023 | 0 | { |
1024 | 0 | move( 4.0, 0.0 ); // #i58242# changed move direction in X |
1025 | 0 | break; |
1026 | 0 | } |
1027 | 0 | case KEY_UP: |
1028 | 0 | { |
1029 | 0 | move( 0.0, 4.0 ); |
1030 | 0 | break; |
1031 | 0 | } |
1032 | 0 | case KEY_DOWN: |
1033 | 0 | { |
1034 | 0 | move( 0.0, -4.0 ); |
1035 | 0 | break; |
1036 | 0 | } |
1037 | 0 | case KEY_PAGEUP: |
1038 | 0 | { |
1039 | 0 | sal_Int32 nLight(mrLightControl.GetSelectedLight() - 1); |
1040 | |
|
1041 | 0 | while((nLight >= 0) && !mrLightControl.GetLightOnOff(nLight)) |
1042 | 0 | { |
1043 | 0 | nLight--; |
1044 | 0 | } |
1045 | |
|
1046 | 0 | if(nLight < 0) |
1047 | 0 | { |
1048 | 0 | nLight = 7; |
1049 | |
|
1050 | 0 | while((nLight >= 0) && !mrLightControl.GetLightOnOff(nLight)) |
1051 | 0 | { |
1052 | 0 | nLight--; |
1053 | 0 | } |
1054 | 0 | } |
1055 | |
|
1056 | 0 | if(nLight >= 0) |
1057 | 0 | { |
1058 | 0 | mrLightControl.SelectLight(nLight); |
1059 | 0 | CheckSelection(); |
1060 | |
|
1061 | 0 | if(maUserSelectionChangeCallback.IsSet()) |
1062 | 0 | { |
1063 | 0 | maUserSelectionChangeCallback.Call(this); |
1064 | 0 | } |
1065 | 0 | } |
1066 | |
|
1067 | 0 | break; |
1068 | 0 | } |
1069 | 0 | case KEY_PAGEDOWN: |
1070 | 0 | { |
1071 | 0 | sal_Int32 nLight(mrLightControl.GetSelectedLight() - 1); |
1072 | |
|
1073 | 0 | while(nLight <= 7 && !mrLightControl.GetLightOnOff(nLight)) |
1074 | 0 | { |
1075 | 0 | nLight++; |
1076 | 0 | } |
1077 | |
|
1078 | 0 | if(nLight > 7) |
1079 | 0 | { |
1080 | 0 | nLight = 0; |
1081 | |
|
1082 | 0 | while(nLight <= 7 && !mrLightControl.GetLightOnOff(nLight)) |
1083 | 0 | { |
1084 | 0 | nLight++; |
1085 | 0 | } |
1086 | 0 | } |
1087 | |
|
1088 | 0 | if(nLight <= 7) |
1089 | 0 | { |
1090 | 0 | mrLightControl.SelectLight(nLight); |
1091 | 0 | CheckSelection(); |
1092 | |
|
1093 | 0 | if(maUserSelectionChangeCallback.IsSet()) |
1094 | 0 | { |
1095 | 0 | maUserSelectionChangeCallback.Call(this); |
1096 | 0 | } |
1097 | 0 | } |
1098 | |
|
1099 | 0 | break; |
1100 | 0 | } |
1101 | 0 | default: |
1102 | 0 | { |
1103 | 0 | bHandled = false; |
1104 | 0 | break; |
1105 | 0 | } |
1106 | 0 | } |
1107 | 0 | return bHandled; |
1108 | 0 | } |
1109 | | |
1110 | | IMPL_LINK_NOARG(SvxLightCtl3D, FocusIn, weld::Widget&, void) |
1111 | 0 | { |
1112 | 0 | if (mrLightControl.IsEnabled()) |
1113 | 0 | { |
1114 | 0 | CheckSelection(); |
1115 | 0 | } |
1116 | 0 | } |
1117 | | |
1118 | | IMPL_LINK_NOARG(SvxLightCtl3D, ScrollBarMove, weld::Scale&, void) |
1119 | 0 | { |
1120 | 0 | const sal_Int32 nHor(mrHorScroller.get_value()); |
1121 | 0 | const sal_Int32 nVer(mrVerScroller.get_value()); |
1122 | |
|
1123 | 0 | mrLightControl.SetPosition( |
1124 | 0 | static_cast<double>(nHor) / 100.0, |
1125 | 0 | static_cast<double>((18000 - nVer) - 9000) / 100.0); |
1126 | |
|
1127 | 0 | if (maUserInteractiveChangeCallback.IsSet()) |
1128 | 0 | { |
1129 | 0 | maUserInteractiveChangeCallback.Call(this); |
1130 | 0 | } |
1131 | 0 | } |
1132 | | |
1133 | | IMPL_LINK_NOARG(SvxLightCtl3D, ButtonPress, weld::Button&, void) |
1134 | 0 | { |
1135 | 0 | if(SvxPreviewObjectType::SPHERE == GetSvx3DLightControl().GetObjectType()) |
1136 | 0 | { |
1137 | 0 | GetSvx3DLightControl().SetObjectType(SvxPreviewObjectType::CUBE); |
1138 | 0 | } |
1139 | 0 | else |
1140 | 0 | { |
1141 | 0 | GetSvx3DLightControl().SetObjectType(SvxPreviewObjectType::SPHERE); |
1142 | 0 | } |
1143 | 0 | } |
1144 | | |
1145 | | IMPL_LINK_NOARG(SvxLightCtl3D, InternalInteractiveChange, Svx3DLightControl*, void) |
1146 | 0 | { |
1147 | 0 | double fHor(0.0), fVer(0.0); |
1148 | |
|
1149 | 0 | mrLightControl.GetPosition(fHor, fVer); |
1150 | 0 | mrHorScroller.set_value( sal_Int32(fHor * 100.0) ); |
1151 | 0 | mrVerScroller.set_value( 18000 - sal_Int32((fVer + 90.0) * 100.0) ); |
1152 | |
|
1153 | 0 | if(maUserInteractiveChangeCallback.IsSet()) |
1154 | 0 | { |
1155 | 0 | maUserInteractiveChangeCallback.Call(this); |
1156 | 0 | } |
1157 | 0 | } |
1158 | | |
1159 | | IMPL_LINK_NOARG(SvxLightCtl3D, InternalSelectionChange, Svx3DLightControl*, void) |
1160 | 0 | { |
1161 | 0 | CheckSelection(); |
1162 | |
|
1163 | 0 | if(maUserSelectionChangeCallback.IsSet()) |
1164 | 0 | { |
1165 | 0 | maUserSelectionChangeCallback.Call(this); |
1166 | 0 | } |
1167 | 0 | } |
1168 | | |
1169 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |