
                      /* Listato 6 */

                /* Paint versione 2.00 */


#include <grafica.h>
#define PORT finestra->UserPort

              /* Pattern */
UWORD p[8] = {0x0f0f,0xf0f0,0x0f0f,0xf0f0,0x0f0f,0xf0f0,0x0f0f,0xf0f0};

 main()
 {
struct Screen *schermo;/* Prepara struttura per lo screen */
struct Window *finestra;/* Prepara struttura per la finestra */
struct IntuiMessage *messaggio;/* Prepara struttura per il messaggio */

ULONG class;


  AttivaG(); /* Apre le librerie */

  /* Schermo 320x512 = Bassa risoluzione interlacciato */
schermo=(struct Screen *)Schermo(0,320,512,2,0,1,LACE,
                                 NULL,"Schermo di prova");
if (schermo==NULL) {
                    EndG();
                    exit(); /* Problemi !*/
                   };

Palette(schermo,0,0,0,0); /* Schermo nero */
Palette(schermo,1,0,0,15); /* Blu */
Palette(schermo,2,0,15,0); /* Verde */
Palette(schermo,3,15,0,0); /* Rosso */

finestra=(struct Window *)Finestra(100,50,150,150,-1,-1,CLOSEWINDOW,
                                   WINDOWCLOSE+WINDOWDRAG+ACTIVATE,
                                   NULL,NULL,
                                   "Finestra",schermo,50,50,600,250);

   Box(finestra,30,30,100,80,2);

   Paint(finestra,40,40,1,p); /* Paint con pattern p */


           /* Aspetta che la finestra sia chiusa */

 for(;;)  /* Ciclo infinito */
     {
              /* Attende un messaggio valido */
       while ((messaggio=(struct IntuiMessage *)GetMsg(PORT))!=NULL)
               {
                    /* Salvo i campi che mi interessano */
                 class=messaggio->Class;
                 ReplyMsg(messaggio); /* Messaggio ricevuto ! */

                 if (class==CLOSEWINDOW) { /* Chiude la finestra */
                                           CloseWindow(finestra);
                                           CloseScreen(schermo);
                                           EndG();
                                           exit();
                                          };

                }; /* Fine while */

 
     };  /* Ciclo infinto */


} /* FINE */


UWORD StdPattern[]={0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff};

Paint(w,x,y,c,p) /* Versione 2.00 */
struct Window *w;
unsigned x,y,c;
UWORD *p;
{
 struct Screen *s; /* Schermo relativo alla window */
 PLANEPTR *TBuf;
 struct RastPort *rp;
 struct TmpRas TRas;
 SHORT l;
 SHORT h;

 s=w->WScreen;  /* Trova lo schermo che contiene la finestra */

 l=s->Width;  /* Memorizza le misure dello schermo */
 h=s->Height;

 if (p==NULL) p=StdPattern;

 rp=(struct RastPort *)CRast(w);
 if ((TBuf=(PLANEPTR *)AllocRaster(l,h))==NULL) /* Problemi di memoria */
                                                    return(-1);


 rp->TmpRas=(struct TmpRas *)InitTmpRas(&TRas,TBuf,RASSIZE(l,h));

 SetAfPt(rp,p,3);
 SetAPen(rp,c);
 SetBPen(rp,0);
 SetDrMd(rp,JAM2);
 Flood(rp,1,x,y);
 FreeRaster(TBuf,l,h);
 return(0);
}

