/*  $Id: progressbar_silver.cpp,v 1.6 2003/09/08 15:03:24 grumbel Exp $
**
**  ClanLib Game SDK
**  Copyright (C) 2003  The ClanLib Team
**  For a total list of contributers see the file CREDITS.
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 of the License, or (at your option) any later version.
**
**  This library is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
**  Lesser General Public License for more details.
**
**  You should have received a copy of the GNU Lesser General Public
**  License along with this library; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
**
*/

#include "API/Display/display.h"
#include "API/Core/Resources/resource_manager.h"
#include "API/GUIStyleSilver/progressbar_silver.h"
#include "API/GUIStyleSilver/stylemanager_silver.h"

/////////////////////////////////////////////////////////////////////////////
// Construction:

CL_ProgressBar_Silver::CL_ProgressBar_Silver(
	CL_ProgressBar *progressbar,
	CL_StyleManager_Silver *style)
:
	CL_ComponentStyle(progressbar),
	style(style),
	progressbar(progressbar)
{
	slot_paint = progressbar->sig_paint().connect(
		this, &CL_ProgressBar_Silver::on_paint);
}

/////////////////////////////////////////////////////////////////////////////
// Callbacks:

void CL_ProgressBar_Silver::on_paint()
{
	int width = progressbar->get_width();
	int height = progressbar->get_height();
	float percent = progressbar->get_percentage();

	// Outline
	CL_Display::draw_rect(CL_Rect(0, 0, width, height), CL_Color(128, 142, 159));

	// Fill
	int length = (int) ((width - 4) * percent);

	CL_Display::fill_rect(
		CL_Rect(2, 2, 2 + length, height - 2),
		CL_Gradient(
			CL_Color::white,
			CL_Color(254, 207, 147),
			CL_Color::white,
			CL_Color(254, 207, 147)));
			
	CL_Display::fill_rect(CL_Rect(2 + length, 2, width - 2, height - 2), CL_Color::white);

	// TODO: Write percentage in text
//	font->draw(...);
}
