Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef _INCLUDE_DOS_MOUSE
  2. #define _INCLUDE_DOS_MOUSE
  3.  
  4. #include <dos.h>
  5.  
  6. inline int GetMouseStatus()
  7. {
  8.   int a, b;
  9.   _AX = 0;
  10.   geninterrupt(0x33);
  11.   a = _AX; b = _BX;
  12.   if (!a) return 0;
  13.   else return b;
  14. }
  15.  
  16. class TCursorVisible
  17. {
  18. public:
  19.   TCursorVisible(int s = 1) : visible(1) {if (!s) Hide();}
  20.   ~TCursorVisible() {Show();}
  21.  
  22.   int IsShowed() const {return visible;}
  23.   int IsHidden() const {return !visible;}
  24.   int Show()
  25.   {
  26.     if (!visible) {_AX = 1; geninterrupt(0x33); visible = 1; return 1;}
  27.     else return 0;
  28.   }
  29.   int Hide()
  30.   {
  31.     if (visible) {_AX = 2; geninterrupt(0x33); visible = 0; return 1;}
  32.     else return 0;
  33.   }
  34.   int Set(int v) {return v ? Show() : Hide();}
  35. private:
  36.   int visible;
  37. public:
  38.   class T_C
  39.   {
  40.   public:
  41.     ~T_C() {Hide();}
  42.  
  43.     int IsShowed() const {return visible;}
  44.     int IsHidden() const {return !visible;}
  45.     int Show()
  46.     {
  47.       if (!visible) {_AX = 1; geninterrupt(0x33); visible = 1; return 1;}
  48.       else return 0;
  49.     }
  50.     int Hide()
  51.     {
  52.       if (visible) {_AX = 2; geninterrupt(0x33); visible = 0; return 1;}
  53.       else return 0;
  54.     }
  55.     int Set(int v) {return v ? Show() : Hide();}
  56.   private:
  57.     T_C() : visible(0) {}
  58.     friend class TCursorVisible;
  59.  
  60.     int visible;
  61.   };
  62.  
  63.   static T_C C;
  64. };
  65.  
  66. extern int MouseStatus;
  67.  
  68. inline void SetShowCursor(int show)
  69. {
  70.   if (MouseStatus)
  71.   {
  72.     _AX = show ? 1 : 2;
  73.     geninterrupt(0x33);
  74.   }
  75. }
  76.  
  77. inline void ShowCursor()
  78. {
  79.   if (MouseStatus)
  80.   {
  81.     _AX = 1;
  82.     geninterrupt(0x33);
  83.   }
  84. }
  85.  
  86. inline void HideCursor()
  87. {
  88.   if (MouseStatus)
  89.   {
  90.     _AX = 2;
  91.     geninterrupt(0x33);
  92.   }
  93. }
  94.  
  95. inline int PosCursor(int &x, int &y)
  96. {
  97.   if (MouseStatus)
  98.   {
  99.     int xx, yy, r;
  100.     _AX = 3;
  101.     geninterrupt(0x33);
  102.     xx = _CX; yy = _DX;
  103.     r = _BX;
  104.     x = xx; y = yy;
  105.     return r;
  106.   }
  107.   else return 0;
  108. }
  109.  
  110. inline int SetPosCursor(int x, int y)
  111. {
  112.   if (MouseStatus)
  113.   {
  114.     _AX = 4; _CX = x; _DX = y;
  115.     geninterrupt(0x33);
  116.     return _BX;
  117.   }
  118.   else return 0;
  119. }
  120.  
  121. inline int GetButtonDown(int n, int &x, int &y)
  122. {
  123.   if (MouseStatus)
  124.   {
  125.     int xx, yy, r;
  126.     _AX = 5; _BX = n;
  127.     geninterrupt(0x33);
  128.     xx = _CX; yy = _DX;
  129.     r = _BX;
  130.     x = xx; y = yy;
  131.     return r;
  132.   }
  133.   else return 0;
  134. }
  135.  
  136. inline int GetButtonUp(int n, int &x, int &y)
  137. {
  138.   if (MouseStatus)
  139.   {
  140.     int xx, yy, r;
  141.     _AX = 6; _BX = n;
  142.     geninterrupt(0x33);
  143.     xx = _CX; yy = _DX;
  144.     r = _BX;
  145.     x = xx; y = yy;
  146.     return r;
  147.   }
  148.   else return 0;
  149. }
  150.  
  151. inline void BoundCursorX(int x1, int x2)
  152. {
  153.   if (MouseStatus)
  154.   {
  155.     _AX = 7; _CX = x1; _DX = x2;
  156.     geninterrupt(0x33);
  157.   }
  158. }
  159.  
  160. inline void BoundCursorY(int y1, int y2)
  161. {
  162.   if (MouseStatus)
  163.   {
  164.     _AX = 8; _CX = y1; _DX = y2;
  165.     geninterrupt(0x33);
  166.   }
  167. }
  168.  
  169. int MouseStatus = GetMouseStatus();
  170. TCursorVisible::T_C TCursorVisible::C;
  171.  
  172. #endif  //_INCLUDE_DOS_MOUSE
  173.