/*  $Id: display.cpp,v 1.25 2004/05/08 10:25:05 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 "Display/display_precomp.h"
#include "API/Display/display.h"
#include "API/Display/display_mode.h"
#include "API/Display/input_context.h"
#include "API/Display/graphic_context.h"
#include "display_window_generic.h"

/////////////////////////////////////////////////////////////////////////////
// CL_Display attributes:

CL_DisplayWindow *CL_Display::get_current_window()
{
	return CL_DisplayWindow_Generic::current;
}

int CL_Display::get_width()
{
	return CL_DisplayWindow_Generic::current->get_width();
}

int CL_Display::get_height()
{
	return CL_DisplayWindow_Generic::current->get_height();
}

bool CL_Display::is_fullscreen()
{
	return CL_DisplayWindow_Generic::current->is_fullscreen();
}

bool CL_Display::has_focus()
{
	return CL_DisplayWindow_Generic::current->has_focus();
}

CL_PixelBuffer *CL_Display::get_buffer(int i)
{
	return &CL_DisplayWindow_Generic::current->get_buffer(i);
}

int CL_Display::get_buffer_count()
{
	return CL_DisplayWindow_Generic::current->get_buffer_count();
}

CL_PixelBuffer &CL_Display::get_front_buffer()
{
	return CL_DisplayWindow_Generic::current->get_front_buffer();
}

CL_PixelBuffer &CL_Display::get_back_buffer()
{
	return CL_DisplayWindow_Generic::current->get_back_buffer();
}

const CL_Rect &CL_Display::get_cliprect()
{
	return CL_DisplayWindow_Generic::current->get_gc()->get_cliprect();
}

const CL_Matrix4x4 &CL_Display::get_modelview()
{
	return CL_DisplayWindow_Generic::current->get_gc()->get_modelview();
}
	
/////////////////////////////////////////////////////////////////////////////
// CL_Display operations:

void CL_Display::set_current_window(CL_DisplayWindow *window)
{
	CL_DisplayWindow_Generic::current = window;
}

void CL_Display::set_fullscreen(int width, int height, int bpp)
{
	CL_DisplayWindow_Generic::current->set_fullscreen(width, height, bpp, 0);
}

void CL_Display::set_fullscreen(const CL_DisplayMode &display_mode)
{
	CL_DisplayWindow_Generic::current->set_fullscreen(display_mode);
}

void CL_Display::set_windowed()
{
	CL_DisplayWindow_Generic::current->set_windowed();
}

void CL_Display::set_title(const std::string &title)
{
	CL_DisplayWindow_Generic::current->set_title(title);
}

void CL_Display::set_position(const CL_Rect &pos)
{
	CL_DisplayWindow_Generic::current->set_position(pos);
}

void CL_Display::set_position(int x, int y)
{
	CL_DisplayWindow_Generic::current->set_position(x, y);
}

void CL_Display::set_size(int width, int height)
{
	CL_DisplayWindow_Generic::current->set_size(width, height);
}

void CL_Display::set_buffer_count(int flipping_buffers)
{
	CL_DisplayWindow_Generic::current->set_buffer_count(flipping_buffers);
}

void CL_Display::update(const CL_Rect &rect)
{
	CL_DisplayWindow_Generic::current->update(rect);
}

void CL_Display::flip(int interval)
{
	CL_DisplayWindow_Generic::current->flip(interval);
}

void CL_Display::flush()
{
	CL_DisplayWindow_Generic::current->get_gc()->flush();
}

void CL_Display::draw_pixel(int x, int y, const CL_Color &color)
{
	CL_DisplayWindow_Generic::current->get_gc()->draw_pixel(x, y, color);
}

void CL_Display::draw_line(int x1, int y1, int x2, int y2, const CL_Color &color)
{
	CL_DisplayWindow_Generic::current->get_gc()->draw_line(x1, y1, x2, y2, color);
}

void CL_Display::draw_rect(const CL_Rect &rect, const CL_Color &color)
{
	CL_DisplayWindow_Generic::current->get_gc()->draw_rect(rect, color);
}

void CL_Display::fill_rect(const CL_Rect &rect, const CL_Gradient &gradient)
{
	CL_DisplayWindow_Generic::current->get_gc()->fill_rect(rect, gradient);
}

void CL_Display::fill_rect(const CL_Rect &rect, const CL_Color &color)
{
	CL_DisplayWindow_Generic::current->get_gc()->fill_rect(rect, color);
}

void CL_Display::draw_quad(const CL_Quad &quad, const CL_Color &color)
{
	CL_DisplayWindow_Generic::current->get_gc()->draw_quad(quad, color);
}

void CL_Display::fill_quad(const CL_Quad &quad, const CL_Gradient &gradient)
{
	CL_DisplayWindow_Generic::current->get_gc()->fill_quad(quad, gradient);
}

void CL_Display::fill_quad(const CL_Quad &quad, const CL_Color &color)
{
	CL_DisplayWindow_Generic::current->get_gc()->fill_quad(quad, color);
}

void CL_Display::clear(const CL_Color &color)
{
	CL_DisplayWindow_Generic::current->get_gc()->clear(color);
}

void CL_Display::set_cliprect(const CL_Rect &rect)
{
	CL_DisplayWindow_Generic::current->get_gc()->set_cliprect(rect);
}

void CL_Display::push_cliprect(const CL_Rect &rect)
{
	CL_DisplayWindow_Generic::current->get_gc()->push_cliprect(rect);
}

void CL_Display::push_cliprect()
{
	CL_DisplayWindow_Generic::current->get_gc()->push_cliprect();
}

void CL_Display::pop_cliprect()
{
	CL_DisplayWindow_Generic::current->get_gc()->pop_cliprect();
}

void CL_Display::set_modelview(const CL_Matrix4x4 &matrix)
{
	CL_DisplayWindow_Generic::current->get_gc()->set_modelview(matrix);
}

void CL_Display::add_modelview(const CL_Matrix4x4 &matrix)
{
	CL_DisplayWindow_Generic::current->get_gc()->add_modelview(matrix);
}

void CL_Display::push_modelview()
{
	CL_DisplayWindow_Generic::current->get_gc()->push_modelview();
}

void CL_Display::set_translate(double x, double y, double z)
{
	CL_DisplayWindow_Generic::current->get_gc()->set_translate(x, y, z);
}

void CL_Display::add_translate(double x, double y, double z)
{
	CL_DisplayWindow_Generic::current->get_gc()->add_translate(x, y, z);
}

void CL_Display::push_translate(double x, double y, double z)
{
	CL_DisplayWindow_Generic::current->get_gc()->push_translate(x, y, z);
}

void CL_Display::set_rotate(double angle, double x, double y, double z)
{
	CL_DisplayWindow_Generic::current->get_gc()->set_rotate(angle, x, y, z);
}

void CL_Display::add_rotate(double angle, double x, double y, double z)
{
	CL_DisplayWindow_Generic::current->get_gc()->add_rotate(angle, x, y, z);
}

void CL_Display::push_rotate(double angle, double x, double y, double z)
{
	CL_DisplayWindow_Generic::current->get_gc()->push_rotate(angle, x, y, z);
}

void CL_Display::set_scale(double x, double y, double z)
{
	CL_DisplayWindow_Generic::current->get_gc()->set_scale(x, y, z);
}

void CL_Display::add_scale(double x, double y, double z)
{
	CL_DisplayWindow_Generic::current->get_gc()->add_scale(x, y, z);
}

void CL_Display::push_scale(double x, double y, double z)
{
	CL_DisplayWindow_Generic::current->get_gc()->push_scale(x, y, z);
}

void CL_Display::pop_modelview()
{
	CL_DisplayWindow_Generic::current->get_gc()->pop_modelview();
}

/////////////////////////////////////////////////////////////////////////////
// CL_Display signals:

CL_Signal_v2<int, int> &CL_Display::sig_resize()
{
	return CL_DisplayWindow_Generic::current->sig_resize();
}

CL_Signal_v1<const CL_Rect &> &CL_Display::sig_paint()
{
	return CL_DisplayWindow_Generic::current->sig_paint();
}

CL_Signal_v0 &CL_Display::sig_lost_focus()
{
	return CL_DisplayWindow_Generic::current->sig_lost_focus();
}

CL_Signal_v0 &CL_Display::sig_got_focus()
{
	return CL_DisplayWindow_Generic::current->sig_got_focus();
}

CL_Signal_v0 &CL_Display::sig_window_close()
{
	return CL_DisplayWindow_Generic::current->sig_window_close();
}
