home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / gadgeted_438.lzh / GadgetED / Source / func1.c < prev    next >
C/C++ Source or Header  |  1991-01-17  |  2KB  |  100 lines

  1. /*----------------------------------------------------------------------*
  2.   func1.c Version 2.0 -  © Copyright 1990 Jaba Development
  3.  
  4.   Author : Jan van den Baard
  5.   Purpose: Some subroutines for the program
  6.  *----------------------------------------------------------------------*/
  7.  
  8. extern ULONG  Class;
  9. extern USHORT Code, Qualifier;
  10. extern struct Gadget *Gadget;
  11. extern struct GadgetList Gadgets;
  12. extern struct Window *MainWindow;
  13. extern SHORT  MainX, MainY;
  14.  
  15. /*
  16.  * read the mouse coordinates
  17.  */
  18. VOID get_xy(x,y)
  19.     SHORT *x, *y;
  20. {
  21.     if(TestBits(MainWindow->Flags,GIMMEZEROZERO))
  22.     { *x = MainWindow->GZZMouseX;
  23.       *y = MainWindow->GZZMouseY;
  24.     }
  25.     else
  26.     { *x = MainWindow->MouseX;
  27.       *y = MainWindow->MouseY;
  28.     }
  29. }
  30.  
  31. /*
  32.  * read a message from the window 'w' user port
  33.  */
  34. LONG read_msg(w)
  35.     struct Window *w;
  36. {
  37.     struct IntuiMessage *msg;
  38.  
  39.     if((msg = (struct IntuiMessage *)GetMsg(w->UserPort)))
  40.     {   Class     = msg->Class;
  41.         Code      = msg->Code;
  42.         Qualifier = msg->Qualifier;
  43.         Gadget    = (struct Gadget *)msg->IAddress;
  44.         ReplyMsg((struct Message *)msg);
  45.         return(TRUE);
  46.     }
  47.     return(FALSE);
  48. }
  49.  
  50. /*
  51.  * wait for the user to select a gadget or
  52.  * press the 'ESC' key
  53.  */
  54. struct Gadget *wait_for_gadget(w)
  55.     struct Window *w;
  56. {
  57.     struct Gadget *g;
  58.  
  59.     while((Class != GADGETUP) AND (Class != GADGETDOWN))
  60.     {   Wait(1 << w->UserPort->mp_SigBit);
  61.         while(read_msg(w))
  62.         {   g = Gadget;
  63.             if((Class == RAWKEY) && (Code == ESC))
  64.             {   while(read_msg(w));
  65.                 return(NULL);
  66.             }
  67.             get_xy(&MainX,&MainY);
  68.         }
  69.     }
  70.     if(Class == GADGETDOWN)
  71.     {   Wait(1 << w->UserPort->mp_SigBit);
  72.         while(read_msg(w))
  73.         {  if((Code == SELECTUP) AND (Class == GADGETUP)) break;
  74.         }
  75.     }
  76.     while(read_msg(w));
  77.     return(g);
  78. }
  79.  
  80. /*
  81.  * draw a box
  82.  */
  83. VOID draw_box(w,x,y,x1,y1)
  84.     struct Window  *w;
  85.     register SHORT x,y,x1,y1;
  86. {
  87.     register SHORT tmp;
  88.     struct RastPort *rp;
  89.  
  90.     if(x > x1) { tmp = x; x = x1; x1 = tmp; }
  91.     if(y > y1) { tmp = y; y = y1; y1 = tmp; }
  92.     rp = w->RPort;
  93.     SetDrMd(rp,JAM1+COMPLEMENT);
  94.     Move(rp,x+1,y);
  95.     Draw(rp,x1,y);
  96.     Draw(rp,x1,y1);
  97.     Draw(rp,x,y1);
  98.     Draw(rp,x,y);
  99. }
  100.