home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 568a.lha / APIG_v1.1 / e11_followmouse.rexx < prev    next >
OS/2 REXX Batch file  |  1991-09-28  |  4KB  |  119 lines

  1. /* dumb mouse line draw example using mousereports */
  2.  
  3. /*  */
  4.  x = addlib("apig.library",0,-30,0)
  5.  
  6.  portname = "example11_port"
  7.  p = openport(portname)
  8.  
  9.  call set_apig_globals()          /* Create Intuition Global constans */
  10.  
  11.  wintitle = "This is your title"
  12.  
  13.  winidcmp = CLOSEWINDOW+GADGETDOWN+GADGETUP+REFRESHWINDOW+MOUSEBUTTONS+MOUSEMOVE
  14.  
  15.  winflags = WINDOWCLOSE + WINDOWDRAG + WINDOWSIZING + WINDOWDEPTH,
  16.            + REPORTMOUSE + ACTIVATE
  17.  
  18.  /* open window */
  19.  w1  = openwindow(portname,0,0,640,200,2,4,winidcmp,winflags,wintitle,0,1,0,0) 
  20.  rpw1 = getwindowrastport(w1)
  21.  
  22.  z = writeconsole(w1,"This is a dumb mouse line draw example" || '0a'x)
  23.  z = writeconsole(w1,"Click Left Mouse Button once to start" || '0a'x)
  24.  z = writeconsole(w1,"Click Left Mouse Button again to stop" || '0a'x)
  25.  z = writeconsole(w1,"Close window when done" || '0a'x)
  26.  
  27. exitme = 0
  28. drawon = 0
  29. xstart = 0
  30. ystart = 0
  31. x      = 0
  32. y      = 0
  33. mouserror = 0
  34. z      = reportmouse(0,w1) 
  35. z      = setdrmd(rpw1,COMPLEMENT)
  36. z      = setapen(rpw1,0)
  37.  
  38. do forever
  39.  
  40.      z = waitpkt(portname)
  41.   
  42.      do forever 
  43.   
  44.         msg = '0000 0000'x
  45.         msg = getpkt(portname)
  46.         if msg = '0000 0000'x then leave
  47.         class = getarg(msg,0)
  48.         select
  49.         when class = CLOSEWINDOW then exitme = 1
  50.         when class = MOUSEBUTTONS then 
  51.              do
  52.                  if getarg(msg,1) = SELECTDOWN then
  53.                     do
  54.                        drawon = drawon + 1
  55.                        if drawon = 1 then  /* start point chosen */  
  56.                           do
  57.                             z      = setapen(rpw1,0)
  58.                             z      = setdrmd(rpw1,JAM1)
  59.                             xstart = getarg(msg,3)
  60.                             ystart = getarg(msg,4)
  61.                             x      = xstart
  62.                             y      = ystart
  63.                             z      = move(rpw1,xstart,ystart)
  64.                             z      = setdrmd(rpw1,COMPLEMENT)
  65.                             z      = reportmouse(1,w1) /* want mousereport */
  66.                           end
  67.                        if drawon = 2 then /* end point chosen */    
  68.                           do
  69.                               z      = move(rpw1,xstart,ystart)
  70.                               z      = draw(rpw1,x,y)     /* erase old  */
  71.                               z      = setapen(rpw1,1)    /* set color  */
  72.                               z      = setdrmd(rpw1,JAM1) /* true line  */
  73.                               z      = move(rpw1,xstart,ystart) /* start */
  74.                               
  75.                               /* end point is:
  76.                                  x = getarg(msg,3)
  77.                                  y = getarg(msg,4)
  78.                               */
  79.                               z      = draw(rpw1,getarg(msg,3),getarg(msg,4))
  80.                               
  81.                               z      = setdrmd(rpw1,COMPLEMENT)
  82.                               z      = reportmouse(0,w1) /* no mousereports */
  83.                               drawon = 0
  84.                           end
  85.                     end
  86.              end
  87.  
  88.         when class = MOUSEMOVE then /* you are moving the mouse around */
  89.              do
  90.                  if drawon = 1 then /* have start point, but no end point */
  91.                     do  /* redraw line as mouse moves */
  92.                         z = move(rpw1,xstart,ystart)
  93.                         z = draw(rpw1,x,y) /* erase old */
  94.                         
  95.                         z = move(rpw1,xstart,ystart)
  96.                         x = getarg(msg,3) /* current x position of mouse */
  97.                         y = getarg(msg,4) /* current y position of mouse */
  98.                         z = draw(rpw1,x,y) /* draw new */
  99.                     end
  100.              end
  101.  
  102.         otherwise nop
  103.  
  104.         end
  105.         
  106.         z = reply(msg,0)  
  107.  
  108.      end  
  109.    if exitme = 1 then leave
  110.    
  111. end
  112.  
  113. a =closewindow(w1)
  114.  
  115. a =closescreen(scr)
  116.  
  117. exit
  118.  
  119.