//----------------------------------------------------------------------------//
void RenderedStringTextComponent::draw(GeometryBuffer& buffer,
                                       const Vector2& position,
                                       const ColourRect* mod_colours,
                                       const Rect* clip_rect,
                                       const float vertical_space,
                                       const float space_extra) const
{
    Font* fnt = d_font ? d_font : System::getSingleton().getDefaultFont();

    if (!fnt)
        return;

    Vector2 final_pos(position);
    float y_scale = 1.0f;

    // handle formatting options
    switch (d_verticalFormatting)
    {
    case VF_BOTTOM_ALIGNED:
        final_pos.d_y += vertical_space - getPixelSize().d_height;
        break;

    case VF_CENTRE_ALIGNED:
        final_pos.d_y += (vertical_space - getPixelSize().d_height) / 2 ;
        break;

    case VF_STRETCHED:
        y_scale = vertical_space / getPixelSize().d_height;
        break;

    case VF_TOP_ALIGNED:
        // nothing additional to do for this formatting option.
        break;

    default:
        throw InvalidRequestException("RenderedStringTextComponent::draw: "
                "unknown VerticalFormatting option specified.");
    }

    // apply padding to position:
    final_pos += d_padding.getPosition();

    // apply modulative colours if needed.
    ColourRect final_cols(d_colours);
    if (mod_colours)
        final_cols *= *mod_colours;

    // draw the text string.
    fnt->drawText(buffer, d_text, final_pos, clip_rect, final_cols,
                  space_extra, 1.0f, y_scale);
}
Пример #2
0
void FalagardActionButton::drawCorner(float z)
{
    //Draw CornerChar
    ColourRect final_cols(colour(1.0f, 1.0f, 1.0f));

    //Top Left
    if(!d_CornerChar_TopLeft.d_Char.empty())
    {
        d_renderCache.cacheText(this,
                                d_CornerChar_TopLeft.d_Char, getFont(), (TextFormatting)LeftAligned,
                                Rect(2, 2, getAbsoluteSize().d_width, getAbsoluteSize().d_height), 0.0f, final_cols);
    }
    //Top Right
    if(!d_CornerChar_TopRight.d_Char.empty())
    {
        d_renderCache.cacheText(this,
                                d_CornerChar_TopRight.d_Char, getFont(), (TextFormatting)RightAligned,
                                Rect(0, 2, getAbsoluteSize().d_width-2, getAbsoluteSize().d_height), 0.0f, final_cols);
    }
    //Bottom Left
    if(!d_CornerChar_BotLeft.d_Char.empty())
    {
        //Get the font height
        float fFontHeight = getFont()->getFontHeight();
        d_renderCache.cacheText(this,
                                d_CornerChar_BotLeft.d_Char, getFont(), (TextFormatting)LeftAligned,
                                Rect(2, getAbsoluteSize().d_height-fFontHeight-2, getAbsoluteSize().d_width, getAbsoluteSize().d_height), 0.0f, final_cols);
    }
    //Bottom Right
    if(!d_CornerChar_BotRight.d_Char.empty())
    {
        //Get the font height
        float fFontHeight = getFont()->getFontHeight();
        d_renderCache.cacheText(this,
                                d_CornerChar_BotRight.d_Char, getFont(), (TextFormatting)RightAligned,
                                Rect(0, getAbsoluteSize().d_height-fFontHeight-2, getAbsoluteSize().d_width-2, getAbsoluteSize().d_height), 0.0f, final_cols);
    }
}
Пример #3
0
	void CPFRotatingText::renderRotatingText()
	{
		Font* font = d_window->getFont();
		// can't render text without a font :)
		if( font==NULL){
			return;
		}

		// get destination area for the text.
		Rect absarea(getTextRenderArea());
		Rect clipper(absarea);

		float textHeight = font->getFormattedLineCount(d_window->getText(), absarea, (TextFormatting)d_horzFormatting) * font->getLineSpacing();

		Scrollbar* vertScrollbar = getVertScrollbar();
		Scrollbar* horzScrollbar = getHorzScrollbar();

		// calculate X offset
		static float xOffset = horzScrollbar->getPageSize();
		if( xOffset<-(horzScrollbar->getDocumentSize()+horzScrollbar->getPageSize()) ){
			xOffset = horzScrollbar->getPageSize();
		}
		static boost::system_time previous_time = boost::get_system_time();
		boost::system_time time = boost::get_system_time();
		boost::system_time::time_duration_type time_step = (time-previous_time);
		xOffset -= (static_cast<float>(time_step.total_milliseconds())*d_textSpeed);
		previous_time = time;
		absarea.offset(Point(xOffset, 0));

		// see if we may need to adjust horizontal position
		if( horzScrollbar->isVisible() ){
			switch(d_horzFormatting)
			{
			case LeftAligned:
			case WordWrapLeftAligned:
			case Justified:
			case WordWrapJustified:
				absarea.offset(Point(-horzScrollbar->getScrollPosition(), 0));
				break;

			case Centred:
			case WordWrapCentred:
				absarea.setWidth(horzScrollbar->getDocumentSize());
				absarea.offset(Point(-horzScrollbar->getScrollPosition(), 0));
				break;

			case RightAligned:
			case WordWrapRightAligned:
				absarea.offset(Point(horzScrollbar->getScrollPosition(), 0));
				break;
			}
		}

		// adjust y positioning according to formatting option
		switch(d_vertFormatting)
		{
		case TopAligned:
			absarea.d_top -= vertScrollbar->getScrollPosition();
			break;

		case VertCentred:
			// if scroll bar is in use, act like TopAligned
			if( vertScrollbar->isVisible() ){
				absarea.d_top -= vertScrollbar->getScrollPosition();
			}
			// no scroll bar, so centre text instead.
			else{
				absarea.d_top += PixelAligned((absarea.getHeight() - textHeight) * 0.5f);
			}
			break;

		case BottomAligned:
			absarea.d_top = absarea.d_bottom - textHeight;
			absarea.d_top += vertScrollbar->getScrollPosition();
			break;
		}

		// offset the font little down so that it's centered within its own spacing
		absarea.d_top += (font->getLineSpacing() - font->getFontHeight()) * 0.5f;
		// calculate final colours
		ColourRect final_cols(d_textCols);
		final_cols.modulateAlpha(d_window->getEffectiveAlpha());
		// cache the text for rendering.
		d_window->getRenderCache().cacheText(d_window->getText(), font, (TextFormatting)d_horzFormatting, absarea, 0, final_cols, &clipper);
	}
//----------------------------------------------------------------------------//
void RenderedStringImageComponent::draw(const Window* ref_wnd,
                                        std::vector<GeometryBuffer*>& geometry_buffers,
                                        const glm::vec2& position,
                                        const ColourRect* mod_colours,
                                        const Rectf* clip_rect,
                                        const float vertical_space,
                                        const float /*space_extra*/) const
{
    if (!d_image)
        return;

    Rectf dest(position.x, position.y, 0, 0);
    float y_scale = 1.0f;

    // handle formatting options
    switch (d_verticalFormatting)
    {
    case VF_BOTTOM_ALIGNED:
        dest.d_min.y += vertical_space - getPixelSize(ref_wnd).d_height;
        break;

    case VF_CENTRE_ALIGNED:
        dest.d_min.y += (vertical_space - getPixelSize(ref_wnd).d_height) / 2 ;
        break;

    case VF_STRETCHED:
        y_scale = vertical_space / getPixelSize(ref_wnd).d_height;
        break;

    case VF_TOP_ALIGNED:
        // nothing additional to do for this formatting option.
        break;

    default:
        throw InvalidRequestException(
            "unknown VerticalFormatting option specified.");
    }

    Sizef sz(d_image->getRenderedSize());
    if (d_size.d_width != 0.0)
        sz.d_width = d_size.d_width;
    if (d_size.d_height != 0.0)
        sz.d_height = d_size.d_height;
    
    sz.d_height *= y_scale;
    dest.setSize(sz);

    // apply padding to position
    dest.offset(d_padding.getPosition());

    // render the selection if needed
    if (d_selectionImage && d_selected)
    {
        const Rectf select_area(position, getPixelSize(ref_wnd));
        d_selectionImage->render(geometry_buffers, select_area, clip_rect, true, ColourRect(0xFF002FFF));
    }

    // apply modulative colours if needed.
    ColourRect final_cols(d_colours);
    if (mod_colours)
        final_cols *= *mod_colours;

    // draw the image. 
    d_image->render(geometry_buffers, dest, clip_rect, true, final_cols);
}
//----------------------------------------------------------------------------//
void RenderedStringTextComponent::draw(const Window* ref_wnd,
                                       GeometryBuffer& buffer,
                                       const Vector2f& position,
                                       const ColourRect* mod_colours,
                                       const Rectf* clip_rect,
                                       const float vertical_space,
                                       const float space_extra) const
{
    const Font* fnt = getEffectiveFont(ref_wnd); 

    if (!fnt)
        return;

    Vector2f final_pos(position);
    float y_scale = 1.0f;

    // handle formatting options
    switch (d_verticalFormatting)
    {
    case VF_BOTTOM_ALIGNED:
        final_pos.d_y += vertical_space - getPixelSize(ref_wnd).d_height;
        break;

    case VF_CENTRE_ALIGNED:
        final_pos.d_y += (vertical_space - getPixelSize(ref_wnd).d_height) / 2 ;
        break;

    case VF_STRETCHED:
        y_scale = vertical_space / getPixelSize(ref_wnd).d_height;
        break;

    case VF_TOP_ALIGNED:
        // nothing additional to do for this formatting option.
        break;

    default:
        CEGUI_THROW(InvalidRequestException(
            "unknown VerticalFormatting option specified."));
    }

    // apply padding to position:
    final_pos += d_padding.getPosition();

    // apply modulative colours if needed.
    ColourRect final_cols(d_colours);
    if (mod_colours)
        final_cols *= *mod_colours;

    // render selection
    if (d_selectionImage && d_selectionLength)
    {
        float sel_start_extent = 0, sel_end_extent = 0;

        if (d_selectionStart > 0)
            sel_start_extent = fnt->getTextExtent(d_text.substr(0, d_selectionStart));

        sel_end_extent = fnt->getTextExtent(d_text.substr(0, d_selectionStart + d_selectionLength));

        Rectf sel_rect(position.d_x + sel_start_extent,
                       position.d_y,
                       position.d_x + sel_end_extent,
                       position.d_y + vertical_space);

        d_selectionImage->render(buffer, sel_rect, clip_rect, ColourRect(0xFF002FFF));
    }

    // draw the text string.
    fnt->drawText(buffer, d_text, final_pos, clip_rect, final_cols,
                  space_extra, 1.0f, y_scale);
}