// Renders the element's background, if it has one.
void ElementBackground::RenderBackground()
{
	if (background_dirty)
	{
		background_dirty = false;
		GenerateBackground();
	}

	geometry.Render(element->GetAbsoluteOffset(Box::PADDING));
}
Exemple #2
0
void Menu::Begin()
{
	menutime = 0;
	sliderindex = 0;
	slidertarget = 0;
	rendertime = 0;

	titlefont = FontCache::LoadFont( "resources/armalite.ttf", 80 );
	optionfont = FontCache::LoadFont( "resources/armalite.ttf", 32 );

    background = nullptr;
    GenerateBackground();

	// AUDIO->PlayMusic( "resources/Paul Hannay (Feekzoid) - Last_Ninja_4_intro [1].ogg", true );
}
// Generates the background geometry for the element.
void ElementBackground::GenerateBackground()
{
	// Fetch the new colour for the background. If the colour is transparent, then we don't render any background.
	Colourb colour = element->GetProperty(BACKGROUND_COLOR)->value.Get< Colourb >();
	float opacity = element->GetProperty<float>(OPACITY);

	// Apply opacity
	colour.alpha = (byte)(opacity * (float)colour.alpha);

	if (colour.alpha <= 0)
	{
		geometry.GetVertices().clear();
		geometry.GetIndices().clear();
		geometry.Release();

		return;
	}

	// Work out how many boxes we need to generate geometry for.
	int num_boxes = 0;

	for (int i = 0; i < element->GetNumBoxes(); ++i)
	{
		const Box& box = element->GetBox(i);
		Vector2f size = box.GetSize(Box::PADDING);
		if (size.x > 0 && size.y > 0)
			num_boxes++;
	}

	std::vector< Vertex >& vertices = geometry.GetVertices();
	std::vector< int >& indices = geometry.GetIndices();

	int index_offset = 0;
	vertices.resize(4 * num_boxes);
	indices.resize(6 * num_boxes);

	if (num_boxes > 0)
	{
		Vertex* raw_vertices = &vertices[0];
		int* raw_indices = &indices[0];

		for (int i = 0; i < element->GetNumBoxes(); ++i)
			GenerateBackground(raw_vertices, raw_indices, index_offset, element->GetBox(i), colour);
	}

	geometry.Release();
}