Exemplo n.º 1
0
/*************************************************************************
	Handler for mouse wheel changes
*************************************************************************/
void Listbox::onMouseWheel(MouseEventArgs& e)
{
	// base class processing.
	Window::onMouseWheel(e);

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

	if (vertScrollbar->isVisible() && (vertScrollbar->getDocumentSize() > vertScrollbar->getPageSize()))
	{
		vertScrollbar->setScrollPosition(vertScrollbar->getScrollPosition() + vertScrollbar->getStepSize() * -e.wheelChange);
	}
	else if (horzScrollbar->isVisible() && (horzScrollbar->getDocumentSize() > horzScrollbar->getPageSize()))
	{
		horzScrollbar->setScrollPosition(horzScrollbar->getScrollPosition() + horzScrollbar->getStepSize() * -e.wheelChange);
	}

	++e.handled;
}
Exemplo n.º 2
0
/*************************************************************************
	Ensure the item at the specified index is visible within the list box.
*************************************************************************/
void Listbox::ensureItemIsVisible(size_t item_index)
{
    Scrollbar* vertScrollbar = getVertScrollbar();

	// handle simple "scroll to the bottom" case
	if (item_index >= getItemCount())
	{
		vertScrollbar->setScrollPosition(vertScrollbar->getDocumentSize() - vertScrollbar->getPageSize());
	}
	else
	{
		float bottom;
		float listHeight = getListRenderArea().getHeight();
		float top = 0;

		// get height to top of item
		size_t i;
		for (i = 0; i < item_index; ++i)
		{
			top += d_listItems[i]->getPixelSize().d_height;
		}

		// calculate height to bottom of item
		bottom = top + d_listItems[i]->getPixelSize().d_height;

		// account for current scrollbar value
		float currPos = vertScrollbar->getScrollPosition();
		top		-= currPos;
		bottom	-= currPos;

		// if top is above the view area, or if item is too big to fit
		if ((top < 0.0f) || ((bottom - top) > listHeight))
		{
			// scroll top of item to top of box.
			vertScrollbar->setScrollPosition(currPos + top);
		}
		// if bottom is below the view area
		else if (bottom >= listHeight)
		{
			// position bottom of item at the bottom of the list
			vertScrollbar->setScrollPosition(currPos + bottom - listHeight);
		}

		// Item is already fully visible - nothing more to do.
	}

}
Exemplo n.º 3
0
    float FalagardScrollbar::getValueFromThumb(void) const
    {
        Scrollbar* w = (Scrollbar*)d_window;
        const WidgetLookFeel& wlf = getLookNFeel();
        const Rectf area(wlf.getNamedArea("ThumbTrackArea").getArea().getPixelRect(*w));

        Thumb* theThumb = w->getThumb();
        float posExtent = w->getDocumentSize() - w->getPageSize();

        if (d_vertical)
        {
            float slideExtent = area.getHeight() - theThumb->getPixelSize().d_height;
            return (CoordConverter::asAbsolute(theThumb->getYPosition(), w->getPixelSize().d_height) - area.top()) / (slideExtent / posExtent);
        }
        else
        {
            float slideExtent = area.getWidth() - theThumb->getPixelSize().d_width;
            return (CoordConverter::asAbsolute(theThumb->getXPosition(), w->getPixelSize().d_width) - area.left()) / (slideExtent / posExtent);
        }
    }
Exemplo n.º 4
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);
	}