home *** CD-ROM | disk | FTP | other *** search
/ Cutting-Edge 3D Game Programming with C++ / CE3DC++.ISO / BOOK / CHAP11 / MORPH / MOUSELIB.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-21  |  3.1 KB  |  154 lines

  1. //
  2. // File name: MouseLib.HPP
  3. //
  4. // Description: Class declaration for a mouse object
  5. //
  6. // Author: John De Goes
  7. //
  8. // Project: Cutting Edge 3D Game Programming
  9. //
  10.  
  11. #include <Dos.H>
  12. #include <String.H>
  13.  
  14. int ResetMouse ( void );
  15. void ShowMouse ( void );
  16. void HideMouse ( void );
  17. void SetMousePos ( int X, int Y );
  18. void GetMousePos ( int &X, int &Y );
  19. void GetButtonPos ( int &Lb, int &Rb );
  20.  
  21. class MousePtr {
  22. protected:
  23.   int X, Y, ClipFlag, MapFlag, LeftB, RightB;
  24.   int X1, Y1, X2, Y2, RangeX, RangeY, XCenter, YCenter;
  25.   int CorrectIfMap, Width, Height;
  26.   unsigned char *CImage;
  27.   void CorrectClip ( int Left, int Top, int Right, int Bottom )
  28.      {
  29.      X1 = ( Left * 638 / RangeX );
  30.      X2 = ( Right * 638 / RangeX );
  31.      Y1 = ( Top * 199 / RangeY );
  32.      Y2 = ( Bottom * 199 / RangeY );
  33.      }
  34.   void ClipPoint ( int &Sx, int &Sy )
  35.      {
  36.      if ( Sx < 0 )
  37.         Sx = 0;
  38.      if ( Sx > 319 )
  39.         Sx = 319;
  40.       
  41.      if ( Sy < 0 )
  42.         Sy = 0;
  43.      if ( Sy > 199 )
  44.         Sy = 199;
  45.      }
  46. public:
  47.   MousePtr ()
  48.      {
  49.      CorrectIfMap = ClipFlag = 0; 
  50.      MapFlag = LeftB = RightB = 0;
  51.      Width = Height = X = Y = 0;
  52.      XCenter = YCenter = 0;
  53.      CImage = NULL;
  54.      }
  55.   int Init () { return ResetMouse (); }
  56.   void Update ()
  57.      {
  58.      GetMousePos ( X, Y );
  59.      if ( ClipFlag )
  60.         {
  61.         if ( X < X1 )
  62.            X = X1;
  63.         if ( X > X2 )
  64.            X = X2;
  65.         if ( Y < Y1 )
  66.            Y = Y1;
  67.         if ( Y > Y2 )
  68.            Y = Y2;
  69.         SetMousePos ( X, Y );   
  70.         }
  71.      GetButtonPos ( LeftB, RightB );
  72.      }
  73.   void MappingRange ( int Xrange, int Yrange )
  74.      {
  75.      MapFlag = 1;
  76.      RangeX = Xrange;
  77.      RangeY = Yrange;
  78.      if ( CorrectIfMap )
  79.         {
  80.         CorrectIfMap = 0;
  81.         CorrectClip ( X1, Y1, X2, Y2 );
  82.         }
  83.      }
  84.   int GetX ()
  85.     {
  86.     Update ();
  87.     if ( MapFlag )
  88.        return X * RangeX / 638;
  89.     return X;
  90.     }
  91.   int GetY ()
  92.     {
  93.     Update ();
  94.     if ( MapFlag )
  95.        return Y * RangeY / 199;
  96.     return Y;
  97.     }
  98.   int GetSx ()
  99.     {
  100.     Update ();
  101.     return ( X / 2 );
  102.     }
  103.   int GetSy ()
  104.     {
  105.     Update ();
  106.     return Y;
  107.     }
  108.   int GetLb ()
  109.     {
  110.     Update ();
  111.     return LeftB;
  112.     }
  113.   int GetRb ()
  114.     {
  115.     Update ();
  116.     return RightB;
  117.     }
  118.   void Show ()
  119.      {
  120.      ShowMouse ();
  121.      }
  122.   void Hide ()
  123.      {
  124.      HideMouse ();
  125.      }   
  126.   void SetXY ( int X, int Y )
  127.      {
  128.      SetMousePos ( X, Y );
  129.      }
  130.   void ChangeCursor ( unsigned char *Cursor, int CWidth, 
  131.                        int CHeight, int XC = 0, int YC = 0 )
  132.      {
  133.      Width = CWidth;
  134.      Height = CHeight;
  135.      CImage = Cursor;
  136.      XCenter = XC;
  137.      YCenter = YC;
  138.      }                  
  139.   void Clip ( int Left, int Top, int Right, int Bottom )
  140.      {
  141.      ClipFlag = 1;
  142.      if ( MapFlag )
  143.         {
  144.         CorrectClip ( Left, Top, Right, Bottom );
  145.         }
  146.      else {   
  147.           CorrectIfMap = 1;
  148.           X1 = Left; X2 = Right;
  149.           Y1 = Top; Y2 = Bottom;
  150.           }
  151.      }
  152.   void Display ( unsigned char *Buffer = NULL );
  153. };
  154.