home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff204.lzh / MouseBounce / MouseBounce.c < prev    next >
C/C++ Source or Header  |  1989-04-30  |  2KB  |  84 lines

  1. #include <intuition/intuitionbase.h>
  2. #include <devices/input.h>
  3. #include <hardware/cia.h>
  4.  
  5. struct IntuitionBase *IntuitionBase;
  6. struct InputEvent MyEvent;
  7. struct IOStdReq *MyRequest;
  8. struct MsgPort *MyPort;
  9. struct Window *Window;
  10. struct IntuiMessage *Msg;
  11.  
  12. struct NewWindow win={
  13.     30,20,180,10,-1,-1,CLOSEWINDOW,WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH,
  14.     NULL,NULL,"MouseBounce",NULL,NULL,0,0,0,0,WBENCHSCREEN};
  15.  
  16. main()
  17. {
  18.     int x=0,y=0,xs=1,ys=1;
  19.     IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",0);
  20.     Window=(struct Window *) OpenWindow(&win);
  21.     MyPort=CreatePort(0,0);
  22.     MyRequest=CreateStdIO(MyPort);
  23.     OpenDevice("input.device",0,MyRequest,0);
  24.     MoveMouse(1,1);
  25.     for (;;) {
  26.         MM(xs,ys);
  27.         if (Window->WScreen->MouseX==(Window->WScreen->Width-1) ||
  28.             Window->WScreen->MouseX==0) xs=-xs;
  29.         if (Window->WScreen->MouseY==(Window->WScreen->Height-1) ||
  30.             Window->WScreen->MouseY==0) ys=-ys;
  31.         if (MBut()) {
  32.             if (xs<0) --xs; else ++xs;
  33.             ys=(xs/3)+1;
  34.             while (MBut());
  35.             if (xs>20 || xs<-20) Quit();
  36.         }
  37.         if (Msg=GetMsg(Window->UserPort)) {
  38.             ReplyMsg(Msg);
  39.             Quit();
  40.         }
  41.     }
  42. }
  43.  
  44. MoveMouse(x,y)
  45. int x,y;
  46. {
  47.     MM(-704,-574);
  48.     MM(x,y);
  49. }
  50.  
  51. MM(x,y)
  52. int x,y;
  53. {
  54.     MyRequest->io_Command=IND_WRITEEVENT;
  55.     MyRequest->io_Flags=0;
  56.     MyRequest->io_Length=sizeof(struct InputEvent);
  57.     MyRequest->io_Data=(APTR)&MyEvent;
  58.     MyEvent.ie_NextEvent=NULL;
  59.     MyEvent.ie_Class=IECLASS_RAWMOUSE;
  60.     MyEvent.ie_TimeStamp.tv_secs=0;
  61.     MyEvent.ie_TimeStamp.tv_micro=0;
  62.     MyEvent.ie_Code=IECODE_NOBUTTON;
  63.     MyEvent.ie_Qualifier=IEQUALIFIER_RELATIVEMOUSE;
  64.     MyEvent.ie_X=x;
  65.     MyEvent.ie_Y=y;
  66.     DoIO(MyRequest);
  67.     return(0);
  68. }
  69.  
  70. MBut()
  71. {
  72.     return(!((USHORT)ciaa.ciapra >> 6 & 1));
  73. }
  74.  
  75. Quit()
  76. {
  77.     CloseWindow(Window);
  78.     CloseDevice(MyRequest);
  79.     DeleteStdIO(MyRequest);
  80.     DeletePort(MyPort);
  81.     CloseLibrary(IntuitionBase);
  82.     exit(0);
  83. }
  84.