Пример #1
0
static void
calc_node_type(cairo_t *cr, designer_node_type_t *nt)
{
    node_type_data_t *ntd = node_type_data(nt);
    _rect_t br, ir, or, sr;

    ntd->is = g_slist_length(nt->input_slot_specs);
    ntd->os = g_slist_length(nt->output_slot_specs);

    set_slot_font(cr);
    sr = text_rect(cr, "Mg");
    /* add sep space */
    sr.s.h += 3;

    ir = _rect(0, 0, 10, 0);
    for (int i=0; i<ntd->is; i++) {
	designer_slot_spec_t *slot =
	    g_slist_nth_data(nt->input_slot_specs, i);
	slot_spec_data_t *ssd = slot_spec_data(slot);
	
	ssd->offset = _size(3, 5 + sr.s.h * i);
	ir = _union(ir, text_rect(cr, slot->name));
    }
    /* offset left */
    ir = _offset(ir, _size(0, 5));
    /* add slot and sep space */
    ir.s.w += 5+5;
    /* height including sep space */
    ir.s.h = ntd->is * sr.s.h - 3;

    or = _rect(0, 0, 10, 0);
    for (int i=0; i<ntd->os; i++) {
	designer_slot_spec_t *slot =
	    g_slist_nth_data(nt->output_slot_specs, i);
	slot_spec_data_t *ssd = slot_spec_data(slot);
	
	ssd->offset = _size(3, 5 + sr.s.h * i);
	or = _union(or, text_rect(cr, slot->name));
    }
    /* move right, including sep space */
    or = _offset(or, _size(ir.s.w + 5, 5));
    /* add slot and sep space */
    or.s.w += 5+5;
    /* height including sep space */
    or.s.h = ntd->os * sr.s.h - 3;

    br = _union(ir, or);
    /* reserve space around area */
    br = _inset(br, _size(-5, -5));

    ntd->br = br;
    ntd->ir = _splith(&ir, 6);
    _splith(&or, or.s.w - 6);
    ntd->or = or;
    ntd->sr = sr;
}
Пример #2
0
void
Menu::draw(DrawingContext& context)
{
  if (!items[active_item]->help.empty())
  {
    int text_width  = (int) Resources::normal_font->get_text_width(items[active_item]->help);
    int text_height = (int) Resources::normal_font->get_text_height(items[active_item]->help);

    Rectf text_rect(pos.x - text_width/2 - 8,
                   SCREEN_HEIGHT - 48 - text_height/2 - 4,
                   pos.x + text_width/2 + 8,
                   SCREEN_HEIGHT - 48 + text_height/2 + 4);

    context.draw_filled_rect(Rectf(text_rect.p1 - Vector(4,4),
                                   text_rect.p2 + Vector(4,4)),
                             Color(0.2f, 0.3f, 0.4f, 0.8f),
                             16.0f,
                             LAYER_GUI-10);

    context.draw_filled_rect(text_rect,
                             Color(0.6f, 0.7f, 0.8f, 0.5f),
                             16.0f,
                             LAYER_GUI-10);

    context.draw_text(Resources::normal_font, items[active_item]->help,
                      Vector(pos.x, SCREEN_HEIGHT - 48 - text_height/2),
                      ALIGN_CENTER, LAYER_GUI);
  }

  for(unsigned int i = 0; i < items.size(); ++i)
  {
    draw_item(context, i);
  }
}
Пример #3
0
void	UIButton::DrawText()
{
	if (!config_.button_text_.empty())
	{
		UIColor color = config_.text_normal_color_;
		if (button_status_ == kUIButtonStatusHover || 
			button_status_ == kUIButtonStatusPressed)
		{
			color = config_.text_focus_color_;
		}
		else if(button_status_ == kUIButtonStatusDisable)
		{
			color = config_.text_disable_color_;
		}
		UIPoint &offset = config_.text_offset_;
		int width = frame_.GetWidth();
		int height= frame_.GetHeight();
		int x = frame_.GetX() + offset.x;
		int y = frame_.GetY() + offset.y;
		UIRect text_rect(x,y,width,height);

		std::wstring &button_text = config_.button_text_;
		UICanvas *canvas = CurrentCanvas();
		canvas->DrawText(button_text.c_str(),button_text.length(),&text_rect,color,
			config_.text_alignment_ | DT_VCENTER | DT_SINGLELINE,&config_.font_);
		
	}
}
Пример #4
0
void
Menu::draw(DrawingContext& context)
{
  if (!items[active_item]->help.empty())
  {
    int text_width  = static_cast<int>(Resources::normal_font->get_text_width(items[active_item]->help));
    int text_height = static_cast<int>(Resources::normal_font->get_text_height(items[active_item]->help));

    Rectf text_rect(pos.x - static_cast<float>(text_width) / 2.0f - 8.0f,
                    static_cast<float>(SCREEN_HEIGHT) - 48.0f - static_cast<float>(text_height) / 2.0f - 4.0f,
                    pos.x + static_cast<float>(text_width) / 2.0f + 8.0f,
                    static_cast<float>(SCREEN_HEIGHT) - 48.0f + static_cast<float>(text_height) / 2.0f + 4.0f);

    context.color().draw_filled_rect(Rectf(text_rect.p1 - Vector(4,4),
                                             text_rect.p2 + Vector(4,4)),
                                       Color(0.2f, 0.3f, 0.4f, 0.8f),
                                       16.0f,
                                       LAYER_GUI-10);

    context.color().draw_filled_rect(text_rect,
                                       Color(0.6f, 0.7f, 0.8f, 0.5f),
                                       16.0f,
                                       LAYER_GUI-10);

    context.color().draw_text(Resources::normal_font, items[active_item]->help,
                              Vector(pos.x, static_cast<float>(SCREEN_HEIGHT) - 48.0f - static_cast<float>(text_height) / 2.0f),
                              ALIGN_CENTER, LAYER_GUI);
  }

  for(unsigned int i = 0; i < items.size(); ++i)
  {
    draw_item(context, i);
  }
}
void NumberButtonDelegate::paint(QPainter *painter,
                                      const QStyleOptionViewItem &option,
                                      const QModelIndex &index) const
{
    if (index.data().isNull() || index.data().toString().isEmpty()) {
        ItemDelegate::paint(painter, option, index);
        return;
    }

    if(option.state & QStyle::State_MouseOver) {
        painter->save();
        QPainterPath path;
        QRect button_rect = this->contentsRect(option.rect);
        path.addRoundedRect(button_rect, 8, 8);
        if (this->pressed) {
            painter->fillPath(path, Qt::black);
        } else {
            painter->fillPath(path, QColor("#58524F"));
        }

        QString text = tr("CALL");
        QRect text_rect(button_rect);
        text_rect.translate(16, 0);
        painter->setPen(QColor("white"));
        painter->drawText(text_rect, Qt::AlignVCenter, text);

        painter->restore();

        ItemDelegate::drawBorder(painter, option);
        return;
    }

    ItemDelegate::paint(painter, option, index);
}
Пример #6
0
static void
calc_node(cairo_t *cr, designer_node_t *n)
{
    node_data_t *nd = node_data(n);
    node_type_data_t *ntd = node_type_data(n->type);
    _rect_t nr, lr, tr, ir, or, br, xr;

    set_title_font(cr);
    lr = text_rect(cr, n->name);

    tr = _inset(lr, _size(-5, -5));
    tr.s.w += 20; /* button space */

    br = ntd->br;

    /* move into place */
    br.o.y = tr.o.y + tr.s.h;
    nr = _union(tr, br);

    /* break down areas once again */
    br = nr; tr = _splitv(&br, tr.s.h);

    /* split off close button */
    xr = tr; _splith(&xr, tr.s.w - 16);
    xr = _splitv(&xr, 16);
    xr = _inset(xr, _size(4, 4));

    ir = ntd->ir;
    /* align inputs to the left */
    ir.o = _move(br.o, _size(5, 5));

    or = ntd->or;
    /* align outputs to the right */
    or.o = _move(br.o, _size(br.s.w - or.s.w - 5, 5));

    nd->nr = nr;
    nd->lr = lr;
    nd->tr = tr;
    nd->br = br;
    nd->ir = ir;
    nd->or = or;
    nd->xr = xr;
}
Пример #7
0
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);
	}
}
Пример #8
0
void QueuedItemDelegate::DrawBox(
    QPainter* painter, const QRect& line_rect, const QFont& font,
    const QString& text, int width) const {
  QFont smaller = font;
  smaller.setPointSize(smaller.pointSize() - 1);
  smaller.setBold(true);

  if (width == -1)
    width = QFontMetrics(font).width(text + "  ");

  QRect rect(line_rect);
  rect.setLeft(rect.right() - width - kQueueBoxBorder);
  rect.setWidth(width);
  rect.setTop(rect.top() + kQueueBoxBorder);
  rect.setBottom(rect.bottom() - kQueueBoxBorder - 1);

  QRect text_rect(rect);
  text_rect.setBottom(text_rect.bottom() + 1);

  QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
  gradient.setColorAt(0.0, kQueueBoxGradientColor1);
  gradient.setColorAt(1.0, kQueueBoxGradientColor2);

  // Turn on antialiasing
  painter->setRenderHint(QPainter::Antialiasing);

  // Draw the box
  painter->translate(0.5, 0.5);
  painter->setPen(QPen(Qt::white, 1));
  painter->setBrush(gradient);
  painter->drawRoundedRect(rect, kQueueBoxCornerRadius, kQueueBoxCornerRadius);

  // Draw the text
  painter->setFont(smaller);
  painter->drawText(rect.translated(-1, -1), Qt::AlignCenter, text);
  painter->translate(-0.5, -0.5);
}
Пример #9
0
void CTip::Show(CPoint point, LPCTSTR lpszTitleText)
{
    if (!IsWindow(m_hWnd))
        Create(m_pParentWnd);

	ASSERT( ::IsWindow( GetSafeHwnd() ) );

	CClientDC dc(this);

	
	CFont *pOld = dc.SelectObject(m_pParentWnd->GetFont());
	
	CSize size = GetTextSize(lpszTitleText, &dc);
	int offset = dc.GetTextExtent(_T(" ")).cx;

	CRect rectDisplay;
	rectDisplay.left = point.x;
	rectDisplay.right = point.x + size.cx + offset * 2 + 2;
	rectDisplay.top = point.y - (size.cy + 2);
	rectDisplay.bottom = point.y;
	
	// Show the titletip
    SetWindowPos( &wndTop, rectDisplay.left, rectDisplay.top, 
        rectDisplay.Width(), rectDisplay.Height(), 
        SWP_SHOWWINDOW|SWP_NOACTIVATE );
	dc.SetBkMode( TRANSPARENT );

	CRect client_rect;
	GetClientRect(&client_rect);
	FillRect(dc.GetSafeHdc(), &client_rect, (HBRUSH)(COLOR_INFOBK +1));

	CRect text_rect(offset, 0, size.cx+offset, size.cy);
	dc.DrawText(lpszTitleText, &text_rect, DT_LEFT|DT_TOP);

	dc.SelectObject(pOld);
}
Пример #10
0
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();
}
Пример #11
0
void GUIPauseMenu::regenerateGui(v2u32 screensize)
{
	/*
		Remove stuff
	*/
	removeChildren();
	
	/*
		Calculate new sizes and positions
	*/
    core::rect<s32> rect(
                         screensize.X/2 - screensize.X * 0.4,
                         screensize.Y/2 - screensize.Y * 0.3,
                         screensize.X/2 + screensize.X * 0.4,
                         screensize.Y/2 + screensize.Y * 0.3
                         );
	
	DesiredRect = rect;
	recalculateAbsolutePosition(false);

	v2s32 size = rect.getSize();

	/*
		Add stuff
	*/
	const s32 btn_height = size.Y * 0.1;
    const s32 btn_width  = size.X * 0.3;
	const s32 btn_gap = size.Y * 0.05;
	const s32 btn_num = m_simple_singleplayer_mode ? 4 : 5;
	s32 btn_y = size.Y/2-((btn_num*btn_height+(btn_num-1)*btn_gap))/2 +btn_height;
	
	{
		core::rect<s32> rect(0, 0, btn_width, btn_height);
		rect = rect + v2s32(size.X/2-btn_width/2, btn_y);
		
		Environment->addButton(rect, this, 256,
			_("Continue"));
		
	}
	btn_y += btn_height + btn_gap;
	if(!m_simple_singleplayer_mode)
	{
		{
			core::rect<s32> rect(0, 0, btn_width, btn_height);
			rect = rect + v2s32(size.X/2-btn_width/2, btn_y);
			
			Environment->addButton(rect, this, 261,
				_("Change Password"));
			
		}
		btn_y += btn_height + btn_gap;
	}
	{
		core::rect<s32> rect(0, 0, btn_width, btn_height);
		rect = rect + v2s32(size.X/2-btn_width/2, btn_y);
		
		Environment->addButton(rect, this, 262,
			_("Settings"));
		
	}
	btn_y += btn_height + btn_gap;
	{
		core::rect<s32> rect(0, 0, btn_width, btn_height);
		rect = rect + v2s32(size.X/2-btn_width/2, btn_y);
		
		Environment->addButton(rect, this, 260,
			_("Exit to Menu"));
	}
	btn_y += btn_height + btn_gap;

    if (menudata.simple_singleplayer_mode)
    {
        std::string text = ("Server IP/Port: ");
        text += g_settings->get("local_server_ip");
        text += ":";
        text += g_settings->get("local_server_port");
    
        int width = Environment->getSkin()->getFont()->getDimension(_(text.c_str())).Width;
        int x = (rect.getWidth()-width)/2;
        int y = rect.getHeight() * 0.02;
        core::rect<s32> text_rect(x, y, x + width, y + g_the_font_height * 1.2);
        Environment->addStaticText( _(text.c_str()), text_rect, false,
                               true, this,100);
    }
	
}
Пример #12
0
static void 
draw_node(cairo_t *cr, designer_node_t *n, int flags)
{
    designer_node_type_t *nt = n->type;
    node_type_data_t *ntd = node_type_data(nt);
    node_data_t *nd = node_data(n);

    _point_t pos = nd->origin;

    cairo_save(cr);
    cairo_translate(cr, pos.x, pos.y);

    /* drop shadow */
    cairo_set_source_rgba(cr, RGBA_DROP_SHADOW);
    round_path(cr, _offset(nd->nr, _size(3, 3)), round_s);
    cairo_fill(cr);

    /* title area color */
    cairo_set_source_rgba(cr, RGBA_TITLE_AREA);
    round_path(cr, nd->tr, upper_s);
    cairo_fill(cr);

    /* title text */
    set_title_font(cr);
    cairo_set_source_rgba(cr, RGBA_TITLE_TEXT);
    cairo_move_to(cr, nd->lr.o.x - 1, 
	nd->lr.o.y + nd->lr.s.h - 1);
    cairo_show_text(cr, n->name);

    /* close button */
    cairo_set_line_width(cr, 1.0);
    rect_path(cr, nd->xr);
    cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.8);
    cairo_fill_preserve(cr);
    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.5);
    cairo_stroke(cr);
    cross_path(cr, nd->xr, 2);
    cairo_stroke(cr);

    /* body area color */
    cairo_set_source_rgba(cr, RGBA_BODY_AREA);
    round_path(cr, nd->br, lower_s);
    cairo_fill(cr);

#if 0
    /* slot border */
    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.3);
    cairo_set_line_width(cr, 1.0);
    rect_path(cr, nd->ir);
    cairo_stroke(cr);
    rect_path(cr, nd->or);
    cairo_stroke(cr);
#endif

    /* prepare for slots */
    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.6);
    cairo_set_line_width(cr, 1.0);
    set_slot_font(cr);

    /* input slots */
    for (int i=0; i<ntd->is; i++) {
	designer_slot_spec_t *slot =
	    g_slist_nth_data(nt->input_slot_specs, i);
	slot_spec_data_t *ssd = slot_spec_data(slot);
	_point_t sl = _move(nd->ir.o, ssd->offset);
	
	cairo_move_to(cr, sl.x + 6, sl.y + 3);
	cairo_show_text(cr, slot->name);
	cairo_stroke(cr);
	circle_path(cr, sl, 3.0);
	cairo_stroke(cr);
    }

    for (int i=0; i<ntd->os; i++) {
	designer_slot_spec_t *slot =
	    g_slist_nth_data(nt->output_slot_specs, i);
	slot_spec_data_t *ssd = slot_spec_data(slot);
	_rect_t sr = text_rect(cr, slot->name);
	_point_t sl = _move(nd->or.o, ssd->offset);

	cairo_move_to(cr, sl.x - sr.s.w - 8, sl.y + 3);
	cairo_show_text(cr, slot->name);
	cairo_stroke(cr);
	circle_path(cr, sl, 3.0);
	cairo_stroke(cr);
    }
    /* filter border */
    cairo_set_line_width(cr, 1.0);
    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.8);
    round_path(cr, nd->nr, round_s);
    cairo_stroke(cr);

    cairo_move_to(cr, nd->br.o.x, nd->br.o.y);
    cairo_line_to(cr, nd->br.o.x + nd->br.s.w, nd->br.o.y);
    cairo_stroke(cr);

    /* root node? */
    if (flags & 0x1) {
	cairo_set_line_width(cr, 2.0);
	cairo_set_source_rgba(cr, RGBA_ROOT_NODE);
	// cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
	// cairo_set_dash(cr, round_d, 2, 0);
	round_path(cr, _inset(nd->nr, _size(-3,-3)), rnd13_s);
	cairo_stroke(cr);
    }


/*
    rect_path(cr, nd->ir);
    cairo_stroke(cr);
    rect_path(cr, nd->or);
    cairo_stroke(cr); */

    cairo_restore(cr);
}
Пример #13
0
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();
}
Пример #14
0
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();
}
Пример #15
0
void GameWidget::paintEvent(QPaintEvent* /*event*/)
{
    QPainter painter(this);
    painter.fillRect(0, 0, width(), height(), QBrush(Qt::black));
    painter.translate(xoff, yoff);

    painter.setPen(QPen(Qt::black));
    QFont font("Courier");
    font.setPixelSize(20);
    font.setBold(true);
    painter.setFont(font);

    //draw bubbles
    for(int i = 0; i < grid_size; i++) {
        for(int j = 0; j < grid_size; j++) {
            if(!grid[i][j].color) //empty
                continue;

            QRectF target(
                (i-grid[i][j].xoffset) * (bubblesize+margin) + margin,
                (j-grid[i][j].yoffset) * (bubblesize+margin) + margin,
                bubblesize, bubblesize);
            QRectF source(0, 0, bubblesize, bubblesize);
            painter.drawPixmap(target, bubblePixmap[grid[i][j].color][grid[i][j].scale_step], source);
        }
    }


    //show current score
    painter.translate(-xoff, -yoff);
    painter.setBrush(QBrush(QColor(255, 255, 255, 160)));
    QRect score_rect = QRect(-5, -12, 150, 37);

    painter.drawRoundedRect(score_rect, 5, 5);
    painter.drawText(score_rect, Qt::AlignHCenter | Qt::AlignBottom, tr("Score: %1").arg(score));


    //draw selection (if there is one)
    if(selection.empty() or selection.size() == 1)
        return;

    painter.translate(xoff, yoff);
    const short color = grid[selection.first().x][selection.first().y].color;
    painter.setPen(QPen(bubbleColor[color], margin/3, Qt::DotLine, Qt::RoundCap));
    QPainterPath path;

    foreach(Box b, selection) {
        if(b.x == 0 || grid[b.x-1][b.y].color != color) {
            QPointF point(b.x*(bubblesize+margin)+qreal(margin)/2, qreal(b.y*(bubblesize+margin)+margin/2));
            path.moveTo(point);
            point.ry() += bubblesize+margin;
            path.lineTo(point);

        }
        if(b.x == grid_size-1 || grid[b.x+1][b.y].color != color) {
            QPointF point(b.x*(bubblesize+margin)+qreal(margin)*3/2+bubblesize, b.y*(bubblesize+margin)+qreal(margin)/2);
            path.moveTo(point);
            point.ry() += bubblesize+margin;
            path.lineTo(point);
        }
        if(b.y == 0 || grid[b.x][b.y-1].color != color) {
            QPointF point(qreal(b.x*(bubblesize+margin)+margin/2), qreal(b.y*(bubblesize+margin)+margin/2));
            path.moveTo(point);
            point.rx() += bubblesize+margin;
            path.lineTo(point);
        }
        if(b.y == grid_size-1 || grid[b.x][b.y+1].color != color) {
            QPointF point(qreal(b.x*(bubblesize+margin)+margin/2), qreal(b.y*(bubblesize+margin)+margin*3/2+bubblesize));
            path.moveTo(point);
            point.rx() += bubblesize+margin;
            path.lineTo(point);
        }
    }
    painter.drawPath(path);


    //show points awarded for removing selected bubbles
    QString points = QString::number(selection.size() * selection.size());
    const int text_width = points.length()*15;

    QColor pen_color = bubbleColor[color];
    painter.setPen(QPen(pen_color));
    painter.setBrush(QBrush(QColor(0, 0, 0, 200)));

    const int bg_width = text_width+6;
    const int bg_height = 26;
    QPoint center = path.boundingRect().center().toPoint();
    QRect text_rect(center.x()-bg_width/2, center.y()-bg_height/2, bg_width, bg_height);
    painter.drawRoundedRect(text_rect, 4, 4);

    if(pen_color == Qt::blue) //too dark for text
        pen_color = pen_color.lighter(150);
    painter.setPen(QPen(pen_color));
    painter.drawText(text_rect, Qt::AlignCenter, points);
}
void DataViewTable::paintCell(QPainter* painter, int row, int col,
                              const QRect& cr, bool selected, const QColorGroup& cg) {
  if (selector_ == NULL || row < 0 || col < 0)
    return;

  QRect rect(0, 0, cr.width(), cr.height());
  if (selected) {
    painter->fillRect(rect, cg.highlight());
    painter->setPen(cg.highlightedText());
  } else {
    if (row % 2) {
      painter->fillRect(rect, cg.base());
    } else {
      painter->fillRect(rect, cg.background().light(135));
    }
    painter->setPen(cg.text());
  }

  const SelectList &flist = selector_->pickList();

  // Check for row out of bounds.
  int max_row_id = flist.size() - 1;
  if (row > max_row_id)
    return;

  // determine if table has optional col for the feature id
  bool show_id = Preferences::getConfig().dataViewShowFID;

  if (show_id && col == 0) {
    painter->drawText(rect, Qt::AlignRight, QString::number(flist[row]));
    return;
  }

  if (!selector_->HasAttrib()) {
    // we don't have anny attribs, bail now
    return;
  }

  // we don't have to worry about fails attribute fetches since we are anly
  // asking for records that are already in our select list and they cannot
  // get into the select list w/o a valid record.
  gstRecordHandle rec;
  try {
    rec = theSourceManager->GetAttributeOrThrow(
        UniqueFeatureId(selector_->getSourceID(), selector_->layer(),
                        flist[row]));
  } catch (...) {
    // silently ignore. see comment before 'try'
    return;
  }

  int num_fields = static_cast<int>(rec->NumFields());
  // Check for column out of bounds.
  int max_column_id = show_id ? num_fields : num_fields - 1;
  if (col > max_column_id)
    return;

  gstValue* val = rec->Field(show_id ? col - 1 : col);
  int tf = val->IsNumber() ? Qt::AlignRight : Qt::AlignLeft;
  int rowHeight = this->rowHeight(row);
  int colWidth  = this->columnWidth(col);
  QRect bounding_rect = fontMetrics().boundingRect(val->ValueAsUnicode());

  // fontMetrics should account for the font descenders, but it
  // seems to be broken.
  // I accounted for the descenders by adding a margin of 4 around the cell
  // contents to account for errors in the fontMetrics
  // height estimation for font descenders, e.g., the tail of
  // the "y" or "p") . This seems to work for even large fonts and
  // is readable for smaller fonts.
  int added_cell_margin = 4;
  int cellWidth = bounding_rect.width() + added_cell_margin * 2;
  int cellHeight = bounding_rect.height() + added_cell_margin * 2;
  if (cellHeight > rowHeight) {
    setRowHeight(row, cellHeight);
  }
  if (cellWidth > colWidth) {
    setColumnWidth(col, cellWidth);
  }

  // When drawing, we're going to force the horizontal margin here.
  QRect text_rect(added_cell_margin, 0, cr.width() - added_cell_margin, cr.height());

  painter->drawText(text_rect, tf, val->ValueAsUnicode());
}