home *** CD-ROM | disk | FTP | other *** search
/ Cutting-Edge 3D Game Programming with C++ / CE3DC++.ISO / BOOK / CHAP12 / MOUSELIB.HPP < prev    next >
C/C++ Source or Header  |  1996-01-24  |  3KB  |  159 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 GetSx ()
  102.     {
  103.     Update ();
  104.     return ( X / 2 );
  105.     }
  106.   int GetSy ()
  107.     {
  108.     Update ();
  109.     return Y;
  110.     }
  111.   int GetLb ()
  112.     {
  113.     Update ();
  114.     return LeftB;
  115.     }
  116.   int GetRb ()
  117.     {
  118.     Update ();
  119.     return RightB;
  120.     }
  121.   void Show ()
  122.      {
  123.      ShowMouse ();
  124.      }
  125.   void Hide ()
  126.      {
  127.      HideMouse ();
  128.      }   
  129.   void SetXY ( int X, int Y )
  130.      {
  131.      SetMousePos ( X, Y );
  132.      }
  133.   void ChangeCursor ( unsigned char *Cursor, int CWidth, 
  134.                        int CHeight, int XC = 0, int YC = 0 )
  135.      {
  136.      Width = CWidth;
  137.      Height = CHeight;
  138.      CImage = Cursor;
  139.      XCenter = XC;
  140.      YCenter = YC;
  141.      }                  
  142.   void Clip ( int Left, int Top, int Right, int Bottom )
  143.      {
  144.      ClipFlag = 1;
  145.      if ( MapFlag )
  146.         {
  147.         CorrectClip ( Left, Top, Right, Bottom );
  148.         }
  149.      else {   
  150.           CorrectIfMap = 1;
  151.           X1 = Left; X2 = Right;
  152.           Y1 = Top; Y2 = Bottom;
  153.           }
  154.      }
  155.   void Display ( unsigned char *Buffer = NULL );
  156. };
  157.  
  158. #endif
  159.