From 181ac27742ff8c7b7aaff10cc1f382fd41994ccd Mon Sep 17 00:00:00 2001 From: Eugene Mutavchi Date: Thu, 12 Nov 2009 19:46:27 +0200 Subject: Initial implementation of normal task EXT-2159 (Create Vertical Slider to use for zoom in / out controls in view) --HG-- branch : product-engine --- indra/llui/llslider.cpp | 134 ++++++++++++++++----- indra/llui/llslider.h | 21 +++- indra/newview/llagent.cpp | 4 - indra/newview/llfloatercamera.cpp | 92 +++++++++++++- indra/newview/llfloatercamera.h | 3 +- .../skins/default/xui/en/floater_camera.xml | 69 ++++++++--- .../skins/default/xui/en/floater_test_slider.xml | 8 ++ .../skins/default/xui/en/widgets/slider_bar.xml | 8 +- 8 files changed, 275 insertions(+), 64 deletions(-) (limited to 'indra') diff --git a/indra/llui/llslider.cpp b/indra/llui/llslider.cpp index f86776384a..da2fc7c68b 100644 --- a/indra/llui/llslider.cpp +++ b/indra/llui/llslider.cpp @@ -47,14 +47,17 @@ static LLDefaultChildRegistry::Register r1("slider_bar"); // have ambigious template lookup problem LLSlider::Params::Params() -: track_color("track_color"), +: orientation ("orientation", std::string ("horizontal")), + track_color("track_color"), thumb_outline_color("thumb_outline_color"), thumb_center_color("thumb_center_color"), thumb_image("thumb_image"), thumb_image_pressed("thumb_image_pressed"), thumb_image_disabled("thumb_image_disabled"), - track_image("track_image"), - track_highlight_image("track_highlight_image"), + track_image_horizontal("track_image_horizontal"), + track_image_vertical("track_image_vertical"), + track_highlight_horizontal_image("track_highlight_horizontal_image"), + track_highlight_vertical_image("track_highlight_vertical_image"), mouse_down_callback("mouse_down_callback"), mouse_up_callback("mouse_up_callback") { @@ -64,14 +67,17 @@ LLSlider::Params::Params() LLSlider::LLSlider(const LLSlider::Params& p) : LLF32UICtrl(p), mMouseOffset( 0 ), + mOrientation ((p.orientation() == "horizontal") ? HORIZONTAL : VERTICAL), mTrackColor(p.track_color()), mThumbOutlineColor(p.thumb_outline_color()), mThumbCenterColor(p.thumb_center_color()), mThumbImage(p.thumb_image), mThumbImagePressed(p.thumb_image_pressed), mThumbImageDisabled(p.thumb_image_disabled), - mTrackImage(p.track_image), - mTrackHighlightImage(p.track_highlight_image) + mTrackImageHorizontal(p.track_image_horizontal), + mTrackImageVertical(p.track_image_vertical), + mTrackHighlightHorizontalImage(p.track_highlight_horizontal_image), + mTrackHighlightVerticalImage(p.track_highlight_vertical_image) { mViewModel->setValue(p.initial_value); updateThumbRect(); @@ -111,14 +117,29 @@ void LLSlider::updateThumbRect() S32 thumb_width = mThumbImage ? mThumbImage->getWidth() : DEFAULT_THUMB_SIZE; S32 thumb_height = mThumbImage ? mThumbImage->getHeight() : DEFAULT_THUMB_SIZE; - S32 left_edge = (thumb_width / 2); - S32 right_edge = getRect().getWidth() - (thumb_width / 2); - - S32 x = left_edge + S32( t * (right_edge - left_edge) ); - mThumbRect.mLeft = x - (thumb_width / 2); - mThumbRect.mRight = mThumbRect.mLeft + thumb_width; - mThumbRect.mBottom = getLocalRect().getCenterY() - (thumb_height / 2); - mThumbRect.mTop = mThumbRect.mBottom + thumb_height; + + if ( mOrientation == HORIZONTAL ) + { + S32 left_edge = (thumb_width / 2); + S32 right_edge = getRect().getWidth() - (thumb_width / 2); + + S32 x = left_edge + S32( t * (right_edge - left_edge) ); + mThumbRect.mLeft = x - (thumb_width / 2); + mThumbRect.mRight = mThumbRect.mLeft + thumb_width; + mThumbRect.mBottom = getLocalRect().getCenterY() - (thumb_height / 2); + mThumbRect.mTop = mThumbRect.mBottom + thumb_height; + } + else + { + S32 top_edge = (thumb_height / 2); + S32 bottom_edge = getRect().getHeight() - (thumb_height / 2); + + S32 y = top_edge + S32( t * (bottom_edge - top_edge) ); + mThumbRect.mLeft = getLocalRect().getCenterX() - (thumb_width / 2); + mThumbRect.mRight = mThumbRect.mLeft + thumb_width; + mThumbRect.mBottom = y - (thumb_height / 2); + mThumbRect.mTop = mThumbRect.mBottom + thumb_height; + } } @@ -138,18 +159,32 @@ BOOL LLSlider::handleHover(S32 x, S32 y, MASK mask) { if( hasMouseCapture() ) { - S32 thumb_half_width = mThumbImage->getWidth()/2; - S32 left_edge = thumb_half_width; - S32 right_edge = getRect().getWidth() - (thumb_half_width); + if ( mOrientation == HORIZONTAL ) + { + S32 thumb_half_width = mThumbImage->getWidth()/2; + S32 left_edge = thumb_half_width; + S32 right_edge = getRect().getWidth() - (thumb_half_width); - x += mMouseOffset; - x = llclamp( x, left_edge, right_edge ); + x += mMouseOffset; + x = llclamp( x, left_edge, right_edge ); - F32 t = F32(x - left_edge) / (right_edge - left_edge); - setValueAndCommit(t * (mMaxValue - mMinValue) + mMinValue ); + F32 t = F32(x - left_edge) / (right_edge - left_edge); + setValueAndCommit(t * (mMaxValue - mMinValue) + mMinValue ); + } + else // mOrientation == VERTICAL + { + S32 thumb_half_height = mThumbImage->getHeight()/2; + S32 top_edge = thumb_half_height; + S32 bottom_edge = getRect().getHeight() - (thumb_half_height); + + y += mMouseOffset; + y = llclamp(y, top_edge, bottom_edge); + F32 t = F32(y - top_edge) / (bottom_edge - top_edge); + setValueAndCommit(t * (mMaxValue - mMinValue) + mMinValue ); + } getWindow()->setCursor(UI_CURSOR_ARROW); - lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" << llendl; + lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" << llendl; } else { @@ -198,7 +233,9 @@ BOOL LLSlider::handleMouseDown(S32 x, S32 y, MASK mask) // Find the offset of the actual mouse location from the center of the thumb. if (mThumbRect.pointInRect(x,y)) { - mMouseOffset = (mThumbRect.mLeft + mThumbImage->getWidth()/2) - x; + mMouseOffset = (mOrientation == HORIZONTAL) + ? (mThumbRect.mLeft + mThumbImage->getWidth()/2) - x + : (mThumbRect.mBottom + mThumbImage->getHeight()/2) - y; } else { @@ -220,15 +257,12 @@ BOOL LLSlider::handleKeyHere(KEY key, MASK mask) BOOL handled = FALSE; switch(key) { - case KEY_UP: case KEY_DOWN: - // eat up and down keys to be consistent - handled = TRUE; - break; case KEY_LEFT: setValueAndCommit(getValueF32() - getIncrement()); handled = TRUE; break; + case KEY_UP: case KEY_RIGHT: setValueAndCommit(getValueF32() + getIncrement()); handled = TRUE; @@ -239,6 +273,17 @@ BOOL LLSlider::handleKeyHere(KEY key, MASK mask) return handled; } +BOOL LLSlider::handleScrollWheel(S32 x, S32 y, S32 clicks) +{ + if ( mOrientation == VERTICAL ) + { + F32 new_val = getValueF32() - clicks * getIncrement(); + setValueAndCommit(new_val); + return TRUE; + } + return LLF32UICtrl::handleScrollWheel(x,y,clicks); +} + void LLSlider::draw() { F32 alpha = getDrawContext().mAlpha; @@ -252,13 +297,36 @@ void LLSlider::draw() gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); // Track - LLRect track_rect(mThumbImage->getWidth() / 2, - getLocalRect().getCenterY() + (mTrackImage->getHeight() / 2), - getRect().getWidth() - mThumbImage->getWidth() / 2, - getLocalRect().getCenterY() - (mTrackImage->getHeight() / 2) ); - LLRect highlight_rect(track_rect.mLeft, track_rect.mTop, mThumbRect.getCenterX(), track_rect.mBottom); - mTrackImage->draw(track_rect, LLColor4::white % alpha); - mTrackHighlightImage->draw(highlight_rect, LLColor4::white % alpha); + LLPointer& trackImage = ( mOrientation == HORIZONTAL ) + ? mTrackImageHorizontal + : mTrackImageVertical; + + LLPointer& trackHighlightImage = ( mOrientation == HORIZONTAL ) + ? mTrackHighlightHorizontalImage + : mTrackHighlightVerticalImage; + + LLRect track_rect; + LLRect highlight_rect; + + if ( mOrientation == HORIZONTAL ) + { + track_rect.set(mThumbImage->getWidth() / 2, + getLocalRect().getCenterY() + (trackImage->getHeight() / 2), + getRect().getWidth() - mThumbImage->getWidth() / 2, + getLocalRect().getCenterY() - (trackImage->getHeight() / 2) ); + highlight_rect.set(track_rect.mLeft, track_rect.mTop, mThumbRect.getCenterX(), track_rect.mBottom); + } + else + { + track_rect.set(getLocalRect().getCenterX() - (trackImage->getWidth() / 2), + getRect().getHeight(), + getLocalRect().getCenterX() + (trackImage->getWidth() / 2), + 0); + highlight_rect.set(track_rect.mLeft, track_rect.mTop, track_rect.mRight, track_rect.mBottom); + } + + trackImage->draw(track_rect, LLColor4::white % alpha); + trackHighlightImage->draw(highlight_rect, LLColor4::white % alpha); // Thumb if (hasFocus()) diff --git a/indra/llui/llslider.h b/indra/llui/llslider.h index e2a94e4d8c..6ab0ed7922 100644 --- a/indra/llui/llslider.h +++ b/indra/llui/llslider.h @@ -39,8 +39,12 @@ class LLSlider : public LLF32UICtrl { public: + enum ORIENTATION { HORIZONTAL, VERTICAL }; + struct Params : public LLInitParam::Block { + Optional orientation; + Optional track_color, thumb_outline_color, thumb_center_color; @@ -48,8 +52,10 @@ public: Optional thumb_image, thumb_image_pressed, thumb_image_disabled, - track_image, - track_highlight_image; + track_image_horizontal, + track_image_vertical, + track_highlight_horizontal_image, + track_highlight_vertical_image; Optional mouse_down_callback, mouse_up_callback; @@ -77,6 +83,7 @@ public: virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask); virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask); virtual BOOL handleKeyHere(KEY key, MASK mask); + virtual BOOL handleScrollWheel(S32 x, S32 y, S32 clicks); virtual void draw(); private: @@ -90,10 +97,14 @@ private: LLPointer mThumbImage; LLPointer mThumbImagePressed; LLPointer mThumbImageDisabled; - LLPointer mTrackImage; - LLPointer mTrackHighlightImage; + LLPointer mTrackImageHorizontal; + LLPointer mTrackImageVertical; + LLPointer mTrackHighlightHorizontalImage; + LLPointer mTrackHighlightVerticalImage; + + const ORIENTATION mOrientation; - LLRect mThumbRect; + LLRect mThumbRect; LLUIColor mTrackColor; LLUIColor mThumbOutlineColor; LLUIColor mThumbCenterColor; diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index d2c8558f0b..ca1688ad1f 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -3080,10 +3080,6 @@ void LLAgent::updateCamera() mOrbitLeftKey > 0.f, // right mOrbitDownKey > 0.f); // bottom - camera_floater->mZoom->setToggleState( - mOrbitInKey > 0.f, // top - mOrbitOutKey > 0.f); // bottom - camera_floater->mTrack->setToggleState( mPanLeftKey > 0.f, // left mPanUpKey > 0.f, // top diff --git a/indra/newview/llfloatercamera.cpp b/indra/newview/llfloatercamera.cpp index d1317f7c36..92e958b32d 100644 --- a/indra/newview/llfloatercamera.cpp +++ b/indra/newview/llfloatercamera.cpp @@ -40,10 +40,12 @@ // Viewer includes #include "lljoystickbutton.h" #include "llviewercontrol.h" +#include "llviewercamera.h" #include "llbottomtray.h" #include "llagent.h" #include "lltoolmgr.h" #include "lltoolfocus.h" +#include "llslider.h" // Constants const F32 CAMERA_BUTTON_DELAY = 0.0f; @@ -54,6 +56,93 @@ const F32 CAMERA_BUTTON_DELAY = 0.0f; #define PRESETS "camera_presets" #define CONTROLS "controls" +// Zoom the camera in and out +class LLPanelCameraZoom +: public LLPanel +{ + LOG_CLASS(LLPanelCameraZoom); +public: + LLPanelCameraZoom(); + + /* virtual */ BOOL postBuild(); + /* virtual */ void onOpen(const LLSD& key); + +protected: + void onZoomPlusHeldDown(); + void onZoomMinusHeldDown(); + void onSliderValueChanged(); + +private: + F32 mSavedSliderVal; + LLButton* mPlusBtn; + LLButton* mMinusBtn; + LLSlider* mSlider; +}; + +static LLRegisterPanelClassWrapper t_camera_zoom_panel("camera_zoom_panel"); + +//------------------------------------------------------------------------------- +// LLPanelCameraZoom +//------------------------------------------------------------------------------- + +LLPanelCameraZoom::LLPanelCameraZoom() +: mPlusBtn( NULL ), + mMinusBtn( NULL ), + mSlider( NULL ), + mSavedSliderVal(0.f) +{ + mCommitCallbackRegistrar.add("Zoom.minus", boost::bind(&LLPanelCameraZoom::onZoomPlusHeldDown, this)); + mCommitCallbackRegistrar.add("Zoom.plus", boost::bind(&LLPanelCameraZoom::onZoomMinusHeldDown, this)); + mCommitCallbackRegistrar.add("Slider.value_changed", boost::bind(&LLPanelCameraZoom::onSliderValueChanged, this)); +} + +BOOL LLPanelCameraZoom::postBuild() +{ + mPlusBtn = getChild ("zoom_plus_btn"); + mMinusBtn = getChild ("zoom_minus_btn"); + mSlider = getChild ("zoom_slider"); + mSlider->setMinValue(.0f); + mSlider->setMaxValue(8.f); + return LLPanel::postBuild(); +} + +void LLPanelCameraZoom::onOpen(const LLSD& key) +{ + LLVector3d to_focus = gAgent.getPosGlobalFromAgent(LLViewerCamera::getInstance()->getOrigin()) - gAgent.calcFocusPositionTargetGlobal(); + mSavedSliderVal = 8.f - (F32)to_focus.magVec(); // maximum minus current + mSlider->setValue( mSavedSliderVal ); +} + +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(); +} + +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(); +} + +void LLPanelCameraZoom::onSliderValueChanged() +{ + F32 val = mSlider->getValueF32(); + F32 rate = val - mSavedSliderVal; + + gAgent.unlockView(); + gAgent.cameraOrbitIn(rate); + + mSavedSliderVal = val; +} // // Member functions @@ -125,6 +214,7 @@ void LLFloaterCamera::onOpen(const LLSD& key) anchor_panel, this, getDockTongue(), LLDockControl::TOP)); + mZoom->onOpen(key); } void LLFloaterCamera::onClose(bool app_quitting) @@ -147,7 +237,7 @@ BOOL LLFloaterCamera::postBuild() setIsChrome(TRUE); mRotate = getChild(ORBIT); - mZoom = getChild(ZOOM); + mZoom = getChild(ZOOM); mTrack = getChild(PAN); assignButton2Mode(CAMERA_CTRL_MODE_ORBIT, "orbit_btn"); diff --git a/indra/newview/llfloatercamera.h b/indra/newview/llfloatercamera.h index 583f279e62..4873a34e00 100644 --- a/indra/newview/llfloatercamera.h +++ b/indra/newview/llfloatercamera.h @@ -39,6 +39,7 @@ class LLJoystickCameraRotate; class LLJoystickCameraZoom; class LLJoystickCameraTrack; class LLFloaterReg; +class LLPanelCameraZoom; enum ECameraControlMode { @@ -74,7 +75,7 @@ public: virtual void onClose(bool app_quitting); LLJoystickCameraRotate* mRotate; - LLJoystickCameraZoom* mZoom; + LLPanelCameraZoom* mZoom; LLJoystickCameraTrack* mTrack; private: diff --git a/indra/newview/skins/default/xui/en/floater_camera.xml b/indra/newview/skins/default/xui/en/floater_camera.xml index 5c09bc3a02..2af451400e 100644 --- a/indra/newview/skins/default/xui/en/floater_camera.xml +++ b/indra/newview/skins/default/xui/en/floater_camera.xml @@ -49,22 +49,57 @@ top="22" visible="false" width="78" /> - - + + + + + + + + - + + thumb_image_disabled="SliderThumb_Disabled" + track_image_horizontal="SliderTrack_Horiz" + track_image_vertical="SliderTrack_Vert" + track_highlight_horizontal_image="SliderTrack_Horiz" + track_highlight_vertical_image="SliderTrack_Vert" /> -- cgit v1.2.3