/*  $Id: image.cpp,v 1.13 2004/04/20 13:36:27 sphair 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 "precomp.h"
#include "API/Core/XML/dom_element.h"
#include "API/Display/surface.h"
#include "API/GUI/image.h"
#include "API/GUI/stylemanager.h"
#include "API/Display/surface.h"
#include "image_generic.h"

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

CL_Image::CL_Image(
	CL_Component *parent,
	CL_StyleManager *style)
: CL_Component(parent, style), impl(NULL)
{
	impl = new CL_Image_Generic(this, NULL, false);
	get_style_manager()->connect_styles("image", this);
	find_preferred_size();
}

CL_Image::CL_Image(
	const CL_Rect &pos,
	CL_Component *parent,
	CL_StyleManager *style)
: CL_Component(pos, parent, style), impl(NULL)
{
	impl = new CL_Image_Generic(this, NULL, false);
	get_style_manager()->connect_styles("image", this);
}

CL_Image::CL_Image(
	const CL_Rect &pos,
	CL_Surface *surface,
	bool delete_surface,
	CL_Component *parent,
	CL_StyleManager *style)
: CL_Component(pos, parent, style), impl(NULL)
{
	impl = new CL_Image_Generic(this, surface, delete_surface);
	get_style_manager()->connect_styles("image", this);
}

CL_Image::CL_Image(
	CL_Surface *surface,
	bool delete_surface,
	CL_Component *parent,
	CL_StyleManager *style)
: CL_Component(parent, style), impl(NULL)
{
	impl = new CL_Image_Generic(this, surface, delete_surface);
	get_style_manager()->connect_styles("image", this);
	find_preferred_size();
}

CL_Image::CL_Image(
	const CL_Point &pos,
	CL_Component *parent,
	CL_StyleManager *style)
: CL_Component(CL_Rect(pos.x, pos.y, 0, 0), parent, style), impl(NULL)
{
	impl = new CL_Image_Generic(this, NULL, false);
	get_style_manager()->connect_styles("image", this);
	find_preferred_size();
}

CL_Image::CL_Image(
	const CL_Point &pos,
	CL_Surface *surface,
	bool delete_surface,	
	CL_Component *parent,
	CL_StyleManager *style)
: CL_Component(CL_Rect(pos.x, pos.y, 0, 0), parent, style), impl(NULL)
{
	impl = new CL_Image_Generic(this, surface, delete_surface);
	get_style_manager()->connect_styles("image", this);
	find_preferred_size();
}

CL_Image::~CL_Image()
{
	delete impl;
}

/////////////////////////////////////////////////////////////////////////////
// Attributes:

CL_Surface *CL_Image::get_surface() const
{
	return impl->surface;
}

CL_Image::Mode CL_Image::get_mode() const
{
	return impl->mode;
}

/////////////////////////////////////////////////////////////////////////////
// Operations:

void CL_Image::set_surface(CL_Surface *surface, bool delete_surface)
{
	if(impl->surface && impl->delete_surface)
		delete impl->surface;
		
	impl->surface = surface;
	impl->delete_surface = delete_surface;
}

void CL_Image::set_mode(Mode mode)
{
	impl->mode = mode;
}
