void Slider::draw() { Display::fill_rect(rect, Color(0.0f, 0.0f, 0.0f, 0.5f)); Display::draw_rect(rect, Color(1.0f, 1.0f, 1.0f, 0.5f)); int width = 30; Rectf slider_rect(Vector(rect.left + (rect.get_width()-width) * ((pos-min)/float(max - min)), rect.top + 2), Sizef(width, rect.get_height()-4)); if (is_active()) { Display::fill_rect(slider_rect, Color(1.0f, 1.0f, 1.0f, 0.5f)); Display::draw_rect(slider_rect, Color(1.0f, 1.0f, 1.0f, 1.0f)); } else { Display::draw_rect(slider_rect, Color(1.0f, 1.0f, 1.0f, 0.5f)); } }
LLMultiSliderCtrl::LLMultiSliderCtrl(const LLMultiSliderCtrl::Params& p) : LLF32UICtrl(p), mLabelBox( NULL ), mEditor( NULL ), mTextBox( NULL ), mTextEnabledColor(p.text_color()), mTextDisabledColor(p.text_disabled_color()) { static LLUICachedControl<S32> multi_sliderctrl_spacing ("UIMultiSliderctrlSpacing", 0); S32 top = getRect().getHeight(); S32 bottom = 0; S32 left = 0; S32 label_width = p.label_width; S32 text_width = p.text_width; // Label if( !p.label().empty() ) { if (p.label_width == 0) { label_width = p.font()->getWidth(p.label); } LLRect label_rect( left, top, label_width, bottom ); LLTextBox::Params params; params.name("MultiSliderCtrl Label"); params.rect(label_rect); params.initial_value(p.label()); params.font(p.font); mLabelBox = LLUICtrlFactory::create<LLTextBox> (params); addChild(mLabelBox); } S32 slider_right = getRect().getWidth(); if (p.show_text) { if (!p.text_width.isProvided()) { text_width = 0; // calculate the size of the text box (log max_value is number of digits - 1 so plus 1) if ( p.max_value() ) text_width = p.font()->getWidth(std::string("0")) * ( static_cast < S32 > ( log10 ( p.max_value ) ) + p.decimal_digits + 1 ); if ( p.increment < 1.0f ) text_width += p.font()->getWidth(std::string(".")); // (mostly) take account of decimal point in value if ( p.min_value < 0.0f || p.max_value < 0.0f ) text_width += p.font()->getWidth(std::string("-")); // (mostly) take account of minus sign // padding to make things look nicer text_width += 8; } S32 text_left = getRect().getWidth() - text_width; slider_right = text_left - multi_sliderctrl_spacing; LLRect text_rect( text_left, top, getRect().getWidth(), bottom ); if( p.can_edit_text ) { LLLineEditor::Params params; params.name("MultiSliderCtrl Editor"); params.rect(text_rect); params.font(p.font); params.max_length_bytes(MAX_STRING_LENGTH); params.commit_callback.function(LLMultiSliderCtrl::onEditorCommit); params.prevalidate_callback(&LLTextValidate::validateFloat); params.follows.flags(FOLLOWS_LEFT | FOLLOWS_BOTTOM); mEditor = LLUICtrlFactory::create<LLLineEditor> (params); mEditor->setFocusReceivedCallback( boost::bind(LLMultiSliderCtrl::onEditorGainFocus, _1, this) ); // don't do this, as selecting the entire text is single clicking in some cases // and double clicking in others //mEditor->setSelectAllonFocusReceived(TRUE); addChild(mEditor); } else { LLTextBox::Params params; params.name("MultiSliderCtrl Text"); params.rect(text_rect); params.font(p.font); params.follows.flags(FOLLOWS_LEFT | FOLLOWS_BOTTOM); mTextBox = LLUICtrlFactory::create<LLTextBox> (params); addChild(mTextBox); } } S32 slider_left = label_width ? label_width + multi_sliderctrl_spacing : 0; LLRect slider_rect( slider_left, top, slider_right, bottom ); LLMultiSlider::Params params; params.sliders = p.sliders; params.rect(slider_rect); params.commit_callback.function( LLMultiSliderCtrl::onSliderCommit ); params.mouse_down_callback( p.mouse_down_callback ); params.mouse_up_callback( p.mouse_up_callback ); params.initial_value(p.initial_value()); params.min_value(p.min_value); params.max_value(p.max_value); params.increment(p.increment); params.max_sliders(p.max_sliders); params.allow_overlap(p.allow_overlap); params.draw_track(p.draw_track); params.use_triangle(p.use_triangle); params.control_name(p.control_name); mMultiSlider = LLUICtrlFactory::create<LLMultiSlider> (params); addChild( mMultiSlider ); mCurValue = mMultiSlider->getCurSliderValue(); updateText(); }
LLSliderCtrl::LLSliderCtrl(const std::string& name, const LLRect& rect, const std::string& label, const LLFontGL* font, S32 label_width, S32 text_left, BOOL show_text, BOOL can_edit_text, BOOL volume, void (*commit_callback)(LLUICtrl*, void*), void* callback_user_data, F32 initial_value, F32 min_value, F32 max_value, F32 increment, const std::string& control_which) : LLUICtrl(name, rect, TRUE, commit_callback, callback_user_data ), mFont(font), mShowText( show_text ), mCanEditText( can_edit_text ), mVolumeSlider( volume ), mPrecision( 3 ), mLabelBox( NULL ), mLabelWidth( label_width ), mValue( initial_value ), mEditor( NULL ), mTextBox( NULL ), //mTextEnabledColor( sLabelTextColor ), //mTextDisabledColor( sLabelDisabledColor ), mSliderMouseUpCallback( NULL ), mSliderMouseDownCallback( NULL ) { static LLColor4 sLabelTextColor = LLUI::sColorsGroup->getColor( "LabelTextColor" ); static LLColor4 sLabelDisabledColor = LLUI::sColorsGroup->getColor( "LabelDisabledColor" ); mTextEnabledColor = sLabelTextColor; mTextDisabledColor = sLabelDisabledColor; S32 top = getRect().getHeight(); S32 bottom = 0; S32 left = 0; // Label if( !label.empty() ) { if (label_width == 0) { label_width = font->getWidth(label); } LLRect label_rect( left, top, label_width, bottom ); mLabelBox = new LLTextBox( std::string("SliderCtrl Label"), label_rect, label, font ); addChild(mLabelBox); } S32 slider_right = getRect().getWidth(); if( show_text ) { slider_right = text_left - SLIDERCTRL_SPACING; } S32 slider_left = label_width ? label_width + SLIDERCTRL_SPACING : 0; LLRect slider_rect( slider_left, top, slider_right, bottom ); mSlider = new LLSlider(std::string("slider"), slider_rect, LLSliderCtrl::onSliderCommit, this, initial_value, min_value, max_value, increment, volume, control_which ); addChild( mSlider ); if( show_text ) { LLRect text_rect( text_left, top, getRect().getWidth(), bottom ); if( can_edit_text ) { mEditor = new LLLineEditor( std::string("SliderCtrl Editor"), text_rect, LLStringUtil::null, font, MAX_STRING_LENGTH, &LLSliderCtrl::onEditorCommit, NULL, NULL, this, &LLLineEditor::prevalidateFloat ); mEditor->setFollowsLeft(); mEditor->setFollowsBottom(); mEditor->setFocusReceivedCallback( &LLSliderCtrl::onEditorGainFocus, this ); mEditor->setIgnoreTab(TRUE); // don't do this, as selecting the entire text is single clicking in some cases // and double clicking in others //mEditor->setSelectAllonFocusReceived(TRUE); addChild(mEditor); } else { mTextBox = new LLTextBox( std::string("SliderCtrl Text"), text_rect, LLStringUtil::null, font); mTextBox->setFollowsLeft(); mTextBox->setFollowsBottom(); addChild(mTextBox); } } updateText(); }