home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / FACETV.ZIP / TMOUSE.C < prev    next >
C/C++ Source or Header  |  1994-01-03  |  4KB  |  132 lines

  1. /************************************************************************
  2. **
  3. ** @(#)tmouse.c        05/27/93    Chris Ahlstrom
  4. **
  5. **    This module provides mouse utilities that are functionally
  6. ** partly a subset of the regular MSMOUSE routines, but have different
  7. ** names and parameter-passing conventions.
  8. **
  9. **    They are defined her for convenience, and to avoid using the
  10. ** whole mouse library, since Turbo Vision already provides most of
  11. ** the functionality we need.
  12. **
  13. *************************************************************************/
  14.  
  15. #define TINPMOUS_c
  16.  
  17. #include <dos.h>
  18.  
  19. #include "tmouse.h"
  20.  
  21.  
  22. /************************************************************************
  23. ** LOCAL VERSIONS OF MOUSE ROUTINES
  24. *************************************************************************/
  25.  
  26. /************************************************************************
  27. ** readYmickey
  28. **
  29. **    A global function to return the number of vertical mickeys
  30. ** the mouse moved since the last call to readYmickey.
  31. **
  32. **    I copped this routine from the MSMOUSE library and tailored
  33. ** it to our limited usage.
  34. **
  35. **    Based on Microsoft mouse function 11
  36. **
  37. **    Reads the motion of the mouse (its displacement since the
  38. ** last call), in units of mickeys.  Discards the x displacement, and
  39. ** returns the y displacement.  A positive number indicates travel
  40. ** downwards.  One mickey is about 1/200th inch of mouse movement.
  41. **
  42. **    Note that even if the mouse cursor is at the edge of its
  43. ** area, and stuck there because it can go no farther, this function
  44. ** still returns non-zero mickey values as long as the user continues
  45. ** to move the mouse.
  46. **
  47. *************************************************************************/
  48.  
  49. int
  50. readYmickey
  51. (
  52.     void
  53. )
  54. {
  55.     union REGS mousreg;
  56.  
  57.     mousreg.x.ax = READMICKEY;            // do this function
  58.     int86(MOUSEBIOS, &mousreg, &mousreg);    // call mouse interrupt
  59.     return mousreg.x.dx;            // return vertical movement
  60. }
  61.  
  62.  
  63. /************************************************************************
  64. ** readMouseButtons
  65. **
  66. ** Based on Microsoft mouse function 3
  67. **
  68. **    Returns the status of the mouse buttons.
  69. **
  70. **    button is a bitmask; the following values apply:
  71. **
  72. **          Bit   Meaning if on
  73. **         -----  --------------------------------------------
  74. **        0 = left button is down (LEFT_MOUSEBUTTON)
  75. **        1 = right button is down (RIGHT_MOUSEBUTTON)
  76. **        2 = center button is down (CENTER_MOUSEBUTTON)
  77. **        3 to 15 are reserved
  78. **
  79. **    I created this routine because I'm not satisfied with the
  80. ** behavior of mouseEvent().
  81. **
  82. *************************************************************************/
  83.  
  84. int
  85. readMouseButtons
  86. (
  87.     void
  88. )
  89. {
  90.     union REGS mousreg;
  91.  
  92.     mousreg.x.ax = READMOUSE;
  93.     int86(MOUSEBIOS, &mousreg, &mousreg);    // call the mouse interrupt
  94.     return mousreg.x.bx;
  95. }
  96.  
  97.  
  98. /************************************************************************
  99. ** setMousePosition
  100. **
  101. ** Based on Microsoft mouse function 4
  102. **
  103. **    Places the mouse at position (x,y).  The position is adjusted,
  104. ** if necessary, to lie within the confines specified in any previous
  105. ** calls to functions 7 and 8 (setmousehoriz() and setmousevert()).
  106. **
  107. **    One problem is that the vertical dimension correction factor
  108. ** is text-mode dependent.
  109. **
  110. ** Example call:
  111. **
  112. **    setMousePosition(40, 12);
  113. **
  114. *************************************************************************/
  115.  
  116. void
  117. setMousePosition
  118. (
  119.     int x,
  120.     int y
  121. )
  122. {
  123.     union REGS mousreg;
  124.  
  125.     mousreg.x.ax = MOUSEPOSITION;
  126.     mousreg.x.cx = x * MOUSE_CHAR_WIDTH;    // convert to mouse units
  127.     mousreg.x.dx = y * MOUSE_CHAR_HEIGHT;    // convert to mouse units
  128.  
  129.     int86(MOUSEBIOS, &mousreg, &mousreg);    // call mouse interrupt
  130. }
  131.  
  132.