/* $Revision Header *** Header built automatically - do not edit! ***********
 *
 *	(C) Copyright 1991 by Torsten Jürgeleit
 *
 *	Name .....: render_test.c
 *	Created ..: Thursday 19-Dec-91 15:14:45
 *	Revision .: 1
 *
 *	Date        Author                 Comment
 *	=========   ====================   ====================
 *	30-Apr-92   Torsten Jürgeleit      raster for clear_window()
 *	19-Dec-91   Torsten Jürgeleit      Created this file!
 *
 ****************************************************************************
 *
 *	Test of render and window functions
 *
 * $Revision Header ********************************************************/

	/* Includes */

#include <exec/types.h>
#include <graphics/gfxbase.h>
#include <graphics/text.h>
#include <exec/types.h>
#include <intuition/intuition.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 <string.h>
#include "render.h"

	/* Defines */

#define WINDOW_WIDTH		600
#define WINDOW_HEIGHT		180
#define WINDOW_IDCMP		CLOSEWINDOW
#define WINDOW_FLAGS		(WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH | NOCAREREFRESH | RMBTRAP | ACTIVATE)
#define WINDOW_TITLE		(UBYTE *)" Render 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 RASTER_WIDTH		20
#define RASTER_HEIGHT		10

	/* Globals */

struct IntuitionBase  *IntuitionBase;
struct GfxBase        *GfxBase;
struct Library        *DiskfontBase;

	/* 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  topaz60_attr = { (STRPTR)"topaz.font", TOPAZ_SIXTY,
						   FS_NORMAL, FPF_ROMFONT };
STATIC struct IntuiText  itexts[] = {
   {
	0, 0, JAM1, (WINDOW_WIDTH - 10 * 10) / 2, (WINDOW_HEIGHT - 6 * 8) / 2,
	&topaz60_attr, (UBYTE *)"Text pen 1", &itexts[1]
   }, {
	0, 0, JAM1, (WINDOW_WIDTH - 10 * 10) / 2, (WINDOW_HEIGHT + 4 * 8) / 2,
	&topaz60_attr, (UBYTE *)"Text pen 2", NULL
   }
};
	/* Prototypes */

VOID test_action(struct RenderInfo  *ri, struct Window  *win);

	/* Pragmas */

#pragma regcall(test_action(a0,a1))

	/* Render test */

   LONG
main(VOID)
{
   struct RenderInfo  *ri;
   struct Window      *win;

   MWInit((BPTR)NULL, 0L);
   if (IntuitionBase = OpenLibrary("intuition.library", 0L)) {
      if (GfxBase = OpenLibrary("graphics.library", 0L)) {
	 if (DiskfontBase = OpenLibrary("diskfont.library", 0L)) {
	    if (ri = get_render_info(NULL, RENDER_INFO_FLAGS)) {
	       if (win = open_window(ri, &test_new_window,
						       OPEN_WINDOW_FLAGS)) {
		  test_action(ri, win);
		  close_window(win, FALSE);
	       }
	       free_render_info(ri);
	    }
	    CloseLibrary(DiskfontBase);
	 }
	 CloseLibrary(GfxBase);
      }
      CloseLibrary(IntuitionBase);
   }
   MWTerm();
   return(0L);
}
	/* Perform IDCMP action */

   VOID
test_action(struct RenderInfo  *ri, struct Window  *win)
{
   struct RastPort  *rp = win->RPort;
   struct MsgPort   *up = win->UserPort;
   struct Image     *image = &ri->ri_Images[0];
   ULONG  left_edge = 40;
   USHORT i;
   BOOL   keepon = TRUE;

   /* Draw raster around inner area */
   clear_window(ri, win, 0, 0, -1, -1, CLEAR_WINDOW_FLAG_USE_RASTER);
   clear_window(ri, win, RASTER_WIDTH, RASTER_HEIGHT, WINDOW_WIDTH -
		    2 * RASTER_WIDTH, WINDOW_HEIGHT - 2 * RASTER_HEIGHT, 0);
   /* Init and print intui texts */
   itexts[0].FrontPen = ri->ri_TextPen1;
   itexts[1].FrontPen = ri->ri_TextPen2;
   PrintIText(rp, &itexts[0], 0L, 0L);

   /* Print render images */
   for (i = 0; i < MAX_RENDER_IMAGES; i++, image++, left_edge += 50) {
      DrawImage(rp, image, left_edge, (LONG)((WINDOW_HEIGHT -
				(2 * image->TopEdge + image->Height)) / 2));
   }

   /* Waiting for close window event */
   do {
      struct IntuiMessage  *msg;

      WaitPort(up);
      while (msg = (struct IntuiMessage *)GetMsg(up)) {
	 if (msg->Class == CLOSEWINDOW) {
	    keepon = FALSE;
	 }
	 ReplyMsg((struct Message *)msg);
      }
   } while (keepon == TRUE);
}
