home *** CD-ROM | disk | FTP | other *** search
/ Cutting-Edge 3D Game Programming with C++ / CE3DC++.ISO / BOOK / CHAP08 / MOUSELIB.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-15  |  3.0 KB  |  149 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. #ifndef MOUSELIBHPP
  12. #define MOUSELIBHPP
  13.  
  14. #include <Dos.H>
  15. #include <String.H>
  16.  
  17. int ResetMouse ( void );
  18. void ShowMouse ( void );
  19. void HideMouse ( void );
  20. void SetMousePos ( int X, int Y );
  21. void GetMousePos ( int &X, int &Y );
  22. void GetButtonPos ( int &Lb, int &Rb );
  23.  
  24. class MousePtr {
  25. protected:
  26.   int X, Y, ClipFlag, MapFlag, LeftB, RightB;
  27.   int X1, Y1, X2, Y2, RangeX, RangeY, XCenter, YCenter;
  28.   int CorrectIfMap, Width, Height;
  29.   unsigned char *CImage;
  30.   void CorrectClip ( int Left, int Top, int Right, int Bottom )
  31.      {
  32.      X1 = ( Left * 638 / RangeX );
  33.      X2 = ( Right * 638 / RangeX );
  34.      Y1 = ( Top * 199 / RangeY );
  35.      Y2 = ( Bottom * 199 / RangeY );
  36.      }
  37.   void ClipPoint ( int &Sx, int &Sy )
  38.      {
  39.      if ( Sx < 0 )
  40.         Sx = 0;
  41.      if ( Sx > 319 )
  42.         Sx = 319;
  43.       
  44.      if ( Sy < 0 )
  45.         Sy = 0;
  46.      if ( Sy > 199 )
  47.         Sy = 199;
  48.      }
  49. public:
  50.   MousePtr ()
  51.      {
  52.      CorrectIfMap = ClipFlag = 0; 
  53.      MapFlag = LeftB = RightB = 0;
  54.      Width = Height = X = Y = 0;
  55.      XCenter = YCenter = 0;
  56.      CImage = NULL;
  57.      }
  58.   int Init () { return ResetMouse (); }
  59.   void Update ()
  60.      {
  61.      GetMousePos ( X, Y );
  62.      if ( ClipFlag )
  63.         {
  64.         if ( X < X1 )
  65.            X = X1;
  66.         if ( X > X2 )
  67.            X = X2;
  68.         if ( Y < Y1 )
  69.            Y = Y1;
  70.         if ( Y > Y2 )
  71.            Y = Y2;
  72.         SetMousePos ( X, Y );   
  73.         }
  74.      GetButtonPos ( LeftB, RightB );
  75.      }
  76.   void MappingRange ( int Xrange, int Yrange )
  77.      {
  78.      MapFlag = 1;
  79.      RangeX = Xrange;
  80.      RangeY = Yrange;
  81.      if ( CorrectIfMap )
  82.         {
  83.         CorrectIfMap = 0;
  84.         CorrectClip ( X1, Y1, X2, Y2 );
  85.         }
  86.      }
  87.   int GetX ()
  88.     {
  89.     Update ();
  90.     if ( MapFlag )
  91.        return X * RangeX / 638;
  92.     return X;
  93.     }
  94.   int GetY ()
  95.     {
  96.     Update ();
  97.     if ( MapFlag )
  98.        return Y * RangeY / 199;
  99.     return Y;
  100.     }
  101.   int GetLb ()
  102.     {
  103.     Update ();
  104.     return LeftB;
  105.     }
  106.   int GetRb ()
  107.     {
  108.     Update ();
  109.     return RightB;
  110.     }
  111.   void Show ()
  112.      {
  113.      ShowMouse ();
  114.      }
  115.   void Hide ()
  116.      {
  117.      HideMouse ();
  118.      }   
  119.   void SetXY ( int X, int Y )
  120.      {
  121.      SetMousePos ( X, Y );
  122.      }
  123.   void ChangeCursor ( unsigned char *Cursor, int CWidth, 
  124.                        int CHeight, int XC = 0, int YC = 0 )
  125.      {
  126.      Width = CWidth;
  127.      Height = CHeight;
  128.      CImage = Cursor;
  129.      XCenter = XC;
  130.      YCenter = YC;
  131.      }                  
  132.   void Clip ( int Left, int Top, int Right, int Bottom )
  133.      {
  134.      ClipFlag = 1;
  135.      if ( MapFlag )
  136.         {
  137.         CorrectClip ( Left, Top, Right, Bottom );
  138.         }
  139.      else {   
  140.           CorrectIfMap = 1;
  141.           X1 = Left; X2 = Right;
  142.           Y1 = Top; Y2 = Bottom;
  143.           }
  144.      }
  145.   void Display ( unsigned char *Buffer = NULL );
  146. };
  147.  
  148. #endif
  149.