/*
 * PopUp.cpp
 *
 *  Created on: 2009-07-11
 *      Author: wasyl
 */

#include <allegro5/allegro.h>
#include <allegro5/a5_primitives.h>
#include "../prep/res/Resources.h"
#include "PopUp.h"

PopUp::PopUp()
{
	mShown = false;
	mWorld = NULL;
	Resources::load(mFont, "media/font.ttf");
}

PopUp::~PopUp()
{
}

void PopUp::render()
{
	if (mShown)
	{
		al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba(255, 255, 255, 160));
		al_draw_filled_rectangle(5.0, 5.0, 795.0, 15.0 + lines.size() * 18.0, al_map_rgb(0,0,0));
		al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba(255, 255, 255, 192));
		al_draw_rectangle(5.0, 5.0, 796.0, 15.0 + lines.size() * 18.0, al_map_rgb(0,0,0), 2.0);
		al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba(255, 255, 255, 255));

		for (int y = 0; y < lines.size(); y++)
		{
			al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba(0,0,0,255));
			al_draw_text(mFont, 12.0, 13.0 + y * 18.0, 0, lines[y].left.c_str());
			al_draw_text(mFont, 788.0, 13.0 + y * 18.0, ALLEGRO_ALIGN_RIGHT, lines[y].right.c_str());
			if (lines[y].right != std::string(" "))
			{
				al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba(255, 255, 255, 255));
				al_draw_text(mFont, 12.0, 12.0 + y * 18.0, 0, lines[y].left.c_str());
				al_draw_text(mFont, 788.0, 12.0 + y * 18.0, ALLEGRO_ALIGN_RIGHT, lines[y].right.c_str());
			}
			else
			{
				al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba(255, 255, 0, 255));
				al_draw_text(mFont, 12.0, 12.0 + y * 18.0, 0, lines[y].left.c_str());
				al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, al_map_rgba(255, 255, 0, 255));
			}
		}
	}
}

