
                      /* Listato 3 */

            /* Line e patterns con Grafica.h */


#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,15,15,15); /* Bianco */
Palette(schermo,2,3,5,8);
Palette(schermo,3,7,8,3);

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


       LP(finestra,10,50,100,50,204,3,2); /* P=0000000011001100 */


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



LP(w,x1,y1,x2,y2,p,cf,cb) /* Disegna una linea con il pattern p */
struct Window *w;
unsigned x1,y1,x2,y2,p,cf,cb;
{
 struct RastPort *rp;

 rp=(struct RastPort *)CRast(w); /* Ricava il RastPort
                                    relativo alla finestra w */

 SetAPen(rp,cf); /* Setta il colore della penna A - Bits a 1 */
 SetBPen(rp,cb); /* Setta il colore della penna B - Bits a 0 */
 SetDrMd(rp,JAM2); /* Setta il modo di disegno */
 SetDrPt(rp,p); /* Setta il pattern */
 Move(rp,x1,y1); /* Disegna la linea */
 Draw(rp,x2,y2);
}
 



