home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / grafix / boards / a2410src.lha / Public / Source / BlitDemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-20  |  5.4 KB  |  195 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5. #include <graphics/gfx.h>
  6. #include <intuition/intuition.h>
  7. #include <intuition/intuitionbase.h>
  8. #include <graphics/gfxmacros.h>
  9.  
  10.  
  11. #include <pragmas/exec_pragmas.h>
  12. #include <pragmas/graphics_pragmas.h>
  13. #include <pragmas/intuition_pragmas.h>
  14.  
  15. #include <clib/exec_protos.h>
  16. #include <clib/graphics_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/diskfont_protos.h>
  19.  
  20. #include "gfx_pragmas.h"
  21. #include "graphics.h"
  22.  
  23. /* could be any bitmap you want, see pic4.c */
  24. #include "pic1.c"  
  25. #include "pic2.c"
  26. #include "pic3.c"
  27. #include "pic4.c"
  28.  
  29. //#define Custom
  30.  
  31. struct IntuitionBase *IntuitionBase=NULL;
  32. struct Library *GfxBase=NULL,*AslBase=NULL;
  33. struct Library *GspGfxBase=NULL,*GraphicsBase=NULL,*DiskfontBase=NULL;
  34. struct Screen *screen;
  35. struct Window *window=NULL,*window2,*window3;
  36. struct RastPort *RP;
  37. struct Rectangle *bounds;
  38. struct ClipRect *cliprect;
  39. long x0,y0,x1,y1; 
  40. BOOL Amiga = FALSE;
  41.  
  42. void CleanUp(void);
  43. void TestFunction(void);
  44.  
  45. void main(int argc,char *argv[])
  46. {
  47.     int i;
  48.     struct TextFont *txtfnt;
  49.     struct TextAttr mytxt;
  50.  
  51.     onbreak(CleanUp);
  52.  
  53.     if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0L))) CleanUp();
  54.     if (!(GfxBase       = (struct Library *)OpenLibrary("graphics.library",0L)))  CleanUp();
  55.     if (!(GraphicsBase  = (struct Library *)OpenLibrary("gfx.library",0L)))        CleanUp();
  56.  
  57.     for (i = 1; i <= argc; i++)
  58.         if (strncmp(argv[i],"ami",3)==0) Amiga=TRUE;
  59.  
  60.     window=(struct Window *)OpenWindowTags(NULL,
  61.                         WA_Title,"Test",
  62.                         WA_DragBar,TRUE,
  63.                         WA_AutoAdjust,TRUE,
  64.                         WA_Left,0,
  65.                         WA_Top,0,
  66.                         WA_Width,640,
  67.                         WA_Height,400,
  68.                         WA_MinWidth,256,
  69.                         WA_MinHeight,256,
  70.                         WA_MaxWidth,2000,
  71.                         WA_MaxHeight,2000,
  72.                         WA_DepthGadget,TRUE,
  73.                         WA_CloseGadget,TRUE,
  74.                         WA_SizeGadget,TRUE,
  75.                         WA_IDCMP,IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE,
  76. #ifdef Custom
  77.                         WA_CustomScreen,screen,
  78. #endif
  79.                         TAG_DONE);
  80.  
  81.     TestFunction();
  82.  
  83.     CleanUp();
  84. }
  85.  
  86. void CleanUp(void)
  87. {
  88.     if (window)   CloseWindow(window);
  89.  
  90.     if (GraphicsBase)  CloseLibrary(GraphicsBase);
  91.     if (GfxBase)       CloseLibrary(GfxBase);
  92.     if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  93.     if (DiskfontBase)  CloseLibrary(DiskfontBase);
  94.  
  95.     exit(0);
  96. }
  97.  
  98. int event(void)
  99. {
  100.     struct IntuiMessage *message;
  101.  
  102.     chkabort();
  103.     if(window->UserPort->mp_SigBit)
  104.     {
  105.         if (message = (struct IntuiMessage *)GetMsg(window->UserPort))
  106.         {
  107.             switch(message->Class)
  108.             {
  109.                 case CLOSEWINDOW:
  110.                     ReplyMsg((struct Message *)message);
  111.                     return(0);
  112.                 case NEWSIZE:
  113.                     ReplyMsg((struct Message *)message);
  114.                 return(1);
  115.             }
  116.         }
  117.     }
  118.     return(1);
  119. }
  120.  
  121. void TestFunction(void)
  122. {
  123. #define AREA_SIZE 200
  124.  
  125.     USHORT areaptrn[] = { 0xf0f0, /*0*/ 0x0f0f, /*1*/ 0xf0f0, 0xf0f0, /*2*/ 0x0f0f, 0x0f0f, 0xf0f0, 0xf0f0,/*3*/
  126.                           0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF /*4*/ };
  127.  
  128.     struct BitMap *bm;
  129.     struct Screen *sc;
  130.     WORD areabuffer[AREA_SIZE];
  131.     struct AreaInfo areainfo = {0};
  132.     PLANEPTR planebuffer;
  133.     long planesize;
  134.     struct TmpRas tmpras;
  135.     int i,x,y,x0,y0,width,height;
  136.  
  137.     if (Amiga)
  138.     {
  139.         bm = window->RPort->BitMap;
  140.         do
  141.         {
  142.             x0 = window->LeftEdge;
  143.             y0 = window->TopEdge;
  144.             width = window->Width;
  145.             height = window->Height;
  146.  
  147.             x = (rand() % (width-pic1_width))+x0;
  148.             y = (rand() % (height-pic1_height))+y0;
  149.             BltBitMap(&pic1,0,0,bm,x,y,pic1_width,pic1_height,0xc0,~0,NULL);
  150.  
  151.             x = (rand() % (width-pic2_width))+x0;
  152.             y = (rand() % (height-pic2_height))+y0;
  153.             BltBitMap(&pic2,0,0,bm,x,y,pic2_width,pic2_height,0xc0,~0,NULL);
  154.  
  155.             x = (rand() % (width-pic3_width))+x0;
  156.             y = (rand() % (height-pic3_height))+y0;
  157.             BltBitMap(&pic3,0,0,bm,x,y,pic3_width,pic3_height,0xc0,~0,NULL);
  158.  
  159.             x = (rand() % (width-pic4_width))+x0;
  160.             y = (rand() % (height-pic4_height))+y0;
  161.             BltBitMap(&pic4,0,0,bm,x,y,pic4_width,pic4_height,0xc0,~0,NULL);
  162.         }while (event());
  163.     }
  164.     else
  165.     {
  166.         sc = IntuitionBase->ActiveScreen;
  167.         bm = sc->RastPort.BitMap;
  168.         GfxSetUpScreen(sc);
  169.         do
  170.         {
  171.             x0 = window->LeftEdge;
  172.             y0 = window->TopEdge;
  173.             width = window->Width;
  174.             height = window->Height;
  175.  
  176. //            pic1.Depth = 4;
  177.             x = (rand() % (width-pic1_width))+x0;
  178.             y = (rand() % (height-pic1_height))+y0;
  179.             GfxBltBitMap(&pic1,0,0,bm,x,y,pic1_width,pic1_height,0xc0,~0,NULL);
  180.  
  181.             x = (rand() % (width-pic2_width))+x0;
  182.             y = (rand() % (height-pic2_height))+y0;
  183.             GfxBltBitMap(&pic2,0,0,bm,x,y,pic2_width,pic2_height,0xc0,~0,NULL);
  184.  
  185.             x = (rand() % (width-pic3_width))+x0;
  186.             y = (rand() % (height-pic3_height))+y0;
  187.             GfxBltBitMap(&pic3,0,0,bm,x,y,pic3_width,pic3_height,0xc0,~0,NULL);
  188.  
  189.             x = (rand() % (width-pic4_width))+x0;
  190.             y = (rand() % (height-pic4_height))+y0;
  191.             GfxBltBitMap(&pic4,0,0,bm,x,y,pic4_width,pic4_height,0xc0,~0,NULL);
  192.  
  193.         }while (event());
  194.     }
  195. }