home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / software / varie / charmap / source / helpwin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-04  |  3.8 KB  |  143 lines

  1. /***************************************************************
  2. ** helpwin.c: Affiche une fenêtre d'aide sur le caractère     **
  3. **            Écrit par T.Pierron                             **
  4. **            15-03-1999                                      **
  5. ***************************************************************/
  6.  
  7. #include <Intuition/Intuition.H>
  8. #include <Graphics/Rastport.H>
  9. #include <Graphics/Gfxmacros.H>
  10. #include <Exec/Memory.H>
  11.  
  12. #include    "cmap.h"
  13. #define    CATCOMP_NUMBERS
  14. #define    CATCOMP_STRINGS
  15. #include    "cmap_strings.h"
  16.  
  17. WORD I;
  18.  
  19. /**** Cette fonction, extrêmement importante, permet d'allouer    *****
  20. ***** un nouvel affichage sans être obligé d'ouvrir une fenê-    *****
  21. ***** tre, avec les lourdeurs qui suivent.                            ****/
  22. struct RastPort *Alloc_rastport( WORD larg,WORD haut,WORD depth )
  23. {
  24.     static struct RastPort *RP;
  25.     static struct BitMap *BM;
  26.     static Point *P;
  27.  
  28.     /* Alloue les trois structures: */
  29.     if( (RP=(void *) AllocMem(sizeof(struct tPoint)+sizeof(struct RastPort)+sizeof(struct BitMap),MEMF_PUBLIC))==NULL )
  30.         return NULL;
  31.  
  32.     /* Sauvegarde quelques données: */
  33.     BM = (struct BitMap *) (RP+1);
  34.     P  = (Point *) (BM+1);
  35.     RP->BitMap = BM; P->x = larg; P->y = haut;
  36.  
  37.     /* Prépare le BitMap: */
  38.     InitBitMap( BM, depth, larg, haut );
  39.  
  40.     /* Alloue la mémoire pour le Raster: */ 
  41.     for( I = 0; I < depth; I++ )
  42.     {
  43.         if( (BM->Planes[ I ] = (PLANEPTR) AllocRaster( larg, haut ))==NULL )
  44.             return NULL;
  45.  
  46.         /* Efface la mémoire avec l'aide du Blitter: */
  47.         BltClear( BM->Planes[ I ], RASSIZE( larg, haut ), 0 );
  48.     }
  49.  
  50.     /* Prépare le RastPort, en donnant un pointeur sur le BitMap. */
  51.     InitRastPort( RP );
  52.     RP->BitMap = BM;
  53.     return RP;
  54. }
  55.  
  56. static struct RastPort *RPW=NULL;
  57. extern struct RastPort *RP,RPT;
  58.  
  59. /**** Libère l'affichage alloué avec la fonction ci-dessus: ****/
  60. void Free_helpwin()
  61. {
  62.     register struct BitMap *BM;
  63.     register Point *P;
  64.     register WORD depth;
  65.  
  66.     if(RPW) {
  67.         /* Libère les bitplans un à un: */
  68.         for( I = 0,BM = RPW->BitMap,depth = BM->Depth,P = (Point *)(BM+1); I < depth; I++ )
  69.             if( BM->Planes[ I ] )
  70.                 FreeRaster( BM->Planes[ I ], P->x, P->y );
  71.  
  72.         /* Et la mémoire pour les structures de données: */
  73.         FreeMem(RPW,sizeof(struct tPoint)+sizeof(struct RastPort)+sizeof(struct BitMap));
  74.         RPW=0;
  75.     }
  76. }
  77.  
  78. UBYTE *popmsg[]={ MSG_CODE_STR,MSG_DEC_STR,MSG_HEX_STR,MSG_OCT_STR,0 };
  79. static WORD WinW,WinH,Larg,X,Y;
  80. extern UBYTE Font_height,*Errors[];
  81.  
  82. /**** Calcule la largueur et la hauteur de la fenêtre en fonction de la police: ****/
  83. void Init_helpwin()
  84. {
  85.     extern struct Screen *screen;
  86.     register UBYTE **p;
  87.  
  88.     for(p=popmsg,Larg=0,WinH=3; *p; p++,WinH += Font_height-3)
  89.         if(Larg < (WinW=TextLength(&RPT,*p,strlen(*p)))) Larg = WinW;
  90.  
  91.     Larg += 10; WinW = Larg+5+TextLength(&RPT,"999",3); /* WinH -= 9; */
  92.     if( !(RPW=Alloc_rastport(WinW,WinH,screen->BitMap.Depth)) )
  93.         cleanup(ErrMsg(MSG_ERRNOMEM),30);
  94. }
  95.  
  96. /**** Conversion binaire => Base ****/
  97. void convert_to_base(UBYTE *Str,UBYTE Var,BYTE Base)
  98. {
  99.     UBYTE ChConv[]="0123456789ABCDEF";
  100.     UBYTE *ptr=Str,L=0;
  101.  
  102.     Var &= 0xFF;
  103.  
  104.     do {
  105.         ptr--; L++;
  106.         *ptr = ChConv[ Var%Base ];
  107.     } while(Var /= Base);
  108.  
  109.     Text(RP,ptr,L);
  110. }
  111.  
  112. /**** Affiche toute les infos de la fenêtre: ****/
  113. void Open_helpwin(UBYTE Num,WORD x,WORD y)
  114. {
  115.     extern struct Window *window;
  116.     extern WORD      txtpen,poppen;
  117.     static UBYTE  Str[6];
  118.     int i;
  119.  
  120.     if(x+WinW>window->Width)  x=window->Width-WinW;
  121.     if(y+WinH>window->Height) y=window->Height-WinH;
  122.  
  123.     /* Sauvegarde l'affichage de la fenêtre: */
  124.     ClipBlit(RP,x,y,RPW,0,0,WinW,WinH,0xC0);
  125.  
  126.     SetOPen(RP,txtpen); SetAPen(RP,poppen);
  127.     RectFill(RP,x,y,x+WinW-1,y+WinH-1);
  128.     BNDRYOFF(RP);  SetAPen(RP,txtpen);
  129.  
  130.     X=x; Y=y;
  131.     for(i=0,y+=Font_height-4; i<sizeof(popmsg)/sizeof(UBYTE *)-1; i++,y+=Font_height-3)
  132.     {
  133.         Move(RP,x+5,y);    Text(RP,popmsg[i],strlen(popmsg[i]));    Move(RP,x+Larg,RP->cp_y);
  134.         if(i==0)    Text(RP,&Num,1);
  135.         else convert_to_base(Str+6,Num,i==1? 10 : i==2? 16 : 8);
  136.     }
  137. }
  138.  
  139. void Close_helpwin()
  140. {
  141.     ClipBlit(RPW,0,0,RP,X,Y,WinW,WinH,0xC0);
  142. }
  143.