home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / www / afc / afc-dir / afc_examples.lha / Displayer_Examples.lha / Examples / Displayer_Example2.e < prev   
Text File  |  1997-09-09  |  4KB  |  148 lines

  1.  
  2. /*
  3.   $VER: Displayer_Example 2 - (C)Copyright Amiga Foundation Classes
  4.  
  5.   Written By: Andrea Galimberti
  6.  
  7.   This IS a complete example that exploits the following modules belonging
  8.   TO the Amiga Foundation Classes: Displayer, Mousepointer (AND so Hardsprite).
  9.  
  10.   See how the mouse pointer automatically rescales its movements TO fit
  11.   the changing resolution; the pointer sprite IS bounded TO the
  12.   dimensions OF the viewports it moves into.
  13.  
  14.   You can scroll the topmost bitmap because it's bigger than the viewport
  15.   it's displayed in.
  16. */
  17.  
  18. MODULE 'graphics/modeid',
  19.        'intuition/intuition',
  20.        'AFC/displayer',
  21.        'AFC/mousepointer',
  22.        'AFC/explain_exception'
  23.  
  24.  
  25. PROC main() HANDLE
  26.   DEF myview=NIL:PTR TO displayer
  27.   DEF vp1=NIL, vp2=NIL
  28.   DEF rp1=NIL, rp2=NIL
  29.   DEF win=NIL:PTR TO window, poi:PTR TO INT
  30.   DEF topo:PTR TO mousepointer, vp
  31.   DEF rx=0
  32.  
  33.   NEW topo.mousepointer(2)
  34.  
  35.   topo.image(11,[$0080,$0080,
  36.                  $0080,$0080,
  37.                  $0080,$0080,
  38.                  $0080,$0080,
  39.                  $0080,$0080,
  40.                  $1F7C,$1F7C,
  41.                  $0080,$0080,
  42.                  $0080,$0080,
  43.                  $0080,$0080,
  44.                  $0080,$0080,
  45.                  $0080,$0080]:INT)
  46.  
  47.   topo.hotspot(18,6)  -> the mouse starts from the topmost viewport, so
  48.                       -> its hotspot it's SET in high resolution: the
  49.                       -> auto() method OF mousepointer rescales it TO adapt TO
  50.                       -> the changing resolution.
  51.  
  52.   NEW myview.displayer()
  53.  
  54.   myview.add([VPORT_TOP,0,
  55.               VPORT_LEFT,0,
  56.               VPORT_WIDTH,640,
  57.               VPORT_HEIGHT,100,
  58.               VPORT_DEPTH,3,
  59.               VPORT_MODE,HIRES_KEY,
  60.               VPORT_BMWIDTH,800,    -> bitmap IS wider than viewport
  61.               VPORT_SPRITES,TRUE,
  62.               NIL])
  63.  
  64.   myview.add([VPORT_TOP,110,
  65.               VPORT_LEFT,0,
  66.               VPORT_WIDTH,320,
  67.               VPORT_HEIGHT,50,
  68.               VPORT_DEPTH,3,
  69.               VPORT_MODE,LORES_KEY,
  70.               VPORT_SPRITES,TRUE,
  71.               NIL])
  72.  
  73.   myview.add([VPORT_TOP,170,
  74.               VPORT_LEFT,0,
  75.               VPORT_WIDTH,640,
  76.               VPORT_HEIGHT,80,
  77.               VPORT_DEPTH,3,
  78.               VPORT_MODE,HIRES_KEY,
  79.               VPORT_SPRITES,TRUE,
  80.               NIL])
  81.  
  82.   myview.setup(DEFAULT_MONITOR_ID)  -> choose your monitor database
  83.  
  84. -> this window IS opened only TO clear the standard mouse sprite
  85.   win:=OpenWindowTagList(NIL,[WA_LEFT,0,
  86.                               WA_TOP,0,
  87.                               WA_WIDTH,320,
  88.                               WA_HEIGHT,128,
  89.                               WA_TITLE,'Wow',
  90.                               WA_FLAGS,WFLG_DRAGBAR OR WFLG_CLOSEGADGET OR WFLG_ACTIVATE OR WFLG_SIMPLE_REFRESH,
  91.                               WA_IDCMP,IDCMP_CLOSEWINDOW OR IDCMP_ACTIVEWINDOW,
  92.                               NIL,NIL])
  93.   IF win=NIL THEN Raise("win")
  94.   poi:=[0,0]:INT
  95.   SetPointer(win,poi,1,1,0,0)
  96.  
  97. -> here begins the show
  98.   Forbid()       -> forbid task switching
  99.   myview.show()
  100.  
  101.   rp1:=myview.rastport(0)
  102.   rp2:=myview.rastport(1)
  103.   vp1:=myview.viewport(0)
  104.   vp2:=myview.viewport(1)
  105.  
  106.   SetRast(rp1,3)
  107.   SetRast(rp2,4)
  108.   SetRast(myview.rastport(2),2)
  109.  
  110.   SetRGB4(vp1,2,15,15,15)
  111.   SetAPen(rp1,2)
  112.   Move(rp1,10,10)
  113.   Text(rp1,'First (Hires) ViewPort',22)
  114.   SetRGB4(vp2,2,0,0,15)
  115.   SetAPen(rp2,2)
  116.   Move(rp2,10,10)
  117.   Text(rp2,'Second (Lowres) ViewPort',24)
  118.  
  119.   vp:=vp1
  120.   topo.changeImage(vp1)   -> install NEW image
  121.   topo.move(vp1,100,50)   -> start from topmost viewport
  122.   REPEAT
  123.     topo.auto(myview)  -> auto move
  124.     IF topo.vp()=0        -> IF topmost viewport
  125.       IF topo.x()>=640       -> IF mouse hits the boundaries THEN scroll
  126.         rx:=rx+1
  127.         IF rx>80 THEN rx:=80
  128.         myview.scroll(0,rx,0)
  129.       ENDIF
  130.       IF topo.x()<=0
  131.         rx:=rx-1
  132.         IF rx<0 THEN rx:=0
  133.         myview.scroll(0,rx,0)
  134.       ENDIF
  135.     ENDIF
  136.   UNTIL Mouse()
  137.  
  138.   Permit()  -> permit task switching
  139.   myview.showOldView()   -> restore old view
  140.  
  141. EXCEPT DO
  142.   END topo
  143.   END myview
  144.   IF win THEN CloseWindow(win)
  145.   explain_exception()
  146. ENDPROC
  147.  
  148.