예제 #1
0
unsigned int TextBox::drawImages(Form* form, const Rectangle& clip)
{
    Control::State state = getState();

    if (_caretImage && (state == ACTIVE || hasFocus()))
    {
        // Draw the cursor at its current location.
        const Rectangle& region = _caretImage->getRegion();
        if (!region.isEmpty())
        {
            const Theme::UVs& uvs = _caretImage->getUVs();
            Vector4 color = _caretImage->getColor();
            color.w *= _opacity;

            float caretWidth = region.width * _fontSize / region.height;

            Font* font = getFont(state);
            unsigned int fontSize = getFontSize(state);
            Vector2 point;
            font->getLocationAtIndex(getDisplayedText().c_str(), _textBounds, fontSize, &point, _caretLocation, 
                 getTextAlignment(state), true, getTextRightToLeft(state));

            SpriteBatch* batch = _style->getTheme()->getSpriteBatch();
            startBatch(form, batch);
            batch->draw(point.x - caretWidth * 0.5f, point.y, caretWidth, fontSize, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color, _viewportClipBounds);
            finishBatch(form, batch);

            return 1;
        }
    }

    return 0;
}
예제 #2
0
void TextBox::setCaretLocation(int x, int y)
{
    // Get index into string and cursor location from the latest touch location.
    _prevCaretLocation.set(_caretLocation);
    _caretLocation.set(x + _absoluteBounds.x,
                       y + _absoluteBounds.y);

    Font* font = getFont(_state);
    unsigned int fontSize = getFontSize(_state);
    Font::Justify textAlignment = getTextAlignment(_state);
    bool rightToLeft = getTextRightToLeft(_state);

    int index = font->getIndexAtLocation(_text.c_str(), _textBounds, fontSize, _caretLocation, &_caretLocation,
            textAlignment, true, rightToLeft);

    if (index == -1)
    {
        // Attempt to find the nearest valid caret location.
        Rectangle textBounds;
        font->measureText(_text.c_str(), _textBounds, fontSize, &textBounds, textAlignment, true, true);

        if (_caretLocation.x > textBounds.x + textBounds.width &&
            _caretLocation.y > textBounds.y + textBounds.height)
        {
            font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, (unsigned int)_text.length(),
                textAlignment, true, rightToLeft);
            return;
        }

        if (_caretLocation.x < textBounds.x)
        {
            _caretLocation.x = textBounds.x;
        }
        else if (_caretLocation.x > textBounds.x + textBounds.width)
        {
            _caretLocation.x = textBounds.x + textBounds.width;
        }

        if (_caretLocation.y < textBounds.y)
        {
            _caretLocation.y = textBounds.y;
        }
        else if (_caretLocation.y > textBounds.y + textBounds.height)
        {
            Font* font = getFont(_state);
            GP_ASSERT(font);
            unsigned int fontSize = getFontSize(_state);
            _caretLocation.y = textBounds.y + textBounds.height - fontSize;
        }

        index = font->getIndexAtLocation(_text.c_str(), _textBounds, fontSize, _caretLocation, &_caretLocation,
            textAlignment, true, rightToLeft);

        if (index == -1)
        {
            // We failed to find a valid location; just put the caret back to where it was.
            _caretLocation.set(_prevCaretLocation);
        }
    }
}
예제 #3
0
void TextBox::setCaretLocation(int x, int y)
{
    Control::State state = getState();

    Vector2 point(x + _absoluteBounds.x, y + _absoluteBounds.y);

    // Get index into string and cursor location from the latest touch location.
    Font* font = getFont(state);
    unsigned int fontSize = getFontSize(state);
    Font::Justify textAlignment = getTextAlignment(state);
    bool rightToLeft = getTextRightToLeft(state);
    const std::string displayedText = getDisplayedText();

    int index = font->getIndexAtLocation(displayedText.c_str(), _textBounds, fontSize, point, &point,
            textAlignment, true, rightToLeft);

    if (index == -1)
    {
        // Attempt to find the nearest valid caret location.
        Rectangle textBounds;
        font->measureText(displayedText.c_str(), _textBounds, fontSize, &textBounds, textAlignment, true, true);

        if (point.x > textBounds.x + textBounds.width &&
            point.y > textBounds.y + textBounds.height)
        {
            font->getLocationAtIndex(displayedText.c_str(), _textBounds, fontSize, &point, (unsigned int)_text.length(),
                textAlignment, true, rightToLeft);
            return;
        }

        if (point.x < textBounds.x)
        {
            point.x = textBounds.x;
        }
        else if (point.x > textBounds.x + textBounds.width)
        {
            point.x = textBounds.x + textBounds.width;
        }

        if (point.y < textBounds.y)
        {
            point.y = textBounds.y;
        }
        else if (point.y > textBounds.y + textBounds.height)
        {
            Font* font = getFont(state);
            GP_ASSERT(font);
            unsigned int fontSize = getFontSize(state);
            point.y = textBounds.y + textBounds.height - fontSize;
        }

        index = font->getIndexAtLocation(displayedText.c_str(), _textBounds, fontSize, point, &point,
            textAlignment, true, rightToLeft);
    }

    if (index != -1)
        _caretLocation = index;
}
예제 #4
0
void TextWidget::updateDrawableTextPosition(){
	switch (getTextAlignment()){
		case CentrallyAligned:
			m_drawableText.setOrigin(m_drawableText.getLocalBounds().width / 2.f, m_drawableText.getLocalBounds().height / 2.f);
			m_drawableText.setPosition(getRealPosition() + getSize() / 2.f);
			break;
		case LeftAligned:
			m_drawableText.setOrigin(0, m_drawableText.getLocalBounds().height / 2.f);
			m_drawableText.setPosition(getRealPosition().x + 8, getRealPosition().y + getSize().y / 2.f);
			break;
		case RightAligned:
			m_drawableText.setOrigin(m_drawableText.getLocalBounds().width, m_drawableText.getLocalBounds().height / 2.f);
			m_drawableText.setPosition(getRealPosition().x + getSize().x - 8, getRealPosition().y + getSize().y / 2.f);
			break;
	}
}
예제 #5
0
	void RadioButton::paintComponent( const PaintEvent &paintEvent )
	{
		//draw the radio button
		Color checkFillColor = Color(255,255,255);
		if(getRadioButtonState() == CLICKED)
		{
			checkFillColor = Color(50,95,128);
		}
		else if(getRadioButtonState() == HOVERED)
		{
			checkFillColor = Color(200,220,230);
		}

		paintEvent.graphics()->drawFilledCircle(getRadioButtonPosition(),
			(float)getRadioButtonRadius(),checkFillColor);

		//draw the check mark if needed

		switch(getCheckedState())
		{
		case CHECKED:
			for(int i = 2; i < 8; ++i)
			paintEvent.graphics()->drawFilledCircle(getRadioButtonPosition(),
				(float)(getRadioButtonRadius() / i),Color(20,40 * i,200 * i));
		

			break;
		default:
			break;
		}

		if(isFocused())
		{
			paintEvent.graphics()->drawCircle(getRadioButtonPosition(),(float)getRadioButtonRadius(),
				Color(170,170,170));
		}
		else
		{
			paintEvent.graphics()->drawCircle(getRadioButtonPosition(),(float)getRadioButtonRadius(),
				Color(100,100,100));
		}


		//draw text
		textAreaMan.drawTextArea(paintEvent.graphics(),getFont(),getWordWrapRect(),getFontColor(),
			getTextLines(),getTextAlignment());
	}
예제 #6
0
void TextBox::setCaretLocation(int x, int y)
{
    // Get index into string and cursor location from the latest touch location.
    _prevCaretLocation.set(_caretLocation);
    _caretLocation.set(x + _absoluteBounds.x,
                       y + _absoluteBounds.y);

    Font* font = getFont(_state);
    unsigned int fontSize = getFontSize(_state);
    Font::Justify textAlignment = getTextAlignment(_state);
    bool rightToLeft = getTextRightToLeft(_state);

    int index = font->getIndexAtLocation(_text.c_str(), _textBounds, fontSize, _caretLocation, &_caretLocation,
            textAlignment, true, rightToLeft);

    if (index == -1)
    {
        _caretLocation.set(_prevCaretLocation);
    }
}
예제 #7
0
unsigned int TextBox::drawText(Form* form, const Rectangle& clip)
{
    if (_text.size() <= 0)
        return 0;

    // Draw the text.
    if (_font)
    {
        Control::State state = getState();
        const std::string displayedText = getDisplayedText();
        unsigned int fontSize = getFontSize(state);

        SpriteBatch* batch = _font->getSpriteBatch(fontSize);
        startBatch(form, batch);
        _font->drawText(displayedText.c_str(), _textBounds, _textColor, fontSize, getTextAlignment(state), true, getTextRightToLeft(state), _viewportClipBounds);
        finishBatch(form, batch);

        return 1;
    }

    return 0;
}
예제 #8
0
파일: Label.cpp 프로젝트: reven86/GamePlay
unsigned int Label::drawText(Form* form) const
{
    if (_viewportClipBounds.width <= 0 || _viewportClipBounds.height <= 0)
        return 0;

    // Draw the text.
    if (_text.size() > 0 && _font)
    {
        Control::State state = getState();
        float fontSize = getFontSize(state);

        SpriteBatch* batch = _font->getSpriteBatch(fontSize);
        startBatch(form, batch);
        _font->drawText(_text.c_str(), _textBounds, _textColor, fontSize, getTextAlignment(state), true, getTextDrawingFlags(state), _viewportClipBounds,
            getCharacterSpacing(state), getLineSpacing(state));
        finishBatch(form, batch);

        return 1;
    }

    return 0;
}
예제 #9
0
bool TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
{
    if (_state == FOCUS)
    {
        switch (evt)
        {
            case Keyboard::KEY_PRESS:
            {
                switch (key)
                {
                    case Keyboard::KEY_HOME:
                    {
                        // TODO: Move cursor to beginning of line.
                        // This only works for left alignment...
                        
                        //_caretLocation.x = _viewportClipBounds.x;
                        //_dirty = true;
                        break;
                    }
                    case Keyboard::KEY_END:
                    {
                        // TODO: Move cursor to end of line.
                        break;
                    }
                    case Keyboard::KEY_DELETE:
                    {
                        Font* font = getFont(_state);
                        GP_ASSERT(font);
                        unsigned int fontSize = getFontSize(_state);
                        Font::Justify textAlignment = getTextAlignment(_state);
                        bool rightToLeft = getTextRightToLeft(_state);

                        int textIndex = font->getIndexAtLocation(_text.c_str(), _textBounds, fontSize, _caretLocation, &_caretLocation,
                            textAlignment, true, rightToLeft);
                        
                        _text.erase(textIndex, 1);
                        font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex,
                            textAlignment, true, rightToLeft);
                        _dirty = true;
                        notifyListeners(Listener::TEXT_CHANGED);
                        break;
                    }
                    case Keyboard::KEY_LEFT_ARROW:
                    {
                        Font* font = getFont(_state);
                        GP_ASSERT(font);
                        unsigned int fontSize = getFontSize(_state);
                        Font::Justify textAlignment = getTextAlignment(_state);
                        bool rightToLeft = getTextRightToLeft(_state);

                        int textIndex = font->getIndexAtLocation(_text.c_str(), _textBounds, fontSize, _caretLocation, &_caretLocation,
                            textAlignment, true, rightToLeft);
                        font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex - 1,
                            textAlignment, true, rightToLeft);
                        _dirty = true;
                        break;
                    }
                    case Keyboard::KEY_RIGHT_ARROW:
                    {
                        Font* font = getFont(_state);
                        GP_ASSERT(font);
                        unsigned int fontSize = getFontSize(_state);
                        Font::Justify textAlignment = getTextAlignment(_state);
                        bool rightToLeft = getTextRightToLeft(_state);

                        int textIndex = font->getIndexAtLocation(_text.c_str(), _textBounds, fontSize, _caretLocation, &_caretLocation,
                            textAlignment, true, rightToLeft);
                        font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex + 1,
                            textAlignment, true, rightToLeft);
                        _dirty = true;
                        break;
                    }
                    case Keyboard::KEY_UP_ARROW:
                    {
                        Font* font = getFont(_state);
                        GP_ASSERT(font);
                        unsigned int fontSize = getFontSize(_state);
                        Font::Justify textAlignment = getTextAlignment(_state);
                        bool rightToLeft = getTextRightToLeft(_state);
                        _prevCaretLocation.set(_caretLocation);
                        _caretLocation.y -= fontSize;
                        int textIndex = font->getIndexAtLocation(_text.c_str(), _textBounds, fontSize, _caretLocation, &_caretLocation,
                            textAlignment, true, rightToLeft);
                        if (textIndex == -1)
                        {
                            _caretLocation.set(_prevCaretLocation);
                        }

                        _dirty = true;
                        break;
                    }
                    case Keyboard::KEY_DOWN_ARROW:
                    {
                        Font* font = getFont(_state);
                        GP_ASSERT(font);
                        unsigned int fontSize = getFontSize(_state);
                        Font::Justify textAlignment = getTextAlignment(_state);
                        bool rightToLeft = getTextRightToLeft(_state);
                        _prevCaretLocation.set(_caretLocation);
                        _caretLocation.y += fontSize;
                        int textIndex = font->getIndexAtLocation(_text.c_str(), _textBounds, fontSize, _caretLocation, &_caretLocation,
                            textAlignment, true, rightToLeft);
                        if (textIndex == -1)
                        {
                            _caretLocation.set(_prevCaretLocation);
                        }

                        _dirty = true;
                        break;
                    }
                }
                break;
            }

            case Keyboard::KEY_CHAR:
            {
                Font* font = getFont(_state);
                GP_ASSERT(font);
                unsigned int fontSize = getFontSize(_state);
                Font::Justify textAlignment = getTextAlignment(_state);
                bool rightToLeft = getTextRightToLeft(_state);

                int textIndex = font->getIndexAtLocation(_text.c_str(), _textBounds, fontSize, _caretLocation, &_caretLocation,
                    textAlignment, true, rightToLeft);
                if (textIndex == -1)
                {
                    textIndex = 0;
                    font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, 0,
                        textAlignment, true, rightToLeft);
                }

                switch (key)
                {
                    case Keyboard::KEY_BACKSPACE:
                    {
                        if (textIndex > 0)
                        {
                            --textIndex;
                            _text.erase(textIndex, 1);
                            font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex,
                                textAlignment, true, rightToLeft);

                            _dirty = true;
                        }
                        break;
                    }
                    case Keyboard::KEY_RETURN:
                        // TODO: Handle line-break insertion correctly.
                        break;
                    case Keyboard::KEY_ESCAPE:
                        break;
                    case Keyboard::KEY_TAB:
                        break;
                    default:
                    {
                        // Insert character into string.
                        _text.insert(textIndex, 1, (char)key);

                        // Get new location of caret.
                        font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex + 1,
                            textAlignment, true, rightToLeft);

                        if (key == ' ')
                        {
                            // If a space was entered, check that caret is still within bounds.
                            if (_caretLocation.x >= _textBounds.x + _textBounds.width ||
                                _caretLocation.y >= _textBounds.y + _textBounds.height)
                            {
                                // If not, undo the character insertion.
                                _text.erase(textIndex, 1);
                                font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex,
                                    textAlignment, true, rightToLeft);

                                // No need to check again.
                                break;
                            }
                        }

                        // Always check that the text still fits within the clip region.
                        Rectangle textBounds;
                        font->measureText(_text.c_str(), _textBounds, fontSize, &textBounds, textAlignment, true, true);
                        if (textBounds.x <= _textBounds.x || textBounds.y <= _textBounds.y ||
                            textBounds.width >= _textBounds.width || textBounds.height >= _textBounds.height)
                        {
                            // If not, undo the character insertion.
                            _text.erase(textIndex, 1);
                            font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex,
                                textAlignment, true, rightToLeft);

                            // TextBox is not dirty.
                            break;
                        }
                
                        _dirty = true;
                        break;
                    }
            
                    break;
                }

                notifyListeners(Listener::TEXT_CHANGED);
                break;
            }
        }
    }

    _lastKeypress = key;

    return _consumeInputEvents;
}
예제 #10
0
void TextBox::getCaretLocation(Vector2* p)
{
    GP_ASSERT(p);

    State state = getState();
    getFont(state)->getLocationAtIndex(getDisplayedText().c_str(), _textBounds, getFontSize(state), p, _caretLocation, getTextAlignment(state), true, getTextRightToLeft(state));
}
예제 #11
0
파일: Label.cpp 프로젝트: reven86/GamePlay
void Label::updateBounds()
{
    if (_autoSize != AUTO_SIZE_NONE && _font)
    {
        // Measure bounds based only on normal state so that bounds updates are not always required on state changes.
        // This is a trade-off for functionality vs performance, but changing the size of UI controls on hover/focus/etc
        // is a pretty bad practice so we'll prioritize performance here.
        if (_autoSize & AUTO_SIZE_WIDTH)
        {
            float w, h;
            _font->measureText(_text.c_str(), getFontSize(NORMAL), getTextDrawingFlags(NORMAL), &w, &h, getCharacterSpacing(NORMAL), getLineSpacing(NORMAL));
            setWidthInternal(ceilf(w + getBorder(NORMAL).left + getBorder(NORMAL).right + getPadding().left + getPadding().right));
            if (_autoSize & AUTO_SIZE_HEIGHT)
                setHeightInternal(ceilf(h + getBorder(NORMAL).top + getBorder(NORMAL).bottom + getPadding().top + getPadding().bottom));
        }
        else // _autoSize & AUTO_SIZE_HEIGHT
        {
            GP_ASSERT(_autoSize & AUTO_SIZE_HEIGHT);

            // recalculate height due to word wrapping
            float h = getFontSize(NORMAL);
            if (_textBounds.width > 0.0f)
            {
                gameplay::Rectangle clipBounds(_textBounds.width, FLT_MAX);
                gameplay::Rectangle out;
                _font->measureText(_text.c_str(), clipBounds, getFontSize(NORMAL), getTextDrawingFlags(NORMAL), &out, getTextAlignment(NORMAL), 
                    true, true, getCharacterSpacing(NORMAL), getLineSpacing(NORMAL));

                h = out.height;
            }

            setHeightInternal(ceilf(h + getBorder(NORMAL).top + getBorder(NORMAL).bottom + getPadding().top + getPadding().bottom));
        }
    }

    Control::updateBounds();
}
예제 #12
0
파일: cbuttons.cpp 프로젝트: DaniM/lyngo
//------------------------------------------------------------------------
void CTextButton::draw (CDrawContext* context)
{
	bool highlight = value > 0.5 ? true : false;
	context->setDrawMode (kAntiAliasing);
	context->setLineWidth (frameWidth);
	context->setLineStyle (CLineStyle (CLineStyle::kLineCapRound, CLineStyle::kLineJoinRound));
	context->setFrameColor (highlight ? frameColorHighlighted : frameColor);
	CRect r (getViewSize ());
	r.inset (frameWidth / 2., frameWidth / 2.);
	CGraphicsPath* path = getPath (context);
	if (path)
	{
		CColor color1 = highlight ? gradientStartColorHighlighted : gradientStartColor;
		CColor color2 = highlight ? gradientEndColorHighlighted : gradientEndColor;
		CGradient* gradient = path->createGradient (0.2, 1, color1, color2);
		if (gradient)
		{
			context->fillLinearGradient (path, *gradient, r.getTopLeft (), r.getBottomLeft (), false);
			gradient->forget ();
		}
		else
		{
			context->setFillColor (highlight ? gradientStartColorHighlighted : gradientStartColor);
			context->drawGraphicsPath (path, CDrawContext::kPathFilled);
		}
		context->drawGraphicsPath (path, CDrawContext::kPathStroked);
	}
	else
	{
		context->setFillColor (highlight ? gradientStartColorHighlighted : gradientStartColor);
		context->drawRect (getViewSize (), kDrawFilledAndStroked);
	}
	CRect titleRect = getViewSize ();
	titleRect.inset (frameWidth / 2., frameWidth / 2.);

	CBitmap* iconToDraw = highlight ? (iconHighlighted ? iconHighlighted : icon) : (icon ? icon : iconHighlighted);
	if (iconToDraw)
	{
		CRect iconRect (0, 0, iconToDraw->getWidth (), iconToDraw->getHeight ());
		iconRect.offset (titleRect.left, titleRect.top);
		switch (iconPosition)
		{
			case kLeft:
			{
				iconRect.offset (textMargin, titleRect.getHeight () / 2. - iconRect.getHeight () / 2.);
				titleRect.left = iconRect.right;
				titleRect.right -= textMargin;
				if (getTextAlignment () == kLeftText)
					titleRect.left += textMargin;
				break;
			}
			case kRight:
			{
				iconRect.offset (titleRect.getWidth () - (textMargin + iconRect.getWidth ()), titleRect.getHeight () / 2. - iconRect.getHeight () / 2.);
				titleRect.right = iconRect.left;
				titleRect.left += textMargin;
				if (getTextAlignment () == kRightText)
					titleRect.right -= textMargin;
				break;
			}
			case kCenterAbove:
			{
				iconRect.offset (titleRect.getWidth () / 2. - iconRect.getWidth () / 2., 0);
				if (title.size () > 0)
				{
					iconRect.offset (0, titleRect.getHeight () / 2. - (iconRect.getHeight () / 2. + (textMargin + font->getSize ()) / 2.));
					titleRect.top = iconRect.bottom + textMargin;
					titleRect.setHeight (font->getSize ());
					if (getTextAlignment () == kLeftText)
						titleRect.left += textMargin;
					else if (getTextAlignment () == kRightText)
						titleRect.right -= textMargin;
				}
				else
				{
					iconRect.offset (0, titleRect.getHeight () / 2. - iconRect.getHeight () / 2.);
				}
				break;
			}
			case kCenterBelow:
			{
				iconRect.offset (titleRect.getWidth () / 2. - iconRect.getWidth () / 2., 0);
				if (title.size () > 0)
				{
					iconRect.offset (0, titleRect.getHeight () / 2. - (iconRect.getHeight () / 2.) + (textMargin + font->getSize ()) / 2.);
					titleRect.top = iconRect.top - (textMargin + font->getSize ());
					titleRect.setHeight (font->getSize ());
					if (getTextAlignment () == kLeftText)
						titleRect.left += textMargin;
					else if (getTextAlignment () == kRightText)
						titleRect.right -= textMargin;
				}
				else
				{
					iconRect.offset (0, titleRect.getHeight () / 2. - iconRect.getHeight () / 2.);
				}
				break;
			}
		}
		context->drawBitmap (iconToDraw, iconRect);
	}
	else
	{
		if (getTextAlignment () == kLeftText)
			titleRect.left += textMargin;
		else if (getTextAlignment () == kRightText)
			titleRect.right -= textMargin;
	}
	if (title.size () > 0)
	{
		context->setFont (font);
		context->setFontColor (highlight ? textColorHighlighted : textColor);
		context->drawString (title.c_str (), titleRect, horiTxtAlign);
	}
	setDirty (false);
}
QGraphicsLayout *
RightArrowItem::createLayout()
{
    QGraphicsGridLayout *layout;
    MWidget             *spacer;
    MLabel              *titleLabel;
    MLabel              *subTitleLabel = 0;
    MImageWidget        *iconWidget    = 0;
    MImageWidget        *drillIconWidget;
    Qt::Alignment        textAlignment = getTextAlignment ();
    
    layout = new QGraphicsGridLayout(this);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setSpacing(0);

    titleLabel = titleLabelWidget ();
    titleLabel->setWordWrap (true);

    drillIconWidget = new MImageWidget ("icon-m-common-drilldown-arrow-inverse");
    drillIconWidget->setStyleName ("CommonDrillDownIcon");

    titleLabel->setStyleName(m_TitleStyleName);

    switch (itemStyle()) {
        case TitleWithSubtitle:
            SYS_DEBUG ("TitleWithSubtitle");
            /*
             * The title label.
             */
            layout->addItem (titleLabel, 0, 0);
            layout->setAlignment(titleLabel, 
                    Qt::AlignLeft | Qt::AlignVCenter);
            /*
             * The sub-title label.
             */
            subTitleLabel = subtitleLabelWidget ();
            subTitleLabel->setStyleName("CommonSubTitleInverted");
            layout->addItem (subTitleLabel, 1, 0);
            layout->setAlignment (subTitleLabel, 
                    Qt::AlignLeft | Qt::AlignVCenter);

            spacer = new MWidget;
            layout->addItem (spacer, 2, 0);

            /*
             * The drill down icon.
             */
            layout->addItem(drillIconWidget, 0, 1, 3, 1);
            layout->setAlignment (drillIconWidget, Qt::AlignVCenter | Qt::AlignRight);
            break;

        case IconWithTitleAndSubtitle:
            SYS_DEBUG ("IconWithTitleAndSubtitle");
            /*
             * The left side icon.
             */
            iconWidget = imageWidget();
            layout->addItem (iconWidget, 0, 0, 2, 1);
            layout->setAlignment (iconWidget, Qt::AlignVCenter | Qt::AlignRight);
            /*
             * The title label.
             */
            layout->addItem (titleLabel, 0, 1);
            layout->setAlignment (titleLabel, 
                    Qt::AlignLeft | Qt::AlignVCenter);
            /*
             * The sub-title label.
             */
            subTitleLabel = subtitleLabelWidget ();
            subTitleLabel->setStyleName("CommonSubTitleInverted");
            layout->addItem (subTitleLabel, 1, 1, 
                    Qt::AlignLeft | Qt::AlignVCenter);
            /*
             * The drill down icon.
             */
            layout->addItem(drillIconWidget, 0, 2, 2, 1);
            layout->setAlignment (drillIconWidget, 
                    Qt::AlignVCenter | Qt::AlignRight);
            break;

        case IconWithTitle:
            SYS_DEBUG ("IconWithTitle");

            /*
             * The left side icon.
             */
            iconWidget = imageWidget();
            layout->addItem (iconWidget, 0, 0);
            layout->setAlignment (iconWidget, 
                    Qt::AlignVCenter | Qt::AlignRight);
            /*
             * The title label.
             */
            titleLabel->setAlignment (textAlignment | Qt::AlignVCenter);
            layout->addItem (titleLabel, 0, 1);
            layout->setAlignment (titleLabel, 
                    Qt::AlignLeft | Qt::AlignVCenter);
            /*
             * The drill down icon.
             */
            layout->addItem(drillIconWidget, 0, 2);
            layout->setAlignment (drillIconWidget, Qt::AlignVCenter | Qt::AlignRight);
            break;

        default:
            SYS_WARNING ("itemStyle not supported.");
    }

    setStyleName ("CommonPanelInverted");
    return layout;
}
예제 #14
0
파일: Button.cpp 프로젝트: arvidsson/Agui
	void Button::paintComponent( const PaintEvent &paintEvent )
	{

		resizableText.drawTextArea(paintEvent.graphics(),getFont(),
			getInnerRectangle(),getFontColor(),wrappedText,getTextAlignment());
	}
예제 #15
0
	void TextField::scrollToCaret(bool negetiveChange, bool reposition)
	{
		int retOffset = getLeftPadding();
		
		int textWidth = getFont()->getTextWidth(getText());
		if(textWidth < getAdjustedWidth())
		{
			switch(getTextAlignment())
			{
			case ALIGN_LEFT:
				alignOffset = 0;
				break;
			case ALIGN_CENTER:
				alignOffset = (getAdjustedWidth() - textWidth) / 2;
				break;
			case ALIGN_RIGHT:
				alignOffset = getAdjustedWidth() - textWidth;
				break;
			default:
				break;
			}
			
		}
		else
		{
			alignOffset = 0;
		}

		if(getTextLength() == 0 || getCaretPosition() == 0)
		{
			tOffset = retOffset;
			setTextOffset(retOffset + alignOffset);
			return;
		}

		if(reposition)
		{
			//do we need to move?
			if(getFont()->getTextWidth(unicodeFunctions.subStr(getText(),
				0,getCaretPosition())) > -tOffset + getAdjustedWidth() + getLeftPadding()
				
				)
			{

				//scroll to end
				if(getTextLength() < getCaretPosition() + getMaxCharacterSkip())
				{

					retOffset -= solveCaretRetPos(getFont()->getTextWidth(getText())
						- getAdjustedWidth(),
						retOffset);
				}
				else
				{
					int initialPlace = getFont()->getTextWidth(unicodeFunctions.subStr(getText(),
						0, getCaretPosition() + getMaxCharacterSkip() )) - getAdjustedWidth();
					retOffset -= solveCaretRetPos(initialPlace,retOffset);
					
				}



				tOffset = retOffset;
				setTextOffset(retOffset + alignOffset);
				return;

			}
			else if(tOffset + getFont()->getTextWidth(unicodeFunctions.subStr(getText(),
				0,getCaretPosition())) <= leftPadding)
			{

				if(getCaretPosition() - getMaxCharacterSkip() > 0)
				{
					int initialPlace = getFont()->getTextWidth(unicodeFunctions.subStr(getText(),
						0, getCaretPosition() - getMaxCharacterSkip() ));
					retOffset -= solveCaretRetPos(initialPlace,retOffset);

				}

				tOffset = retOffset;
				setTextOffset(retOffset + alignOffset);
				return;
			}
			else if(negetiveChange )
			{

				int change = getCaretLocation() - getFont()->getTextWidth(unicodeFunctions.subStr(getText(),
					0, getCaretPosition() )) ;
				if(change <= getLeftPadding())
				{
					
					tOffset = change;
					setTextOffset(change);
				}
				else
				{
					tOffset = leftPadding;
					setTextOffset(leftPadding + alignOffset);
				}
				return;
			}
		}

		//if there is more text than width
		//but theres not enough to fill the width
		//then fill the width


			int a = getAdjustedWidth() + getLeftPadding();
			int b = getTextOffset() + textWidth;

			if(a > b && getTextOffset() < getLeftPadding())
			{
				retOffset = -textWidth + getInnerSize().getWidth() - getRightPadding(); 

				tOffset = retOffset;

			}
			else if(getTextOffset() >= getLeftPadding() )
			{

				tOffset = leftPadding;
				setTextOffset(leftPadding + alignOffset);
				return;
			}

		setTextOffset(tOffset + alignOffset);

	}
예제 #16
0
unsigned int Slider::drawImages(Form* form, const Rectangle& clip)
{
    if (!(_minImage && _maxImage && _markerImage && _trackImage))
        return 0;

    // TODO: Vertical slider.

    // The slider is drawn in the center of the control (perpendicular to orientation).
    // The track is stretched according to orientation.
    // Caps and marker are not stretched.
    const Rectangle& minCapRegion = _minImage->getRegion();
    const Rectangle& maxCapRegion = _maxImage->getRegion();
    const Rectangle& markerRegion = _markerImage->getRegion();
    const Rectangle& trackRegion = _trackImage->getRegion();

    const Theme::UVs& minCap = _minImage->getUVs();
    const Theme::UVs& maxCap = _maxImage->getUVs();
    const Theme::UVs& marker = _markerImage->getUVs();
    const Theme::UVs& track = _trackImage->getUVs();

    Vector4 minCapColor = _minImage->getColor();
    Vector4 maxCapColor = _maxImage->getColor();
    Vector4 markerColor = _markerImage->getColor();
    Vector4 trackColor = _trackImage->getColor();

    Control::State state = getState();

    minCapColor.w *= _opacity;
    maxCapColor.w *= _opacity;
    markerColor.w *= _opacity;
    trackColor.w *= _opacity;

    SpriteBatch* batch = _style->getTheme()->getSpriteBatch();
    startBatch(form, batch);

    // Compute area to draw the slider track
    unsigned int fontSize = getFontSize(state);
    float startY, endY;
    if (_text.length() > 0)
    {
        if (_valueTextVisible)
        {
            // Both label and value text are visible.
            // Draw slider in the middle.
            startY = fontSize;
            endY = _viewportBounds.height - fontSize;
        }
        else
        {
            // Only label is visible
            if (getTextAlignment(state) & ALIGN_BOTTOM)
            {
                // Draw slider above label
                startY = 0;
                endY = _viewportBounds.height - fontSize;
            }
            else
            {
                // Draw slider below label
                startY = fontSize;
                endY = _viewportBounds.height;
            }
        }
    }
    else if (_valueTextVisible)
    {
        // Only value text is visible.
        if (_valueTextAlignment & ALIGN_BOTTOM)
        {
            // Draw slider above value text
            startY = 0;
            endY = _viewportBounds.height - fontSize;
        }
        else
        {
            // Draw slider below value text
            startY = fontSize;
            endY = _viewportBounds.height;
        }
    }
    else
    {
        // Only the slider track is visible
        startY = 0;
        endY = _viewportBounds.height;
    }

    // Compute midpoint of track location
    float midY = _viewportBounds.y + startY + (endY - startY) * 0.5f;

    // Draw track below the slider text
    Vector2 pos(_viewportBounds.x + minCapRegion.width, midY - trackRegion.height * 0.5f);
    batch->draw(pos.x, pos.y, _viewportBounds.width - minCapRegion.width - maxCapRegion.width, trackRegion.height, track.u1, track.v1, track.u2, track.v2, trackColor, _viewportClipBounds);

    // Draw min cap to the left of the track
    pos.y = midY - minCapRegion.height * 0.5f;
    pos.x = _viewportBounds.x;
    batch->draw(pos.x, pos.y, minCapRegion.width, minCapRegion.height, minCap.u1, minCap.v1, minCap.u2, minCap.v2, minCapColor, _viewportClipBounds);

    // Draw max cap to the right of the track
    pos.x = _viewportBounds.right() - maxCapRegion.width;
    batch->draw(pos.x, pos.y, maxCapRegion.width, maxCapRegion.height, maxCap.u1, maxCap.v1, maxCap.u2, maxCap.v2, maxCapColor, _viewportClipBounds);

    // Draw the marker at the correct position
    float markerPosition = (_value - _min) / (_max - _min);
    markerPosition *= _viewportBounds.width - markerRegion.width;
    pos.x = _viewportBounds.x + markerPosition;
    pos.y = midY - markerRegion.height * 0.5f;
    batch->draw(pos.x, pos.y, markerRegion.width, markerRegion.height, marker.u1, marker.v1, marker.u2, marker.v2, markerColor, _viewportClipBounds);

    finishBatch(form, batch);

    return 4;
}