1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
|
/**
* @file llfloatercamera.cpp
* @brief Container for camera control buttons (zoom, pan, orbit)
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llfloatercamera.h"
// Library includes
#include "llfloaterreg.h"
// Viewer includes
#include "llagent.h"
#include "llagentcamera.h"
#include "llpresetsmanager.h"
#include "lljoystickbutton.h"
#include "llviewercontrol.h"
#include "llviewercamera.h"
#include "lltoolmgr.h"
#include "lltoolfocus.h"
#include "llslider.h"
#include "llfirstuse.h"
#include "llhints.h"
#include "lltabcontainer.h"
static LLDefaultChildRegistry::Register<LLPanelCameraItem> r("panel_camera_item");
const F32 NUDGE_TIME = 0.25f; // in seconds
const F32 ORBIT_NUDGE_RATE = 0.05f; // fraction of normal speed
// constants
#define ORBIT "cam_rotate_stick"
#define PAN "cam_track_stick"
#define ZOOM "zoom"
#define CONTROLS "controls"
bool LLFloaterCamera::sFreeCamera = false;
bool LLFloaterCamera::sAppearanceEditing = false;
// Zoom the camera in and out
class LLPanelCameraZoom
: public LLPanel
{
LOG_CLASS(LLPanelCameraZoom);
public:
LLPanelCameraZoom();
/* virtual */ BOOL postBuild();
/* virtual */ void draw();
protected:
void onZoomPlusHeldDown();
void onZoomMinusHeldDown();
void onSliderValueChanged();
void onCameraTrack();
void onCameraRotate();
F32 getOrbitRate(F32 time);
private:
LLButton* mPlusBtn;
LLButton* mMinusBtn;
LLSlider* mSlider;
};
LLPanelCameraItem::Params::Params()
: icon_over("icon_over"),
icon_selected("icon_selected"),
picture("picture"),
text("text"),
selected_picture("selected_picture"),
mousedown_callback("mousedown_callback")
{
}
LLPanelCameraItem::LLPanelCameraItem(const LLPanelCameraItem::Params& p)
: LLPanel(p)
{
LLIconCtrl::Params icon_params = p.picture;
mPicture = LLUICtrlFactory::create<LLIconCtrl>(icon_params);
addChild(mPicture);
icon_params = p.icon_over;
mIconOver = LLUICtrlFactory::create<LLIconCtrl>(icon_params);
addChild(mIconOver);
icon_params = p.icon_selected;
mIconSelected = LLUICtrlFactory::create<LLIconCtrl>(icon_params);
addChild(mIconSelected);
icon_params = p.selected_picture;
mPictureSelected = LLUICtrlFactory::create<LLIconCtrl>(icon_params);
addChild(mPictureSelected);
LLTextBox::Params text_params = p.text;
mText = LLUICtrlFactory::create<LLTextBox>(text_params);
addChild(mText);
if (p.mousedown_callback.isProvided())
{
setCommitCallback(initCommitCallback(p.mousedown_callback));
}
}
void set_view_visible(LLView* parent, const std::string& name, bool visible)
{
parent->getChildView(name)->setVisible(visible);
}
BOOL LLPanelCameraItem::postBuild()
{
setMouseEnterCallback(boost::bind(set_view_visible, this, "hovered_icon", true));
setMouseLeaveCallback(boost::bind(set_view_visible, this, "hovered_icon", false));
setMouseDownCallback(boost::bind(&LLPanelCameraItem::onAnyMouseClick, this));
setRightMouseDownCallback(boost::bind(&LLPanelCameraItem::onAnyMouseClick, this));
return TRUE;
}
void LLPanelCameraItem::onAnyMouseClick()
{
if (mCommitSignal) (*mCommitSignal)(this, LLSD());
}
void LLPanelCameraItem::setValue(const LLSD& value)
{
if (!value.isMap()) return;;
if (!value.has("selected")) return;
getChildView("selected_icon")->setVisible( value["selected"]);
getChildView("picture")->setVisible( !value["selected"]);
getChildView("selected_picture")->setVisible( value["selected"]);
}
static LLPanelInjector<LLPanelCameraZoom> t_camera_zoom_panel("camera_zoom_panel");
//-------------------------------------------------------------------------------
// LLPanelCameraZoom
//-------------------------------------------------------------------------------
LLPanelCameraZoom::LLPanelCameraZoom()
: mPlusBtn( NULL ),
mMinusBtn( NULL ),
mSlider( NULL )
{
mCommitCallbackRegistrar.add("Zoom.minus", boost::bind(&LLPanelCameraZoom::onZoomMinusHeldDown, this));
mCommitCallbackRegistrar.add("Zoom.plus", boost::bind(&LLPanelCameraZoom::onZoomPlusHeldDown, this));
mCommitCallbackRegistrar.add("Slider.value_changed", boost::bind(&LLPanelCameraZoom::onSliderValueChanged, this));
mCommitCallbackRegistrar.add("Camera.track", boost::bind(&LLPanelCameraZoom::onCameraTrack, this));
mCommitCallbackRegistrar.add("Camera.rotate", boost::bind(&LLPanelCameraZoom::onCameraRotate, this));
}
BOOL LLPanelCameraZoom::postBuild()
{
mPlusBtn = getChild <LLButton> ("zoom_plus_btn");
mMinusBtn = getChild <LLButton> ("zoom_minus_btn");
mSlider = getChild <LLSlider> ("zoom_slider");
return LLPanel::postBuild();
}
void LLPanelCameraZoom::draw()
{
mSlider->setValue(gAgentCamera.getCameraZoomFraction());
LLPanel::draw();
}
void LLPanelCameraZoom::onZoomPlusHeldDown()
{
F32 val = mSlider->getValueF32();
F32 inc = mSlider->getIncrement();
mSlider->setValue(val - inc);
F32 time = mPlusBtn->getHeldDownTime();
gAgentCamera.unlockView();
gAgentCamera.setOrbitInKey(getOrbitRate(time));
}
void LLPanelCameraZoom::onZoomMinusHeldDown()
{
F32 val = mSlider->getValueF32();
F32 inc = mSlider->getIncrement();
mSlider->setValue(val + inc);
F32 time = mMinusBtn->getHeldDownTime();
gAgentCamera.unlockView();
gAgentCamera.setOrbitOutKey(getOrbitRate(time));
}
void LLPanelCameraZoom::onCameraTrack()
{
// EXP-202 when camera panning activated, remove the hint
LLFirstUse::viewPopup( false );
}
void LLPanelCameraZoom::onCameraRotate()
{
// EXP-202 when camera rotation activated, remove the hint
LLFirstUse::viewPopup( false );
}
F32 LLPanelCameraZoom::getOrbitRate(F32 time)
{
if( time < NUDGE_TIME )
{
F32 rate = ORBIT_NUDGE_RATE + time * (1 - ORBIT_NUDGE_RATE)/ NUDGE_TIME;
return rate;
}
else
{
return 1;
}
}
void LLPanelCameraZoom::onSliderValueChanged()
{
F32 zoom_level = mSlider->getValueF32();
gAgentCamera.setCameraZoomFraction(zoom_level);
}
void activate_camera_tool()
{
LLToolMgr::getInstance()->setTransientTool(LLToolCamera::getInstance());
};
//
// Member functions
//
/*static*/ bool LLFloaterCamera::inFreeCameraMode()
{
LLFloaterCamera* floater_camera = LLFloaterCamera::findInstance();
if (floater_camera && floater_camera->mCurrMode == CAMERA_CTRL_MODE_FREE_CAMERA && gAgentCamera.getCameraMode() != CAMERA_MODE_MOUSELOOK)
{
return true;
}
return false;
}
void LLFloaterCamera::resetCameraMode()
{
LLFloaterCamera* floater_camera = LLFloaterCamera::findInstance();
if (!floater_camera) return;
floater_camera->switchMode(CAMERA_CTRL_MODE_PAN);
}
void LLFloaterCamera::onAvatarEditingAppearance(bool editing)
{
sAppearanceEditing = editing;
LLFloaterCamera* floater_camera = LLFloaterCamera::findInstance();
if (!floater_camera) return;
floater_camera->handleAvatarEditingAppearance(editing);
}
void LLFloaterCamera::handleAvatarEditingAppearance(bool editing)
{
}
void LLFloaterCamera::update()
{
ECameraControlMode mode = determineMode();
if (mode != mCurrMode) setMode(mode);
}
void LLFloaterCamera::toPrevMode()
{
switchMode(mPrevMode);
}
/*static*/ void LLFloaterCamera::onLeavingMouseLook()
{
LLFloaterCamera* floater_camera = LLFloaterCamera::findInstance();
if (floater_camera)
{
floater_camera->updateItemsSelection();
if(floater_camera->inFreeCameraMode())
{
activate_camera_tool();
}
}
}
LLFloaterCamera* LLFloaterCamera::findInstance()
{
return LLFloaterReg::findTypedInstance<LLFloaterCamera>("camera");
}
void LLFloaterCamera::onOpen(const LLSD& key)
{
LLFirstUse::viewPopup();
mZoom->onOpen(key);
// Returns to previous mode, see EXT-2727(View tool should remember state).
// In case floater was just hidden and it isn't reset the mode
// just update state to current one. Else go to previous.
if ( !mClosed )
updateState();
else
toPrevMode();
mClosed = FALSE;
populatePresetCombo();
}
void LLFloaterCamera::onClose(bool app_quitting)
{
//We don't care of camera mode if app is quitting
if(app_quitting)
return;
// It is necessary to reset mCurrMode to CAMERA_CTRL_MODE_PAN so
// to avoid seeing an empty floater when reopening the control.
if (mCurrMode == CAMERA_CTRL_MODE_FREE_CAMERA)
mCurrMode = CAMERA_CTRL_MODE_PAN;
// When mCurrMode is in CAMERA_CTRL_MODE_PAN
// switchMode won't modify mPrevMode, so force it here.
// It is needed to correctly return to previous mode on open, see EXT-2727.
if (mCurrMode == CAMERA_CTRL_MODE_PAN)
mPrevMode = CAMERA_CTRL_MODE_PAN;
switchMode(CAMERA_CTRL_MODE_PAN);
mClosed = TRUE;
gAgent.setMovementLocked(FALSE);
}
LLFloaterCamera::LLFloaterCamera(const LLSD& val)
: LLFloater(val),
mClosed(FALSE),
mCurrMode(CAMERA_CTRL_MODE_PAN),
mPrevMode(CAMERA_CTRL_MODE_PAN)
{
LLHints::getInstance()->registerHintTarget("view_popup", getHandle());
mCommitCallbackRegistrar.add("CameraPresets.ChangeView", boost::bind(&LLFloaterCamera::onClickCameraItem, _2));
mCommitCallbackRegistrar.add("CameraPresets.Save", boost::bind(&LLFloaterCamera::onSavePreset, this));
mCommitCallbackRegistrar.add("CameraPresets.ShowPresetsList", boost::bind(&LLFloaterReg::showInstance, "camera_presets", LLSD(), FALSE));
}
// virtual
BOOL LLFloaterCamera::postBuild()
{
updateTransparency(TT_ACTIVE); // force using active floater transparency (STORM-730)
mRotate = getChild<LLJoystickCameraRotate>(ORBIT);
mZoom = findChild<LLPanelCameraZoom>(ZOOM);
mTrack = getChild<LLJoystickCameraTrack>(PAN);
mPresetCombo = getChild<LLComboBox>("preset_combo");
getChild<LLTextBox>("precise_ctrs_label")->setShowCursorHand(false);
getChild<LLTextBox>("precise_ctrs_label")->setSoundFlags(LLView::MOUSE_UP);
getChild<LLTextBox>("precise_ctrs_label")->setClickedCallback(boost::bind(&LLFloaterReg::showInstance, "prefs_view_advanced", LLSD(), FALSE));
mPresetCombo->setCommitCallback(boost::bind(&LLFloaterCamera::onCustomPresetSelected, this));
LLPresetsManager::getInstance()->setPresetListChangeCameraCallback(boost::bind(&LLFloaterCamera::populatePresetCombo, this));
update();
// ensure that appearance mode is handled while building. See EXT-7796.
handleAvatarEditingAppearance(sAppearanceEditing);
return LLFloater::postBuild();
}
F32 LLFloaterCamera::getCurrentTransparency()
{
static LLCachedControl<F32> camera_opacity(gSavedSettings, "CameraOpacity");
static LLCachedControl<F32> active_floater_transparency(gSavedSettings, "ActiveFloaterTransparency");
return llmin(camera_opacity(), active_floater_transparency());
}
void LLFloaterCamera::fillFlatlistFromPanel (LLFlatListView* list, LLPanel* panel)
{
// copying child list and then iterating over a copy, because list itself
// is changed in process
const child_list_t child_list = *panel->getChildList();
child_list_t::const_reverse_iterator iter = child_list.rbegin();
child_list_t::const_reverse_iterator end = child_list.rend();
for ( ; iter != end; ++iter)
{
LLView* view = *iter;
LLPanel* item = dynamic_cast<LLPanel*>(view);
if (panel)
list->addItem(item);
}
}
ECameraControlMode LLFloaterCamera::determineMode()
{
if (sAppearanceEditing)
{
// this is the only enabled camera mode while editing agent appearance.
return CAMERA_CTRL_MODE_PAN;
}
LLTool* curr_tool = LLToolMgr::getInstance()->getCurrentTool();
if (curr_tool == LLToolCamera::getInstance())
{
return CAMERA_CTRL_MODE_FREE_CAMERA;
}
if (gAgentCamera.getCameraMode() == CAMERA_MODE_MOUSELOOK)
{
return CAMERA_CTRL_MODE_PRESETS;
}
return CAMERA_CTRL_MODE_PAN;
}
void clear_camera_tool()
{
LLToolMgr* tool_mgr = LLToolMgr::getInstance();
if (tool_mgr->usingTransientTool() &&
tool_mgr->getCurrentTool() == LLToolCamera::getInstance())
{
tool_mgr->clearTransientTool();
}
}
void LLFloaterCamera::setMode(ECameraControlMode mode)
{
if (mode != mCurrMode)
{
mPrevMode = mCurrMode;
mCurrMode = mode;
}
updateState();
}
void LLFloaterCamera::switchMode(ECameraControlMode mode)
{
setMode(mode);
switch (mode)
{
case CAMERA_CTRL_MODE_PAN:
sFreeCamera = false;
clear_camera_tool();
break;
case CAMERA_CTRL_MODE_FREE_CAMERA:
sFreeCamera = true;
activate_camera_tool();
break;
case CAMERA_CTRL_MODE_PRESETS:
if(sFreeCamera)
{
switchMode(CAMERA_CTRL_MODE_FREE_CAMERA);
}
break;
default:
//normally we won't occur here
llassert_always(FALSE);
}
}
void LLFloaterCamera::updateState()
{
updateItemsSelection();
if (CAMERA_CTRL_MODE_FREE_CAMERA == mCurrMode)
{
return;
}
//updating buttons
std::map<ECameraControlMode, LLButton*>::const_iterator iter = mMode2Button.begin();
for (; iter != mMode2Button.end(); ++iter)
{
iter->second->setToggleState(iter->first == mCurrMode);
}
}
void LLFloaterCamera::updateItemsSelection()
{
ECameraPreset preset = (ECameraPreset) gSavedSettings.getU32("CameraPreset");
LLSD argument;
argument["selected"] = (preset == CAMERA_PRESET_REAR_VIEW) && !sFreeCamera;
getChild<LLPanelCameraItem>("rear_view")->setValue(argument);
argument["selected"] = (preset == CAMERA_PRESET_GROUP_VIEW) && !sFreeCamera;
getChild<LLPanelCameraItem>("group_view")->setValue(argument);
argument["selected"] = (preset == CAMERA_PRESET_FRONT_VIEW) && !sFreeCamera;
getChild<LLPanelCameraItem>("front_view")->setValue(argument);
argument["selected"] = gAgentCamera.getCameraMode() == CAMERA_MODE_MOUSELOOK;
getChild<LLPanelCameraItem>("mouselook_view")->setValue(argument);
argument["selected"] = mCurrMode == CAMERA_CTRL_MODE_FREE_CAMERA;
getChild<LLPanelCameraItem>("object_view")->setValue(argument);
}
void LLFloaterCamera::onClickCameraItem(const LLSD& param)
{
std::string name = param.asString();
if ("mouselook_view" == name)
{
gAgentCamera.changeCameraToMouselook();
}
else if ("object_view" == name)
{
LLFloaterCamera* camera_floater = LLFloaterCamera::findInstance();
if (camera_floater)
{
camera_floater->switchMode(CAMERA_CTRL_MODE_FREE_CAMERA);
camera_floater->updateItemsSelection();
camera_floater->fromFreeToPresets();
}
}
else
{
LLFloaterCamera* camera_floater = LLFloaterCamera::findInstance();
if (camera_floater)
camera_floater->switchMode(CAMERA_CTRL_MODE_PAN);
switchToPreset(name);
}
}
/*static*/
void LLFloaterCamera::switchToPreset(const std::string& name)
{
sFreeCamera = false;
clear_camera_tool();
if (PRESETS_REAR_VIEW == name)
{
gAgentCamera.switchCameraPreset(CAMERA_PRESET_REAR_VIEW);
}
else if (PRESETS_SIDE_VIEW == name)
{
gAgentCamera.switchCameraPreset(CAMERA_PRESET_GROUP_VIEW);
}
else if (PRESETS_FRONT_VIEW == name)
{
gAgentCamera.switchCameraPreset(CAMERA_PRESET_FRONT_VIEW);
}
else
{
gAgentCamera.switchCameraPreset(CAMERA_PRESET_CUSTOM);
}
if (gSavedSettings.getString("PresetCameraActive") != name)
{
LLPresetsManager::getInstance()->loadPreset(PRESETS_CAMERA, name);
}
LLFloaterCamera* camera_floater = LLFloaterCamera::findInstance();
if (camera_floater)
{
camera_floater->updateItemsSelection();
camera_floater->fromFreeToPresets();
}
}
void LLFloaterCamera::fromFreeToPresets()
{
if (!sFreeCamera && mCurrMode == CAMERA_CTRL_MODE_FREE_CAMERA && mPrevMode == CAMERA_CTRL_MODE_PRESETS)
{
switchMode(CAMERA_CTRL_MODE_PRESETS);
}
}
void LLFloaterCamera::populatePresetCombo()
{
LLPresetsManager::getInstance()->setPresetNamesInComboBox(PRESETS_CAMERA, mPresetCombo, EDefaultOptions::DEFAULT_VIEWS_HIDE);
std::string active_preset_name = gSavedSettings.getString("PresetCameraActive");
if (active_preset_name.empty())
{
gSavedSettings.setU32("CameraPreset", CAMERA_PRESET_CUSTOM);
updateItemsSelection();
mPresetCombo->setLabel(getString("inactive_combo_text"));
}
else if ((ECameraPreset)gSavedSettings.getU32("CameraPreset") == CAMERA_PRESET_CUSTOM)
{
mPresetCombo->selectByValue(active_preset_name);
}
else
{
mPresetCombo->setLabel(getString("inactive_combo_text"));
}
updateItemsSelection();
}
void LLFloaterCamera::onSavePreset()
{
LLFloaterReg::hideInstance("delete_pref_preset", PRESETS_CAMERA);
LLFloaterReg::hideInstance("load_pref_preset", PRESETS_CAMERA);
LLSD key;
key["subdirectory"] = PRESETS_CAMERA;
std::string current_preset = gSavedSettings.getString("PresetCameraActive");
bool is_custom_preset = current_preset != "" && !LLPresetsManager::getInstance()->isDefaultCameraPreset(current_preset);
key["index"] = is_custom_preset ? 1 : 0;
LLFloaterReg::showInstance("save_pref_preset", key);
}
void LLFloaterCamera::onCustomPresetSelected()
{
std::string selected_preset = mPresetCombo->getSelectedItemLabel();
if (getString("inactive_combo_text") != selected_preset)
{
switchToPreset(selected_preset);
}
}
|