/*  $Id: display_window_generic.cpp,v 1.9 2004/05/08 09:47:41 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 "display_window_generic.h"
#include "API/Display/input_device.h"
#include "API/Display/input_context.h"

/////////////////////////////////////////////////////////////////////////////
// CL_DisplayWindow_Generic construction:

CL_DisplayWindow_Generic::CL_DisplayWindow_Generic() : cursor_visible(true), ref_count(0)
{
}

CL_DisplayWindow_Generic::~CL_DisplayWindow_Generic()
{
}

/////////////////////////////////////////////////////////////////////////////
// CL_DisplayWindow_Generic attributes:

CL_DisplayWindow *CL_DisplayWindow_Generic::current = 0;

/////////////////////////////////////////////////////////////////////////////
// CL_DisplayWindow_Generic operations:

void CL_DisplayWindow_Generic::add_ref()
{
	ref_count++;
}

void CL_DisplayWindow_Generic::release_ref()
{
	ref_count--;
	if (ref_count == 0)
	{
		cursor = CL_Sprite();
		delete this;
	}
}

void CL_DisplayWindow_Generic::do_flip(int interval)
{
	CL_InputDevice &mouse = get_ic()->get_mouse();
	if (!cursor.is_null())
	{
		cursor.update();
		cursor.draw(mouse.get_x(), mouse.get_y(), get_gc());
	}
	flip(interval);
}

void CL_DisplayWindow_Generic::set_cursor(const CL_Sprite &sprite)
{
	cursor = sprite;
	cursor_changed();
	if (cursor_visible)
	{
		if (!cursor.is_null()) hide_system_cursor();
		else show_system_cursor();
	}
}

void CL_DisplayWindow_Generic::show_cursor()
{
	if (cursor.is_null()) show_system_cursor();
	cursor_visible = true;
}

void CL_DisplayWindow_Generic::hide_cursor()
{
	if (cursor.is_null()) hide_system_cursor();
	cursor_visible = false;
}

/////////////////////////////////////////////////////////////////////////////
// CL_DisplayWindow_Generic implementation:
