
                      /* Listato 5 */

              /* Paint su schermo 640x256 */


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

 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=(struct Screen *)Schermo(0,640,256,2,0,1,HIRES,
                                 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); /* Prepara un BOX */

   Paint(finestra,40,40,1,NULL); /* Riempie il box in tinta unita */


           /* 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 */


  /* Tinta unita */
UWORD StdPattern[]={0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff};

int Paint(w,x,y,c,p)
struct Window *w;
unsigned x,y,c;
UWORD *p; /* Eventuale pattern */
{
 PLANEPTR *TBuf;
 struct RastPort *rp;
 struct TmpRas TRas;

 if (p==NULL) p=StdPattern; /* Se non c'e' un pattern usa lo StdPattern */

 rp=(struct RastPort *)CRast(w);
 if ((TBuf=(PLANEPTR *)AllocRaster(640,256))==NULL) /* Chiede Memoria */
                          return(-1); /* Problemi di memoria */

     /* Lega la memoria al TmpRas del RastPort */
 rp->TmpRas=(struct TmpRas *)InitTmpRas(&TRas,TBuf,RASSIZE(640,256));

 SetAfPt(rp,p,3); /* Setta il Pattern */
 SetAPen(rp,c); /* Penna punti a 1 */
 SetBPen(rp,0); /* Penna punti a 0 */
 SetDrMd(rp,JAM2); /* Modo di disegno */
 Flood(rp,1,x,y); /* Paint ! */
 FreeRaster(TBuf,640,256); /* Rende la memoria al sistema */
 return(0); /* Tutto OK */
}

