


#include <flare_gui/window.h>





#include <flare_gui/widget.h>
#include <flare_gui/collision_box.h>
#include <allegro_flare/color.h>
#include <allegro5/allegro_primitives.h>





FGUIWindow::FGUIWindow(FGUIParent *parent, float x, float y, float w, float h)
	: FGUIParent(parent, new FGUICollisionBox(x, y, w, h))
	, border_color(color::color(color::aliceblue, 0.2))
	, background_color(color::mix(color::black, color::slategray, 0.5))
{
	//color::color(color::aliceblue, 0.2)
}



void FGUIWindow::on_mouse_enter()
{
	border_color = color::color(color::aliceblue, 0.9);
}



void FGUIWindow::on_mouse_leave()
{
	border_color = color::color(color::aliceblue, 0.2);
}



void FGUIWindow::on_timer()
{

}



void FGUIWindow::on_draw()
{
	placement2d &placement = collision_area->placement;
	//placement.start_transform();
	al_draw_filled_rounded_rectangle(0, 0, placement.w, placement.h, 3, 3, background_color);
	al_draw_rounded_rectangle(0, 0, placement.w, placement.h, 3, 3, border_color, 2.0);

	//for (unsigned i=0; i<children.size(); i++)
	//	children[i]->on_draw();

	//al_draw_circle(local_mouse.x, local_mouse.y, 3, color::dodgerblue, 2.0);
	//al_draw_line(0, 0, local_mouse.x, local_mouse.y, color::dodgerblue, 2.0);

	//placement.restore_transform();

	//al_draw_line(0, 0, placement.x, placement.y, color::color(color::aliceblue, 0.2), 2.0);
	//al_draw_circle(placement.x, placement.y, 5, color::color(color::aliceblue, 0.2), 2.0);
}



void FGUIWindow::on_drag(float x, float y, float dx, float dy)
{
	if (!mouse_blocked)
	{
		placement2d &placement = collision_area->placement;
		placement.x += dx;
		placement.y += dy;
	}
}




void FGUIWindow::on_focus()
{
	bring_to_front();
}



/*
void FGUIWindow::timer_func()
{
	for (unsigned i=0; i<children.size(); i++)
		children[i]->timer_func();
	//FGUIWidget::timer_func();
	FGUIWidget::timer_func();
}



void FGUIWindow::mouse_down_func()
{
	for (unsigned i=0; i<children.size(); i++)
		children[i]->mouse_down_func();
	FGUIWidget::mouse_down_func();
}



void FGUIWindow::mouse_up_func()
{
	for (unsigned i=0; i<children.size(); i++)
		children[i]->mouse_up_func();
	FGUIWidget::mouse_up_func();
}



void FGUIWindow::key_down_func()
{
	for (unsigned i=0; i<children.size(); i++)
		children[i]->key_down_func();
	FGUIWidget::key_down_func();
}



void FGUIWindow::key_up_func()
{
	for (unsigned i=0; i<children.size(); i++)
		children[i]->key_up_func();
	FGUIWidget::key_up_func();
}



void FGUIWindow::key_char_func()
{
	for (unsigned i=0; i<children.size(); i++)
		children[i]->key_char_func();
	FGUIWidget::key_char_func();
}
*/