home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 413a.lha / sMOVIE / source / sMOVIEmouse.c < prev    next >
C/C++ Source or Header  |  1990-09-02  |  3KB  |  130 lines

  1. /*    sMOVIEmouse.c    watches mouse movements so user can control sMOVIE
  2.     Martin J. Round. 15-Oct-89
  3. */
  4.  
  5. #include "sMOVIE.h"
  6.  
  7. MOUSE_INFO mouseinfo;
  8.  
  9. extern int delay;
  10.  
  11. /*    input handler subroutine - called through the handler stub    */
  12.  
  13. struct InputEvent *myhandler(ev, mptr)
  14.  
  15. struct InputEvent *ev;            /*    a pointer to a list of events        */
  16. register MOUSE_INFO *mptr;        /*    a pointer to my data                */
  17.  
  18. {
  19.     register struct InputEvent *ep;
  20.  
  21.     /*    look through the list of events for mouse information    */
  22.     for (ep = ev; ep; ep = ep->ie_NextEvent) {
  23.         if (ep->ie_Class == IECLASS_RAWMOUSE) {
  24.             mptr->ypos += ep->ie_Y;
  25.             switch(ep->ie_Code) {
  26.                 case IECODE_LBUTTON:        /*    pause on/off toggle    */
  27.                     if(mptr->button >= 0)
  28.                         mptr->button = 1 - mptr->button;
  29.                     break;
  30.                 case IECODE_RBUTTON:        /*    abort program        */
  31.                     mptr->button = -1;
  32.                     break;
  33.                 }
  34.             }
  35.         }
  36.  
  37.     /*    any other input handlers (e.g. intuition) won't see a thing!    */
  38.     /*    to let them run as normal return (ev) instead of null.            */
  39.  
  40.     return(NULL);
  41.     
  42. }    /*    end of myhandler    */
  43.  
  44. extern struct IOStdReq *CreateStdIO();
  45.  
  46. extern struct MsgPort  *CreatePort();
  47.  
  48. extern void    HandlerInterface();    /*    assembly language sMOVIEstub.a    */
  49.  
  50. struct MsgPort *inputDevPort;
  51.  
  52. struct IOStdReq *inputRequestBlock;
  53.  
  54. struct Interrupt handlerStuff;
  55.  
  56.  
  57. int mousemonitor() {    
  58.     
  59.     do {
  60.         if (mouseinfo.button >0 ) 
  61.             WaitTOF();                /*    allow input task to work    */
  62.  
  63.         while (mouseinfo.ypos > MOUSETHRESHOLD) {
  64.             mouseinfo.ypos -= MOUSETHRESHOLD;
  65.             if (delay < MAXDELAY) {
  66.                 ++delay;
  67.                 SetTaskPri(FindTask(NULL),21);
  68.                 }
  69.             }
  70.  
  71.         while (mouseinfo.ypos < -MOUSETHRESHOLD) {
  72.             mouseinfo.ypos += MOUSETHRESHOLD;
  73.             if (delay > MINDELAY) {
  74.                 --delay;
  75.                 if (delay == 0)
  76.                     SetTaskPri(FindTask(NULL),20);
  77.                 }
  78.             }
  79.         } while (mouseinfo.button > 0);    /*    holding left button pauses    */
  80.  
  81.     return (mouseinfo.button < 0);    /*    right button aborts program        */
  82.  
  83. }    /*    end of mousemonitor    */
  84.  
  85. int initmousemonitor() {    /*    returns 0 if successful    */
  86.  
  87.     if ((inputDevPort = CreatePort(0,0)) == NULL)
  88.         return(-1);
  89.  
  90.     if ((inputRequestBlock = CreateStdIO(inputDevPort)) == NULL) {
  91.         DeletePort(inputDevPort);
  92.         return (-1);
  93.         }
  94.  
  95.     handlerStuff.is_Data =  (APTR)&mouseinfo;
  96.     handlerStuff.is_Code = HandlerInterface;
  97.     handlerStuff.is_Node.ln_Pri = 52;
  98.  
  99.     mouseinfo.ypos = mouseinfo.button = 0;
  100.  
  101.     if (OpenDevice("input.device",0,(struct IORequest *)inputRequestBlock,0)) {
  102.         DeleteStdIO(inputRequestBlock);
  103.         DeletePort(inputDevPort);
  104.         return (-1);
  105.         }
  106.  
  107.     inputRequestBlock->io_Command = IND_ADDHANDLER;
  108.     inputRequestBlock->io_Data    = (APTR)&handlerStuff;
  109.  
  110.     DoIO((struct IORequest *)inputRequestBlock);
  111.     
  112.     return (0);
  113.  
  114. }    /*    end of initmousemonitor        */
  115.  
  116.  
  117. void removemousemonitor() {
  118.  
  119.     inputRequestBlock->io_Command = IND_REMHANDLER;
  120.     inputRequestBlock->io_Data = (APTR)&handlerStuff;
  121.  
  122.     DoIO((struct IORequest *)inputRequestBlock);
  123.  
  124.     CloseDevice((struct IORequest *)inputRequestBlock);
  125.  
  126.     DeleteStdIO(inputRequestBlock);
  127.  
  128.      DeletePort(inputDevPort);
  129.  
  130. }    /*    end of removemousemonitor    */