//----------------------------------------------------------------------------//
void OpenGL3GeometryBuffer::setClippingRegion(const Rectf& region)
{
    d_clipRect.top(ceguimax(0.0f, region.top()));
    d_clipRect.left(ceguimax(0.0f, region.left()));
    d_clipRect.bottom(ceguimax(0.0f, region.bottom()));
    d_clipRect.right(ceguimax(0.0f, region.right()));
}
//----------------------------------------------------------------------------//
void OpenGLGeometryBuffer::setClippingRegion(const Rect& region)
{
    d_clipRect.d_top    = ceguimax(0.0f, PixelAligned(region.d_top));
    d_clipRect.d_bottom = ceguimax(0.0f, PixelAligned(region.d_bottom));
    d_clipRect.d_left   = ceguimax(0.0f, PixelAligned(region.d_left));
    d_clipRect.d_right  = ceguimax(0.0f, PixelAligned(region.d_right));
}
Exemple #3
0
/*************************************************************************
	Handler called whenever the mouse moves while dragging a segment
*************************************************************************/
bool ListHeader::segmentDragHandler(const EventArgs&)
{
	// what we do here is monitor the position and scroll if we can when mouse is outside area.

	// get mouse position as something local
    const Vector2f localMousePos(CoordConverter::screenToWindow(*this,
        getUnprojectedPosition(getGUIContext().
            getMouseCursor().getPosition())));

	// scroll left?
	if (localMousePos.d_x < 0.0f)
	{
		if (d_segmentOffset > 0.0f)
		{
			setSegmentOffset(ceguimax(0.0f, d_segmentOffset - ScrollSpeed));
		}
	}
	// scroll right?
	else if (localMousePos.d_x >= d_pixelSize.d_width)
	{
		float maxOffset = ceguimax(0.0f, getTotalSegmentsPixelExtent() - d_pixelSize.d_width);

		// if we have not scrolled to the limit
		if (d_segmentOffset < maxOffset)
		{
			// scroll, but never beyond the limit
			setSegmentOffset(ceguimin(maxOffset, d_segmentOffset + ScrollSpeed));
		}

	}

	return true;
}
Exemple #4
0
float colour::getLumination(void) const
{
	float pMax = ceguimax(ceguimax(d_red, d_green), d_blue);
	float pMin = ceguimin(ceguimin(d_red, d_green), d_blue);

	float pLum = (pMax + pMin) / 2;
	return pLum;
}
Exemple #5
0
/*************************************************************************
    Return the horizontal pixel extent given text would be formatted to.
*************************************************************************/
float Font::getFormattedTextExtent(const String& text, const Rect& format_area, TextFormatting fmt, float x_scale)
{
    float lineWidth;
    float widest = 0;

    size_t lineStart = 0, lineEnd = 0;
    String	currLine;

    while (lineEnd < text.length())
    {
        if ((lineEnd = text.find_first_of('\n', lineStart)) == String::npos)
        {
            lineEnd = text.length();
        }

        currLine = text.substr(lineStart, lineEnd - lineStart);
        lineStart = lineEnd + 1;	// +1 to skip \n char

        switch(fmt)
        {
        case Centred:
        case RightAligned:
        case LeftAligned:
            lineWidth = getTextExtent(currLine, x_scale);
            break;

        case Justified:
            // usually we use the width of the rect but we have to ensure the current line is not wider than that
            lineWidth = ceguimax(format_area.getWidth(), getTextExtent(currLine, x_scale));
            break;

        case WordWrapLeftAligned:
        case WordWrapRightAligned:
        case WordWrapCentred:
            lineWidth = getWrappedTextExtent(currLine, format_area.getWidth(), x_scale);
            break;

        case WordWrapJustified:
            // same as above
            lineWidth = ceguimax(format_area.getWidth(), getWrappedTextExtent(currLine, format_area.getWidth(), x_scale));
            break;

        default:
            throw InvalidRequestException("Font::getFormattedTextExtent - Unknown or unsupported TextFormatting value specified.");
        }

        if (lineWidth > widest)
        {
            widest = lineWidth;
        }

    }

    return widest;
}
/************************************************************************
    Configure scroll bars
************************************************************************/
void ScrolledItemListBase::configureScrollbars(const Size& doc_size)
{
    Scrollbar* v = getVertScrollbar();
    Scrollbar* h = getHorzScrollbar();

    Size render_area_size = getItemRenderArea().getSize();

    // setup the pane size
    float pane_size_w = ceguimax(doc_size.d_width, render_area_size.d_width);
    UVector2 pane_size(cegui_absdim(pane_size_w), cegui_absdim(doc_size.d_height));

    d_pane->setMinSize(pane_size);
    d_pane->setMaxSize(pane_size);
    //d_pane->setWindowSize(pane_size);

    // "fix" scrollbar visibility
    if (d_forceVScroll || doc_size.d_height > render_area_size.d_height)
    {
        v->show();
    }
    else
    {
        v->hide();
    }

    //render_area_size = getItemRenderArea().getSize();

    if (d_forceHScroll || doc_size.d_width > render_area_size.d_width)
    {
        h->show();
    }
    else
    {
        h->hide();
    }

    // get a fresh item render area
    Rect render_area = getItemRenderArea();
    render_area_size = render_area.getSize();

    // update the pane clipper area
    static_cast<ClippedContainer*>(d_pane)->setClipArea(render_area);

    // setup vertical scrollbar
    v->setDocumentSize(doc_size.d_height);
    v->setPageSize(render_area_size.d_height);
    v->setStepSize(ceguimax(1.0f, render_area_size.d_height / 10.0f));
    v->setScrollPosition(v->getScrollPosition());

    // setup horizontal scrollbar
    h->setDocumentSize(doc_size.d_width);
    h->setPageSize(render_area_size.d_width);
    h->setStepSize(ceguimax(1.0f, render_area_size.d_width / 10.0f));
    h->setScrollPosition(h->getScrollPosition());
}
Exemple #7
0
	void FalagardScrollbar::changeStateOfButtons(void)
	{

		float max_pos = ceguimax((d_documentSize - d_pageSize), 0.0f);
		//иак╦
		if(!d_increase || !d_decrease) return;
		if(max_pos <= 0.0f)
		{
			static_cast<FalagardButton*>(d_increase)->enableAnimate(false);
			static_cast<FalagardButton*>(d_decrease)->enableAnimate(false);
			return;
		}
		if(d_position ==  0.0f)
		{
			static_cast<FalagardButton*>(d_increase)->enableAnimate(true);
			static_cast<FalagardButton*>(d_decrease)->enableAnimate(false);
		}
		else if(d_position == max_pos)
		{
			static_cast<FalagardButton*>(d_increase)->enableAnimate(false);
			static_cast<FalagardButton*>(d_decrease)->enableAnimate(true);
		}
		else
		{
			static_cast<FalagardButton*>(d_increase)->enableAnimate(true);
			static_cast<FalagardButton*>(d_decrease)->enableAnimate(true);
		}
	}
//----------------------------------------------------------------------------//
void ScrollablePane::configureScrollbars(void)
{
    // controls should all be valid by this stage
    Scrollbar* const vertScrollbar = getVertScrollbar();
    Scrollbar* const horzScrollbar = getHorzScrollbar();

    const bool horzScrollBarWasVisible = horzScrollbar->isVisible();
    const bool vertScrollBarWasVisible = vertScrollbar->isVisible();

    // enable required scrollbars
    vertScrollbar->setVisible(isVertScrollbarNeeded());
    horzScrollbar->setVisible(isHorzScrollbarNeeded());
    
    // Check if the addition of the horizontal scrollbar means we
    // now also need the vertical bar.
    if (horzScrollbar->isVisible())
        vertScrollbar->setVisible(isVertScrollbarNeeded());

    if (horzScrollBarWasVisible != horzScrollbar->isVisible() ||
        vertScrollBarWasVisible != vertScrollbar->isVisible())
    {
        ElementEventArgs args(this);
        onSized(args);
    }

    performChildWindowLayout();
    
    // get viewable area
    const Rectf viewableArea(getViewableArea());
    
    // set up vertical scroll bar values
    vertScrollbar->setDocumentSize(fabsf(d_contentRect.getHeight()));
    vertScrollbar->setPageSize(viewableArea.getHeight());
    vertScrollbar->setStepSize(ceguimax(1.0f, viewableArea.getHeight() * d_vertStep));
    vertScrollbar->setOverlapSize(ceguimax(1.0f, viewableArea.getHeight() * d_vertOverlap));
    vertScrollbar->setScrollPosition(vertScrollbar->getScrollPosition());
    
    // set up horizontal scroll bar values
    horzScrollbar->setDocumentSize(fabsf(d_contentRect.getWidth()));
    horzScrollbar->setPageSize(viewableArea.getWidth());
    horzScrollbar->setStepSize(ceguimax(1.0f, viewableArea.getWidth() * d_horzStep));
    horzScrollbar->setOverlapSize(ceguimax(1.0f, viewableArea.getWidth() * d_horzOverlap));
    horzScrollbar->setScrollPosition(horzScrollbar->getScrollPosition());
}
Exemple #9
0
    void FalagardListbox::render()
    {
    	Listbox* lb = (Listbox*)d_window;
        // render frame and stuff before we handle the items
        cacheListboxBaseImagery();

        //
        // Render list items
        //
        Vector3 itemPos;
        Size    itemSize;
        Rect    itemClipper, itemRect;
        float   widest = lb->getWidestItemWidth();

        // calculate position of area we have to render into
        Rect itemsArea(getListRenderArea());

        // set up some initial positional details for items
        itemPos.d_x = itemsArea.d_left - lb->getHorzScrollbar()->getScrollPosition();
        itemPos.d_y = itemsArea.d_top - lb->getVertScrollbar()->getScrollPosition();
        itemPos.d_z = System::getSingleton().getRenderer()->getZLayer(3) - System::getSingleton().getRenderer()->getCurrentZ();

        float alpha = lb->getEffectiveAlpha();

        // loop through the items
        size_t itemCount = lb->getItemCount();

        for (size_t i = 0; i < itemCount; ++i)
        {
            ListboxItem* listItem = lb->getListboxItemFromIndex(i);
            itemSize.d_height = listItem->getPixelSize().d_height;

            // allow item to have full width of box if this is wider than items
            itemSize.d_width = ceguimax(itemsArea.getWidth(), widest);

            // calculate destination area for this item.
            itemRect.d_left = itemPos.d_x;
            itemRect.d_top  = itemPos.d_y;
            itemRect.setSize(itemSize);
            itemClipper = itemRect.getIntersection(itemsArea);

            // skip this item if totally clipped
            if (itemClipper.getWidth() == 0)
            {
                itemPos.d_y += itemSize.d_height;
                continue;
            }

            // draw this item
            listItem->draw(lb->getRenderCache(), itemRect, itemPos.d_z, alpha, &itemClipper);

            // update position ready for next item
            itemPos.d_y += itemSize.d_height;
        }

    }
RenderedStringTextComponent* RenderedColourStringTextComponent::split(float split_point, bool first_component)
{
	const Font* fnt = d_font ? d_font : System::getSingleton().getDefaultGUIContext().getDefaultFont();

	// This is checked, but should never fail, since if we had no font our
	// extent would be 0 and we would never cause a split to be needed here.
	if (!fnt)
		CEGUI_THROW(InvalidRequestException( "RenderedStringTextComponent::split: "
		"unable to split with no font set."));

	// create 'left' side of split and clone our basic configuration
	RenderedColourStringTextComponent* lhs = new RenderedColourStringTextComponent;
	lhs->d_padding = d_padding;
	lhs->d_verticalFormatting = d_verticalFormatting;
	lhs->d_font = d_font;
	lhs->d_colours = d_colours;

	// calculate the 'best' place to split the text
	size_t left_len = 0;
	float left_extent = 0.0f;

	while (left_len < d_text.length()) {
		size_t token_len = getNextTokenLength(d_text, left_len);
		// exit loop if no more valid tokens.
		if (token_len == 0)
			break;

		const float token_extent = fnt->getTextExtent(d_text.substr(left_len, token_len));

		// does the next token extend past the split point?
		if (left_extent + token_extent > split_point) {
			// if it was the first token, split the token itself
			if (first_component && left_len == 0)
				left_len = ceguimax(static_cast<size_t>(1), fnt->getCharAtPixel(d_text.substr(0, token_len), split_point));

			// left_len is now the character index at which to split the line
			break;
		}

		// add this token to the left side
		left_len += token_len;
		left_extent += token_extent;
	}

	// perform the split.
	lhs->d_text = d_text.substr(0, left_len);

	// here we're trimming leading delimiters from the substring range
	size_t rhs_start = d_text.find_first_not_of(TextUtils::DefaultWrapDelimiters, left_len);
	if (rhs_start == String::npos)
		rhs_start = left_len;

	d_text = d_text.substr(rhs_start);

	return lhs;
}
    void ScrollablePane::configureScrollbars(void)
    {
        // controls should all be valid by this stage
        assert(d_container != 0);
        assert(d_vertScrollbar != 0);
        assert(d_horzScrollbar != 0);

        // enable required scrollbars
        d_vertScrollbar->setVisible(isVertScrollbarNeeded());
        d_horzScrollbar->setVisible(isHorzScrollbarNeeded());

        // Check if the addition of the horizontal scrollbar means we
        // now also need the vertical bar.
        if (d_horzScrollbar->isVisible())
        {
            d_vertScrollbar->setVisible(isVertScrollbarNeeded());
        }

        performChildWindowLayout();

        // get viewable area
        Rect viewableArea(getViewableArea());
		if( d_vertScrollbar )
		{
			// set up vertical scroll bar values
			d_vertScrollbar->setDocumentSize(fabsf(d_contentRect.getHeight()));
			d_vertScrollbar->setPageSize(viewableArea.getHeight());
			d_vertScrollbar->setStepSize(ceguimax(1.0f, viewableArea.getHeight() * d_vertStep));
			d_vertScrollbar->setOverlapSize(ceguimax(1.0f, viewableArea.getHeight() * d_vertOverlap));
			d_vertScrollbar->setScrollPosition(d_vertScrollbar->getScrollPosition());
		}

		if( d_horzScrollbar )
		{
				// set up horizontal scroll bar values
			d_horzScrollbar->setDocumentSize(fabsf(d_contentRect.getWidth()));
			d_horzScrollbar->setPageSize(viewableArea.getWidth());
			d_horzScrollbar->setStepSize(ceguimax(1.0f, viewableArea.getWidth() * d_horzStep));
			d_horzScrollbar->setOverlapSize(ceguimax(1.0f, viewableArea.getWidth() * d_horzOverlap));
			d_horzScrollbar->setScrollPosition(d_horzScrollbar->getScrollPosition());	
		}
    }
Exemple #12
0
/*************************************************************************
	Perform the actual rendering for this Window.
*************************************************************************/
void Listbox::populateRenderCache()
{
    // get the derived class to render general stuff before we handle the items
    cacheListboxBaseImagery();

    //
    // Render list items
    //
    Vector3	itemPos;
    Size	itemSize;
    Rect	itemClipper, itemRect;
    float	widest = getWidestItemWidth();

    // calculate position of area we have to render into
    Rect itemsArea(getListRenderArea());

    // set up some initial positional details for items
    itemPos.d_x = itemsArea.d_left - d_horzScrollbar->getScrollPosition();
    itemPos.d_y = itemsArea.d_top - d_vertScrollbar->getScrollPosition();
    itemPos.d_z = System::getSingleton().getRenderer()->getZLayer(3) - System::getSingleton().getRenderer()->getCurrentZ();

    float alpha = getEffectiveAlpha();

    // loop through the items
    size_t itemCount = getItemCount();

    for (size_t i = 0; i < itemCount; ++i)
    {
        itemSize.d_height = d_listItems[i]->getPixelSize().d_height;

        // allow item to have full width of box if this is wider than items
        itemSize.d_width = ceguimax(itemsArea.getWidth(), widest);

        // calculate destination area for this item.
        itemRect.d_left	= itemPos.d_x;
        itemRect.d_top	= itemPos.d_y;
        itemRect.setSize(itemSize);
        itemClipper = itemRect.getIntersection(itemsArea);

        // skip this item if totally clipped
        if (itemClipper.getWidth() == 0)
        {
            itemPos.d_y += itemSize.d_height;
            continue;
        }

        // draw this item
        d_listItems[i]->draw(d_renderCache, itemRect, itemPos.d_z, alpha, &itemClipper);

        // update position ready for next item
        itemPos.d_y += itemSize.d_height;
    }

}
Exemple #13
0
float colour::getSaturation(void) const
{
	float pMax = ceguimax(ceguimax(d_red, d_green), d_blue);
	float pMin = ceguimin(ceguimin(d_red, d_green), d_blue);

	float pLum = (pMax + pMin) / 2;
	float pSat;

	if( pMax == pMin )
	{
		pSat = 0;
	}
	else
	{
		if( pLum < 0.5 )
			pSat = (pMax - pMin) / (pMax + pMin);
		else
			pSat = (pMax - pMin) / (2 - pMax - pMin);
	}

	return pSat;
}
Exemple #14
0
    void Spinner::setCurrentValue(float value)
    {
        if (value != d_currentValue)
        {
            // limit input value to within valid range for spinner
            value = ceguimax(ceguimin(value, d_maxValue), d_minValue);

            d_currentValue = value;

            WindowEventArgs args(this);
            onValueChanged(args);
        }
    }
Exemple #15
0
float colour::getHue(void) const
{
	float pRed = d_red;
	float pGreen = d_green;
	float pBlue = d_blue;

	float pMax = ceguimax(ceguimax(d_red, d_green), d_blue);
	float pMin = ceguimin(ceguimin(d_red, d_green), d_blue);

	float pHue;

	if( pMax == pMin )
	{
		pHue = 0;
	}
	else
	{
		if( pMax == pRed )
		{
			pHue = (pGreen - pBlue) / (pMax - pMin);
		}
		else if( pMax == pGreen )
		{
			pHue = 2 + (pBlue - pRed) / (pMax - pMin);
		}
		else
		{
			pHue = 4 + (pRed - pGreen) / (pMax - pMin);
		}
	}

	float Hue = pHue / 6;
	if( Hue < 0 )
		Hue += 1;

	return Hue;
}
//----------------------------------------------------------------------------//
Size Direct3D9Renderer::getAdjustedSize(const Size& sz)
{
    Size s(sz);

    if (!d_supportNPOTTex)
    {
        s.d_width  = getSizeNextPOT(sz.d_width);
        s.d_height = getSizeNextPOT(sz.d_height);
    }
    if (!d_supportNonSquareTex)
        s.d_width = s.d_height =
                        ceguimax(s.d_width, s.d_height);

    return s;
}
Exemple #17
0
void GuiChat::historiqueHaut()
{
	CEGUI::Editbox* editbox = static_cast<CEGUI::Editbox*>(chatWindow->getChild("Editbox"));
	d_historyPos = ceguimax(d_historyPos - 1, -1);
	if (d_historyPos >= 0)
	{
		editbox->setText(d_history[d_historyPos]);
		editbox->setCaretIndex(static_cast<size_t>(-1));
	}
	else
	{
		editbox->setText("");
	}

	editbox->activate();
}
//----------------------------------------------------------------------------//
Size IrrlichtRenderer::getAdjustedTextureSize(const Size& sz) const
{
    Size out(sz);

    // if we can't support non power of two sizes, get appropriate POT values.
    if (!d_supportsNPOTTextures)
    {
        out.d_width = getNextPOTSize(out.d_width);
        out.d_height = getNextPOTSize(out.d_height);
    }

    // if we can't support non square textures, make size square.
    if (!d_supportsNSquareTextures)
        out.d_width = out.d_height = ceguimax(out.d_width, out.d_height);

    return out;
}
Exemple #19
0
	void FalagardChatHistory::configureScrollbars()
	{
		// no scrollbars?  Can't configure then!
		if(!d_vertScrollbar) return;

		Rect initialArea(getTextRenderArea());

		//
		// Set up scroll bar values
		//
		Rect renderArea(getTextRenderArea());

		d_vertScrollbar->setDocumentSize(d_totalHeight);
		d_vertScrollbar->setPageSize(renderArea.getHeight());
		d_vertScrollbar->setStepSize(ceguimax(1.0f, renderArea.getHeight() / 10.0f));
		d_vertScrollbar->setScrollPosition(d_vertScrollbar->getScrollPosition());

		requestRedraw();
		d_parentWindow->requestRedraw();
	}
Exemple #20
0
/*************************************************************************
	Set the current position of scroll bar within the document.
*************************************************************************/
void Scrollbar::setScrollPosition(float position)
{
	float old_pos = d_position;

	// max position is (docSize - pageSize), but must be at least 0 (in case doc size is very small)
	float max_pos = ceguimax((d_documentSize - d_pageSize), 0.0f);

	// limit position to valid range:  0 <= position <= max_pos
	d_position = (position >= 0) ? ((position <= max_pos) ? position : max_pos) : 0.0f;

	updateThumb();

	// notification if required
	if (d_position != old_pos)
	{
		WindowEventArgs args(this);
		onScrollPositionChanged(args);
	}

}
//----------------------------------------------------------------------------//
void TreeView::fillRenderingState(TreeViewItemRenderingState& item,
    const ModelIndex& index, float& rendered_max_width, float& rendered_total_height)
{
    String text = d_itemModel->getData(index);
    RenderedString rendered_string = getRenderedStringParser().parse(
        text, getFont(), &d_textColourRect);
    item.d_string = rendered_string;
    item.d_text = text;
    item.d_icon = d_itemModel->getData(index, IDR_Icon);

    item.d_size = Sizef(
        rendered_string.getHorizontalExtent(this),
        rendered_string.getVerticalExtent(this));

    float indent = getViewRenderer()->getSubtreeExpanderXIndent(item.d_nestedLevel) +
        getViewRenderer()->getSubtreeExpanderSize().d_width;
    rendered_max_width = ceguimax(rendered_max_width, item.d_size.d_width + indent);
    rendered_total_height += item.d_size.d_height;

    item.d_isSelected = isIndexSelected(index);
}
Exemple #22
0
//----------------------------------------------------------------------------//
float Font::getTextExtent(const String& text, float x_scale) const
{
    const FontGlyph* glyph;
    float cur_extent = 0, adv_extent = 0, width;

    for (size_t c = 0; c < text.length(); ++c)
    {
        glyph = getGlyphData(text[c]);

        if (glyph)
        {
            width = glyph->getRenderedAdvance(x_scale);

            if (adv_extent + width > cur_extent)
                cur_extent = adv_extent + width;

            adv_extent += glyph->getAdvance(x_scale);
        }
    }

    return ceguimax(adv_extent, cur_extent);
}
    Rectf ImagerySection::getBoundingRect(const Window& wnd, const Rectf& rect) const
    {
        Rectf compRect;
        Rectf bounds(std::numeric_limits<float>::max(), 
                     std::numeric_limits<float>::max(),
                     std::numeric_limits<float>::min(),
                     std::numeric_limits<float>::min());

        // measure all frame components
        for(FrameList::const_iterator frame = d_frames.begin(); frame != d_frames.end(); ++frame)
        {
            compRect = (*frame).getComponentArea().getPixelRect(wnd, rect);

            bounds.left(ceguimin(bounds.left(), compRect.left()));
            bounds.top(ceguimin(bounds.top(), compRect.top()));
            bounds.right(ceguimax(bounds.right(), compRect.right()));
            bounds.bottom(ceguimax(bounds.bottom(), compRect.bottom()));
        }
        // measure all imagery components
        for(ImageryList::const_iterator image = d_images.begin(); image != d_images.end(); ++image)
        {
            compRect = (*image).getComponentArea().getPixelRect(wnd, rect);

            bounds.left(ceguimin(bounds.left(), compRect.left()));
            bounds.top(ceguimin(bounds.top(), compRect.top()));
            bounds.right(ceguimax(bounds.right(), compRect.right()));
            bounds.bottom(ceguimax(bounds.bottom(), compRect.bottom()));
        }
        // measure all text components
        for(TextList::const_iterator text = d_texts.begin(); text != d_texts.end(); ++text)
        {
            compRect = (*text).getComponentArea().getPixelRect(wnd, rect);

            bounds.left(ceguimin(bounds.left(), compRect.left()));
            bounds.top(ceguimin(bounds.top(), compRect.top()));
            bounds.right(ceguimax(bounds.right(), compRect.right()));
            bounds.bottom(ceguimax(bounds.bottom(), compRect.bottom()));
        }

        return bounds;
    }
Exemple #24
0
/*************************************************************************
	display required integrated scroll bars according to current state
	of the list box and update their values.
*************************************************************************/
void Listbox::configureScrollbars(void)
{
    Scrollbar* vertScrollbar;
    Scrollbar* horzScrollbar;

    try
    {
        vertScrollbar = static_cast<Scrollbar*>(WindowManager::getSingleton().getWindow(getName() + "__auto_vscrollbar__"));
        horzScrollbar = static_cast<Scrollbar*>(WindowManager::getSingleton().getWindow(getName() + "__auto_hscrollbar__"));
    }
    catch (UnknownObjectException)
    {
        // no scrollbars?  Can't configure then!
        return;
    }

	float totalHeight	= getTotalItemsHeight();
	float widestItem	= getWidestItemWidth();

	//
	// First show or hide the scroll bars as needed (or requested)
	//
	// show or hide vertical scroll bar as required (or as specified by option)
	if ((totalHeight > getListRenderArea().getHeight()) || d_forceVertScroll)
	{
		vertScrollbar->show();

		// show or hide horizontal scroll bar as required (or as specified by option)
		if ((widestItem > getListRenderArea().getWidth()) || d_forceHorzScroll)
		{
			horzScrollbar->show();
		}
		else
		{
			horzScrollbar->hide();
		}

	}
	else
	{
		// show or hide horizontal scroll bar as required (or as specified by option)
		if ((widestItem > getListRenderArea().getWidth()) || d_forceHorzScroll)
		{
			horzScrollbar->show();

			// show or hide vertical scroll bar as required (or as specified by option)
			if ((totalHeight > getListRenderArea().getHeight()) || d_forceVertScroll)
			{
				vertScrollbar->show();
			}
			else
			{
				vertScrollbar->hide();
			}

		}
		else
		{
			vertScrollbar->hide();
			horzScrollbar->hide();
		}

	}

	//
	// Set up scroll bar values
	//
	Rect renderArea(getListRenderArea());

	vertScrollbar->setDocumentSize(totalHeight);
	vertScrollbar->setPageSize(renderArea.getHeight());
	vertScrollbar->setStepSize(ceguimax(1.0f, renderArea.getHeight() / 10.0f));
	vertScrollbar->setScrollPosition(vertScrollbar->getScrollPosition());

	horzScrollbar->setDocumentSize(widestItem);
	horzScrollbar->setPageSize(renderArea.getWidth());
	horzScrollbar->setStepSize(ceguimax(1.0f, renderArea.getWidth() / 10.0f));
	horzScrollbar->setScrollPosition(horzScrollbar->getScrollPosition());
}
//----------------------------------------------------------------------------//
void FalagardTreeView::renderTreeItem(TreeView* tree_view, const Rectf& items_area,
    glm::vec2& item_pos, const TreeViewItemRenderingState* item_to_render,
    size_t depth)
{
    float expander_margin = tree_view->getSubtreeExpanderMargin();
    for (size_t i = 0; i < item_to_render->d_renderedChildren.size(); ++i)
    {
        TreeViewItemRenderingState* item = item_to_render->d_renderedChildren.at(i);
        RenderedString& rendered_string = item->d_string;
        Sizef size(item->d_size);

        // center the expander compared to the item's height
        float half_diff = (size.d_height - d_subtreeExpanderImagerySize.d_height) / 2.0f;

        size.d_width = ceguimax(items_area.getWidth(), size.d_width);
        float indent = d_subtreeExpanderImagerySize.d_width + expander_margin * 2;
        if (item->d_totalChildCount > 0)
        {
            const ImagerySection* section = item->d_subtreeIsExpanded
                ? d_subtreeCollapserImagery : d_subtreeExpanderImagery;

            Rectf button_rect;
            button_rect.left(item_pos.x + expander_margin);
            button_rect.top(item_pos.y +
                (half_diff > 0 ? half_diff : 0));
            button_rect.setSize(d_subtreeExpanderImagerySize);

            Rectf button_clipper(button_rect.getIntersection(items_area));
            section->render(*tree_view, button_rect, 0, &button_clipper);

            indent = button_rect.getWidth() + expander_margin * 2;
        }

        Rectf item_rect;
        item_rect.left(item_pos.x + indent);
        item_rect.top(item_pos.y + (half_diff < 0 ? -half_diff : 0));
        item_rect.setSize(size);

        if (!item->d_icon.empty())
        {
            Image& img = ImageManager::getSingleton().get(item->d_icon);

            Rectf icon_rect(item_rect);
            icon_rect.setWidth(size.d_height);
            icon_rect.setHeight(size.d_height);

            Rectf icon_clipper(icon_rect.getIntersection(items_area));
            img.render(tree_view->getGeometryBuffers(), icon_rect, &icon_clipper,
                true, ICON_COLOUR_RECT, 1.0f);

            item_rect.left(item_rect.left() + icon_rect.getWidth());
        }

        Rectf item_clipper(item_rect.getIntersection(items_area));
        renderString(tree_view, rendered_string, item_rect,
            tree_view->getFont(), &item_clipper, item->d_isSelected);

        item_pos.y += ceguimax(size.d_height, d_subtreeExpanderImagerySize.d_height);

        if (item->d_renderedChildren.empty())
            continue;

        item_pos.x += indent;

        if (item->d_subtreeIsExpanded)
        {
            renderTreeItem(tree_view, items_area, item_pos, item, depth + 1);
        }

        item_pos.x -= indent;
    }
}
//----------------------------------------------------------------------------//
float Scrollbar::getMaxScrollPosition() const
{
    // max position is (docSize - pageSize)
    // but must be at least 0 (in case doc size is very small)
    return ceguimax((d_documentSize - d_pageSize), 0.0f);
}
/*************************************************************************
	display required integrated scroll bars according to current state
	of the list box and update their values.
*************************************************************************/
void Listbox::configureScrollbars(void)
{
    Scrollbar* vertScrollbar = getVertScrollbar();
    Scrollbar* horzScrollbar = getHorzScrollbar();

	float totalHeight	= getTotalItemsHeight();
	float widestItem	= getWidestItemWidth();

	//
	// First show or hide the scroll bars as needed (or requested)
	//
	// show or hide vertical scroll bar as required (or as specified by option)
	if ((totalHeight > getListRenderArea().getHeight()) || d_forceVertScroll)
	{
		vertScrollbar->show();

		// show or hide horizontal scroll bar as required (or as specified by option)
		if ((widestItem > getListRenderArea().getWidth()) || d_forceHorzScroll)
		{
			horzScrollbar->show();
		}
		else
		{
			horzScrollbar->hide();
		}

	}
	else
	{
		// show or hide horizontal scroll bar as required (or as specified by option)
		if ((widestItem > getListRenderArea().getWidth()) || d_forceHorzScroll)
		{
			horzScrollbar->show();

			// show or hide vertical scroll bar as required (or as specified by option)
			if ((totalHeight > getListRenderArea().getHeight()) || d_forceVertScroll)
			{
				vertScrollbar->show();
			}
			else
			{
				vertScrollbar->hide();
			}

		}
		else
		{
			vertScrollbar->hide();
			horzScrollbar->hide();
		}

	}

	//
	// Set up scroll bar values
	//
	Rect renderArea(getListRenderArea());

	vertScrollbar->setDocumentSize(totalHeight);
	vertScrollbar->setPageSize(renderArea.getHeight());
	vertScrollbar->setStepSize(ceguimax(1.0f, renderArea.getHeight() / 10.0f));
	vertScrollbar->setScrollPosition(vertScrollbar->getScrollPosition());

	horzScrollbar->setDocumentSize(widestItem);
	horzScrollbar->setPageSize(renderArea.getWidth());
	horzScrollbar->setStepSize(ceguimax(1.0f, renderArea.getWidth() / 10.0f));
	horzScrollbar->setScrollPosition(horzScrollbar->getScrollPosition());
}
Exemple #28
0
/*************************************************************************
    Renders text on the display.  Return number of lines output.
*************************************************************************/
size_t Font::drawText(const String& text, const Rect& draw_area, float z, const Rect& clip_rect, TextFormatting fmt, const ColourRect& colours, float x_scale, float y_scale)
{
    size_t thisCount;
    size_t lineCount = 0;

    float	y_base = draw_area.d_top + getBaseline(y_scale);

    Rect tmpDrawArea(
        PixelAligned(draw_area.d_left),
        PixelAligned(draw_area.d_top),
        PixelAligned(draw_area.d_right),
        PixelAligned(draw_area.d_bottom)
    );

    size_t lineStart = 0, lineEnd = 0;
    String	currLine;

    while (lineEnd < text.length())
    {
        if ((lineEnd = text.find_first_of('\n', lineStart)) == String::npos)
            lineEnd = text.length();

        currLine = text.substr(lineStart, lineEnd - lineStart);
        lineStart = lineEnd + 1;	// +1 to skip \n char

        switch(fmt)
        {
        case LeftAligned:
            drawTextLine(currLine, Vector3(tmpDrawArea.d_left, y_base, z), clip_rect, colours, x_scale, y_scale);
            thisCount = 1;
            y_base += getLineSpacing(y_scale);
            break;

        case RightAligned:
            drawTextLine(currLine, Vector3(tmpDrawArea.d_right - getTextExtent(currLine, x_scale), y_base, z), clip_rect, colours, x_scale, y_scale);
            thisCount = 1;
            y_base += getLineSpacing(y_scale);
            break;

        case Centred:
            drawTextLine(currLine, Vector3(PixelAligned(tmpDrawArea.d_left + ((tmpDrawArea.getWidth() - getTextExtent(currLine, x_scale)) / 2.0f)), y_base, z), clip_rect, colours, x_scale, y_scale);
            thisCount = 1;
            y_base += getLineSpacing(y_scale);
            break;

        case Justified:
            // new function in order to keep drawTextLine's signature unchanged
            drawTextLineJustified(currLine, draw_area, Vector3(tmpDrawArea.d_left, y_base, z), clip_rect, colours, x_scale, y_scale);
            thisCount = 1;
            y_base += getLineSpacing(y_scale);
            break;

        case WordWrapLeftAligned:
            thisCount = drawWrappedText(currLine, tmpDrawArea, z, clip_rect, LeftAligned, colours, x_scale, y_scale);
            tmpDrawArea.d_top += thisCount * getLineSpacing(y_scale);
            break;

        case WordWrapRightAligned:
            thisCount = drawWrappedText(currLine, tmpDrawArea, z, clip_rect, RightAligned, colours, x_scale, y_scale);
            tmpDrawArea.d_top += thisCount * getLineSpacing(y_scale);
            break;

        case WordWrapCentred:
            thisCount = drawWrappedText(currLine, tmpDrawArea, z, clip_rect, Centred, colours, x_scale, y_scale);
            tmpDrawArea.d_top += thisCount * getLineSpacing(y_scale);
            break;

        case WordWrapJustified:
            // no change needed
            thisCount = drawWrappedText(currLine, tmpDrawArea, z, clip_rect, Justified, colours, x_scale, y_scale);
            tmpDrawArea.d_top += thisCount * getLineSpacing(y_scale);
            break;

        default:
            throw InvalidRequestException("Font::drawText - Unknown or unsupported TextFormatting value specified.");
        }

        lineCount += thisCount;

    }

    // should not return 0
    return ceguimax(lineCount, (size_t)1);
}
/*************************************************************************
	display required integrated scroll bars according to current state
	of the edit box and update their values.
*************************************************************************/
void MultiLineEditbox::configureScrollbars(void)
{
	float totalHeight	= (float)d_lines.size() * getFont()->getLineSpacing();
	float widestItem	= d_widestExtent;

	//
	// First show or hide the scroll bars as needed (or requested)
	//
	// show or hide vertical scroll bar as required (or as specified by option)
	if ((totalHeight > getTextRenderArea().getHeight()) || d_forceVertScroll)
	{
		d_vertScrollbar->show();

		// show or hide horizontal scroll bar as required (or as specified by option)
		if ((widestItem > getTextRenderArea().getWidth()) || d_forceHorzScroll)
		{
			d_horzScrollbar->show();
		}
		else
		{
			d_horzScrollbar->hide();
		}

	}
	else
	{
		// show or hide horizontal scroll bar as required (or as specified by option)
		if ((widestItem > getTextRenderArea().getWidth()) || d_forceHorzScroll)
		{
			d_horzScrollbar->show();

			// show or hide vertical scroll bar as required (or as specified by option)
			if ((totalHeight > getTextRenderArea().getHeight()) || d_forceVertScroll)
			{
				d_vertScrollbar->show();
			}
			else
			{
				d_vertScrollbar->hide();
			}

		}
		else
		{
			d_vertScrollbar->hide();
			d_horzScrollbar->hide();
		}

	}

	//
	// Set up scroll bar values
	//
	Rect renderArea(getTextRenderArea());

	d_vertScrollbar->setDocumentSize(totalHeight);
	d_vertScrollbar->setPageSize(renderArea.getHeight());
	d_vertScrollbar->setStepSize(ceguimax(1.0f, renderArea.getHeight() / 10.0f));
	d_vertScrollbar->setScrollPosition(d_vertScrollbar->getScrollPosition());

	d_horzScrollbar->setDocumentSize(widestItem);
	d_horzScrollbar->setPageSize(renderArea.getWidth());
	d_horzScrollbar->setStepSize(ceguimax(1.0f, renderArea.getWidth() / 10.0f));
	d_horzScrollbar->setScrollPosition(d_horzScrollbar->getScrollPosition());
}
Exemple #30
0
/*************************************************************************
    display required integrated scroll bars according to current state
    of the tree and update their values.
*************************************************************************/
void Tree::configureScrollbars(void)
{
    Rectf renderArea(getTreeRenderArea());
    
    //This is becuase CEGUI IS GAY! and fires events before the item is initialized
    if(!d_vertScrollbar)
        d_vertScrollbar = createVertScrollbar("__auto_vscrollbar__");
    if(!d_horzScrollbar)
        d_horzScrollbar = createHorzScrollbar("__auto_hscrollbar__");
    
    float totalHeight = getTotalItemsHeight();
    float widestItem  = getWidestItemWidth() + 20;
    
    //
    // First show or hide the scroll bars as needed (or requested)
    //
    // show or hide vertical scroll bar as required (or as specified by option)
    if ((totalHeight > renderArea.getHeight()) || d_forceVertScroll)
    {
        d_vertScrollbar->show();
        renderArea.d_max.d_x -= d_vertScrollbar->getWidth().d_offset + d_vertScrollbar->getXPosition().d_offset;
        // show or hide horizontal scroll bar as required (or as specified by option)
        if ((widestItem > renderArea.getWidth()) || d_forceHorzScroll)
        {
            d_horzScrollbar->show();
            renderArea.d_max.d_y -= d_horzScrollbar->getHeight().d_offset;
        }
        else
        {
            d_horzScrollbar->hide();
            d_horzScrollbar->setScrollPosition(0);
        }
    }
    else
    {
        // show or hide horizontal scroll bar as required (or as specified by option)
        if ((widestItem > renderArea.getWidth()) || d_forceHorzScroll)
        {
            d_horzScrollbar->show();
            renderArea.d_max.d_y -= d_vertScrollbar->getHeight().d_offset;
            
            // show or hide vertical scroll bar as required (or as specified by option)
            if ((totalHeight > renderArea.getHeight()) || d_forceVertScroll)
            {
                d_vertScrollbar->show();
                //            renderArea.d_right -= d_vertScrollbar->getAbsoluteWidth();
                renderArea.d_max.d_x -= d_vertScrollbar->getWidth().d_offset;
            }
            else
            {
                d_vertScrollbar->hide();
                d_vertScrollbar->setScrollPosition(0);
            }
        }
        else
        {
            d_vertScrollbar->hide();
            d_vertScrollbar->setScrollPosition(0);
            d_horzScrollbar->hide();
            d_horzScrollbar->setScrollPosition(0);
        }
    }
    
    //
    // Set up scroll bar values
    //
    
    float itemHeight;
    if (!d_listItems.empty())
        itemHeight = d_listItems[0]->getPixelSize().d_height;
    else
        itemHeight = 10;
    
    d_vertScrollbar->setDocumentSize(totalHeight);
    d_vertScrollbar->setPageSize(renderArea.getHeight());
    d_vertScrollbar->setStepSize(ceguimax(1.0f, renderArea.getHeight() / itemHeight));
    d_vertScrollbar->setScrollPosition(d_vertScrollbar->getScrollPosition());
    
    d_horzScrollbar->setDocumentSize(widestItem + d_vertScrollbar->getWidth().d_offset);
    //   d_horzScrollbar->setDocumentSize(widestItem + d_vertScrollbar->getAbsoluteWidth());
    d_horzScrollbar->setPageSize(renderArea.getWidth());
    d_horzScrollbar->setStepSize(ceguimax(1.0f, renderArea.getWidth() / HORIZONTAL_STEP_SIZE_DIVISOR));
    d_horzScrollbar->setScrollPosition(d_horzScrollbar->getScrollPosition());
}