/*	MiscTime.cpp
 *
 *		Timer routines.
 */

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

  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>
#include <XMisc.h>

#if OPT_XWIN
#include <time.h>
#include <sys/times.h>
#endif

/**@name Support--Timer Routines
 *
 *		These routines provide a standard interface for getting the 
 *	elapsed time, for the purpose of timing double-click actions and 
 *	cursor blinks.
 */
//@{

/************************************************************************/
/*																		*/
/*	Macintosh															*/
/*																		*/
/************************************************************************/

#if OPT_MACOS

/*$	XGGetTime
 *
 *		Get the elapsed time. Returns the time in elapsed units whose
 *	duration is specified in XGGetSecond
 */

unsigned long XGGetTime(void)
{
	return TickCount();
}

/*$	XGGetDoubleClick
 *
 *		Get the double click time; this is the amount of time
 *	between clicks to count as a double click
 */

unsigned long XGGetDoubleClick(void)
{
	return GetDblTime();
}

/*$	XGGetCursorBlink
 *
 *		Gets the amount of time between blinking cursors
 */

unsigned long XGGetCursorBlink(void)
{
	return GetCaretTime();
}

/*$	XGGetSecond
 *
 *		Number of ticks per second of this clock. This is
 *	a constant, but is returned by a function in case the
 *	time may change from hardware platform to hardware platform
 */

unsigned long XGGetSecond(void)
{
	return 60L;
}

#endif

//@}

/************************************************************************/
/*																		*/
/*	Windows																*/
/*																		*/
/************************************************************************/

#if OPT_WINOS

/*	XGGetTime
 *
 *		Get the elapsed time. Uses tick count
 */

unsigned long XGGetTime(void)
{
	return GetTickCount();
}

/*	XGGetDoubleClick
 *
 *		Get the double click time; this is the amount of time
 *	between clicks to count as a double click
 */

unsigned long XGGetDoubleClick(void)
{
	return 250L;
}

/*	XGGetCursorBlink
 *
 *		Gets the amount of time between blinking cursors
 */

unsigned long XGGetCursorBlink(void)
{
	return 500L;
}

/*	XGGetSecond
 *
 *		Number of ticks per second of this clock. This is
 *	a constant, but is returned by a function in case the
 *	time may change from hardware platform to hardware platform
 */

unsigned long XGGetSecond(void)
{
	return 1000L;
}

#endif

/************************************************************************/
/*																		*/
/*	X Windows															*/
/*																		*/
/************************************************************************/

#if OPT_XWIN

/*	XGGetTime
 *
 *		Get the elapsed time. Uses tick count
 */

unsigned long XGGetTime(void)
{
	struct tms buf;
	return times(&buf);
}

/*	XGGetDoubleClick
 *
 *		Get the double click time; this is the amount of time
 *	between clicks to count as a double click
 */

unsigned long XGGetDoubleClick(void)
{
	return CLK_TCK/4;
}

/*	XGGetCursorBlink
 *
 *		Gets the amount of time between blinking cursors
 */

unsigned long XGGetCursorBlink(void)
{
	return CLK_TCK/2;
}

/*	XGGetSecond
 *
 *		Number of ticks per second of this clock. This is
 *	a constant, but is returned by a function in case the
 *	time may change from hardware platform to hardware platform
 */

unsigned long XGGetSecond(void)
{
	return CLK_TCK;
}

#endif
