home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 357.lha / intuisup_v1.15 / examples / bmaprport / test.c < prev    next >
C/C++ Source or Header  |  1990-03-10  |  6KB  |  206 lines

  1. /**********************************************************************
  2.  *
  3.  *       fichier:  main.c
  4.  *
  5.  *       fonction: test des fonctions de   BMapRPort.c
  6.  *
  7.  *       creation: 19-Sep-88  jm forgeas
  8.  *       revision: 19-Sep-88  jm forgeas
  9.  *
  10.  **********************************************************************/
  11.  
  12.  
  13. /******* Included Files ***********************************************/
  14.  
  15. #include <intuition/intuition.h>
  16. #include <intuition/intuitionbase.h>
  17. #include <exec/types.h>
  18. #include <exec/tasks.h>
  19. #include <exec/memory.h>
  20. #include <libraries/dos.h>
  21. #include <graphics/GfxBase.h>
  22. #include <graphics/gels.h>
  23. #include <graphics/gfxmacros.h>
  24. #include <graphics/view.h>
  25.  
  26. #include <intuition/intuisup.h>
  27.  
  28.  
  29. /******* Exported *****************************************************/
  30.  
  31. struct GfxBase  *GfxBase=0;
  32. struct IntuitionBase  *IntuitionBase=0;
  33. #ifdef ISUP_RUNTIME
  34. struct   Library  *iSupBase;
  35. #endif
  36.  
  37.  
  38. /******* Imported *****************************************************/
  39.  
  40.  
  41. /******* Program ******************************************************/
  42.  
  43. static  VOID    Cleanup();
  44.  
  45. #define DEPTH   4
  46. #define COLNUM  (2 << DEPTH)
  47.  
  48. static  SHORT WIDTH    = 450;
  49. static  SHORT HEIGHT   = 100;
  50. static  SHORT RXOFFSET =  30;
  51.  
  52. static struct View      *v=0, *oldview=0;
  53. static struct ViewPort  *vp=0;
  54. static struct RasInfo   *ri=0;
  55. static struct BitMap    *bm=0;
  56. static struct RastPort  *rp=0;
  57.  
  58. static USHORT  colortable[] = {
  59.         0x000, 0xf00, 0x0f0, 0x00f,
  60.         0xff0, 0xdd0, 0xbb0, 0x880,
  61.         0x440, 0x000, 0xfff, 0xfff,
  62.         0xfff, 0xccc, 0x888, 0x444
  63.         };
  64.  
  65.  
  66. /**********************************************************************
  67.  *
  68.  *      Routines
  69.  *
  70.  **********************************************************************/
  71.  
  72. static SetWBLike( view, adrwidth, adrheight )
  73. struct View *view;
  74. SHORT *adrwidth, *adrheight;
  75. {
  76.     struct Screen wbScrData;
  77.  
  78.         if (! (IntuitionBase = (struct IntuitionBase *) OpenLibrary( "intuition.library", 0))) return(NULL);
  79.         if (! (GetScreenData( &wbScrData, sizeof(struct Screen), WBENCHSCREEN, NULL ))) return(NULL);
  80.         view->DxOffset = IntuitionBase->ViewLord.DxOffset;
  81.         view->DyOffset = IntuitionBase->ViewLord.DyOffset;
  82.         *adrwidth  = wbScrData.Width;
  83.         *adrheight = wbScrData.Height;
  84.         CloseLibrary( IntuitionBase ); IntuitionBase=0;
  85.         return(TRUE);
  86. }
  87.  
  88. static VOID AllocAllocs()
  89. {
  90.         if (! (v  = (struct View *) AllocMem( sizeof(struct View), MEMF_PUBLIC | MEMF_CLEAR))) Cleanup();
  91.         InitView( v );
  92.  
  93.         if (! (vp = (struct ViewPort *) AllocMem( sizeof(struct ViewPort), MEMF_PUBLIC | MEMF_CLEAR))) Cleanup();
  94.         InitVPort( vp );
  95.         v->ViewPort  = vp;
  96.         if (! (vp->ColorMap = (struct ColorMap *) GetColorMap( COLNUM ))) Cleanup();
  97.  
  98.         if (! (ri = (struct RasInfo *) AllocMem( sizeof(struct RasInfo), MEMF_PUBLIC | MEMF_CLEAR))) Cleanup();
  99.         vp->RasInfo  = ri;
  100.  
  101.         if (! (bm = (struct BitMap *) is_AllocBMap( DEPTH, WIDTH, HEIGHT ))) Cleanup();
  102.         if (! (rp = (struct RastPort *) is_AllocRPort())) Cleanup();
  103. /*
  104.         if (! (rp = (struct RastPort *) is_AllocBMapRPort( DEPTH, WIDTH, HEIGHT ))) Cleanup();
  105.         bm = rp->BitMap;
  106. */
  107. }
  108.  
  109. static VOID FreeAllocs()
  110. {
  111. /*
  112.         is_FreeBMapRPort( rp );
  113. */
  114.         is_FreeBMap( bm );
  115.         is_FreeRPort( rp );
  116.  
  117.         if (ri) FreeMem( ri, sizeof(struct RasInfo) );
  118.         if (vp) {
  119.                 if (vp->ColorMap) FreeColorMap( vp->ColorMap );
  120.                 FreeVPortCopLists( vp );
  121.                 FreeMem( vp, sizeof(struct ViewPort) );
  122.                 }
  123.         if (v)  {
  124.                 if (v->LOFCprList) FreeCprList( v->LOFCprList );
  125.                 if (v->SHFCprList) FreeCprList( v->SHFCprList );
  126.                 FreeMem( v, sizeof(struct View) );
  127.                 }
  128. }
  129.  
  130. /**********************************************************************
  131.  *
  132.  *      Main program
  133.  *
  134.  **********************************************************************/
  135.  
  136. static VOID Cleanup()
  137. {
  138.         if (oldview) LoadView( oldview );
  139.         FreeAllocs();
  140. #ifdef ISUP_RUNTIME
  141.         if (iSupBase) CloseLibrary(iSupBase);
  142. #endif
  143.         if (GfxBase)  CloseLibrary(GfxBase);
  144.         exit(0);
  145. }
  146.  
  147. static VOID DoItNice()
  148. {
  149.     register SHORT x;
  150.  
  151.         /*--------- fond ---------*/
  152.         SetAPen( rp, 5 ); RectFill( rp, 0,0, 145,90 );
  153.         SetAPen( rp, 2 ); RectFill( rp, 150,0, 295,90 );
  154.         SetAPen( rp, 3 ); RectFill( rp, 300,0, 449,90 );
  155.  
  156.         /*--------- bords --------*/
  157.         for (x=0; x<6; x++)
  158.                 { SetAPen( rp, 9-x ); RectFill( rp, RXOFFSET+x,x, RXOFFSET+vp->DWidth-1-x, 10-x ); }
  159.         BltBitMap( bm, RXOFFSET,0, bm, RXOFFSET,vp->DHeight-12, vp->DWidth,11, 0xc0, 0xff, 0 );
  160. }
  161.  
  162. VOID main()
  163. {
  164.     register SHORT i, BMinc=3, time=0;
  165.     SHORT i_height, i_width;
  166.  
  167.     if (  !(GfxBase       = (struct GfxBase *)OpenLibrary("graphics.library", 0))
  168. #ifdef ISUP_RUNTIME
  169.        || !(iSupBase      = (struct Library *)OpenLibrary("isup.library", 0))
  170. #endif
  171.        ) Cleanup();;
  172.         oldview = GfxBase->ActiView;
  173.  
  174.         AllocAllocs();
  175.         if (! SetWBLike( v, &i_width, &i_height )) Cleanup();
  176.  
  177.         vp->DyOffset = i_height - HEIGHT;
  178.         vp->DWidth   = i_width >> 1;
  179.         vp->DHeight  = HEIGHT;
  180.  
  181.         ri->BitMap = rp->BitMap = bm;    /* avec is_AllocBMap()      */
  182.        /* ri->BitMap = rp->BitMap;*/     /* avec is_AllocBMapRPort() */
  183.         ri->RxOffset = RXOFFSET;
  184.  
  185.         LoadRGB4( vp, colortable, COLNUM );
  186.         DoItNice();
  187.  
  188.         MakeVPort( v, vp );
  189.         MrgCop( v );
  190.         LoadView( v );
  191.         FOREVER
  192.             {
  193.             if (++time > 5*50) break;
  194.  
  195.             i = ri->RxOffset;
  196.             i += BMinc; if (i>100 || i<1) BMinc = -BMinc;
  197.             ri->RxOffset = i;
  198.  
  199.             MakeVPort( v, vp );
  200.             WaitBOVP( vp );
  201.             MrgCop( v );
  202.             }
  203.         Cleanup();
  204. }
  205.  
  206.