diff options
Diffstat (limited to 'indra/newview/llfloatercamera.cpp')
-rw-r--r-- | indra/newview/llfloatercamera.cpp | 332 |
1 files changed, 221 insertions, 111 deletions
diff --git a/indra/newview/llfloatercamera.cpp b/indra/newview/llfloatercamera.cpp index d84ebef1dd..24fba61315 100644 --- a/indra/newview/llfloatercamera.cpp +++ b/indra/newview/llfloatercamera.cpp @@ -2,31 +2,25 @@ * @file llfloatercamera.cpp * @brief Container for camera control buttons (zoom, pan, orbit) * - * $LicenseInfo:firstyear=2001&license=viewergpl$ - * - * Copyright (c) 2001-2009, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * 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. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * 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. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * 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$ */ @@ -47,15 +41,22 @@ #include "lltoolfocus.h" #include "llslider.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 const F32 CAMERA_BUTTON_DELAY = 0.0f; #define ORBIT "cam_rotate_stick" #define PAN "cam_track_stick" #define ZOOM "zoom" -#define PRESETS "camera_presets" +#define PRESETS "preset_views_list" #define CONTROLS "controls" +bool LLFloaterCamera::sFreeCamera = false; + // Zoom the camera in and out class LLPanelCameraZoom : public LLPanel @@ -71,6 +72,7 @@ protected: void onZoomPlusHeldDown(); void onZoomMinusHeldDown(); void onSliderValueChanged(); + F32 getOrbitRate(F32 time); private: LLButton* mPlusBtn; @@ -78,6 +80,68 @@ private: 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)); + } +} + +BOOL LLPanelCameraItem::postBuild() +{ + setMouseEnterCallback(boost::bind(&LLPanelCameraItem::childSetVisible, this, "hovered_icon", true)); + setMouseLeaveCallback(boost::bind(&LLPanelCameraItem::childSetVisible, 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; + childSetVisible("selected_icon", value["selected"]); + childSetVisible("picture", !value["selected"]); + childSetVisible("selected_picture", value["selected"]); +} + static LLRegisterPanelClassWrapper<LLPanelCameraZoom> t_camera_zoom_panel("camera_zoom_panel"); //------------------------------------------------------------------------------- @@ -89,8 +153,8 @@ LLPanelCameraZoom::LLPanelCameraZoom() mMinusBtn( NULL ), mSlider( NULL ) { - mCommitCallbackRegistrar.add("Zoom.minus", boost::bind(&LLPanelCameraZoom::onZoomPlusHeldDown, this)); - mCommitCallbackRegistrar.add("Zoom.plus", boost::bind(&LLPanelCameraZoom::onZoomMinusHeldDown, this)); + 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)); } @@ -113,9 +177,9 @@ void LLPanelCameraZoom::onZoomPlusHeldDown() F32 val = mSlider->getValueF32(); F32 inc = mSlider->getIncrement(); mSlider->setValue(val - inc); - // commit only if value changed - if (val != mSlider->getValueF32()) - mSlider->onCommit(); + F32 time = mPlusBtn->getHeldDownTime(); + gAgentCamera.unlockView(); + gAgentCamera.setOrbitInKey(getOrbitRate(time)); } void LLPanelCameraZoom::onZoomMinusHeldDown() @@ -123,9 +187,22 @@ void LLPanelCameraZoom::onZoomMinusHeldDown() F32 val = mSlider->getValueF32(); F32 inc = mSlider->getIncrement(); mSlider->setValue(val + inc); - // commit only if value changed - if (val != mSlider->getValueF32()) - mSlider->onCommit(); + F32 time = mMinusBtn->getHeldDownTime(); + gAgentCamera.unlockView(); + gAgentCamera.setOrbitOutKey(getOrbitRate(time)); +} + +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() @@ -153,16 +230,11 @@ void activate_camera_tool() return false; } -bool LLFloaterCamera::inAvatarViewMode() -{ - return mCurrMode == CAMERA_CTRL_MODE_AVATAR_VIEW; -} - void LLFloaterCamera::resetCameraMode() { LLFloaterCamera* floater_camera = LLFloaterCamera::findInstance(); if (!floater_camera) return; - floater_camera->switchMode(CAMERA_CTRL_MODE_ORBIT); + floater_camera->switchMode(CAMERA_CTRL_MODE_PAN); } void LLFloaterCamera::update() @@ -180,9 +252,13 @@ void LLFloaterCamera::toPrevMode() /*static*/ void LLFloaterCamera::onLeavingMouseLook() { LLFloaterCamera* floater_camera = LLFloaterCamera::findInstance(); - if (floater_camera && floater_camera->inFreeCameraMode()) + if (floater_camera) { - activate_camera_tool(); + floater_camera->updateItemsSelection(); + if(floater_camera->inFreeCameraMode()) + { + activate_camera_tool(); + } } } @@ -216,24 +292,24 @@ void LLFloaterCamera::onClose(bool app_quitting) //We don't care of camera mode if app is quitting if(app_quitting) return; - // When mCurrMode is in CAMERA_CTRL_MODE_ORBIT + // 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_ORBIT) - mPrevMode = CAMERA_CTRL_MODE_ORBIT; + if (mCurrMode == CAMERA_CTRL_MODE_PAN) + mPrevMode = CAMERA_CTRL_MODE_PAN; // HACK: Should always close as docked to prevent toggleInstance without calling onOpen. if ( !isDocked() ) setDocked(true); - switchMode(CAMERA_CTRL_MODE_ORBIT); + switchMode(CAMERA_CTRL_MODE_PAN); mClosed = TRUE; } LLFloaterCamera::LLFloaterCamera(const LLSD& val) : LLTransientDockableFloater(NULL, true, val), mClosed(FALSE), - mCurrMode(CAMERA_CTRL_MODE_ORBIT), - mPrevMode(CAMERA_CTRL_MODE_ORBIT) + mCurrMode(CAMERA_CTRL_MODE_PAN), + mPrevMode(CAMERA_CTRL_MODE_PAN) { } @@ -247,16 +323,32 @@ BOOL LLFloaterCamera::postBuild() mZoom = getChild<LLPanelCameraZoom>(ZOOM); mTrack = getChild<LLJoystickCameraTrack>(PAN); - assignButton2Mode(CAMERA_CTRL_MODE_ORBIT, "orbit_btn"); + assignButton2Mode(CAMERA_CTRL_MODE_MODES, "avatarview_btn"); assignButton2Mode(CAMERA_CTRL_MODE_PAN, "pan_btn"); - assignButton2Mode(CAMERA_CTRL_MODE_FREE_CAMERA, "freecamera_btn"); - assignButton2Mode(CAMERA_CTRL_MODE_AVATAR_VIEW, "avatarview_btn"); + assignButton2Mode(CAMERA_CTRL_MODE_PRESETS, "presets_btn"); update(); return LLDockableFloater::postBuild(); } +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() { LLTool* curr_tool = LLToolMgr::getInstance()->getCurrentTool(); @@ -267,10 +359,10 @@ ECameraControlMode LLFloaterCamera::determineMode() if (gAgentCamera.getCameraMode() == CAMERA_MODE_MOUSELOOK) { - return CAMERA_CTRL_MODE_AVATAR_VIEW; + return CAMERA_CTRL_MODE_PRESETS; } - return CAMERA_CTRL_MODE_ORBIT; + return CAMERA_CTRL_MODE_PAN; } @@ -301,21 +393,16 @@ void LLFloaterCamera::setModeTitle(const ECameraControlMode mode) std::string title; switch(mode) { - case CAMERA_CTRL_MODE_ORBIT: - title = getString("orbit_mode_title"); + case CAMERA_CTRL_MODE_MODES: + title = getString("camera_modes_title"); break; case CAMERA_CTRL_MODE_PAN: title = getString("pan_mode_title"); break; - case CAMERA_CTRL_MODE_AVATAR_VIEW: - title = getString("avatar_view_mode_title"); - break; - case CAMERA_CTRL_MODE_FREE_CAMERA: - title = getString("free_mode_title"); + case CAMERA_CTRL_MODE_PRESETS: + title = getString("presets_mode_title"); break; default: - // title should be provided for all modes - llassert(false); break; } setTitle(title); @@ -327,19 +414,28 @@ void LLFloaterCamera::switchMode(ECameraControlMode mode) switch (mode) { - case CAMERA_CTRL_MODE_ORBIT: - clear_camera_tool(); + case CAMERA_CTRL_MODE_MODES: + if(sFreeCamera) + { + switchMode(CAMERA_CTRL_MODE_FREE_CAMERA); + } break; 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_AVATAR_VIEW: + case CAMERA_CTRL_MODE_PRESETS: + if(sFreeCamera) + { + switchMode(CAMERA_CTRL_MODE_FREE_CAMERA); + } break; default: @@ -368,66 +464,80 @@ void LLFloaterCamera::assignButton2Mode(ECameraControlMode mode, const std::stri void LLFloaterCamera::updateState() { + childSetVisible(ZOOM, CAMERA_CTRL_MODE_PAN == mCurrMode); + + bool show_presets = (CAMERA_CTRL_MODE_PRESETS == mCurrMode) || (CAMERA_CTRL_MODE_FREE_CAMERA == mCurrMode + && CAMERA_CTRL_MODE_PRESETS == mPrevMode); + childSetVisible(PRESETS, show_presets); + + bool show_camera_modes = CAMERA_CTRL_MODE_MODES == mCurrMode || (CAMERA_CTRL_MODE_FREE_CAMERA == mCurrMode + && CAMERA_CTRL_MODE_MODES == mPrevMode); + childSetVisible("camera_modes_list", show_camera_modes); + + 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); } - - childSetVisible(ORBIT, CAMERA_CTRL_MODE_ORBIT == mCurrMode); - childSetVisible(PAN, CAMERA_CTRL_MODE_PAN == mCurrMode); - childSetVisible(ZOOM, CAMERA_CTRL_MODE_AVATAR_VIEW != mCurrMode); - childSetVisible(PRESETS, CAMERA_CTRL_MODE_AVATAR_VIEW == mCurrMode); - - updateCameraPresetButtons(); setModeTitle(mCurrMode); - - - //hiding or showing the panel with controls by reshaping the floater - bool showControls = CAMERA_CTRL_MODE_FREE_CAMERA != mCurrMode; - if (showControls == childIsVisible(CONTROLS)) return; - - childSetVisible(CONTROLS, showControls); - - LLRect rect = getRect(); - LLRect controls_rect; - if (childGetRect(CONTROLS, controls_rect)) - { - S32 floater_header_size = getHeaderHeight(); - S32 height = controls_rect.getHeight() - floater_header_size; - S32 newHeight = rect.getHeight(); - - if (showControls) - { - newHeight += height; - } - else - { - newHeight -= height; - } - - rect.setOriginAndSize(rect.mLeft, rect.mBottom, rect.getWidth(), newHeight); - reshape(rect.getWidth(), rect.getHeight()); - setRect(rect); - - } } -void LLFloaterCamera::updateCameraPresetButtons() +void LLFloaterCamera::updateItemsSelection() { ECameraPreset preset = (ECameraPreset) gSavedSettings.getU32("CameraPreset"); - - childSetValue("rear_view", preset == CAMERA_PRESET_REAR_VIEW); - childSetValue("group_view", preset == CAMERA_PRESET_GROUP_VIEW); - childSetValue("front_view", preset == CAMERA_PRESET_FRONT_VIEW); - childSetValue("mouselook_view", gAgentCamera.cameraMouselook()); + LLSD argument; + argument["selected"] = preset == CAMERA_PRESET_REAR_VIEW; + getChild<LLPanelCameraItem>("rear_view")->setValue(argument); + argument["selected"] = preset == CAMERA_PRESET_GROUP_VIEW; + getChild<LLPanelCameraItem>("group_view")->setValue(argument); + argument["selected"] = preset == CAMERA_PRESET_FRONT_VIEW; + 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::onClickCameraPresets(const LLSD& param) +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); + } + else + { + switchToPreset(name); + } + + LLFloaterCamera* camera_floater = LLFloaterCamera::findInstance(); + if (camera_floater) + { + camera_floater->updateItemsSelection(); + camera_floater->fromFreeToPresets(); + } +} + +/*static*/ +void LLFloaterCamera::switchToPreset(const std::string& name) +{ + sFreeCamera = false; + clear_camera_tool(); if ("rear_view" == name) { gAgentCamera.switchCameraPreset(CAMERA_PRESET_REAR_VIEW); @@ -440,12 +550,12 @@ void LLFloaterCamera::onClickCameraPresets(const LLSD& param) { gAgentCamera.switchCameraPreset(CAMERA_PRESET_FRONT_VIEW); } - else if ("mouselook_view" == name) +} + +void LLFloaterCamera::fromFreeToPresets() +{ + if (!sFreeCamera && mCurrMode == CAMERA_CTRL_MODE_FREE_CAMERA && mPrevMode == CAMERA_CTRL_MODE_PRESETS) { - gAgentCamera.changeCameraToMouselook(); + switchMode(CAMERA_CTRL_MODE_PRESETS); } - - LLFloaterCamera* camera_floater = LLFloaterCamera::findInstance(); - if (camera_floater) - camera_floater->updateCameraPresetButtons(); } |