#include <intuition/intuition.h>
#include <graphics/text.h>

#ifdef LATTICE
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <stdlib.h>
#else
#include <functions.h>
#endif

#define GNOM "graphics.library"
#define INOM "intuition.library"
#define NPUN  8

struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Window *wdw;
struct Screen *scr;

SHORT punti [] = {
 30,60, 90,60, 90,20, 100,80,
 90,140, 90,90, 30,90, 30,60 
};

struct Border linee = {
 0,0, 5,0, JAM1, NPUN, &punti[0]
};

struct TextAttr Fonte1 = {
 "topaz.font", 8, FS_NORMAL, FPF_ROMFONT
};
struct TextAttr Fonte2 = {
 "topaz.font", 9, FS_NORMAL, FPF_ROMFONT
};

struct IntuiText m[] = {
 { 1,2, JAM2, 120,30, &Fonte1, "IntuiText 1", &m[1] },
 { 2,1, JAM2, 120,50, &Fonte2, "IntuiText 2", &m[2] },
 { 2,0, JAM1, 120,70, &Fonte1, "IntuiText 3", &m[3] },
 { 3,1, JAM2, 120,90, &Fonte2, "IntuiText 4", NULL }
};

struct NewScreen NewScreenS = {
 0,0, 320,200, 2,1, 2, NULL, CUSTOMSCREEN,
 NULL, (UBYTE *)"Customscreen", NULL, NULL
};

struct NewWindow NewWindowS = {
 0,50, 320,150, -1,-1, CLOSEWINDOW,
 SMART_REFRESH + ACTIVATE + WINDOWCLOSE,
 NULL, NULL, (UBYTE *) "Intuition1",
 NULL, NULL, 0,0, 0,0, CUSTOMSCREEN
};

void die( n ) /* Chiusura ed uscita pulita */
SHORT n;
{
 if ( wdw ) CloseWindow( wdw );
 if ( scr ) CloseScreen( scr );
 if ( GfxBase ) CloseLibrary( GfxBase );
 if ( IntuitionBase ) CloseLibrary( IntuitionBase );
 _exit( n );
}

void main()
{
 register struct RastPort *rp;

/* Apertura delle librerie necessarie */
 IntuitionBase=(struct IntuitionBase *)OpenLibrary(INOM,33L);
 if ( ! IntuitionBase ) die( 10 );

 GfxBase = (struct GfxBase *) OpenLibrary( GNOM, 33L );
 if ( ! GfxBase ) die( 11 );

/* Apertura dello schermo */

 scr = (struct Screen *) OpenScreen( &NewScreenS );
 if ( scr == NULL ) die( 12 );

/* Apriamo la nostra finestra nello schermo */

 NewWindowS.Screen = scr;
 wdw = (struct Window *) OpenWindow( &NewWindowS );
 if ( wdw == NULL ) die( 13 );

/* Memorizziamo puntatore a RastPort e tracciamo freccia */

 rp = wdw -> RPort;
 DrawBorder( rp, &linee, 0, 0 );

/* Ora scriviamo con PrintIText() una serie di IntuiText */

 PrintIText( rp, &m[0], 0, 0 );

/* Attendiamo l'evento CLOSEWINDOW per finire */

 Wait( 1L << wdw -> UserPort -> mp_SigBit );
 die( 0 );
}
