示例#1
0
void TraceGroup::paint_label(QPainter &p, const QRect &rect, bool hover)
{
	const QRectF r = label_rect(rect).adjusted(
		LineThickness / 2, LineThickness / 2,
		-LineThickness / 2, -LineThickness / 2);

	// Paint the label
	const QPointF points[] = {
		r.topRight(),
		r.topLeft(),
		r.bottomLeft(),
		r.bottomRight()
	};

	if (selected()) {
		const QPen pen(highlight_pen());
		p.setPen(QPen(pen.brush(), pen.width() + LineThickness,
			Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
		p.setBrush(Qt::transparent);
		p.drawPolyline(points, countof(points));
	}

	p.setPen(QPen(QBrush(LineColour.darker()), LineThickness,
		Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
	p.drawPolyline(points, countof(points));
	p.setPen(QPen(QBrush(hover ? LineColour.lighter() : LineColour),
		LineThickness - 2, Qt::SolidLine, Qt::SquareCap,
		Qt::RoundJoin));
	p.drawPolyline(points, countof(points));
}
LLListView::LLListView(const Params& p)
:	LLUICtrl(p),
	mLabel(NULL),
	mBgColor(p.bg_color()),
	mFgSelectedColor(p.fg_selected_color()),
	mBgSelectedColor(p.bg_selected_color())
{
	LLRect label_rect(0, 20, 300, 0);
	LLTextBox::Params text_box_params;
	text_box_params.rect(label_rect);
	text_box_params.initial_value("This is a list-view");
	mLabel = LLUICtrlFactory::create<LLTextBox>(text_box_params);
	addChild(mLabel);
}
示例#3
0
wxRect wxRibbonAUIArtProvider::GetPanelExtButtonArea(wxDC& dc,
                        const wxRibbonPanel* wnd,
                        wxRect rect)
{
    wxRect true_rect(rect);
    RemovePanelPadding(&true_rect);

    true_rect.x++;
    true_rect.width -= 2;
    true_rect.y++;

    dc.SetFont(m_panel_label_font);
    wxSize label_size = dc.GetTextExtent(wnd->GetLabel());
    int label_height = label_size.GetHeight() + 5;
    wxRect label_rect(true_rect);
    label_rect.height = label_height - 1;

    rect = wxRect(label_rect.GetRight()-13, label_rect.GetBottom()-13, 13, 13);
    return rect;
}
示例#4
0
文件: label.cpp 项目: lisicheng/ttk
void TtkLabel::handle_redraw_event(const TtkRect& redraw_rect)
{
	TtkGcInterface& gc = ws_env().gc();
	gc.set_clipping_rect(redraw_rect);

	TtkRect label_rect(rect());
	TtkRect text_rect(label_rect.tl_.x_ + 1,
			  label_rect.tl_.y_ + 1,
			  label_rect.br_.x_ - 1,
			  label_rect.br_.y_ - 1);
	gc.clear(label_rect);
	if (action_ || !action_) {	//for test
		gc.set_pen_color(kTtkColorBlue);
		if (has_focus())
			gc.draw_rect(label_rect);
		gc.draw_text(text_, text_rect, true);
	} else {
		gc.set_pen_color(kTtkColorBlack);
		gc.draw_text(text_, text_rect, false);
	}
}
LLSpinCtrl::LLSpinCtrl(const LLSpinCtrl::Params& p)
:	LLF32UICtrl(p),
	mLabelBox(NULL),
	mbHasBeenSet( FALSE ),
	mPrecision(p.decimal_digits),
	mTextEnabledColor(p.text_enabled_color()),
	mTextDisabledColor(p.text_disabled_color())
{
	static LLUICachedControl<S32> spinctrl_spacing ("UISpinctrlSpacing", 0);
	static LLUICachedControl<S32> spinctrl_btn_width ("UISpinctrlBtnWidth", 0);
	static LLUICachedControl<S32> spinctrl_btn_height ("UISpinctrlBtnHeight", 0);
	S32 centered_top = getRect().getHeight();
	S32 centered_bottom = getRect().getHeight() - 2 * spinctrl_btn_height;
	S32 btn_left = 0;
	// reserve space for spinner
	S32 label_width = llclamp(p.label_width(), 0, llmax(0, getRect().getWidth() - 40));

	// Label
	if( !p.label().empty() )
	{
		LLRect label_rect( 0, centered_top, label_width, centered_bottom );
		LLTextBox::Params params;
		params.wrap(p.label_wrap);
		params.name("SpinCtrl Label");
		params.rect(label_rect);
		params.initial_value(p.label());
		if (p.font.isProvided())
		{
			params.font(p.font);
		}
		mLabelBox = LLUICtrlFactory::create<LLTextBox> (params);
		addChild(mLabelBox);

		btn_left += label_rect.mRight + spinctrl_spacing;
	}

	S32 btn_right = btn_left + spinctrl_btn_width;
	
	// Spin buttons
	LLButton::Params up_button_params(p.up_button);
	up_button_params.rect = LLRect(btn_left, getRect().getHeight(), btn_right, getRect().getHeight() - spinctrl_btn_height);
	up_button_params.click_callback.function(boost::bind(&LLSpinCtrl::onUpBtn, this, _2));
	up_button_params.mouse_held_callback.function(boost::bind(&LLSpinCtrl::onUpBtn, this, _2));

	mUpBtn = LLUICtrlFactory::create<LLButton>(up_button_params);
	addChild(mUpBtn);

	LLButton::Params down_button_params(p.down_button);
	down_button_params.rect = LLRect(btn_left, getRect().getHeight() - spinctrl_btn_height, btn_right, getRect().getHeight() - 2 * spinctrl_btn_height);
	down_button_params.click_callback.function(boost::bind(&LLSpinCtrl::onDownBtn, this, _2));
	down_button_params.mouse_held_callback.function(boost::bind(&LLSpinCtrl::onDownBtn, this, _2));
	mDownBtn = LLUICtrlFactory::create<LLButton>(down_button_params);
	addChild(mDownBtn);

	LLRect editor_rect( btn_right + 1, centered_top, getRect().getWidth(), centered_bottom );
	LLLineEditor::Params params;
	params.name("SpinCtrl Editor");
	params.rect(editor_rect);
	if (p.font.isProvided())
	{
		params.font(p.font);
	}
	params.max_length.bytes(MAX_STRING_LENGTH);
	params.commit_callback.function((boost::bind(&LLSpinCtrl::onEditorCommit, this, _2)));
	
	//*NOTE: allow entering of any chars for LLCalc, proper input will be evaluated on commit
	
	params.follows.flags(FOLLOWS_LEFT | FOLLOWS_BOTTOM);
	mEditor = LLUICtrlFactory::create<LLLineEditor> (params);
	mEditor->setFocusReceivedCallback( boost::bind(&LLSpinCtrl::onEditorGainFocus, _1, this ));
	//RN: this seems to be a BAD IDEA, as it makes the editor behavior different when it has focus
	// than when it doesn't.  Instead, if you always have to double click to select all the text, 
	// it's easier to understand
	//mEditor->setSelectAllonFocusReceived(TRUE);
	mEditor->setSelectAllonCommit(FALSE);
	addChild(mEditor);

	updateEditor();
	setUseBoundingRect( TRUE );
}
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();
}
示例#7
0
void SpeedPlotView::paintEvent(QPaintEvent *)
{
    QPainter painter(this->viewport());

    QRect full_rect = this->viewport()->rect();
    QRect rect = this->viewport()->rect();
    QFontMetrics font_metrics = painter.fontMetrics();

    rect.adjust(4, 4, 0, -4); // Add padding

    double max_y = maxYValue();

    rect.adjust(0, font_metrics.height(), 0, 0); // Add top padding for top speed text

    // draw Y axis speed labels
    QVector<QString> speed_labels(QVector<QString>() <<
                                  Utils::Misc::friendlyUnit(max_y, true) <<
                                  Utils::Misc::friendlyUnit(0.75 * max_y, true) <<
                                  Utils::Misc::friendlyUnit(0.5 * max_y, true) <<
                                  Utils::Misc::friendlyUnit(0.25 * max_y, true) <<
                                  Utils::Misc::friendlyUnit(0, true));

    int y_axe_width = 0;
    for (int i = 0; i < speed_labels.size(); ++i) {
        if (font_metrics.width(speed_labels[i]) > y_axe_width)
            y_axe_width = font_metrics.width(speed_labels[i]);
    }

    for (int i = 0; i < speed_labels.size(); ++i) {
        QRectF label_rect(rect.topLeft() + QPointF(-y_axe_width, i * 0.25 * rect.height() - font_metrics.height()),
                          QSizeF(2 * y_axe_width, font_metrics.height()));
        painter.drawText(label_rect, speed_labels[i], QTextOption((Qt::AlignRight) | (Qt::AlignTop)));
    }

    // draw grid lines
    rect.adjust(y_axe_width + 4, 0, 0, 0);

    QPen grid_pen;
    grid_pen.setStyle(Qt::DashLine);
    grid_pen.setWidthF(1);
    grid_pen.setColor(QColor(128, 128, 128, 128));
    painter.setPen(grid_pen);

    painter.drawLine(full_rect.left(), rect.top(), rect.right(), rect.top());
    painter.drawLine(full_rect.left(), rect.top() + 0.25 * rect.height(), rect.right(), rect.top() + 0.25 * rect.height());
    painter.drawLine(full_rect.left(), rect.top() + 0.50 * rect.height(), rect.right(), rect.top() + 0.50 * rect.height());
    painter.drawLine(full_rect.left(), rect.top() + 0.75 * rect.height(), rect.right(), rect.top() + 0.75 * rect.height());
    painter.drawLine(full_rect.left(), rect.bottom(), rect.right(), rect.bottom());

    painter.drawLine(rect.left(), full_rect.top(), rect.left(), full_rect.bottom());
    painter.drawLine(rect.left() + 0.2 * rect.width(), full_rect.top(), rect.left() + 0.2 * rect.width(), full_rect.bottom());
    painter.drawLine(rect.left() + 0.4 * rect.width(), full_rect.top(), rect.left() + 0.4 * rect.width(), full_rect.bottom());
    painter.drawLine(rect.left() + 0.6 * rect.width(), full_rect.top(), rect.left() + 0.6 * rect.width(), full_rect.bottom());
    painter.drawLine(rect.left() + 0.8 * rect.width(), full_rect.top(), rect.left() + 0.8 * rect.width(), full_rect.bottom());

    // Set antialiasing for graphs
    painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing);

    // draw graphs
    rect.adjust(3, 0, 0, 0); // Need, else graphs cross left gridline

    double y_multiplier = rect.height() / max_y;
    double x_tick_size = double(rect.width()) / m_viewablePointsCount;

    for (QMap<GraphID, QQueue<double> >::const_iterator it = m_yData.begin(); it != m_yData.end(); ++it) {

        if (!m_properties[it.key()].m_enable)
            continue;

        QQueue<double> &queue = m_yData[it.key()];
        QVector<QPointF> points;

        for (int i = queue.size() - 1, j = 0; i >= 0 && j <= m_viewablePointsCount; --i, ++j) {
            points.push_back(QPointF(rect.right() - j * x_tick_size,
                                    rect.bottom() - queue.at(i) * y_multiplier));
        }

        painter.setPen(m_properties[it.key()].m_pen);
        painter.drawPolyline(points.data(), points.size());
    }

    // draw legend
    QPoint legend_top_left(rect.left() + 4, full_rect.top() + 4);

    double legend_height = 0;
    int legend_width = 0;
    for (QMap<GraphID, GraphProperties>::const_iterator it = m_properties.begin(); it != m_properties.end(); ++it) {

        if (!it.value().m_enable)
            continue;

        if (font_metrics.width(it.value().m_name) > legend_width)
            legend_width =  font_metrics.width(it.value().m_name);
        legend_height += 1.5 * font_metrics.height();
    }

    QRectF legend_background_rect(legend_top_left, QSizeF(legend_width, legend_height));
    painter.fillRect(legend_background_rect, QColor(255, 255, 255, 128)); // 50% transparent

    int i = 0;
    for (QMap<GraphID, GraphProperties>::const_iterator it = m_properties.begin(); it != m_properties.end(); ++it) {

        if (!it.value().m_enable)
            continue;

        int name_size = font_metrics.width(it.value().m_name);
        double indent = 1.5 * i * font_metrics.height();

        painter.setPen(it.value().m_pen);
        painter.drawLine(legend_top_left + QPointF(0, indent + font_metrics.height()),
                         legend_top_left + QPointF(name_size, indent + font_metrics.height()));
        painter.drawText(QRectF(legend_top_left + QPointF(0, indent), QSizeF(2 * name_size, font_metrics.height())),
                         it.value().m_name, QTextOption(Qt::AlignVCenter));
        ++i;
    }
}
示例#8
0
LLSpinCtrl::LLSpinCtrl(	const std::string& name, const LLRect& rect, const std::string& label, const LLFontGL* font,
	void (*commit_callback)(LLUICtrl*, void*),
	void* callback_user_data,
	F32 initial_value, F32 min_value, F32 max_value, F32 increment,
	const std::string& control_name,
	S32 label_width)
	:
	LLUICtrl(name, rect, TRUE, commit_callback, callback_user_data, FOLLOWS_LEFT | FOLLOWS_TOP ),
	mValue( initial_value ),
	mInitialValue( initial_value ),
	mMaxValue( max_value ),
	mMinValue( min_value ),
	mIncrement( increment ),
	mPrecision( 3 ),
	mLabelBox( NULL ),
	mTextEnabledColor( LLUI::sColorsGroup->getColor( "LabelTextColor" ) ),
	mTextDisabledColor( LLUI::sColorsGroup->getColor( "LabelDisabledColor" ) ),
	mbHasBeenSet( FALSE )
{
	S32 top = getRect().getHeight();
	S32 bottom = top - 2 * SPINCTRL_BTN_HEIGHT;
	S32 centered_top = top;
	S32 centered_bottom = bottom;
	S32 btn_left = 0;

	// Label
	if( !label.empty() )
	{
		LLRect label_rect( 0, centered_top, label_width, centered_bottom );
		mLabelBox = new LLTextBox( std::string("SpinCtrl Label"), label_rect, label, font );
		addChild(mLabelBox);

		btn_left += label_rect.mRight + SPINCTRL_SPACING;
	}

	S32 btn_right = btn_left + SPINCTRL_BTN_WIDTH;
	
	// Spin buttons
	LLRect up_rect( btn_left, top, btn_right, top - SPINCTRL_BTN_HEIGHT );
	std::string out_id = "UIImgBtnSpinUpOutUUID";
	std::string in_id = "UIImgBtnSpinUpInUUID";
	mUpBtn = new LLButton(std::string("SpinCtrl Up"), up_rect,
								   out_id,
								   in_id,
								   LLStringUtil::null,
								   &LLSpinCtrl::onUpBtn, this, LLFontGL::getFontSansSerif() );
	mUpBtn->setFollowsLeft();
	mUpBtn->setFollowsBottom();
	mUpBtn->setHeldDownCallback( &LLSpinCtrl::onUpBtn );
	mUpBtn->setTabStop(FALSE);
	addChild(mUpBtn);

	LLRect down_rect( btn_left, top - SPINCTRL_BTN_HEIGHT, btn_right, bottom );
	out_id = "UIImgBtnSpinDownOutUUID";
	in_id = "UIImgBtnSpinDownInUUID";
	mDownBtn = new LLButton(std::string("SpinCtrl Down"), down_rect,
							out_id,
							in_id,
							LLStringUtil::null,
							&LLSpinCtrl::onDownBtn, this, LLFontGL::getFontSansSerif() );
	mDownBtn->setFollowsLeft();
	mDownBtn->setFollowsBottom();
	mDownBtn->setHeldDownCallback( &LLSpinCtrl::onDownBtn );
	mDownBtn->setTabStop(FALSE);
	addChild(mDownBtn);

	LLRect editor_rect( btn_right + 1, centered_top, getRect().getWidth(), centered_bottom );
	mEditor = new LLLineEditor( std::string("SpinCtrl Editor"), editor_rect, LLStringUtil::null, font,
								MAX_STRING_LENGTH,
								&LLSpinCtrl::onEditorCommit, NULL, NULL, this,
								&LLLineEditor::prevalidateFloat );
	mEditor->setFollowsLeft();
	mEditor->setFollowsBottom();
	mEditor->setFocusReceivedCallback( &LLSpinCtrl::onEditorGainFocus, this );
	//RN: this seems to be a BAD IDEA, as it makes the editor behavior different when it has focus
	// than when it doesn't.  Instead, if you always have to double click to select all the text, 
	// it's easier to understand
	//mEditor->setSelectAllonFocusReceived(TRUE);
	mEditor->setIgnoreTab(TRUE);
	addChild(mEditor);

	updateEditor();
	setUseBoundingRect( TRUE );
}
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();
}
LLSliderCtrl::LLSliderCtrl(const LLSliderCtrl::Params& p)
:	LLF32UICtrl(p),
	mLabelBox( NULL ),
	mEditor( NULL ),
	mTextBox( NULL ),
	mFont(p.font),
	mShowText(p.show_text),
	mCanEditText(p.can_edit_text),
	mPrecision(p.decimal_digits),
	mTextEnabledColor(p.text_color()),
	mTextDisabledColor(p.text_disabled_color())
{
	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.isProvided())
		{
			label_width = p.font()->getWidth(p.label);
		}
		LLRect label_rect( left, top, label_width, bottom );
		LLTextBox::Params params(p.slider_label);
		params.rect.setIfNotProvided(label_rect);
		params.font.setIfNotProvided(p.font);
		params.initial_value(p.label());
		mLabelBox = LLUICtrlFactory::create<LLTextBox> (params);
		addChild(mLabelBox);
	}

	if (p.show_text && !p.text_width.isProvided())
	{
		// 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;
	static LLUICachedControl<S32> sliderctrl_spacing ("UISliderctrlSpacing", 0);

	S32 slider_right = getRect().getWidth();
	if( p.show_text )
	{
		slider_right = text_left - sliderctrl_spacing;
	}

	S32 slider_left = label_width ? label_width + sliderctrl_spacing : 0;
	LLSlider::Params slider_p(p.slider_bar);
	slider_p.name("slider_bar");
	slider_p.rect.setIfNotProvided(LLRect(slider_left,top,slider_right,bottom));
	slider_p.initial_value.setIfNotProvided(p.initial_value().asReal());
	slider_p.min_value.setIfNotProvided(p.min_value);
	slider_p.max_value.setIfNotProvided(p.max_value);
	slider_p.increment.setIfNotProvided(p.increment);
	slider_p.orientation.setIfNotProvided(p.orientation);
	
	slider_p.commit_callback.function(&LLSliderCtrl::onSliderCommit);
	slider_p.control_name(p.control_name);
	slider_p.mouse_down_callback( p.mouse_down_callback );
	slider_p.mouse_up_callback( p.mouse_up_callback );
	mSlider = LLUICtrlFactory::create<LLSlider> (slider_p);

	addChild( mSlider );
	
	if( p.show_text() )
	{
		LLRect text_rect( text_left, top, getRect().getWidth(), bottom );
		if( p.can_edit_text() )
		{
			LLLineEditor::Params line_p(p.value_editor);
			line_p.rect.setIfNotProvided(text_rect);
			line_p.font.setIfNotProvided(p.font);
			line_p.commit_callback.function(&LLSliderCtrl::onEditorCommit);
			line_p.prevalidate_callback(&LLTextValidate::validateFloat);
			mEditor = LLUICtrlFactory::create<LLLineEditor>(line_p);

			mEditor->setFocusReceivedCallback( boost::bind(&LLSliderCtrl::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 text_p(p.value_text);
			text_p.rect.setIfNotProvided(text_rect);
			text_p.font.setIfNotProvided(p.font);
			mTextBox = LLUICtrlFactory::create<LLTextBox>(text_p);
			addChild(mTextBox);
		}
	}

	updateText();
}
示例#11
0
void wxRibbonAUIArtProvider::DrawPanelBackground(
                        wxDC& dc,
                        wxRibbonPanel* wnd,
                        const wxRect& rect)
{
    dc.SetPen(*wxTRANSPARENT_PEN);
    dc.SetBrush(m_background_brush);
    dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);

    wxRect true_rect(rect);
    RemovePanelPadding(&true_rect);

    dc.SetPen(m_panel_border_pen);
    dc.SetBrush(*wxTRANSPARENT_BRUSH);
    dc.DrawRectangle(true_rect.x, true_rect.y, true_rect.width, true_rect.height);

    true_rect.x++;
    true_rect.width -= 2;
    true_rect.y++;

    dc.SetFont(m_panel_label_font);
    wxSize label_size = dc.GetTextExtent(wnd->GetLabel());
    int label_height = label_size.GetHeight() + 5;
    wxRect label_rect(true_rect);
    label_rect.height = label_height - 1;
    dc.DrawLine(label_rect.x, label_rect.y + label_rect.height,
        label_rect.x + label_rect.width, label_rect.y + label_rect.height);

    wxColour label_bg_colour = m_panel_label_background_colour;
    wxColour label_bg_grad_colour = m_panel_label_background_gradient_colour;
    if(wnd->IsHovered())
    {
        label_bg_colour = m_panel_hover_label_background_colour;
        label_bg_grad_colour = m_panel_hover_label_background_gradient_colour;
        dc.SetTextForeground(m_panel_hover_label_colour);
    }
    else
    {
        dc.SetTextForeground(m_panel_label_colour);
    }
    dc.GradientFillLinear(label_rect,
#ifdef __WXMAC__
        label_bg_grad_colour, label_bg_colour, wxSOUTH);
#else
        label_bg_colour, label_bg_grad_colour, wxSOUTH);
#endif
    dc.SetFont(m_panel_label_font);
    dc.DrawText(wnd->GetLabel(), label_rect.x + 3, label_rect.y + 2);

    if(wnd->IsHovered())
    {
        wxRect gradient_rect(true_rect);
        gradient_rect.y += label_rect.height + 1;
        gradient_rect.height = true_rect.height - label_rect.height - 3;
#ifdef __WXMAC__
        wxColour colour = m_page_hover_background_gradient_colour;
        wxColour gradient = m_page_hover_background_colour;
#else
        wxColour colour = m_page_hover_background_colour;
        wxColour gradient = m_page_hover_background_gradient_colour;
#endif
        dc.GradientFillLinear(gradient_rect, colour, gradient, wxSOUTH);
    }

    if(wnd->HasExtButton())
    {
        if(wnd->IsExtButtonHovered())
        {
            dc.SetPen(m_panel_hover_button_border_pen);
            dc.SetBrush(m_panel_hover_button_background_brush);
            dc.DrawRoundedRectangle(label_rect.GetRight() - 13, label_rect.GetBottom() - 13, 13, 13, 1.0);
            dc.DrawBitmap(m_panel_extension_bitmap[1], label_rect.GetRight() - 10, label_rect.GetBottom() - 10, true);
        }
        else
            dc.DrawBitmap(m_panel_extension_bitmap[0], label_rect.GetRight() - 10, label_rect.GetBottom() - 10, true);
    }
}
示例#12
0
void wxRibbonMetroArtProvider::DrawPanelBackground(
                        wxDC& dc,
                        wxRibbonPanel* wnd,
                        const wxRect& rect)
{
    DrawPartialPageBackground(dc, wnd, rect, false);

    wxRect true_rect(rect);
    RemovePanelPadding(&true_rect);
    bool has_ext_button = wnd->HasExtButton();

	// draw panel label
    {
		// int label_height;
        dc.SetFont(m_panel_label_font);
        dc.SetPen(*wxTRANSPARENT_PEN);
		dc.SetBrush(*wxTRANSPARENT_BRUSH);
        dc.SetTextForeground(m_panel_label_colour);

        wxRect label_rect(true_rect);
        wxString label = wnd->GetLabel();
        bool clip_label = false;
        wxSize label_size(dc.GetTextExtent(label));

        label_rect.SetX(label_rect.GetX() + 1);
        label_rect.SetWidth(label_rect.GetWidth() - 2);
        label_rect.SetHeight(label_size.GetHeight() + 2);
        label_rect.SetY(true_rect.GetBottom() - label_rect.GetHeight());
        // label_height = label_rect.GetHeight();

        wxRect label_bg_rect = label_rect;

        if(has_ext_button)
            label_rect.SetWidth(label_rect.GetWidth() - 13);

        if(label_size.GetWidth() > label_rect.GetWidth())
        {
            // Test if there is enough length for 3 letters and ...
            wxString new_label = label.Mid(0, 3) + wxT("...");
            label_size = dc.GetTextExtent(new_label);
            if(label_size.GetWidth() > label_rect.GetWidth())
            {
                // Not enough room for three characters and ...
                // Display the entire label and just crop it
                clip_label = true;
            }
            else
            {
                // Room for some characters and ...
                // Display as many characters as possible and append ...
                for(size_t len = label.Len() - 1; len >= 3; --len)
                {
                    new_label = label.Mid(0, len) + wxT("...");
                    label_size = dc.GetTextExtent(new_label);
                    if(label_size.GetWidth() <= label_rect.GetWidth())
                    {
                        label = new_label;
                        break;
                    }
                }
            }
        }

        dc.DrawRectangle(label_bg_rect);
        if(clip_label)
        {
            wxDCClipper clip(dc, label_rect);
            dc.DrawText(label, label_rect.x, label_rect.y +
                (label_rect.GetHeight() - label_size.GetHeight()) / 2);
        }
        else
        {
            dc.DrawText(label, label_rect.x +
                (label_rect.GetWidth() - label_size.GetWidth()) / 2,
                label_rect.y +
                (label_rect.GetHeight() - label_size.GetHeight()) / 2);
        }

        if(has_ext_button)
        {
            if(wnd->IsExtButtonHovered())
            {
                dc.SetPen(m_panel_hover_button_border_pen);
                dc.SetBrush(m_panel_hover_button_background_brush);
                dc.DrawRectangle(label_rect.GetRight(), label_rect.GetBottom() - 14, 14, 14);
                dc.DrawBitmap(m_panel_extension_bitmap[1], label_rect.GetRight() + 3, label_rect.GetBottom() - 10, true);
            }
            else
                dc.DrawBitmap(m_panel_extension_bitmap[0], label_rect.GetRight() + 3, label_rect.GetBottom() - 10, true);
        }
    }
	
	if (wnd->GetParent()->IsKindOf(CLASSINFO(wxFrame))) // expanded panels are in their own wxFrame otherwise normal panel
	{	
		wxRect shadow(rect);
		shadow.x +=4;
		shadow.y +=4;
		dc.SetPen(*wxRED);
		dc.DrawLine(shadow.GetBottomLeft(), shadow.GetBottomRight());
		dc.DrawLine(shadow.GetTopRight(), shadow.GetBottomRight());
		dc.SetBrush(*wxTRANSPARENT_BRUSH);
		dc.SetPen(m_panel_border_pen);
		dc.DrawRoundedRectangle(rect, 1.0);
	}
	else
		DrawPanelBorder(dc, true_rect, m_panel_border_pen, m_panel_border_gradient_pen);
}