home *** CD-ROM | disk | FTP | other *** search
/ Cutting-Edge 3D Game Programming with C++ / CE3DC++.ISO / BOOK / CHAP03 / EXTRA / MOUSELIB.HPP < prev    next >
C/C++ Source or Header  |  1995-10-24  |  3KB  |  135 lines

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