home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / OMEGA2 / OMMOUSE.CPP < prev    next >
C/C++ Source or Header  |  1992-04-25  |  5KB  |  242 lines

  1. //
  2. // *************************************************************************
  3. // *                                                                       *
  4. // *    OMEGA C++ Windowing Class Library                                  *
  5. // *    =================================                                  *
  6. // *                                                                       *
  7. // *    Copyright 1991,92 Tom Clancy                                       *
  8. // *    Submitted to the public domain, April 1992                         *
  9. // *                                                                       *
  10. // *************************************************************************
  11. // *                                                                       *
  12. // *    Mouse Class Methods                                                *
  13. // *                                                                       *
  14. // *************************************************************************
  15. //
  16.  
  17.  
  18. #include <dos.h>
  19. #include <mem.h>
  20. #include "ommouse.hpp"
  21.  
  22. #define MOUSE 0x33
  23.  
  24. union  REGS  mregs;
  25. struct SREGS sregs;
  26.  
  27.  
  28. int amouse;
  29.  
  30. int installmousedriver(void) {
  31.  
  32.   //void far *gag;
  33.   //unsigned char c=0xCF;
  34.   //
  35.   //gag=getvect(MOUSE);
  36.   //if(gag==NULL || !memcmp(gag,(void far *)c,1)) {
  37.   //    amouse=0;
  38.   //    return amouse;
  39.   //  }
  40.  
  41.   mregs.x.ax=0x0000;
  42.   int86(MOUSE,&mregs,&mregs);
  43.   amouse=mregs.x.ax;
  44.   return mregs.x.ax;
  45. }
  46.  
  47. void initmouse() {
  48.  
  49.   installmousedriver();
  50. }
  51.  
  52.  
  53.  
  54. //
  55. //    Constructor initializes the mouse and sets the amouse boolean to
  56. //      -1 if a mouse is installed or 0 if it isn't.
  57. //
  58. mouse::mouse(void){}
  59.  
  60. //
  61. //         hides the mouse upon exiting the program.
  62. //
  63. mouse::~mouse(void)
  64. {
  65.   //hidemouse();
  66. }
  67.  
  68. //
  69. //        Resets the mouse.  Returns a -1 if a mouse driver is installed
  70. //        otherwise it returns a 0.
  71. //
  72.  
  73.  
  74. int  mouse::mouseinstalled() {
  75.  
  76.   return amouse;
  77. }
  78.  
  79. int mouse::myint() {
  80.  
  81.    if(amouse) {
  82.      int86(MOUSE,&mregs,&mregs);
  83.      return 1;
  84.    }
  85.    return 0;
  86. }
  87.  
  88. //
  89. //     Resets the mouse driver.
  90. //
  91. void mouse::resetmouse(void) {
  92.   mregs.h.ah=0;
  93.   myint();
  94. }
  95.  
  96.  
  97. //
  98. //    Shows the mouse on screen if mouse is hidden.
  99. //
  100. void mouse::showmouse(void)
  101. {
  102.   mregs.x.ax=1;
  103.   myint();
  104. }
  105.  
  106.  
  107. //
  108. //    Hides the mouse.
  109. //
  110. void mouse::hidemouse(void)
  111. {
  112.   mregs.x.ax=2;
  113.   myint();
  114. }
  115.  
  116. void mouse::mouse_exclusion(int x, int y, int x2, int y2) {
  117.  
  118.   mregs.x.ax=16;
  119.   mregs.x.cx=x;
  120.   mregs.x.dx=y;
  121.   mregs.x.si=x2;
  122.   mregs.x.di=y2;
  123.   myint();
  124. }
  125.  
  126.  
  127. //
  128. //    Text based getmouse routines.  Returns x and y with a max of
  129. //    80 x 25.
  130. //
  131. void mouse::getmouse(int &x, int &y, int &button)
  132. {
  133.   mregs.x.ax=3;
  134.   x=0;
  135.   y=0;
  136.   button=0;
  137.   if(myint()) {
  138.     x=(mregs.x.cx/8)+1;
  139.     y=(mregs.x.dx/8)+1;
  140.     button=mregs.x.bx;
  141.   }
  142. }
  143.  
  144.  
  145. //
  146. //    Puts the mouse at location x,y (uses text mode coordinates).
  147. //
  148. void mouse::setmouse(int x, int y)
  149. {
  150.   mregs.x.ax=4;
  151.   mregs.x.cx=(x-1)*8;
  152.   mregs.x.dx=(y-1)*8;
  153.   myint();
  154. }
  155.  
  156.  
  157. //
  158. //    Returns number of presses, xpresses and ypresses for button "button"
  159. //
  160. void mouse::getbuttonpress(int button, int &stat, int &presses, int &xpress, int &ypress)
  161. {
  162.   mregs.x.ax=5;
  163.   mregs.x.bx=button;
  164.   stat=0;
  165.   presses=0;
  166.   xpress=0;
  167.   ypress=0;
  168.   if(myint()) {
  169.     stat=mregs.x.ax;
  170.     presses=mregs.x.bx;
  171.     xpress=mregs.x.cx;
  172.     ypress=mregs.x.dx;
  173.   }
  174. }
  175.  
  176. void mouse::getbuttonrelease(int button, int &status, int &presses, int &xrelease, int &yrelease)
  177. {
  178.   mregs.x.ax=6;
  179.   mregs.x.bx=button;
  180.   status=0;
  181.   presses=0;
  182.   xrelease=0;
  183.   yrelease=0;
  184.   if(myint()) {
  185.     status=mregs.x.ax;
  186.     presses=mregs.x.bx;
  187.     xrelease=mregs.x.cx;
  188.     yrelease=mregs.x.dx;
  189.   }
  190. }
  191.  
  192.  
  193. //
  194. //    Sets the mouses horizontal limit between min and max.
  195. //
  196. void mouse::hmouselimit(int min, int max)
  197. {
  198.   mregs.x.ax=7;
  199.   mregs.x.cx=min;
  200.   mregs.x.dx=max;
  201.   myint();
  202. }
  203.  
  204.  
  205. //
  206. //    Sets the mouses vertical limit between min and max.
  207. //
  208. void mouse::vmouselimit(int min, int max)
  209. {
  210.   mregs.x.ax=8;
  211.   mregs.x.cx=min;
  212.   mregs.x.dx=max;
  213.   myint();
  214. }
  215.  
  216.  
  217.  
  218. //
  219. //    Sets the text cursor attribute and character
  220. //
  221. void mouse::settextcursor(int cursorselect, int screenmask, int cursormask)
  222. {
  223.   mregs.x.ax=10;
  224.   mregs.x.bx=cursorselect;
  225.   mregs.x.cx=screenmask;
  226.   mregs.x.dx=cursormask;
  227.   myint();
  228. }
  229.  
  230.  
  231. //
  232. //    Sets the mouse ratio
  233. //
  234. void mouse::setmickeyratio(int xmickey, int ymickey)
  235. {
  236.   mregs.x.ax=15;
  237.   mregs.x.cx=xmickey;
  238.   mregs.x.dx=ymickey;
  239.   myint();
  240. }
  241.  
  242.