/*  $Id: graphic_context.cpp,v 1.28 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 "Display/display_precomp.h"
#include "API/Display/graphic_context.h"
#include "graphic_context_generic.h"

/////////////////////////////////////////////////////////////////////////////
// CL_GraphicContext construction:

CL_GraphicContext::CL_GraphicContext()
: impl(0)
{
}

CL_GraphicContext::CL_GraphicContext(const CL_GraphicContext &copy)
: impl(copy.impl)
{
	if (impl) impl->add_ref();
}

CL_GraphicContext::CL_GraphicContext(CL_GraphicContext_Generic *impl)
: impl(impl)
{
	if (impl) impl->add_ref();
}

CL_GraphicContext::~CL_GraphicContext()
{
	if (impl) impl->release_ref();
}

/////////////////////////////////////////////////////////////////////////////
// CL_GraphicContext attributes:

int CL_GraphicContext::get_width() const
{
	return impl->get_width();
}

int CL_GraphicContext::get_height() const
{
	return impl->get_height();
}

const CL_Rect &CL_GraphicContext::get_cliprect() const
{
	return impl->get_cliprect();
}

const CL_Matrix4x4 &CL_GraphicContext::get_modelview() const
{
	return impl->get_modelview();
}

CL_Color CL_GraphicContext::get_pixel(int x, int y) const
{
	return impl->get_pixel(x, y);
}

CL_Size CL_GraphicContext::get_max_surface_size() const
{
	return impl->get_max_surface_size();
}

/////////////////////////////////////////////////////////////////////////////
// CL_GraphicContext operations:

CL_GraphicContext &CL_GraphicContext::operator =(const CL_GraphicContext &copy)
{
	if (impl) impl->release_ref();
	impl = copy.impl;
	if (impl) impl->add_ref();
	return *this;
}

void CL_GraphicContext::flush()
{
	impl->flush();
}

void CL_GraphicContext::set_cliprect(const CL_Rect &rect)
{
	if (rect.right < rect.left || rect.bottom < rect.top)
	{
		static CL_Rect null_rect(0,0,0,0);
		impl->set_cliprect(null_rect);
	}
	impl->set_cliprect(rect);
}

void CL_GraphicContext::push_cliprect(const CL_Rect &rect)
{
	if (rect.right < rect.left || rect.bottom < rect.top)
	{
		static CL_Rect null_rect(0,0,0,0);
		impl->push_cliprect(null_rect);
	}
	impl->push_cliprect(rect);
}

void CL_GraphicContext::push_cliprect()
{
	impl->push_cliprect();
}

void CL_GraphicContext::pop_cliprect()
{
	impl->pop_cliprect();
}

void CL_GraphicContext::draw_pixel(int x, int y, const CL_Color &color)
{
	impl->draw_pixel(x, y, color);
}

void CL_GraphicContext::draw_line(int x1, int y1, int x2, int y2, const CL_Color &color)
{
	impl->draw_line(x1, y1, x2, y2, color);
}

void CL_GraphicContext::draw_rect(const CL_Rect &rect, const CL_Color &color)
{
	impl->draw_rect(rect, color);
}

void CL_GraphicContext::fill_rect(const CL_Rect &rect, const CL_Gradient &gradient)
{
	impl->fill_rect(rect, gradient);
}

void CL_GraphicContext::fill_rect(const CL_Rect &rect, const CL_Color &color)
{
	impl->fill_rect(rect, color);
}

void CL_GraphicContext::draw_quad(const CL_Quad &quad, const CL_Color &color)
{
	impl->draw_quad(quad, color);
}

void CL_GraphicContext::fill_quad(const CL_Quad &quad, const
	CL_Gradient &gradient)
{
	impl->fill_quad(quad, gradient);
}

void CL_GraphicContext::fill_quad(const CL_Quad &quad, const CL_Color
&color)
{
	impl->fill_quad(quad, color);
}

void CL_GraphicContext::clear(const CL_Color &color)
{
	impl->clear(color);
}

void CL_GraphicContext::set_modelview(const CL_Matrix4x4 &matrix)
{
	impl->set_modelview(matrix);
}

void CL_GraphicContext::add_modelview(const CL_Matrix4x4 &matrix)
{
	impl->add_modelview(matrix);
}

void CL_GraphicContext::push_modelview()
{
	impl->push_modelview();
}

void CL_GraphicContext::set_translate(double x, double y, double z)
{
	impl->set_translate(x, y, z);
}

void CL_GraphicContext::add_translate(double x, double y, double z)
{
	impl->add_translate(x, y, z);
}

void CL_GraphicContext::push_translate(double x, double y, double z)
{
	impl->push_translate(x, y, z);
}

void CL_GraphicContext::set_rotate(double angle, double x, double y, double z)
{
	impl->set_rotate(angle, x, y, z);
}

void CL_GraphicContext::add_rotate(double angle, double x, double y, double z)
{
	impl->add_rotate(angle, x, y, z);
}

void CL_GraphicContext::push_rotate(double angle, double x, double y, double z)
{
	impl->push_rotate(angle, x, y, z);
}

void CL_GraphicContext::set_scale(double x, double y, double z)
{
	impl->set_scale(x, y, z);
}

void CL_GraphicContext::add_scale(double x, double y, double z)
{
	impl->add_scale(x, y, z);
}

void CL_GraphicContext::push_scale(double x, double y, double z)
{
	impl->push_scale(x, y, z);
}

void CL_GraphicContext::pop_modelview()
{
	impl->pop_modelview();
}

void CL_GraphicContext::clear_stencil(int value)
{
	impl->clear_stencil(value);
}

void CL_GraphicContext::enable_stencil_write(bool enabled, bool visible, float alpha_limit)
{
	impl->enable_stencil_write(enabled, visible, alpha_limit);
}

void CL_GraphicContext::enable_stencil_test(bool enabled, CL_StencilFunc func, int ref)
{
	impl->enable_stencil_test(enabled, func, ref);
}

void CL_GraphicContext::set_stencil_operation(CL_StencilOp pass, CL_StencilOp fail, CL_StencilFunc func, int ref)
{
	impl->set_stencil_operation(pass, fail, func, ref);
}

/////////////////////////////////////////////////////////////////////////////
// Implementation:
