home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / compleximage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  4.6 KB  |  150 lines

  1. /* compleximage.c - program to show the use of a complex Intuition Image.
  2. **
  3. ** compiled with:
  4. ** lc -b1 -cfist -v -y compleximage.c
  5. ** blink FROM LIB:c.o compleximage.o TO compleximage LIB LIB:lc.lib LIB:amiga.lib
  6. */
  7.  
  8. #define INTUI_V36_NAMES_ONLY
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/intuitionbase.h>
  13.  
  14. #include <clib/exec_protos.h>
  15. #include <clib/dos_protos.h>
  16. #include <clib/intuition_protos.h>
  17.  
  18. #include <stdio.h>
  19.  
  20. #ifdef LATTICE
  21. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  22. int chkabort(void) { return(0); }  /* really */
  23. #endif
  24.  
  25. struct IntuitionBase *IntuitionBase = NULL;
  26.  
  27. #define MYIMAGE_LEFT    (0)
  28. #define MYIMAGE_TOP     (0)
  29. #define MYIMAGE_WIDTH   (24)
  30. #define MYIMAGE_HEIGHT  (10)
  31. #define MYIMAGE_DEPTH   (2)
  32.  
  33. /* This is the image data.  It is a two bitplane open rectangle which
  34. ** is 24 pixels wide and 10 high.  Make sure that it is in CHIP memory,
  35. ** or allocate a block of chip memory with a call like:
  36. **
  37. **     AllocMem(data_size,MEMF_CHIP)
  38. **
  39. ** and copy the data to that block.  See the Exec chapter on
  40. ** Memory Allocation for more information on AllocMem().
  41. */
  42. UWORD __chip myImageData[] =
  43.     {
  44.     /* first bitplane of data,
  45.     ** open rectangle.
  46.     */
  47.     0xFFFF, 0xFF00,
  48.     0xC000, 0x0300,
  49.     0xC000, 0x0300,
  50.     0xC000, 0x0300,
  51.     0xC000, 0x0300,
  52.     0xC000, 0x0300,
  53.     0xC000, 0x0300,
  54.     0xC000, 0x0300,
  55.     0xC000, 0x0300,
  56.     0xFFFF, 0xFF00,
  57.  
  58.     /* second bitplane of data,
  59.     ** filled rectangle to appear within open rectangle.
  60.     */
  61.     0x0000, 0x0000,
  62.     0x0000, 0x0000,
  63.     0x0000, 0x0000,
  64.     0x00FF, 0x0000,
  65.     0x00FF, 0x0000,
  66.     0x00FF, 0x0000,
  67.     0x00FF, 0x0000,
  68.     0x0000, 0x0000,
  69.     0x0000, 0x0000,
  70.     0x0000, 0x0000,
  71.     };
  72.  
  73. /* used to get the "new look" on a custom screen */
  74. UWORD pens[] = { ~0 };
  75.  
  76.  
  77. /*
  78. ** main routine. Open required library and window and draw the images.
  79. ** This routine opens a very simple window with no IDCMP.  See the
  80. ** chapters on "Windows" and "Input and Output Methods" for more info.
  81. ** Free all resources when done.
  82. */
  83. VOID main(int argc, char *argv[])
  84. {
  85. struct Screen *scr;
  86. struct Window *win;
  87. struct Image myImage;
  88.  
  89. IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37);
  90. if (IntuitionBase != NULL)
  91.     {
  92.     if (NULL != (scr = OpenScreenTags(NULL,
  93.                         SA_Depth,       4,
  94.                         SA_Pens,        &pens,
  95.                         TAG_END)))
  96.         {
  97.         if (NULL != (win = OpenWindowTags(NULL,
  98.                             WA_RMBTrap,      TRUE,
  99.                             WA_CustomScreen, scr,
  100.                             TAG_END)))
  101.             {
  102.             myImage.LeftEdge    = MYIMAGE_LEFT;
  103.             myImage.TopEdge     = MYIMAGE_TOP;
  104.             myImage.Width       = MYIMAGE_WIDTH;
  105.             myImage.Height      = MYIMAGE_HEIGHT;
  106.             myImage.Depth       = MYIMAGE_DEPTH;
  107.             myImage.ImageData   = myImageData;
  108.             myImage.PlanePick   = 0x3;              /* use first two bitplanes */
  109.             myImage.PlaneOnOff  = 0x0;              /* clear all unused planes  */
  110.             myImage.NextImage   = NULL;
  111.  
  112.             /* Draw the image into the first two bitplanes */
  113.             DrawImage(win->RPort,&myImage,10,10);
  114.  
  115.             /* Draw the same image at a new location */
  116.             DrawImage(win->RPort,&myImage,100,10);
  117.  
  118.             /* Change the image to use the second and fourth bitplanes,
  119.             ** PlanePick is 1010 binary or 0xA,
  120.             ** and draw it again at a different location
  121.             */
  122.             myImage.PlanePick = 0xA;
  123.             DrawImage(win->RPort,&myImage,10,50);
  124.  
  125.             /* Now set all the bits in the first bitplane with PlaneOnOff.
  126.             ** This will make all the bits set in the second bitplane
  127.             ** appear as color 3 (0011 binary), all the bits set in the
  128.             ** fourth bitplane appear as color 9 (1001 binary) and all
  129.             ** other pixels will be color 1 (0001 binary.  If there were
  130.             ** any points in the image where both bits were set, they
  131.             ** would appear as color 11 (1011 binary).
  132.             ** Draw the image at a different location.
  133.             */
  134.             myImage.PlaneOnOff = 0x1;
  135.             DrawImage(win->RPort,&myImage,100,50);
  136.  
  137.             /* Wait a bit, then quit.
  138.             ** In a real application, this would be an event loop, like the
  139.             ** one described in the Intuition Input and Output Methods chapter.
  140.             */
  141.             Delay(200);
  142.  
  143.             CloseWindow(win);
  144.             }
  145.         CloseScreen(scr);
  146.         }
  147.     CloseLibrary((struct Library *)IntuitionBase);
  148.     }
  149. }
  150.