/*	Copyright_xwin.cpp
 *
 *		Copyright display routines (stubs)
 */

/**********************************************************************

  YAAF is Copyright 1997-1999 by William Woody.

  Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions 
  are met:

  Redistributions of source code must retain the above copyright notice, 
  this list of conditions and the following disclaimer.

  Neither the name of the copyright holder or other contributors may
  be used to promote products derived from this software without
  specific written prior permission.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
  SOFTWARE.
  
  Contact:   woody@alumni.caltech.edu
  Web page:  http://www.pandawave.com/yaaf/

**********************************************************************/

#include <XConfig.h>

#if OPT_XWIN

#include <XApplication.h>
#include <XDraw.h>
#include <XWindow.h>
#include <XDataUtil.h>

#include <time.h>
#include <sys/times.h>

/************************************************************************/
/*																		*/
/*	Globals																*/
/*																		*/
/************************************************************************/

static clock_t		GTimer;
static Window		GCopyWindow;

/************************************************************************/
/*																		*/
/*	Temporary copyright window											*/
/*																		*/
/************************************************************************/

/*	XGAppCore::OpenCopyright
 *
 *		Open the copyright window
 */

void XGAppCore::OpenCopyright(void)
{
	void *data;
	XRect r;
	XSetWindowAttributes attrib;
	XPoint size;
	int i;
	GC gc;
	struct tms buf;
	
	/*
	 *	Get the bitmap
	 */
	
	data = ::GetResourceData('bmap',128);
	if (data == NULL) return;				// does it exist?
	size = GetBitmapSize(128);
	r.left = 0;
	r.top = 0;
	i = DefaultScreen(_GDisplay);
	r.right = DisplayWidth(_GDisplay,i);
	r.bottom = DisplayHeight(_GDisplay,i);

	r.left = (r.right - size.h) / 2;
	r.right = r.left + size.h;
	r.top = (r.bottom - size.v) / 2;
	r.bottom = r.top + size.v;
	
	/*
	 *	Pop open the window
	 */
	
	attrib.event_mask = KeyPressMask |
						ButtonPressMask |
						ButtonReleaseMask |
						EnterWindowMask |
						LeaveWindowMask |
						PointerMotionHintMask |
						PointerMotionMask |
						ExposureMask |
						StructureNotifyMask |
						ColormapChangeMask;
	attrib.override_redirect = true;
	GCopyWindow = ::XCreateWindow(_GDisplay,
							  DefaultRootWindow(_GDisplay),
							  r.left,
							  r.top,
							  r.right-r.left,
							  r.bottom-r.top,
							  0,
							  CopyFromParent,
							  InputOutput,
							  CopyFromParent,
							  CWEventMask | CWOverrideRedirect,
							  &attrib);
	::XMapRaised(_GDisplay,GCopyWindow);
	
	/*
	 *	Now draw the contents into a created graphics context
	 */
	
	gc = ::XCreateGC(_GDisplay,GCopyWindow,0,NULL);
	::DrawXBitmap(_GDisplay,GCopyWindow,gc,128,0,0);
	::XFreeGC(_GDisplay,gc);
	::XFlush(_GDisplay);
	
	/*
	 *	And store the current time
	 */
	
	GTimer = times(&buf) + CLK_TCK * 2;
}

/*	XGAppCore::CloseCopyright
 *
 *		Delay and then close. This guarentees a minimum 2 second delay
 */

void XGAppCore::CloseCopyright(void)
{
	struct tms buf;
	while (GTimer > times(&buf)) ;
	
	::XDestroyWindow(_GDisplay,GCopyWindow);
}

/*	XGAppCore::ShowCopyright
 *
 *		Show the copyright and wait until mouse or keyboard events
 */

void XGAppCore::ShowCopyright(void)
{
}

#endif // OPT_XWIN
