/*  $Id: graphic_context_sdl.h,v 1.10 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
*/

#ifndef header_graphic_context_sdl
#define header_graphic_context_sdl

#if _MSC_VER > 1000
#pragma once
#endif

#include "Display/graphic_context_generic.h"
#include "API/signals.h"
#include <SDL/SDL.h>

class CL_DisplayWindow_Generic;

//: SDL graphic context
class CL_GraphicContext_SDL : public CL_GraphicContext_Generic
{
//! Construction:
public:
	CL_GraphicContext_SDL(CL_DisplayWindow_Generic *window);

	virtual ~CL_GraphicContext_SDL();

//! Attributes:
public:
	//: Returns the current width of the context.
	virtual int get_width() const;

	//: Returns the current height of the context.
	virtual int get_height() const;

	//: Returns a pixel value at specified coordinates.
	virtual CL_Color get_pixel(int x, int y) const;

//! Operations:
public:
	//: Draw a pixel at (x, y) using the specified color.
	virtual void draw_pixel(int x, int y, const CL_Color &color);

	//: Draw a line from (x1, y1) to (x2, y2) using the specified color.
	virtual void draw_line(int x1, int y1, int x2, int y2, const CL_Color &color);

	//: Draw a rectangle using the specified color.
	virtual void draw_rect(const CL_Rect &rect, const CL_Color &color);

	//: Draw a gradient rectangle using the specified gradient.
	virtual void fill_rect(const CL_Rect &rect, const CL_Gradient &gradient);

	//: Draw a filled rectangle using the specified color.
	virtual void fill_rect(const CL_Rect &rect, const CL_Color &color);
	
	//: Draw a quad using the specified color.
	virtual void draw_quad(const CL_Quad &quad, const CL_Color &color);

	//: Draw a gradient quad using the specified gradient.
	virtual void fill_quad(const CL_Quad &quad, const CL_Gradient &gradient);

	//: Draw a filled quad using the specified color.
	virtual void fill_quad(const CL_Quad &quad, const CL_Color &color);

	//: Clears the whole context using the specified color.
	virtual void clear(const CL_Color &color);

	//: Set the current clipping rectangle.
	virtual void set_cliprect(const CL_Rect &rect);

	//: Push current clipping rectangle to stack; then set clipping rectangle to the
	//: union of the current rectangle and the passed rectangle.
	virtual void push_cliprect(const CL_Rect &rect);

	//: Push current clipping rectangle to the stack.
	virtual void push_cliprect();

	//: Pop current clipping rectangle from the stack.
	virtual void pop_cliprect();

	//: Called every time the active modelview have changed.
	virtual void modelview_changed();

	//: Clears the stencil buffer contents.
	//param int value: stencil buffer contents will be cleared to this value. Default: 0
	virtual void clear_stencil(int value);

	//: Set stencil test function when writing to stencil, and operations to do when a test passes or fails
	//param CL_StencilOp pass : Modification to stencil buffer when a test passes.
	//param CL_StencilOp fail : Modification to stencil buffer when a test fails.
	//param CL_StencilFunc func : Type of test to do when writing to stencil.
	//param int ref : value compared to stencil contents. Default: 1
	virtual void set_stencil_operation(CL_StencilOp pass, CL_StencilOp fail, CL_StencilFunc func, int ref);

	//: Enables writing to the stencil buffer 
	//param bool enabled : Enables/disables stencil testing.
	//param bool visible : Enables/disables color buffer writing if stencil writing is enabled. Default: true.
	//param float alpha_limit : Only pixels with alpha >= alpha limit are drawn to the stencil buffer.
	virtual void enable_stencil_write(bool enabled, bool visible, float alpha_limit);

	//: Enables stencil buffer testing
	//- <p> Individual pixels are tested against the values in the stencil buffer, and
	//- drawn depending on the comparison result. This can be used for masking and
	//- boolean operations on bitmaps </p>
	//param bool enabled : Enables/disables stencil testing.
	//param int func : Type of comparison. Default: lequal (pass if ref <= stencil)
	//param int ref : Reference value that the stencil is compared with. Default: 1
	virtual void enable_stencil_test(bool enabled, CL_StencilFunc func, int ref);

	//: Called when 2D operations are begun.
	virtual void setup_2d();

	//: Called when 2D operations are ended.
	virtual void setup_3d();

//! Implementation:
private:
	//: Updates SDLs cliprect with current clip rect.
	void update_cliprect();

	//: SDL window.
	CL_DisplayWindow_Generic *window;
};

#endif
