/*  $Id: image_generic.cpp,v 1.8 2004/03/28 13:56:24 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 "image_generic.h"
#include "API/Display/surface.h"
#include "API/Core/Resources/resource_manager.h"
#include "API/GUI/stylemanager.h"

CL_Image_Generic::CL_Image_Generic(CL_Image *self, CL_Surface *surface, bool delete_surface)
: surface(surface), delete_surface(delete_surface), mode(CL_Image::center), image(self)
{
	slot_set_options = image->sig_set_options().connect(
		this, &CL_Image_Generic::on_set_options);
}

CL_Image_Generic::~CL_Image_Generic()
{
	if(delete_surface && surface)
		delete surface;
}

void CL_Image_Generic::on_set_options(const CL_DomElement &options)
{
	if (options.has_attribute("surface"))
	{
		CL_ResourceManager *resources = image->get_style_manager()->get_resources();
		image->set_surface(new CL_Surface(options.get_attribute("surface"), resources), true);
	}
}
