Ejemplo n.º 1
0
void ProgressBar::render(const Rect& finalRect, const Rect& finalClip)
{
	Renderer& r = m_system.getRenderer();

	// rendering caption
	float left = 0;
	float right = 0;
	float height = 0;
	
	Size imgSize;
	Rect targetRect(finalClip);
	if(m_signed)
	{
		float offset = targetRect.getWidth() / 2.f;
		targetRect.setWidth(offset);
		if(m_progress > 0.f)
			targetRect.offset(point(offset, 0.f));
	}
	Rect clip(targetRect);

	if(fabs(m_progress) > 1.f)
	{
		m_progress > 0.f ? m_progress = 1.f : m_progress = -1.f;
	}

	float clipsize = clip.getWidth() * fabs(m_progress);
	clip.setWidth(clipsize);
	
	if(m_progress < 0.f)
	{
		clip.m_left = targetRect.m_right - clipsize;
		clip.m_right = targetRect.m_right;
	}	

	Rect componentRect(targetRect);

	if (m_leftImg)
    {
        // calculate final destination area
		imgSize = m_leftImg->size();
		componentRect.m_right = componentRect.m_left + imgSize.width;
		componentRect.m_bottom = componentRect.m_top + imgSize.height;
		left  = imgSize.width;
		height = imgSize.height;

        // draw this element.
		r.draw(*m_leftImg, componentRect, 1.f, clip, m_backColor, ImageOps::Stretch, ImageOps::Stretch);
    }
	componentRect = targetRect;
	// right image
    if (m_rightImg)
    {
		imgSize = m_rightImg->size();
        componentRect.m_left = componentRect.m_right - imgSize.width;
        componentRect.m_bottom = componentRect.m_top + imgSize.height;

		right = imgSize.width;

        // draw this element.
		r.draw(*m_rightImg, componentRect, 1.f, clip, m_backColor, ImageOps::Stretch, ImageOps::Stretch);
    }
	componentRect = targetRect;
	// center image
    if (m_backImg)
    {
		componentRect.m_left += left;
		componentRect.m_right -= right;
		componentRect.m_bottom = componentRect.m_top + height;
        
		// draw this element.
		r.draw(*m_backImg, componentRect, 1.f, clip, m_backColor, ImageOps::Tile, ImageOps::Stretch);
    }

	Progress::render(finalRect, finalClip);
}
Ejemplo n.º 2
0
	void ScrollBar::render(const Rect& finalRect, const Rect& finalClip)
	{
		float left = 0;
		float right = 0;
		Rect componentRect(finalRect);
		Size imgSize;

		Renderer& r = m_system.getRenderer();

		if(m_horiz)
		{
			// left image
			if (m_leftImg)
			{
				// calculate final destination area
				imgSize = m_leftImg->GetSize();
				componentRect.m_left = finalRect.m_left;
				componentRect.m_top  = finalRect.m_top;
				componentRect.setSize(imgSize);
				componentRect = finalRect.getIntersection (componentRect);
				left  = imgSize.width;

				// draw this element.
				r.draw(*m_leftImg, componentRect, 1.f, finalClip,  m_backColor, Stretch, Stretch);
			}
			// right image
			if (m_rightImg)
			{
				imgSize = m_rightImg->GetSize();
				componentRect.m_left = finalRect.m_right - imgSize.width;
				componentRect.m_top  = finalRect.m_top;
				componentRect.setSize(imgSize);
				componentRect = finalRect.getIntersection (componentRect);

				right = imgSize.width;

				// draw this element.
				r.draw(*m_rightImg, componentRect, 1.f, finalClip,  m_backColor, Stretch, Stretch);
			}
			// center image
			if (m_backImg)
			{
				componentRect = finalRect;
				componentRect.m_left += left;
				componentRect.m_right -= right;
		        
				// draw this element.
				r.draw(*m_backImg, componentRect, 1.f, finalClip,  m_backColor, Tile, Stretch);
			}
		}
		else
		{
			// top image
			if (m_leftImg)
			{
				// calculate final destination area
				imgSize = m_leftImg->GetSize();
				componentRect.m_left = finalRect.m_left;
				componentRect.m_top  = finalRect.m_top;
				componentRect.setSize(imgSize);
				componentRect = finalRect.getIntersection (componentRect);
				left  = imgSize.height;

				// draw this element.
				r.draw(*m_leftImg, componentRect, 1.f, finalClip,  m_backColor, Stretch, Stretch);
			}
			// bottom image
			if (m_rightImg)
			{
				imgSize = m_rightImg->GetSize();
				componentRect.m_left = finalRect.m_left;
				componentRect.m_top  = finalRect.m_bottom - imgSize.height;
				componentRect.setSize(imgSize);
				componentRect = finalRect.getIntersection (componentRect);

				right = imgSize.height;

				// draw this element.
				r.draw(*m_rightImg, componentRect, 1.f, finalClip,  m_backColor, Stretch, Stretch);
			}
			// center image
			if (m_backImg)
			{
				componentRect = finalRect;
				componentRect.m_top += left;
				componentRect.m_bottom -= right;
		        
				// draw this element.
				r.draw(*m_backImg, componentRect, 1.f, finalClip,  m_backColor, Stretch, Tile);
			}
		}
	}