Exemplo n.º 1
0
/**\brief Draws the StatusBar
 * \param x x-coordinate
 * \param y y-coordinate
 *
 * \bug This can segfault with an empty title.
 */
void StatusBar::Draw(int x, int y) {
	int widthRemaining = this->width;
	Image *BorderLeft = Image::Get( "Resources/Graphics/hud_bar_left.png" );
	Image *BorderMiddle = Image::Get( "Resources/Graphics/hud_bar_middle.png" );
	Image *BorderRight= Image::Get( "Resources/Graphics/hud_bar_right.png" );

	if(pos==UPPER_RIGHT||pos==LOWER_RIGHT){
		x = Video::GetWidth() - BorderLeft->GetWidth() - width - BorderRight->GetWidth();
	}

	// Draw the Border
	BorderLeft->Draw(x,y);
	x += BorderLeft->GetWidth();
	BorderMiddle->DrawTiled(x,y,width, BorderMiddle->GetHeight());
	BorderRight->Draw(x+width,y);

	BitType->SetColor(1.f,1.f,1.f,1.f);

	// Draw the Title
	int wTitle = BitType->RenderTight( x, y+BorderMiddle->GetHalfHeight(), title,Font::LEFT,Font::MIDDLE );
	widthRemaining -= wTitle;
	x += wTitle + 5;

	// Draw Name
	if( !name.empty() ) {
		int wName = BitType->RenderTight( x, y+BorderMiddle->GetHalfHeight(), GetName() ,Font::LEFT,Font::MIDDLE );
		widthRemaining -= wName;
		x += wName;
	}

	// Draw the Bar
	if ( (int)(ratio*widthRemaining) > 0 ) {
		Image *BarLeft = Image::Get( "Resources/Graphics/hud_hullstr_leftbar.png" );
		Image *BarMiddle = Image::Get( "Resources/Graphics/hud_hullstr_bar.png" );
		Image *BarRight = Image::Get( "Resources/Graphics/hud_hullstr_rightbar.png" );

		int bar_y = y + BorderLeft->GetHalfHeight() - BarLeft->GetHalfHeight();
		BarLeft->Draw( x, bar_y );
		x += BarLeft->GetWidth();
		int bar_w = widthRemaining - BarLeft->GetWidth() - BarRight->GetWidth();
		BarMiddle->DrawTiled( x, bar_y,static_cast<int>(bar_w*ratio), BarMiddle->GetHeight() );
		BarRight->Draw( x + static_cast<int>(bar_w*ratio), bar_y );
	}
}
Exemplo n.º 2
0
/**\brief Draws the StatusBar
 * \param x x-coordinate
 * \param y y-coordinate
 *
 * \bug This can segfault with an empty title.
 */
void StatusBar::Draw(int x, int y) {
	int widthRemaining = this->width;

	Image *BackgroundLeft = Image::Get( "data/skin/hud_bar_left.png" );
	Image *BackgroundMiddle = Image::Get( "data/skin/hud_bar_middle.png" );
	Image *BackgroundRight= Image::Get( "data/skin/hud_bar_right.png" );

	if(pos == UPPER_RIGHT || pos == LOWER_RIGHT) {
		x = Video::GetWidth() - BackgroundLeft->GetWidth() - width - BackgroundRight->GetWidth();
	}

	// Draw the Border
	BackgroundLeft->Draw(x,y);
	x += BackgroundLeft->GetWidth();
	BackgroundMiddle->DrawTiled(x, y, width, BackgroundMiddle->GetHeight());
	BackgroundRight->Draw(x + width, y);


	// Draw the Title
	int wTitle = font->RenderTight( x, y + BackgroundMiddle->GetHalfHeight(), title, Font::LEFT, Font::MIDDLE );
	widthRemaining -= wTitle;
	x += wTitle + 5;

	// Draw Name
	int wName = font->RenderTight( x, y + BackgroundMiddle->GetHalfHeight(), name, Font::LEFT, Font::MIDDLE );
	widthRemaining -= wName;
	x += wName;

	// Draw the Bar
	if ( (int)(ratio*widthRemaining) > 0 ) {
		Image *BarLeft = Image::Get( "data/skin/hud_hullstr_leftbar.png" );
		Image *BarMiddle = Image::Get( "data/skin/hud_hullstr_bar.png" );
		Image *BarRight = Image::Get( "data/skin/hud_hullstr_rightbar.png" );

		int bar_y = y + BackgroundLeft->GetHalfHeight() - BarLeft->GetHalfHeight();
		BarLeft->Draw( x, bar_y );
		x += BarLeft->GetWidth();
		int bar_w = widthRemaining - BarLeft->GetWidth() - BarRight->GetWidth();
		BarMiddle->DrawTiled( x, bar_y,static_cast<int>(bar_w*ratio), BarMiddle->GetHeight() );
		BarRight->Draw( x + static_cast<int>(bar_w*ratio), bar_y );
	}
}