/*  $Id: label_silver.cpp,v 1.4 2004/02/17 21:30:39 mbn 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/font.h"
#include "API/Display/display.h"
#include "API/Core/Resources/resource_manager.h"
#include "API/GUI/component_style.h"
#include "API/GUIStyleSilver/label_silver.h"
#include "API/GUIStyleSilver/stylemanager_silver.h"

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

CL_Label_Silver::CL_Label_Silver(
	CL_Label *label,
	CL_StyleManager_Silver *style)
:
	CL_ComponentStyle(label),
	label(label)
{
	resources = style->get_resources();
	
	font = new CL_Font("Label/font", resources);
	
	slot_paint = label->sig_paint().connect(
		this, &CL_Label_Silver::on_paint);
	slot_get_preferred_size = label->sig_get_preferred_size().connect(
		this, &CL_Label_Silver::on_get_preferred_size);
}

CL_Label_Silver::~CL_Label_Silver()
{
	delete font;
}

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

void CL_Label_Silver::on_get_preferred_size(CL_Size &size)
{
	size.width = font->get_width(label->get_text());
	size.height = font->get_height(label->get_text());
}

void CL_Label_Silver::on_paint()
{
	const char *text = label->get_text().c_str();

	CL_Point pos = calc_origin(label->get_alignment(), CL_Size(label->get_width() / 2, label->get_height()));
	
	font->draw(
		CL_Rect(
			pos.x,
			pos.y,
			pos.x+label->get_width(),
			pos.y+label->get_height()),
		text);
}
