home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d170 / surf.lha / Surf / src / mouse.c < prev    next >
C/C++ Source or Header  |  1988-11-22  |  2KB  |  119 lines

  1. #include "scrnio.ih"
  2. #ifdef MANX
  3. #include <functions.h>
  4. #endif
  5. #include "scrnio.h"
  6. #include "mytypes.h"
  7.  
  8. #include "bezpt.h"
  9. #include "control.h"
  10.  
  11.  
  12. static bool buttondown;  /* is left button down */
  13. static short mousex, mousey;
  14. static bool isleftbut;  /* left button or pseudo middle button */
  15.  
  16. void HandleTicks(mesg)
  17. struct IntuiMessage *mesg;
  18. {
  19.     int x, y;
  20.  
  21.     x = CntrX(mesg->MouseX);
  22.     y = CntrY(mesg->MouseY);
  23.  
  24.     if(!buttondown || (mousex == x && mousey == y )){
  25.         return;
  26.     }
  27.  
  28.     mousex = x;
  29.     mousey = y;
  30.  
  31.     switch( CurMode ) {
  32.  
  33.     case DRAWPOLY:
  34.          EditBezPt( mousex, mousey);
  35.          break;
  36.  
  37.     case FITBEZIER:
  38.         /*
  39.          * need to select between the two
  40.          */
  41.         if( isleftbut ) {
  42.             EditControl0(mousex, mousey);
  43.         }
  44.         else {
  45.             EditControl1(mousex, mousey);
  46.         }
  47.         break;
  48.  
  49.     default:
  50.         break;
  51.     }
  52. }
  53.  
  54.  
  55.  
  56. void HandleMButtons(mesg)
  57. struct IntuiMessage *mesg;
  58. {
  59.  
  60.     long leftdist, rightdist;
  61.     long tx, ty;
  62.  
  63.     mousex = CntrX(mesg->MouseX);
  64.     mousey = CntrY(mesg->MouseY);
  65.  
  66.     switch( mesg->Code) {
  67.     case SELECTDOWN:
  68.         buttondown = true;  /* down */
  69.  
  70.         switch( CurMode ) {
  71.         case DRAWPOLY:
  72.             InitBezPt( mousex, mousey);
  73.             if( GetNumSegs() == 0 ) {
  74.                 InitBezPt( mousex, mousey );
  75.             }
  76.             break;
  77.  
  78.         case FITBEZIER:
  79.             tx = mousex - Cntrl1X(GetCurSeg());
  80.             ty = mousey - Cntrl1Y(GetCurSeg());
  81.             leftdist = tx *tx + ty * ty;
  82.  
  83.             tx = mousex - Cntrl2X(GetCurSeg());
  84.             ty = mousey - Cntrl2Y(GetCurSeg());
  85.             rightdist = tx *tx + ty * ty;
  86.  
  87.             if( isleftbut = (leftdist <= rightdist) ) {
  88.                 EditControl0( mousex, mousey );
  89.             }
  90.             else {
  91.                 EditControl1( mousex, mousey );
  92.             }
  93.             break;
  94.  
  95.         default:
  96.             break;
  97.         }
  98.         break;
  99.  
  100.  
  101.     case SELECTUP:
  102.         buttondown = false; /* up */
  103.         break;
  104.  
  105.     case MENUUP:
  106.         if( CurMode == FITBEZIER ) {
  107.             DrawControl0();
  108.             DrawControl1();
  109.             NextSeg();
  110.             DrawControl0();
  111.             DrawControl1();
  112.         }
  113.         break;
  114.  
  115.     default:
  116.         break;
  117.     }
  118. }
  119.