/* $Revision Header *** Header built automatically - do not edit! ***********
 *
 *	(C) Copyright 1992 by Torsten Jürgeleit
 *
 *	Name .....: pointer_test.c
 *	Created ..: Thursday 09-Jan-92 00:26:55
 *	Revision .: 1
 *
 *	Date        Author                 Comment
 *	=========   ====================   ====================
 *	11-Jul-92   Torsten Jürgeleit      now get pointer to console device
 *	09-Jan-92   Torsten Jürgeleit      Created this file!
 *
 ****************************************************************************
 *
 *	Test for mouse pointer functions
 *
 * $Revision Header ********************************************************/

	/* Includes */

#include <exec/types.h>
#ifdef AZTEC_C
#include <functions.h>   /* needed for Aztec C - prototypes and pragmas for all Amiga system functions */
#endif
#include <libraries/memwatch.h>   /* header file for memory debug link library (Fish 240) - AFTER functions.h */
#include "/render/render.h"
#include "/gadgets/gadgets.h"
#include "pointer.h"

	/* Defines */

#define WINDOW_WIDTH		600
#define WINDOW_HEIGHT		180
#define WINDOW_IDCMP		(CLOSEWINDOW | GADGET_IDCMP_FLAGS_BUTTON)
#define WINDOW_FLAGS		(WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH | NOCAREREFRESH | RMBTRAP | ACTIVATE)
#define WINDOW_TITLE		(UBYTE *)" Mouse pointer test "

#define RENDER_INFO_FLAGS	(USHORT)(RENDER_INFO_FLAG_INNER_WINDOW | RENDER_INFO_FLAG_BACK_FILL)
#define OPEN_WINDOW_FLAGS	(USHORT)(OPEN_WINDOW_FLAG_CENTER_SCREEN | OPEN_WINDOW_FLAG_RENDER_PENS)

#define CLOSE_GADGET_X	16
#define CLOSE_GADGET_Y	5

	/* Globals */

struct IntuitionBase  *IntuitionBase;
struct GfxBase        *GfxBase;
struct Library        *DiskfontBase;
struct Library        *LayersBase;
struct Device         *ConsoleDevice;

	/* Statics */

STATIC struct NewWindow  test_new_window = {
   0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, WINDOW_IDCMP, WINDOW_FLAGS,
   NULL, NULL, WINDOW_TITLE, NULL, NULL, 0, 0, 0, 0, WBENCHSCREEN
};
STATIC struct TextAttr  topaz80_attr = { (STRPTR)"topaz.font", TOPAZ_EIGHTY,
						   FS_NORMAL, FPF_ROMFONT },
			topaz60_attr = { (STRPTR)"topaz.font", TOPAZ_SIXTY,
						   FS_NORMAL, FPF_ROMFONT };
	/* Defines for test gadgets */

#define TEST_GADGET_MOVE_POINTER	0
#define TEST_GADGET_BUSY_POINTER	1

#define TEST_GADGET1_TYPE		GADGET_DATA_TYPE_BUTTON
#define TEST_GADGET1_FLAGS		GADGET_DATA_FLAG_HOTKEY
#define TEST_GADGET1_LEFT_EDGE		((WINDOW_WIDTH / 2 - TEST_GADGET1_WIDTH) / 2)
#define TEST_GADGET1_TOP_EDGE		((WINDOW_HEIGHT - TEST_GADGET1_HEIGHT) / 2)
#define TEST_GADGET1_WIDTH		((12 + 2) * 10)
#define TEST_GADGET1_HEIGHT		19
#define TEST_GADGET1_TEXT		"_Move pointer"
#define TEST_GADGET1_TEXT_ATTR		&topaz60_attr

#define TEST_GADGET2_TYPE		GADGET_DATA_TYPE_BUTTON
#define TEST_GADGET2_FLAGS		(GADGET_DATA_FLAG_HOTKEY | GADGET_DATA_FLAG_BUTTON_TOGGLE)
#define TEST_GADGET2_LEFT_EDGE		(WINDOW_WIDTH - (TEST_GADGET2_WIDTH + TEST_GADGET1_LEFT_EDGE))
#define TEST_GADGET2_TOP_EDGE		TEST_GADGET1_TOP_EDGE
#define TEST_GADGET2_WIDTH		TEST_GADGET1_WIDTH
#define TEST_GADGET2_HEIGHT		TEST_GADGET1_HEIGHT
#define TEST_GADGET2_TEXT		"_Busy pointer"
#define TEST_GADGET2_TEXT_ATTR		TEST_GADGET1_TEXT_ATTR

STATIC struct GadgetData  test_gadget_data[] = {
   {
	TEST_GADGET1_TYPE,		/* gd_Type */
	TEST_GADGET1_FLAGS,		/* gd_Flags */
	TEST_GADGET1_LEFT_EDGE,		/* gd_LeftEdge */
	TEST_GADGET1_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET1_WIDTH,		/* gd_Width */
	TEST_GADGET1_HEIGHT,		/* gd_Height */
	TEST_GADGET1_TEXT,		/* *gd_Text */
	TEST_GADGET1_TEXT_ATTR,		/* *gd_TextAttr */
	{ 0, 0, 0 }
   }, {
	TEST_GADGET2_TYPE,		/* gd_Type */
	TEST_GADGET2_FLAGS,		/* gd_Flags */
	TEST_GADGET2_LEFT_EDGE,		/* gd_LeftEdge */
	TEST_GADGET2_TOP_EDGE,		/* gd_TopEdge */
	TEST_GADGET2_WIDTH,		/* gd_Width */
	TEST_GADGET2_HEIGHT,		/* gd_Height */
	TEST_GADGET2_TEXT,		/* *gd_Text */
	TEST_GADGET2_TEXT_ATTR,		/* *gd_TextAttr */
	{ 0, 0, 0 }
   }, {
	INTUISUP_DATA_END		/* mark end of gadget data array */
   }
};
	/* Prototypes */

VOID test_action(struct RenderInfo  *ri, struct Window  *win,
						    struct GadgetList  *gl);
	/* Pragmas */

#pragma regcall(test_action(a0,a1,a2))

	/* Mouse pointer test */

   LONG
main(VOID)
{
   struct IOStdReq    io;
   struct RenderInfo  *ri;
   struct Window      *win;
   struct GadgetList  *gl;

   MWInit((BPTR)NULL, 0L);
   if (IntuitionBase = OpenLibrary("intuition.library", 0L)) {
      if (GfxBase = OpenLibrary("graphics.library", 0L)) {
	 if (DiskfontBase = OpenLibrary("diskfont.library", 0L)) {
	    if (LayersBase = OpenLibrary("layers.library", 0L)) {
	       if (!OpenDevice("console.device", -1L,
					     (struct IORequest *)&io, 0L)) {
		  ConsoleDevice = io.io_Device;
		  if (ri = get_render_info(NULL, RENDER_INFO_FLAGS)) {
		     if (win = open_window(ri, &test_new_window,
						       OPEN_WINDOW_FLAGS)) {
			if (gl = create_gadgets(ri, &test_gadget_data[0], 0, 0,
								    NULL)) {
			   display_gadgets(win, gl);
			   test_action(ri, win, gl);
			   remove_gadgets(gl);
			   free_gadgets(gl);
			}
			close_window(win, FALSE);
		     }
		     free_render_info(ri);
		  }
		  CloseDevice((struct IORequest *)&io);
	       }
	       CloseLibrary(LayersBase);
	    }
	    CloseLibrary(DiskfontBase);
	 }
	 CloseLibrary(GfxBase);
      }
      CloseLibrary(IntuitionBase);
   }
   MWTerm();
   return(0L);
}
	/* Perform IDCMP action */

   VOID
test_action(struct RenderInfo  *ri, struct Window  *win,
						     struct GadgetList  *gl)
{
   struct MsgPort  *up = win->UserPort;
   BOOL busy = FALSE, keepon = TRUE;

   do {
      struct IntuiMessage  *msg;

      WaitPort(up);
      while (msg = (struct IntuiMessage *)get_msg(up)) {
	 switch (msg->Class) {
	    case CLOSEWINDOW :
	       keepon = FALSE;
	       break;

	    case ISUP_ID :
	       switch (msg->Code) {
		  case TEST_GADGET_MOVE_POINTER :
		     move_mouse_pointer(win, CLOSE_GADGET_X, CLOSE_GADGET_Y,
								     FALSE);
		     break;

		  case TEST_GADGET_BUSY_POINTER :
		     if (busy == FALSE) {
			change_mouse_pointer(win, NULL, FALSE);
			busy = TRUE;
		     } else {
			restore_mouse_pointer(win);
			busy = FALSE;
		     }
		     break;
	       }
	       break;
	 }
	 reply_msg(msg);
      }
   } while (keepon == TRUE);
   if (busy == TRUE) {
      restore_mouse_pointer(win);
   }
}
