home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / rkrmsrc / intuition / images_text / compleximage.e next >
Text File  |  1977-12-31  |  3KB  |  84 lines

  1. -> compleximage.e - Program to show the use of a complex Intuition Image.
  2.  
  3. OPT OSVERSION=37  -> E-Note: silently require V37
  4.  
  5. MODULE 'exec/memory',
  6.        'intuition/intuition',
  7.        'intuition/screens'
  8.  
  9. ENUM ERR_NONE, ERR_SCRN, ERR_WIN
  10.  
  11. RAISE ERR_SCRN IF OpenScreenTagList()=NIL,
  12.       ERR_WIN  IF OpenWindowTagList()=NIL
  13.  
  14. CONST MYIMAGE_LEFT=0, MYIMAGE_TOP=0,
  15.       MYIMAGE_WIDTH=24, MYIMAGE_HEIGHT=10,
  16.       MYIMAGE_DEPTH=2
  17.  
  18. -> E-Note: get some Chip memory and copy list (quick, since LONG aligned)
  19. PROC copyListToChip(data)
  20.   DEF size, mem
  21.   size:=ListLen(data)*SIZEOF LONG
  22.   mem:=NewM(size, MEMF_CHIP)
  23.   CopyMemQuick(data, mem, size)
  24. ENDPROC mem
  25.  
  26. -> Main routine. Open required window and draw the images.  This routine opens
  27. -> a very simple window with no IDCMP.  See the chapters on "Windows" and
  28. -> "Input and Output Methods" for more info.  Free all resources when done.
  29. PROC main() HANDLE
  30.   DEF scr=NIL, win=NIL:PTR TO window, myImage:image
  31.   scr:=OpenScreenTagList(NIL, [SA_DEPTH, 4, SA_PENS, [-1]:INT, NIL])
  32.   win:=OpenWindowTagList(NIL, [WA_RMBTRAP, TRUE, WA_CUSTOMSCREEN, scr, NIL])
  33.  
  34.   -> This contains the image data.  It is a two bit-plane open rectangle which
  35.   -> is 24 pixels wide and 10 high.  Make sure it's in CHIP memory by allocating
  36.   -> a block of chip memory with a call like this: NewM(data_size,MEMF_CHIP),
  37.   -> and then copy the data to that block.
  38.   myImage:=[MYIMAGE_LEFT, MYIMAGE_TOP, MYIMAGE_WIDTH,
  39.             MYIMAGE_HEIGHT, MYIMAGE_DEPTH,
  40.             copyListToChip([ -> First bit-plane of data, open rectangle
  41.                             $FFFFFF00, $C0000300, $C0000300, $C0000300,
  42.                             $C0000300, $C0000300, $C0000300, $C0000300,
  43.                             $C0000300, $FFFFFF00,
  44.                              -> Second bit-plane of data, filled rectangle
  45.                             $00000000, $00000000, $00000000, $00FF0000,
  46.                             $00FF0000, $00FF0000, $00FF0000, $00000000,
  47.                             $00000000, $00000000]),
  48.             3, 0, NIL]:image  -> Use first two bit-planes, clear unused planes
  49.  
  50.   -> Draw the 1 bit-plane image into the first two bit-planes
  51.   DrawImage(win.rport, myImage, 10, 10)
  52.  
  53.   -> Draw the same image at a new location
  54.   DrawImage(win.rport, myImage, 100, 10)
  55.  
  56.   -> Change the image to use the second and fourth bitplanes, PlanePick is 1010
  57.   -> binary or $0A, and draw it again at a different location
  58.   myImage.planepick:=$0A
  59.   DrawImage(win.rport, myImage, 10, 50)
  60.  
  61.   -> Now set all the bits in the first bitplane with PlaneOnOff.  This will
  62.   -> make all the bits set in the second bitplane appear as color 3 (0011
  63.   -> binary), all the bits set in the fourth bitplane appear as color 9 (1001
  64.   -> binary) and all other pixels will be color 1 (0001 binary.  If there were
  65.   -> any points in the image where both bits were set, they would appear as
  66.   -> color 11 (1011 binary).  Draw the image at a different location.
  67.   myImage.planeonoff:=$01
  68.   DrawImage(win.rport, myImage, 100, 50)
  69.  
  70.   -> Wait a bit, then quit.
  71.   -> In a real application, this would be an event loop, like the one described
  72.   -> in the Intuition Input and Output Methods chapter.
  73.   Delay(200)
  74.  
  75. EXCEPT DO
  76.   IF win THEN CloseWindow(win)
  77.   IF scr THEN CloseScreen(scr)
  78.   SELECT exception
  79.   CASE ERR_SCRN; WriteF('Error: Failed to open custom screen.\n')
  80.   CASE ERR_WIN;  WriteF('Error: Failed to open window.\n')
  81.   CASE "MEM";    WriteF('Error: Ran out of (chip) memory.\n')
  82.   ENDSELECT
  83. ENDPROC
  84.