home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / gchsrc31 / include / mousepos.h < prev    next >
C/C++ Source or Header  |  1992-04-27  |  3KB  |  86 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is part of the Atari Machine Specific Library,
  4. //  and is Copyright 1992 by Warwick W. Allison.
  5. //
  6. //  You are free to copy and modify these sources, provided you acknoledge
  7. //  the origin by retaining this notice, and adhere to the conditions
  8. //  described in the file COPYING.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11.  
  12. #ifndef _MousePosition_h
  13. #define _MousePosition_h
  14. //
  15. //
  16. //  Support for the Atari Mouse - directly.  Do not use with AES.
  17. //
  18. //  Simply use Mouse.X(), Mouse.Y(), Mouse.LeftButton(), Mouse.RightButton()
  19. //   to directly access mouse state.
  20. //
  21. //  The mouse may be used in one of two modes.  Bound and Unbound.
  22. //
  23. //      When the mouse is bound, it operates similarly to the way the
  24. //      mouse does in the GEM environment.
  25. //
  26. //      When the mouse is unbound, you will probably use the MoveTo and
  27. //      MoveBy methods to move the mouse into appropriate locations.
  28. //
  29. //  Mouse.Speed() can be used to _decrease_ mouse speed 0=normal 255=slowest.
  30. //
  31.  
  32. #include <values.h>
  33. #include <bool.h>
  34.  
  35. class MousePosition;
  36. extern MousePosition Mouse;
  37.  
  38.  
  39. // **** Only one MousePosition may be declared (ie. Mouse above) ****
  40.  
  41.  
  42.  
  43. class MousePosition
  44. {
  45. public:
  46.     MousePosition();
  47.     ~MousePosition();
  48.  
  49.     int X();
  50.     int Y();
  51.     bool LeftButton();
  52.     bool RightButton();
  53.     int MoveTo(int,int);
  54.     int MoveBy(int,int);
  55.     void Speed(short x,short y); // Thresholds
  56.  
  57.     void Unbound(); // Default
  58.     void Bound(int MinX=0, int MinY=0,
  59.         int Width=MAXINT, int Height=MAXINT);
  60.     void SetLeft(int);
  61.     void SetRight(int);
  62.  
  63. private:
  64.     void Bind();
  65.     bool Bounded=0;
  66.     int minx,miny,maxx,maxy;
  67.     void* OldVec;
  68.     volatile int x,y;
  69.     volatile bool Left,Right;
  70. };
  71.  
  72. inline bool MousePosition::LeftButton() { return Left; }
  73. inline bool MousePosition::RightButton() { return Right; }
  74. inline int MousePosition::X() { return x; }
  75. inline int MousePosition::Y() { return y; }
  76. inline int MousePosition::MoveTo(int X,int Y) { x=X; y=Y; if (Bounded) Bind(); }
  77. inline int MousePosition::MoveBy(int X,int Y) { x+=X; y+=Y; if (Bounded) Bind(); }
  78. inline void MousePosition::Unbound() { Bounded=0; }
  79. inline void MousePosition::Bound(int MinX=0, int MinY=0, int Width=MAXINT, int Height=MAXINT)
  80.         { Bounded=1; minx=MinX; miny=MinY; maxx=Width+minx-1; maxy=Height+miny-1; Bind(); }
  81. inline void MousePosition::SetLeft(int on) { Left=on; }
  82. inline void MousePosition::SetRight(int on) { Right=on; }
  83.  
  84.  
  85. #endif
  86.