/* Steven Andrews 1/99 */
/* Moved string stuff out 11/01 */
/* See documentation called Utility doc */
/* Copyright 2003 by Steven Andrews.  Permission is granted
   for non-commercial use of and modifications to the code. */


#include <stdio.h>
#include <time.h>
#include <sioux.h>
#include "Utility.h"

void WaitTime(float dt) {
	clock_t a;

	a=clock();
	while((clock()-a)/CLOCKS_PER_SEC<dt)
		;
	return; }

char Wait4Event() {
	EventRecord event;

	FlushEvents(everyEvent,0);
	while(!GetNextEvent(keyDownMask,&event))
		;
	return(event.message&charCodeMask); }

char Wait4Mouse(int *x,int *y) {
	EventRecord event;
	Point pt;

	while(!GetNextEvent(keyDownMask+mDownMask,&event))
		;
	GetMouse(&pt);
	*x=pt.h;
	*y=pt.v;
	return(event.message&charCodeMask); }

char inkey() {
	EventRecord event;

	if(GetNextEvent(keyDownMask+autoKeyMask,&event))
		return(event.message&charCodeMask);
	else
		return(0); }

void beep() {
	printf("\7"); }

void SiouxWindow(float left,float top,int columns,int rows,int event) {
	#if TARGET_API_MAC_CARBON
		BitMap theScreenBits;
	#endif
	Rect r;
	
	#if TARGET_API_MAC_CARBON
		GetQDGlobalsScreenBits(&theScreenBits);
		r=theScreenBits.bounds;
	#else
		r=qd.screenBits.bounds;
	#endif
	SIOUXSettings.leftpixel=(r.right-r.left)*left+r.left;
	SIOUXSettings.toppixel=(r.bottom-r.top)*top+r.top;
	SIOUXSettings.columns=columns;
	SIOUXSettings.rows=rows;
	if(event) SIOUXSettings.standalone=false;
	return; }

int CheckEvents(EventRecord *eventptr) {
	int i;

	i=GetNextEvent(everyEvent,eventptr);
	if(i) i=!SIOUXHandleOneEvent(eventptr);
	return i; }


