/* $Revision Header *** Header built automatically - do not edit! ***********
 *
 *	(C) Copyright 1991 by Torsten Jürgeleit
 *
 *	Name .....: texts_test.c
 *	Created ..: Thursday 19-Dec-91 16:47:04
 *	Revision .: 1
 *
 *	Date        Author                 Comment
 *	=========   ====================   ====================
 *	11-Jul-92   Torsten Jürgeleit      now get pointer to console device
 *	19-Dec-91   Torsten Jürgeleit      Created this file!
 *
 ****************************************************************************
 *
 *	Test for text output and converting functions
 *
 * $Revision Header ********************************************************/

	/* Includes */

#include <exec/types.h>
#include <graphics/gfxbase.h>
#include <graphics/text.h>
#include <intuition/intuitionbase.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/render.h"
#include "texts.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 *)" Texts 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)

	/* 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  topaz60_attr = { (STRPTR)"topaz.font", TOPAZ_SIXTY,
						   FS_NORMAL, FPF_ROMFONT },
			topaz80_attr = { (STRPTR)"topaz.font", TOPAZ_EIGHTY,
						   FS_NORMAL, FPF_ROMFONT };
	/* Defines for texts */

#define TEST_TEXT1_TYPE		TEXT_DATA_TYPE_TEXT
#define TEST_TEXT1_FLAGS	(TEXT_DATA_FLAG_CENTER | TEXT_DATA_FLAG_BOLD | TEXT_DATA_FLAG_UNDERLINED)
#define TEST_TEXT1_LEFT_EDGE	0
#define TEST_TEXT1_TOP_EDGE	20
#define TEST_TEXT1_TEXT		"Texts test"
#define TEST_TEXT1_TEXT_ATTR	&topaz60_attr

#define TEST_TEXT2_TYPE		TEXT_DATA_TYPE_TEXT
#define TEST_TEXT2_FLAGS	TEXT_DATA_FLAG_CENTER
#define TEST_TEXT2_LEFT_EDGE	0
#define TEST_TEXT2_TOP_EDGE	(TEST_TEXT1_TOP_EDGE + 20)
#define TEST_TEXT2_TEXT		"Text pen 1"
#define TEST_TEXT2_TEXT_ATTR	&topaz80_attr

#define TEST_TEXT3_TYPE		TEXT_DATA_TYPE_TEXT
#define TEST_TEXT3_FLAGS	(TEXT_DATA_FLAG_CENTER | TEXT_DATA_FLAG_COLOR2)
#define TEST_TEXT3_LEFT_EDGE	0
#define TEST_TEXT3_TOP_EDGE	(TEST_TEXT2_TOP_EDGE + 20)
#define TEST_TEXT3_TEXT		"Text pen 2"
#define TEST_TEXT3_TEXT_ATTR	&topaz80_attr

#define TEST_TEXT4_TYPE		TEXT_DATA_TYPE_TEXT
#define TEST_TEXT4_FLAGS	(TEXT_DATA_FLAG_PLACE_LEFT)
#define TEST_TEXT4_LEFT_EDGE	(WINDOW_WIDTH / 2 - 4)
#define TEST_TEXT4_TOP_EDGE	(TEST_TEXT3_TOP_EDGE + 30)
#define TEST_TEXT4_TEXT		"Unsigned dec"
#define TEST_TEXT4_TEXT_ATTR	&topaz80_attr

#define TEST_TEXT5_TYPE		TEXT_DATA_TYPE_NUM_UNSIGNED_DEC
#define TEST_TEXT5_FLAGS	TEXT_DATA_FLAG_COLOR2
#define TEST_TEXT5_LEFT_EDGE	(WINDOW_WIDTH / 2 + 4)
#define TEST_TEXT5_TOP_EDGE	TEST_TEXT4_TOP_EDGE
#define TEST_TEXT5_TEXT		(BYTE *)0x0f0f0f0f
#define TEST_TEXT5_TEXT_ATTR	&topaz80_attr

#define TEST_TEXT6_TYPE		TEXT_DATA_TYPE_TEXT
#define TEST_TEXT6_FLAGS	(TEXT_DATA_FLAG_PLACE_LEFT | TEXT_DATA_FLAG_ITALIC)
#define TEST_TEXT6_LEFT_EDGE	(WINDOW_WIDTH / 2 - 4)
#define TEST_TEXT6_TOP_EDGE	(TEST_TEXT5_TOP_EDGE + 20)
#define TEST_TEXT6_TEXT		"Signed dec"
#define TEST_TEXT6_TEXT_ATTR	&topaz80_attr

#define TEST_TEXT7_TYPE		TEXT_DATA_TYPE_NUM_SIGNED_DEC
#define TEST_TEXT7_FLAGS	(TEXT_DATA_FLAG_COLOR2 | TEXT_DATA_FLAG_NUM_LEADING_ZEROES)
#define TEST_TEXT7_LEFT_EDGE	(WINDOW_WIDTH / 2 + 4)
#define TEST_TEXT7_TOP_EDGE	TEST_TEXT6_TOP_EDGE
#define TEST_TEXT7_TEXT		(BYTE *)0x0f0f0f0f
#define TEST_TEXT7_TEXT_ATTR	&topaz80_attr

#define TEST_TEXT8_TYPE		TEXT_DATA_TYPE_TEXT
#define TEST_TEXT8_FLAGS	(TEXT_DATA_FLAG_PLACE_LEFT | TEXT_DATA_FLAG_ITALIC)
#define TEST_TEXT8_LEFT_EDGE	(WINDOW_WIDTH / 2 - 4)
#define TEST_TEXT8_TOP_EDGE	(TEST_TEXT7_TOP_EDGE + 20)
#define TEST_TEXT8_TEXT		"Hex"
#define TEST_TEXT8_TEXT_ATTR	&topaz80_attr

#define TEST_TEXT9_TYPE		TEXT_DATA_TYPE_NUM_HEX
#define TEST_TEXT9_FLAGS	(TEXT_DATA_FLAG_COLOR2 | TEXT_DATA_FLAG_NUM_IDENTIFIER | TEXT_DATA_FLAG_NUM_C_STYLE | TEXT_DATA_FLAG_NUM_UPPER_CASE)
#define TEST_TEXT9_LEFT_EDGE	(WINDOW_WIDTH / 2 + 4)
#define TEST_TEXT9_TOP_EDGE	TEST_TEXT8_TOP_EDGE
#define TEST_TEXT9_TEXT		(BYTE *)0x0f0f0f0f
#define TEST_TEXT9_TEXT_ATTR	&topaz80_attr

#define TEST_TEXT10_TYPE	TEXT_DATA_TYPE_TEXT
#define TEST_TEXT10_FLAGS	(TEXT_DATA_FLAG_PLACE_LEFT | TEXT_DATA_FLAG_ITALIC)
#define TEST_TEXT10_LEFT_EDGE	(WINDOW_WIDTH / 2 - 4)
#define TEST_TEXT10_TOP_EDGE	(TEST_TEXT9_TOP_EDGE + 20)
#define TEST_TEXT10_TEXT	"Bin"
#define TEST_TEXT10_TEXT_ATTR	&topaz80_attr

#define TEST_TEXT11_TYPE	TEXT_DATA_TYPE_NUM_BIN
#define TEST_TEXT11_FLAGS	(TEXT_DATA_FLAG_COLOR2 | TEXT_DATA_FLAG_NUM_IDENTIFIER | TEXT_DATA_FLAG_NUM_LEADING_ZEROES)
#define TEST_TEXT11_LEFT_EDGE	(WINDOW_WIDTH / 2 + 4)
#define TEST_TEXT11_TOP_EDGE	TEST_TEXT10_TOP_EDGE
#define TEST_TEXT11_TEXT	(BYTE *)0x0f0f0f0f
#define TEST_TEXT11_TEXT_ATTR	&topaz80_attr

	/* Statics for texts */

STATIC struct TextData  test_text_data[] = {
   {
	TEST_TEXT1_TYPE,	/* td_Type */
	TEST_TEXT1_FLAGS,	/* td_Flags */
	TEST_TEXT1_LEFT_EDGE,	/* td_LeftEdge */
	TEST_TEXT1_TOP_EDGE,	/* td_TopEdge */
	TEST_TEXT1_TEXT,	/* *td_Text */
	TEST_TEXT1_TEXT_ATTR	/* *td_TextAttr */
   }, {
	TEST_TEXT2_TYPE,	/* td_Type */
	TEST_TEXT2_FLAGS,	/* td_Flags */
	TEST_TEXT2_LEFT_EDGE,	/* td_LeftEdge */
	TEST_TEXT2_TOP_EDGE,	/* td_TopEdge */
	TEST_TEXT2_TEXT,	/* *td_Text */
	TEST_TEXT2_TEXT_ATTR	/* *td_TextAttr */
   }, {
	TEST_TEXT3_TYPE,	/* td_Type */
	TEST_TEXT3_FLAGS,	/* td_Flags */
	TEST_TEXT3_LEFT_EDGE,	/* td_LeftEdge */
	TEST_TEXT3_TOP_EDGE,	/* td_TopEdge */
	TEST_TEXT3_TEXT,	/* *td_Text */
	TEST_TEXT3_TEXT_ATTR	/* *td_TextAttr */
   }, {
	TEST_TEXT4_TYPE,	/* td_Type */
	TEST_TEXT4_FLAGS,	/* td_Flags */
	TEST_TEXT4_LEFT_EDGE,	/* td_LeftEdge */
	TEST_TEXT4_TOP_EDGE,	/* td_TopEdge */
	TEST_TEXT4_TEXT,	/* *td_Text */
	TEST_TEXT4_TEXT_ATTR	/* *td_TextAttr */
   }, {
	TEST_TEXT5_TYPE,	/* td_Type */
	TEST_TEXT5_FLAGS,	/* td_Flags */
	TEST_TEXT5_LEFT_EDGE,	/* td_LeftEdge */
	TEST_TEXT5_TOP_EDGE,	/* td_TopEdge */
	TEST_TEXT5_TEXT,	/* *td_Text */
	TEST_TEXT5_TEXT_ATTR	/* *td_TextAttr */
   }, {
	TEST_TEXT6_TYPE,	/* td_Type */
	TEST_TEXT6_FLAGS,	/* td_Flags */
	TEST_TEXT6_LEFT_EDGE,	/* td_LeftEdge */
	TEST_TEXT6_TOP_EDGE,	/* td_TopEdge */
	TEST_TEXT6_TEXT,	/* *td_Text */
	TEST_TEXT6_TEXT_ATTR	/* *td_TextAttr */
   }, {
	TEST_TEXT7_TYPE,	/* td_Type */
	TEST_TEXT7_FLAGS,	/* td_Flags */
	TEST_TEXT7_LEFT_EDGE,	/* td_LeftEdge */
	TEST_TEXT7_TOP_EDGE,	/* td_TopEdge */
	TEST_TEXT7_TEXT,	/* *td_Text */
	TEST_TEXT7_TEXT_ATTR	/* *td_TextAttr */
   }, {
	TEST_TEXT8_TYPE,	/* td_Type */
	TEST_TEXT8_FLAGS,	/* td_Flags */
	TEST_TEXT8_LEFT_EDGE,	/* td_LeftEdge */
	TEST_TEXT8_TOP_EDGE,	/* td_TopEdge */
	TEST_TEXT8_TEXT,	/* *td_Text */
	TEST_TEXT8_TEXT_ATTR	/* *td_TextAttr */
   }, {
	TEST_TEXT9_TYPE,	/* td_Type */
	TEST_TEXT9_FLAGS,	/* td_Flags */
	TEST_TEXT9_LEFT_EDGE,	/* td_LeftEdge */
	TEST_TEXT9_TOP_EDGE,	/* td_TopEdge */
	TEST_TEXT9_TEXT,	/* *td_Text */
	TEST_TEXT9_TEXT_ATTR	/* *td_TextAttr */
   }, {
	TEST_TEXT10_TYPE,	/* td_Type */
	TEST_TEXT10_FLAGS,	/* td_Flags */
	TEST_TEXT10_LEFT_EDGE,	/* td_LeftEdge */
	TEST_TEXT10_TOP_EDGE,	/* td_TopEdge */
	TEST_TEXT10_TEXT,	/* *td_Text */
	TEST_TEXT10_TEXT_ATTR	/* *td_TextAttr */
   }, {
	TEST_TEXT11_TYPE,	/* td_Type */
	TEST_TEXT11_FLAGS,	/* td_Flags */
	TEST_TEXT11_LEFT_EDGE,	/* td_LeftEdge */
	TEST_TEXT11_TOP_EDGE,	/* td_TopEdge */
	TEST_TEXT11_TEXT,	/* *td_Text */
	TEST_TEXT11_TEXT_ATTR	/* *td_TextAttr */
   }, {
	INTUISUP_DATA_END	/* mark end of text data array */
   }
};
	/* Prototypes */

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

	/* Pragmas */

#pragma regcall(test_action(a0,a1))

	/* Texts test */

   LONG
main(VOID)
{
   struct IOStdReq    io;
   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 (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)) {
			test_action(ri, win);
			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 MsgPort  *up = win->UserPort;
   BOOL keepon = TRUE;

   display_texts(ri, win, &test_text_data[0], 0, 0, NULL);
   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);
}
