LLScrollbar::LLScrollbar(const Params & p) : LLUICtrl(p), mChangeCallback( p.change_callback() ), mOrientation( p.orientation ), mDocSize( p.doc_size ), mDocPos( p.doc_pos ), mPageSize( p.page_size ), mStepSize( p.step_size ), mDocChanged(FALSE), mDragStartX( 0 ), mDragStartY( 0 ), mHoverGlowStrength(0.15f), mCurGlowStrength(0.f), mTrackColor( p.track_color() ), mThumbColor ( p.thumb_color() ), mThumbImageV(p.thumb_image_vertical), mThumbImageH(p.thumb_image_horizontal), mTrackImageV(p.track_image_vertical), mTrackImageH(p.track_image_horizontal), mThickness(p.thickness.isProvided() ? p.thickness : LLUI::sSettingGroups["config"]->getS32("UIScrollbarSize")), mBGVisible(p.bg_visible), mBGColor(p.bg_color) { updateThumbRect(); // Page up and page down buttons LLRect line_up_rect; LLRect line_down_rect; if( VERTICAL == mOrientation ) { line_up_rect.setLeftTopAndSize( 0, getRect().getHeight(), mThickness, mThickness ); line_down_rect.setOriginAndSize( 0, 0, mThickness, mThickness ); } else // HORIZONTAL { line_up_rect.setOriginAndSize( 0, 0, mThickness, mThickness ); line_down_rect.setOriginAndSize( getRect().getWidth() - mThickness, 0, mThickness, mThickness ); } LLButton::Params up_btn(mOrientation == VERTICAL ? p.up_button : p.left_button); up_btn.name(std::string("Line Up")); up_btn.rect(line_up_rect); up_btn.click_callback.function(boost::bind(&LLScrollbar::onLineUpBtnPressed, this, _2)); up_btn.mouse_held_callback.function(boost::bind(&LLScrollbar::onLineUpBtnPressed, this, _2)); up_btn.tab_stop(false); up_btn.follows.flags = (mOrientation == VERTICAL ? (FOLLOWS_RIGHT | FOLLOWS_TOP) : (FOLLOWS_LEFT | FOLLOWS_BOTTOM)); addChild(LLUICtrlFactory::create<LLButton>(up_btn)); LLButton::Params down_btn(mOrientation == VERTICAL ? p.down_button : p.right_button); down_btn.name(std::string("Line Down")); down_btn.rect(line_down_rect); down_btn.follows.flags(FOLLOWS_RIGHT|FOLLOWS_BOTTOM); down_btn.click_callback.function(boost::bind(&LLScrollbar::onLineDownBtnPressed, this, _2)); down_btn.mouse_held_callback.function(boost::bind(&LLScrollbar::onLineDownBtnPressed, this, _2)); down_btn.tab_stop(false); addChild(LLUICtrlFactory::create<LLButton>(down_btn)); }
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), mTrackImageHorizontal(p.track_image_horizontal), mTrackImageVertical(p.track_image_vertical), mTrackHighlightHorizontalImage(p.track_highlight_horizontal_image), mTrackHighlightVerticalImage(p.track_highlight_vertical_image), mMouseDownSignal(NULL), mMouseUpSignal(NULL) { mViewModel->setValue(p.initial_value); updateThumbRect(); mDragStartThumbRect = mThumbRect; setControlName(p.control_name, NULL); setValue(getValueF32()); if (p.mouse_down_callback.isProvided()) { setMouseDownCallback(initCommitCallback(p.mouse_down_callback)); } if (p.mouse_up_callback.isProvided()) { setMouseUpCallback(initCommitCallback(p.mouse_up_callback)); } }
void LLScrollbar::setDocParams( S32 size, S32 pos ) { mDocSize = size; setDocPos(pos); mDocChanged = TRUE; updateThumbRect(); }
void LLSlider::draw() { F32 alpha = getDrawContext().mAlpha; // since thumb image might still be decoding, need thumb to accomodate image size updateThumbRect(); // Draw background and thumb. // drawing solids requires texturing be disabled 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); // Thumb if (hasFocus()) { // Draw focus highlighting. mThumbImage->drawBorder(mThumbRect, gFocusMgr.getFocusColor() % alpha, gFocusMgr.getFocusFlashWidth()); } if( hasMouseCapture() ) { // Show ghost where thumb was before dragging began. if (mThumbImage.notNull()) { mThumbImage->draw(mDragStartThumbRect, mThumbCenterColor % (0.3f * alpha)); mThumbImage->draw(mThumbRect, mThumbOutlineColor % alpha); } } else if(!getEnabled()) { if (mThumbImage.notNull()) { mThumbImage->draw(mThumbRect, mThumbCenterColor % (0.3f * alpha)); } } else { if (mThumbImage.notNull()) { mThumbImage->draw(mThumbRect, mThumbCenterColor % alpha); } } // Fill in the thumb. LLUICtrl::draw(); }
void LLScrollbar::setPageSize( S32 page_size ) { if (page_size != mPageSize) { mPageSize = page_size; setDocPos(mDocPos); mDocChanged = TRUE; updateThumbRect(); } }
void LLScrollbar::setDocSize(S32 size) { if (size != mDocSize) { mDocSize = size; setDocPos(mDocPos); mDocChanged = TRUE; updateThumbRect(); } }
void LLSlider::setValue(F32 value, BOOL from_event) { value = llclamp( value, mMinValue, mMaxValue ); // Round to nearest increment (bias towards rounding down) value -= mMinValue; value += mIncrement/2.0001f; value -= fmod(value, mIncrement); value += mMinValue; if (!from_event && mValue != value) { setControlValue(value); } mValue = value; updateThumbRect(); }
void LLScrollbar::setDocPos(S32 pos, BOOL update_thumb) { pos = llclamp(pos, 0, getDocPosMax()); if (pos != mDocPos) { mDocPos = pos; mDocChanged = TRUE; if( mChangeCallback ) { mChangeCallback( mDocPos, this, mCallbackUserData ); } if( update_thumb ) { updateThumbRect(); } } }
void LLScrollbar::reshape(S32 width, S32 height, BOOL called_from_parent) { if (width == getRect().getWidth() && height == getRect().getHeight()) return; LLView::reshape( width, height, called_from_parent ); LLButton* up_button = getChild<LLButton>("Line Up"); LLButton* down_button = getChild<LLButton>("Line Down"); if (mOrientation == VERTICAL) { up_button->reshape(up_button->getRect().getWidth(), llmin(getRect().getHeight() / 2, SCROLLBAR_SIZE)); down_button->reshape(down_button->getRect().getWidth(), llmin(getRect().getHeight() / 2, SCROLLBAR_SIZE)); up_button->setOrigin(up_button->getRect().mLeft, getRect().getHeight() - up_button->getRect().getHeight()); } else { up_button->reshape(llmin(getRect().getWidth() / 2, SCROLLBAR_SIZE), up_button->getRect().getHeight()); down_button->reshape(llmin(getRect().getWidth() / 2, SCROLLBAR_SIZE), down_button->getRect().getHeight()); down_button->setOrigin(getRect().getWidth() - down_button->getRect().getWidth(), down_button->getRect().mBottom); } updateThumbRect(); }
// returns true if document position really changed bool LLScrollbar::setDocPos(S32 pos, BOOL update_thumb) { pos = llclamp(pos, 0, getDocPosMax()); if (pos != mDocPos) { mDocPos = pos; mDocChanged = TRUE; if( mChangeCallback ) { mChangeCallback( mDocPos, this ); } if( update_thumb ) { updateThumbRect(); } return true; } return false; }
LLSlider::LLSlider( const std::string& name, const LLRect& rect, void (*on_commit_callback)(LLUICtrl* ctrl, void* userdata), void* callback_userdata, F32 initial_value, F32 min_value, F32 max_value, F32 increment, BOOL volume, const std::string& control_name) : LLUICtrl( name, rect, TRUE, on_commit_callback, callback_userdata, FOLLOWS_LEFT | FOLLOWS_TOP), mValue( initial_value ), mInitialValue( initial_value ), mMinValue( min_value ), mMaxValue( max_value ), mIncrement( increment ), mVolumeSlider( volume ), mMouseOffset( 0 ), mTrackColor( LLUI::sColorsGroup->getColor( "SliderTrackColor" ) ), mThumbOutlineColor( LLUI::sColorsGroup->getColor( "SliderThumbOutlineColor" ) ), mThumbCenterColor( LLUI::sColorsGroup->getColor( "SliderThumbCenterColor" ) ), mMouseDownSignal( NULL ), mMouseUpSignal( NULL ) { mThumbImage = LLUI::getUIImage("icn_slide-thumb_dark.tga"); mTrackImage = LLUI::getUIImage("icn_slide-groove_dark.tga"); mTrackHighlightImage = LLUI::getUIImage("icn_slide-highlight.tga"); // properly handle setting the starting thumb rect // do it this way to handle both the operating-on-settings // and standalone ways of using this setControlName(control_name, NULL); setValue(getValueF32()); updateThumbRect(); mDragStartThumbRect = mThumbRect; }
void LLSlider::draw() { // since thumb image might still be decoding, need thumb to accomodate image size updateThumbRect(); // Draw background and thumb. // drawing solids requires texturing be disabled gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); F32 opacity = getEnabled() ? 1.f : 0.3f; LLColor4 center_color = (mThumbCenterColor % opacity); LLColor4 track_color = (mTrackColor % opacity); // 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); mTrackHighlightImage->draw(highlight_rect); // Thumb if( hasMouseCapture() ) { // Show ghost where thumb was before dragging began. mThumbImage->draw(mDragStartThumbRect, mThumbCenterColor % 0.3f); } if (hasFocus()) { // Draw focus highlighting. mThumbImage->drawBorder(mThumbRect, gFocusMgr.getFocusColor(), gFocusMgr.getFocusFlashWidth()); } // Fill in the thumb. mThumbImage->draw(mThumbRect, hasMouseCapture() ? mThumbOutlineColor : center_color); LLUICtrl::draw(); }
LLScrollbar::LLScrollbar( const std::string& name, LLRect rect, LLScrollbar::ORIENTATION orientation, S32 doc_size, S32 doc_pos, S32 page_size, void (*change_callback)( S32 new_pos, LLScrollbar* self, void* userdata ), void* callback_user_data, S32 step_size) : LLUICtrl( name, rect, TRUE, NULL, NULL ), mChangeCallback( change_callback ), mCallbackUserData( callback_user_data ), mOrientation( orientation ), mDocSize( doc_size ), mDocPos( doc_pos ), mPageSize( page_size ), mStepSize( step_size ), mDocChanged(FALSE), mDragStartX( 0 ), mDragStartY( 0 ), mHoverGlowStrength(0.15f), mCurGlowStrength(0.f), mTrackColor( LLUI::sColorsGroup->getColor("ScrollbarTrackColor") ), mThumbColor ( LLUI::sColorsGroup->getColor("ScrollbarThumbColor") ), mHighlightColor ( LLUI::sColorsGroup->getColor("DefaultHighlightLight") ), mShadowColor ( LLUI::sColorsGroup->getColor("DefaultShadowLight") ), mOnScrollEndCallback( NULL ), mOnScrollEndData( NULL ) { //llassert( 0 <= mDocSize ); //llassert( 0 <= mDocPos && mDocPos <= mDocSize ); setTabStop(FALSE); updateThumbRect(); // Page up and page down buttons LLRect line_up_rect; std::string line_up_img; std::string line_up_selected_img; std::string line_down_img; std::string line_down_selected_img; LLRect line_down_rect; if( LLScrollbar::VERTICAL == mOrientation ) { line_up_rect.setLeftTopAndSize( 0, getRect().getHeight(), SCROLLBAR_SIZE, SCROLLBAR_SIZE ); line_up_img="UIImgBtnScrollUpOutUUID"; line_up_selected_img="UIImgBtnScrollUpInUUID"; line_down_rect.setOriginAndSize( 0, 0, SCROLLBAR_SIZE, SCROLLBAR_SIZE ); line_down_img="UIImgBtnScrollDownOutUUID"; line_down_selected_img="UIImgBtnScrollDownInUUID"; } else { // Horizontal line_up_rect.setOriginAndSize( 0, 0, SCROLLBAR_SIZE, SCROLLBAR_SIZE ); line_up_img="UIImgBtnScrollLeftOutUUID"; line_up_selected_img="UIImgBtnScrollLeftInUUID"; line_down_rect.setOriginAndSize( getRect().getWidth() - SCROLLBAR_SIZE, 0, SCROLLBAR_SIZE, SCROLLBAR_SIZE ); line_down_img="UIImgBtnScrollRightOutUUID"; line_down_selected_img="UIImgBtnScrollRightInUUID"; } LLButton* line_up_btn = new LLButton(std::string("Line Up"), line_up_rect, line_up_img, line_up_selected_img, LLStringUtil::null, &LLScrollbar::onLineUpBtnPressed, this, LLFontGL::getFontSansSerif() ); if( LLScrollbar::VERTICAL == mOrientation ) { line_up_btn->setFollowsRight(); line_up_btn->setFollowsTop(); } else { // horizontal line_up_btn->setFollowsLeft(); line_up_btn->setFollowsBottom(); } line_up_btn->setHeldDownCallback( &LLScrollbar::onLineUpBtnPressed ); line_up_btn->setTabStop(FALSE); line_up_btn->setScaleImage(TRUE); addChild(line_up_btn); LLButton* line_down_btn = new LLButton(std::string("Line Down"), line_down_rect, line_down_img, line_down_selected_img, LLStringUtil::null, &LLScrollbar::onLineDownBtnPressed, this, LLFontGL::getFontSansSerif() ); line_down_btn->setFollowsRight(); line_down_btn->setFollowsBottom(); line_down_btn->setHeldDownCallback( &LLScrollbar::onLineDownBtnPressed ); line_down_btn->setTabStop(FALSE); line_down_btn->setScaleImage(TRUE); addChild(line_down_btn); }
void LLSlider::draw() { F32 alpha = getDrawContext().mAlpha; // since thumb image might still be decoding, need thumb to accomodate image size updateThumbRect(); // Draw background and thumb. // drawing solids requires texturing be disabled gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); // Track LLPointer<LLUIImage>& trackImage = ( mOrientation == HORIZONTAL ) ? mTrackImageHorizontal : mTrackImageVertical; LLPointer<LLUIImage>& 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()) { // Draw focus highlighting. mThumbImage->drawBorder(mThumbRect, gFocusMgr.getFocusColor() % alpha, gFocusMgr.getFocusFlashWidth()); } if( hasMouseCapture() ) // currently clicking on slider { // Show ghost where thumb was before dragging began. if (mThumbImage.notNull()) { mThumbImage->draw(mDragStartThumbRect, mThumbCenterColor.get() % (0.3f * alpha)); } if (mThumbImagePressed.notNull()) { mThumbImagePressed->draw(mThumbRect, mThumbOutlineColor % alpha); } } else if (!isInEnabledChain()) { if (mThumbImageDisabled.notNull()) { mThumbImageDisabled->draw(mThumbRect, mThumbCenterColor % alpha); } } else { if (mThumbImage.notNull()) { mThumbImage->draw(mThumbRect, mThumbCenterColor % alpha); } } LLUICtrl::draw(); }