Per dubbi, consigli o richieste, potete mandare un'e-mail ad Andrea Carolfi.
Ringraziamo Amiga Transactor Mailing List per questo tangibile contributo!
Purtroppo, quello che manca a questa libreria è un completo supporto RTG per l'hardware che fortunatamente è possibile aggiungere tramite CGX o Picasso96 sostituendo alcune funzioni di questa libreria per permettergli di operare anche senza il chipset (vedi DraCo). Comunque, seguendo alcuni accorgimenti è possibile, avvalendosi del display database, far girare la propria applicazione grafica sia su schermo OCS/ECS/AGA che su scheda grafica. Prima di vedere le primitive grafiche di questa lezione, è
necessario specificare che praticamente tutte le funzioni grafiche necessitano
di una bitmap associata ad una rastport. BitMap e RastPort typedef UBYTE *PLANEPTR; struct BitMap { UWORD BytesPerRow; UWORD Rows; UBYTE Flags; UBYTE Depth; UWORD pad; PLANEPTR Planes[8]; }; struct RastPort { struct Layer *Layer; struct BitMap *BitMap; UWORD *AreaPtrn; /* ptr to areafill pattern */ struct TmpRas *TmpRas; struct AreaInfo *AreaInfo; struct GelsInfo *GelsInfo; UBYTE Mask; /* write mask for this raster */ BYTE FgPen; /* foreground pen for this raster */ BYTE BgPen; /* background pen */ BYTE AOlPen; /* areafill outline pen */ BYTE DrawMode; /* drawing mode for fill, lines, and text */ BYTE AreaPtSz; /* 2^n words for areafill pattern */ BYTE linpatcnt; /* current line drawing pattern preshift */ BYTE dummy; UWORD Flags; /* miscellaneous control bits */ UWORD LinePtrn; /* 16 bits for textured lines */ WORD cp_x, cp_y; /* current pen position */ UBYTE minterms[8]; WORD PenWidth; WORD PenHeight; struct TextFont *Font; /* current font address */ UBYTE AlgoStyle; /* the algorithmically generated style */ UBYTE TxFlags; /* text specific flags */ UWORD TxHeight; /* text height */ UWORD TxWidth; /* text nominal width */ UWORD TxBaseline; /* text baseline */ WORD TxSpacing; /* text spacing (per character) */ APTR *RP_User; ULONG longreserved[2]; #ifndef GFX_RASTPORT_1_2 UWORD wordreserved[7]; /* used to be a node */ UBYTE reserved[8]; /* for future use */ #endif };
La bitmap è proprio dove le operazioni grafiche andranno a scrivere o
leggere (a seconda della funzione chiamata). La rastport contiene informazioni
sullo stato attuale di colore di sfondo, colore di primo piano, posizione del
cursore grafico, carattere utilizzato e via di seguito. struct RastPort rp; struct BitMap *bm; InitRastPort(&rp); if((bm = AllocBitMap(320,200,8,BMF_CLEAR,NULL))) { rp.BitMap = bm; ... FreeBitMap(bm); }
Questo stralcio di codice, inizializza una rastport ai valori predefiniti,
alloca una bitmap ad otto piani (256 colori) di dimensioni 320x200
inizializzandola al colore 0 e collegandola alla rastport precedentemente
valorizzata. Il campo NULL della funzione è un puntatore ad una bitmap "amica" (in questo caso nessuna) che può essere richiesta per allocare la bitmap in modo da rendere le blittate dalla bitmap a quella amica più efficenti. Primitive grafiche Vediamo adesso alcune primitive grafiche: void DrawEllipse( struct RastPort *rp, long xCenter, long yCenter,
long a, long b ); void SetRast( struct RastPort *rp, unsigned long pen ); void Move( struct RastPort *rp, long x, long y ); void Draw( struct RastPort *rp, long x, long y ); void RectFill( struct RastPort *rp, long xMin, long yMin, long xMax,
long yMax ); !!! ATTENZIONE !!! if(xMax < xMin || yMax < yMin) crashsystem(); In parole :-) : le coordinate xMax e yMax devono essere maggiori o uguali a xMin e yMin, altrimenti si pianta tutto il sistema. ULONG ReadPixel( struct RastPort *rp, long x, long y ); LONG WritePixel( struct RastPort *rp, long x, long y ); void SetAPen( struct RastPort *rp, unsigned long pen ); void SetBPen( struct RastPort *rp, unsigned long pen ); void SetOPen( struct RastPort *rp, unsigned long pen ); void SetDrMd( struct RastPort *rp, unsigned long drawMode );
WORD TextLength( struct RastPort *rp, STRPTR string, unsigned long
count ); LONG Text( struct RastPort *rp, STRPTR string, unsigned long count );
LONG SetFont( struct RastPort *rp, struct TextFont *textFont ); struct TextFont *OpenFont( struct TextAttr *textAttr ); struct TextAttr { STRPTR ta_Name; /* name of the font */ UWORD ta_YSize; /* height of the font */ UBYTE ta_Style; /* intrinsic font style */ UBYTE ta_Flags; /* font preferences and flags */ }; Un esempio di inizializzazione è: struct TextAttr MyFont = {"helvetica.font",15,FS_NORMAL,FPF_DISKFONT}; I flags sono definiti in include:graphics/text.h void CloseFont( struct TextFont *textFont ); ULONG AskSoftStyle( struct RastPort *rp ); ULONG SetSoftStyle( struct RastPort *rp, unsigned long style,
unsigned long enable);
Anche se onestamente non ho mai usato gli ultimi tre. Listato di questa lezione
|