home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / mouse.swg / 0001_MOUSLIB.PAS.pas next >
Encoding:
Pascal/Delphi Source File  |  1993-05-28  |  37.9 KB  |  1,165 lines

  1. {
  2. ***************************************************************************
  3. *                                  MouseLib                               *    *
  4. * Release 6.0 - Added demo Program - Please refer to MOUSETST.PAS to      *
  5. * see a demo of the mouseLib Unit usage.                                  *
  6. ***************************************************************************
  7. }
  8.  
  9. Unit Mouse;
  10.  
  11. Interface
  12.  
  13. Uses
  14.   Dos;
  15.  
  16. Const
  17.         MOUSEinT = $33; {mouse driver interrupt}
  18.   LEFTBUTtoN = 1; {bit 0}
  19.   RIGHTBUTtoN = 2; {bit 1}
  20.   MIDDLEBUTtoN = 4; {bit 2}
  21.  
  22.   CURSor_LOCATION_CHANGED = 1; {event mask bits}
  23.   LEFT_BUTtoN_PRESSED = 2;
  24.   LEFT_BUTtoN_RELEASED = 4;
  25.   RIGHT_BUTtoN_PRESSED = 8;
  26.   RIGHT_BUTtoN_RELEASED = 16;
  27.   MIDDLE_BUTtoN_PRESSED = 32;
  28.   MIDDLE_BUTtoN_RELEASED = 64;
  29.  
  30. Type
  31.         mouseType = (twoButton,threeButton,another);
  32.   buttonState = (buttonDown,buttonUp);
  33.   direction = (moveRight,moveLeft,moveUp,moveDown,noMove);
  34.   grCursorType = Record
  35.           xH,yH : Byte; {x,y Hot Point}
  36.     data  : Pointer;  {cursor look Pointer}
  37.   end;
  38.  
  39. Var
  40.         mouse_present : Boolean;
  41.   mouse_buttons : mouseType;
  42.   eventX,eventY,eventButtons : Word; {any event handler should update}
  43.   eventhappened : Boolean;           {these Vars to use getLastEvent }
  44.   XMotions,YMotions : Word;          {per 8 pixels}
  45.   mouseCursorLevel : Integer;
  46.  
  47.   {if > 0 mouse cursor is visiable, otherwise not, containes the level
  48.    of showMouseCursor/hideMouseCursor}
  49.  
  50. Const
  51.         LastMask : Word = 0;
  52.   lastHandler : Pointer = Nil;
  53.  
  54.   {when changing the interrupt handler temporarily, save BEForE the
  55.    change these to Variables, and restore them when neccessary}
  56.  
  57.   lastCursor : grCursorType = (
  58.                                                           xH : 0;
  59.                                                     yH : 0;
  60.                                                   data : nil );
  61.  
  62.   {when changing Graphic cursor temporarily, save these values BEForE
  63.           the change, and restore when neccessary}
  64.  
  65. Const
  66.         click_Repeat  = 10; { Recommended value For waitForRelease timeOut }
  67.  
  68. Procedure initMouse; {when replacing mouse mode do that..!}
  69. Procedure showMouseCursor;
  70. Procedure hideMouseCursor;
  71. Function  getMouseX : Word;
  72. Function  getMouseY : Word;
  73. Function  getButton(Button : Byte) : buttonState;
  74. Function  buttonPressed : Boolean;
  75. Procedure setMouseCursor(x,y : Word);
  76. Function  LastXPress(Button : Byte) : Word;
  77. Function  LastYPress(Button : Byte) : Word;
  78. Function  ButtonPresses(Button : Byte) : Word; {from last last check}
  79. Function  LastXRelease(Button : Byte) : Word;
  80. Function  LastYRelease(Button : Byte) : Word;
  81. Function  ButtonReleases(Button : Byte) : Word; {from last last check}
  82. Procedure mouseBox(left,top,right,bottom : Word); {limit mouse rectangle}
  83. Procedure GraphicMouseCursor(xHotPoint,yHotPoint : Byte; dataofs : Pointer);
  84. Procedure HardwareTextCursor(fromLine,toLine : Byte);
  85. Procedure softwareTextCursor(screenMask,cursorMask : Word);
  86. Function  recentXmovement : direction;
  87. Function  recentYmovement : direction;
  88. Procedure setArrowCursor;
  89. Procedure setWatchCursor;
  90. Procedure setUpArrowCursor;
  91. Procedure setLeftArrowCursor;
  92. Procedure setCheckMarkCursor;
  93. Procedure setPointingHandCursor;
  94. Procedure setDiagonalCrossCursor;
  95. Procedure setRectangularCrossCursor;
  96. Procedure setHourGlassCursor;
  97. Procedure setNewWatchCursor;
  98. Procedure setEventHandler(mask : Word; handler  : Pointer);
  99. Procedure setDefaultHandler(mask : Word);
  100. Procedure enableLightPenEmulation;
  101. Procedure disableLightPenEmulation;
  102. Procedure defineSensetivity(x,y : Word);
  103. Procedure setHideCursorBox(left,top,right,bottom : Word);
  104. Procedure defineDoubleSpeedTreshHold(treshHold : Word);
  105. Procedure disableTreshHold;
  106. Procedure defaultTreshHold;
  107. Procedure setMouseGraph;
  108. Procedure resetMouseGraph;
  109. Procedure waitForRelease(timeOut : Word);
  110. Procedure swapEventHandler(mask : Word; handler : Pointer);
  111. { return old in lastMask and lastHandler }
  112. Function  getMouseSaveStateSize : Word;
  113. { get mouse from interrupted Program, and stop it ..}
  114. Procedure interceptMouse;
  115. Procedure restoreMouse;
  116. {
  117. **************************************************************************
  118. *                                  MouseLib                              *     *
  119. *                                                                        *     *
  120. *               mouseLib     -      Release 2   and abo                  *
  121. *                                                                        *
  122. *  because of quirks in hercules Graphic mode that is not detectab       *     *
  123. *   by the mouse driver we have to know when we initMouse if we wa       *     *
  124. *   to check For Graphic mode or not, if we do we must perForm a         *
  125. *   setMouseGraph beFore initGraph, to initGraph in Text mode we m       *     *
  126. *   resetMouseGraph beFore.. , if these calling conventions are no       *     *
  127. *   taken we might have problems in hercules cards!                      *
  128. *                                                                        *     *
  129. *  each call to hideMouseCursor must be balanced by a matching call      *     *
  130. *   to showMouseCursor, 2 calls to hideMou.. and only 1 to showM..       *
  131. *   will not show the mouse cursor on the screen!                        *
  132. **************************************************************************
  133. }
  134.  
  135.  
  136. Implementation
  137.  
  138. Const watchData : Array [0..31] of Word =
  139.         ($E007,$C003,$8001,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$8001,$C003,$E007,
  140.          $0,$1FF8,$318C,$6186,$4012,$4022,$4042,$718C,$718C,$4062,$4032,
  141.          $4002,$6186,$318C,$1FF8,$0);
  142.  
  143. Const arrowData : Array [0..31] of Word =
  144.         ($FFFF,$8FFF,$8FFF,$87FF,$83FF,$81FF,$80FF,$807F,$803F,$801F,$800F,
  145.          $801F,$807F,$887F,$DC3F,$FC3F,
  146.          $0,$0,$2000,$3000,$3800,$3C00,$3E00,$3F00,$3F80,$3FC0,
  147.          $3FE0,$3E00,$3300,$2300,$0180,$0180);
  148.  
  149. Const UpArrowCursor : Array [0..31] of Word =
  150.          ($f9ff,$f0ff,$e07f,$e07f,$c03f,$c03f,$801f,$801f,
  151.           $f,$f,$f0ff,$f0ff,$f0ff,$f0ff,$f0ff,$f0ff,
  152.           $0,$600,$f00,$f00,$1f80,$1f80,$3fc0,$3fc0,
  153.           $7fe0,$600, $600, $600, $600, $600, $600, $600);
  154.  
  155. Const  LeftArrowCursor : Array [0..31] of Word
  156.        = ($fe1f,$f01f,$0,   $0,   $0,   $f01f,$fe1f,$ffff,
  157.           $ffff,$ffff,$ffff,$ffff,$ffff,$ffff,$ffff,$ffff,
  158.           $0,   $c0,  $7c0, $7ffe,$7c0, $c0,  $0,   $0,
  159.           $0,   $0,   $0,   $0,   $0,   $0,   $0,   $0);
  160.  
  161. Const  CheckMarkCursor : Array [0..31] of Word
  162.        = ($fff0,$ffe0,$ffc0,$ff81,$ff03,$607, $f,   $1f,
  163.           $c03f,$f07f,$ffff,$ffff,$ffff,$ffff,$ffff,$ffff,
  164.           $0,   $6,   $c,   $18,  $30,  $60,  $70c0,$1d80,
  165.           $700, $0,   $0,   $0,   $0,   $0,   $0,   $0);
  166.  
  167. Const  PointingHandCursor : Array [0..31] of Word
  168.        = ($e1ff,$e1ff,$e1ff,$e1ff,$e1ff,$e000,$e000,$e000,
  169.           $0,   $0,   $0,   $0,   $0,   $0,   $0,   $0,
  170.           $1e00,$1200,$1200,$1200,$1200,$13ff,$1249,$1249,
  171.           $f249,$9001,$9001,$9001,$8001,$8001,$8001,$ffff);
  172.  
  173. Const  DiagonalcrossCursor : Array [0..31] of Word
  174.        = ($7e0, $180, $0,   $c003,$f00f,$c003,$0,   $180,
  175.           $7e0, $ffff,$ffff,$ffff,$ffff,$ffff,$ffff,$ffff,
  176.           $0,   $700e,$1c38,$660, $3c0, $660, $1c38,$700e,
  177.           $0,   $0,   $0,   $0,   $0,   $0,   $0,   $0);
  178.  
  179. Const  RectangularCrossCursor : Array [0..31] of Word
  180.        = ($fc3f,$fc3f,$fc3f,$0,$0,   $0,   $fc3f,$fc3f,
  181.           $fc3f,$ffff,$ffff,$ffff,$ffff,$ffff,$ffff,$ffff,
  182.           $0,   $180, $180, $180, $7ffe,$180, $180, $180,
  183.           $0,   $0,   $0,   $0,   $0,   $0,   $0,   $0);
  184.  
  185. Const  HourglassCursor : Array [0..31] of Word
  186.        = ($0,   $0,   $0,   $0,   $8001,$c003,$e007,$f00f,
  187.           $e007,$c003,$8001,$0,   $0,   $0,   $0,   $ffff,
  188.           $0,   $7ffe,$6006,$300c,$1818,$c30, $660, $3c0,
  189.           $660, $c30, $1998,$33cc,$67e6,$7ffe,$0,   $0);
  190.  
  191. Const newWatchCursor : Array [0..31] of Word
  192.        = ( $ffff, $c003, $8001, $0, $0, $0, $0, $0, $0,
  193.            $0, $0, $0, $0, $8001, $c003, $ffff, $0, $0,
  194.            $1ff8, $2004, $4992, $4022, $4042, $518a, $4782,
  195.            $4002, $4992, $4002, $2004, $1ff8, $0, $0 );
  196.  
  197.  
  198. Const
  199.         mouseGraph : Boolean = False; {assume Text mode upon entry}
  200.  
  201. Type
  202.         box = Record
  203.           left,top,right,bottom : Word;
  204.   end; {Do not change field order !!!}
  205.  
  206. Var
  207.   hideBox : box;
  208.   reg : Registers;  {general Registers used}
  209.   grMode,
  210.   grDrv : Integer; {detect Graphic mode if any}
  211.   grCode : Integer;     {return initGraph code in here}
  212.   interceptX,
  213.   interceptY : Word;
  214. {
  215. ***************************************************************************
  216. *                                  callMouse                              *    *
  217. *                                                                         *    *
  218. * used to call mouse interrupt With global data reg - used as parameters  *    *
  219. ***************************************************************************
  220. }
  221. Procedure callMouse;
  222. begin
  223.         intr(MOUSEinT,REG);
  224. end; {callMouse}
  225.  
  226. (******************************************************************************
  227. *                                  initMouse                                  *
  228. * For some reason grCode is assigned a value of -11,($FFF5) in the second time*
  229. *  we call initmouse after we allready are in Graphics mode, override.. was   *
  230. *  born because of that situation.                                            *
  231. ******************************************************************************)
  232.  
  233. Procedure initMouse;
  234. Var
  235.         overRideDriver : Boolean; { True if we over-ridden stupid driver hercules b}
  236. begin
  237.     overRideDriver := False;
  238.     if (mouseGraph and (mem[0:$449] = 7)) then begin { assume no mda - hercules}
  239.           mem[0:$449] := 6;
  240.       overRideDriver := True;
  241.     end;
  242.           {trick stupid mouse driver to know we are in Graphic mode}
  243.         With reg do
  244.                                 begin
  245.                 ax:=0; {detect genius mouse}
  246.           bx:=0; {be sure what mode we get}
  247.           callMouse;
  248.           mouse_present := (ax <> 0); {not an iret..}
  249.           if ((bx and 2) <> 0) then
  250.                                                 mouse_buttons := twoButton
  251.           else if ((bx and 3) <> 0)        then
  252.                                                  mouse_buttons := threeButton
  253.           else
  254.                                                 mouse_buttons := another; {unknown to us}
  255.         end; {with}
  256.     if (overRideDriver) then
  257.           mem[0:$449] := 7;
  258.           {restore the stupid situation}
  259.        eventX := 0;
  260.        eventButtons := 0;
  261.        eventY := 0;
  262.        eventhappened := False;
  263.        XMotions := 8;
  264.        YMotions := 16;
  265.        mouseCursorLevel := 0; { not visiable, one show to appear }
  266. end; {initMouse}
  267.  
  268. (******************************************************************************
  269.  
  270. *                               showMouseCursor                               *
  271.  
  272. ******************************************************************************)
  273.  
  274. Procedure showMouseCursor;
  275.  
  276. begin
  277.         reg.ax:=1; {enable cursor display}
  278.         callMouse;
  279.         inc(mouseCursorLevel);
  280. end; {showMouseCursor}
  281.  
  282. (******************************************************************************
  283.  
  284. *                               hideMouseCursor                               *
  285.  
  286. ******************************************************************************)
  287.  
  288. Procedure hideMouseCursor;
  289.  
  290. begin
  291.         reg.ax:=2; {disable cursor display}
  292.         callMouse;
  293.         dec(mouseCursorLevel);
  294. end; {hideMouseCursor}
  295.  
  296. (******************************************************************************
  297.  
  298. *                                  getMouseX                                  *
  299.  
  300. ******************************************************************************)
  301.  
  302. Function getMouseX : Word;
  303.  
  304.  
  305. begin
  306.         reg.ax := 3;
  307.         callMouse;
  308.         getMouseX := reg.cx;
  309. end; {getMouseX}
  310.  
  311. (******************************************************************************
  312.  
  313. *                                  getMouseY                                  *
  314.  
  315. ******************************************************************************)
  316.  
  317. Function getMouseY : Word;
  318.  
  319. begin
  320.         reg.ax := 3;
  321.         callMouse;
  322.         getMouseY := reg.dx;
  323. end; {getMouseX}
  324.  
  325. (******************************************************************************
  326.  
  327. *                                  getButton                                  *
  328.  
  329. ******************************************************************************)
  330.  
  331. Function getButton(Button : Byte) : buttonState;
  332.  
  333. begin
  334.         reg.ax := 3;
  335.         callMouse;
  336.         if ((reg.bx and Button) <> 0) then
  337.                 getButton := buttonDown
  338.                 {bit 0 = left, 1 = right, 2 = middle}
  339.         else getButton := buttonUp;
  340. end; {getButton}
  341.  
  342. (******************************************************************************
  343.  
  344. *                                buttonPressed                                *
  345.  
  346. ******************************************************************************)
  347.  
  348. Function buttonPressed : Boolean;
  349.  
  350. begin
  351.         reg.ax := 3;
  352.         callMouse;
  353.          if ((reg.bx and 7) <> 0) then
  354.                 buttonPressed := True
  355.         else buttonPressed := False;
  356. end; {buttonPressed}
  357.  
  358. (******************************************************************************
  359.  
  360. *                               setMouseCursor                                *
  361.  
  362. ******************************************************************************)
  363.  
  364. Procedure setMouseCursor(x,y : Word);
  365.  
  366. begin
  367.         With reg do begin
  368.                 ax := 4;
  369.                 cx := x;
  370.                 dx := y; {prepare parameters}
  371.                 callMouse;
  372.         end; {with}
  373. end; {setMouseCursor}
  374.  
  375. (******************************************************************************
  376.  
  377. *                                 lastXPress                                  *
  378.  
  379. ******************************************************************************)
  380.  
  381. Function lastXPress(Button : Byte) : Word;
  382.  
  383. begin
  384.         reg.ax := 5;
  385.         reg.bx := Button;
  386.         callMouse;
  387.         lastXPress := reg.cx;
  388. end; {lastXpress}
  389.  
  390. (******************************************************************************
  391.  
  392. *                                 lastYPress                                  *
  393.  
  394. ******************************************************************************)
  395.  
  396. Function lastYPress(Button : Byte) : Word;
  397.  
  398. begin
  399.         reg.ax := 5;
  400.         reg.bx := Button;
  401.         callMouse;
  402.         lastYPress := reg.dx;
  403. end; {lastYpress}
  404.  
  405. (******************************************************************************
  406.  
  407. *                                buttonPresses                                *
  408.  
  409. ******************************************************************************)
  410.  
  411. Function buttonPresses(Button : Byte) : Word; {from last check}
  412.  
  413. begin
  414.         reg.ax := 5;
  415.         reg.bx := Button;
  416.         callMouse;
  417.         buttonPresses := reg.bx;
  418. end; {buttonPresses}
  419.  
  420.  
  421. (******************************************************************************
  422.  
  423. *                                lastXRelease                                 *
  424.  
  425. ******************************************************************************)
  426.  
  427. Function lastXRelease(Button : Byte) : Word;
  428.  
  429. begin
  430.         reg.ax := 6;
  431.         reg.bx := Button;
  432.         callMouse;
  433.         lastXRelease := reg.cx;
  434. end; {lastXRelease}
  435.  
  436. (******************************************************************************
  437.  
  438. *                                lastYRelease                                 *
  439.  
  440. ******************************************************************************)
  441.  
  442. Function lastYRelease(Button : Byte) : Word;
  443.  
  444. begin
  445.         reg.ax := 6;
  446.         reg.bx := Button;
  447.         callMouse;
  448.         lastYRelease := reg.dx;
  449. end; {lastYRelease}
  450.  
  451. (******************************************************************************
  452.  
  453. *                               buttonReleases                                *
  454.  
  455. ******************************************************************************)
  456.  
  457. Function buttonReleases(Button : Byte) : Word; {from last check}
  458.  
  459. begin
  460.         reg.ax := 6;
  461.         reg.bx := Button;
  462.         callMouse;
  463.         buttonReleases := reg.bx;
  464. end; {buttonReleases}
  465.  
  466. (******************************************************************************
  467.  
  468. *                                    swap                                     *
  469.  
  470. ******************************************************************************)
  471.  
  472. Procedure swap(Var a,b : Word);
  473.  
  474. Var c : Word;
  475.  
  476. begin
  477.         c := a;
  478.         a := b;
  479.         b := c; {swap a and b}
  480. end; {swap}
  481.  
  482. (******************************************************************************
  483.  
  484. *                                  mouseBox                                   *
  485.  
  486. ******************************************************************************)
  487.  
  488. Procedure mouseBox(left,top,right,bottom : Word);
  489.  
  490. begin
  491.         if (left > right) then swap(left,right);
  492.         if (top > bottom) then swap(top,bottom); {make sure they are ordered}
  493.         reg.ax := 7;
  494.         reg.cx := left;
  495.         reg.dx := right;
  496.         callMouse; {set x range}
  497.         reg.ax := 8;
  498.         reg.cx := top;
  499.         reg.dx := bottom;
  500.         callMouse; {set y range}
  501. end; {mouseBox}
  502.  
  503. (******************************************************************************
  504.  
  505. *                             GraphicMouseCursor                              *
  506.  
  507. ******************************************************************************)
  508.  
  509. Procedure GraphicMouseCursor(xHotPoint,yHotPoint : Byte; dataofs : Pointer);
  510.  
  511. {define 16*16 cursor mask and screen mask, pointed by data,
  512.         dataofs is Pointer to data of the masks.}
  513.  
  514. begin
  515.         reg.ax := 9;
  516.         reg.bx := xHotPoint;
  517.         reg.cx := yHotPoint;
  518.         reg.dx := ofs(dataofs^);        {DS:DX point to masks}
  519.         reg.es := seg(dataofs^);
  520.         callMouse;
  521.         lastCursor.xH := xHotPoint;
  522.         lastCursor.yH := yHotPoint;
  523.         lastCursor.data := dataofs;
  524.         {save it in lastCursor, if someone needs to change cursor temporary}
  525. end; {GraphicMouseCursor}
  526.  
  527. (******************************************************************************
  528.  
  529. *                             HardwareTextCursor                              *
  530.  
  531. ******************************************************************************)
  532.  
  533. Procedure HardwareTextCursor(fromLine,toLine : Byte);
  534.  
  535. {set Text cursor to Text, using the scan lines from..to,
  536.  
  537. (Continued to next message)
  538. --- FreeMail 1.07b
  539.  * origin: Meredith Place BBS * Tucson, AZ * 602-579-0869 * (1:300/15)
  540. <<<>>>
  541.  
  542.  
  543. Date: 03-02-93 (20:07)              Number: 14561 of 14567 (Echo)
  544.   to: ROBERT BAKER                  Refer#: NONE
  545. From: STEVE CONNET                    Read: NO
  546. Subj: MOUSE               6/10      Status: PUBLIC MESSAGE
  547. Conf: F-PASCAL (1221)            Read Type: GENERAL (+)
  548.  
  549. (Continued from previous message)
  550.  
  551.         same as intr 10 cursor set in bios :
  552.         color scan lines 0..7, monochrome 0..13 }
  553.  
  554. begin
  555. {        reg.ah:=$10;
  556.         reg.ch:=fromLine;
  557.         reg.cl:=toLine;
  558. }
  559.         reg.ax := 10;
  560.         reg.bx := 1; {hardware Text}
  561.         reg.cx := fromLine;
  562.         reg.dx := toLine;
  563.         callMouse;
  564. end; {hardwareTextCursor}
  565.  
  566. (******************************************************************************
  567.  
  568. *                             softwareTextCursor                              *
  569.  
  570. ******************************************************************************)
  571.  
  572. Procedure softwareTextCursor(screenMask,cursorMask : Word);
  573.  
  574. { when in this mode the cursor will be achived by anding the screen Word
  575.         With the screen mask (Attr,Char in high,low order) and
  576.         xoring the cursor mask, ussually used by putting the screen attr
  577.         we want preserved in screen mask (and 0 into screen mask Character
  578.         Byte), and Character + attributes we want to set into cursor mask}
  579.  
  580. begin
  581.         reg.ax := 10;
  582.         reg.bx := 0;    {software cursor}
  583.         reg.cx := screenMask;
  584.         reg.dx := cursorMask;
  585.         callMouse;
  586. end; {softwareMouseCursor}
  587.  
  588. (******************************************************************************
  589.  
  590. *                               recentXmovement                               *
  591.  
  592. ******************************************************************************)
  593.  
  594. Function recentXmovement : direction;
  595.  
  596. {from recent call to which direction did we move ?}
  597.  
  598. Var d : Integer;
  599.  
  600. begin
  601.         reg.ax := 11;
  602.         callMouse;
  603.         d := reg.cx;
  604.         if (d > 0)
  605.                 then recentXmovement := moveRight
  606.         else if (d < 0)
  607.                 then recentXmovement := moveLeft
  608.         else recentXmovement := noMove;
  609. end; {recentXmovement}
  610.  
  611. (******************************************************************************
  612.  
  613. *                               recentYmovement                               *
  614.  
  615. ******************************************************************************)
  616.  
  617. Function recentYmovement : direction;
  618.  
  619. {from recent call to which direction did we move ?}
  620.  
  621. Var
  622.    d : Integer;
  623. begin
  624.         reg.ax := 11;
  625.         callMouse;
  626.         d := reg.dx;
  627.         if (d > 0)
  628.                 then recentYmovement := moveDown
  629.         else if (d < 0)
  630.                 then recentYmovement := moveUp
  631.         else recentYmovement := noMove;
  632. end; {recentYmovement}
  633.  
  634. (******************************************************************************
  635.  
  636. *                               setWatchCursor                                *
  637.  
  638. ******************************************************************************)
  639.  
  640. Procedure setWatchCursor;
  641. begin
  642.         GraphicMouseCursor(0,0,@watchData);
  643. end; {setWatchCursor}
  644.  
  645. (******************************************************************************
  646.  
  647. *                              setNewWatchCursor                              *
  648.  
  649. ******************************************************************************)
  650.  
  651. Procedure setNewWatchCursor;
  652. begin
  653.    GraphicMouseCursor(0, 0, @newWatchCursor);
  654. end; {setNewWatchCursor}
  655.  
  656. (******************************************************************************
  657.  
  658. *                              setUpArrowCursor                               *
  659.  
  660. ******************************************************************************)
  661.  
  662. Procedure setUpArrowCursor;
  663.  
  664. begin
  665.         GraphicMouseCursor(5, 0, @upArrowCursor);
  666. end; {setUpArrowCursor}
  667.  
  668. (******************************************************************************
  669.  
  670. *                             setLeftArrowCursor                              *
  671.  
  672. ******************************************************************************)
  673.  
  674. Procedure setLeftArrowCursor;
  675. begin
  676.         GraphicMouseCursor(0, 3, @leftArrowCursor);
  677. end; {setLeftArrowCursor}
  678.  
  679. (******************************************************************************
  680.  
  681. *                             setCheckMarkCursor                              *
  682.  
  683. ******************************************************************************)
  684.  
  685. Procedure setCheckMarkCursor;
  686. begin
  687.         GraphicMouseCursor(6, 7, @checkMarkCursor);
  688. end; {setCheckMarkCursor}
  689.  
  690. (******************************************************************************
  691.  
  692. *                            setPointingHandCursor                            *
  693.  
  694. ******************************************************************************)
  695.  
  696. Procedure setPointingHandCursor;
  697. begin
  698.         GraphicMouseCursor(5, 0, @pointingHandCursor);
  699. end; {setPointingHandCursor}
  700.  
  701. (******************************************************************************
  702.  
  703. *                           setDiagonalCrossCursor                            *
  704.  
  705. ******************************************************************************)
  706.  
  707. Procedure setDiagonalCrossCursor;
  708. begin
  709.         GraphicMouseCursor(7, 4, @diagonalCrossCursor);
  710. end; {setDiagonalCrossCursor}
  711.  
  712. (******************************************************************************
  713.  
  714. *                          setRectangularCrossCursor                          *
  715.  
  716. ******************************************************************************)
  717.  
  718. Procedure setRectangularCrossCursor;
  719. begin
  720.         GraphicMouseCursor(7, 4, @rectangularCrossCursor);
  721. end; {setRectangularCrossCursor}
  722.  
  723. (******************************************************************************
  724.  
  725. *                             setHourGlassCursor                              *
  726.  
  727. ******************************************************************************)
  728.  
  729. Procedure setHourGlassCursor;
  730. begin
  731.         GraphicMouseCursor(7, 7, @hourGlassCursor);
  732. end; {setHourGlassCursor}
  733.  
  734. (******************************************************************************
  735.  
  736. *                               setArrowCursor                                *
  737.  
  738. ******************************************************************************)
  739.  
  740. Procedure setArrowCursor;
  741. begin
  742.         GraphicMouseCursor(1,1,@arrowData);
  743. end; {setArrowCursor}
  744.  
  745. (******************************************************************************
  746.  
  747. *                               setEventHandler                               *
  748.  
  749. ******************************************************************************)
  750.  
  751. Procedure setEventHandler(mask : Word; handler  : Pointer);
  752.  
  753. {handler must be a Far interrupt routine }
  754.  
  755. begin
  756.         reg.ax := 12; {set event handler Function in mouse driver}
  757.         reg.cx := mask;
  758.         reg.es := seg(handler^);
  759.         reg.dx := ofs(handler^);
  760.         callMouse;
  761.         lastMask := mask;
  762.         lastHandler := handler;
  763. end; {set event Handler}
  764.  
  765. (******************************************************************************
  766.  
  767. *                               defaultHandler                                *
  768.  
  769. ******************************************************************************)
  770.  
  771. {$F+} Procedure defaultHandler; Assembler; {$F-}
  772. Asm
  773.    push ds; { save TP mouse driver }
  774.    mov ax, SEG @data;
  775.    mov ds, ax; { ds = TP:ds, not the driver's ds }
  776.    mov eventX, cx; { where in the x region did it occur }
  777.    mov eventY, dx;
  778.    mov eventButtons, bx;
  779.    mov eventHappened, 1; { eventHapppened := True }
  780.    pop ds; { restore driver's ds }
  781.    ret;
  782. end;
  783.  
  784. {   this is the default event handler , it simulates :
  785.  
  786.       begin
  787.                eventX := cx;
  788.                eventY := dx;
  789.                eventButtons := bx;
  790.                eventhappened := True;
  791.       end;
  792.  
  793. }
  794.  
  795. (******************************************************************************
  796.  
  797. *                                GetLastEvent                                 *
  798.  
  799. ******************************************************************************)
  800.  
  801. Function GetLastEvent(Var x,y : Word;
  802.         Var left_button,right_button,middle_button : buttonState) : Boolean;
  803.  
  804. begin
  805.         getLastEvent := eventhappened; {indicate if any event happened}
  806.         eventhappened := False; {clear to next read/event}
  807.         x := eventX;
  808.         y := eventY;
  809.         if ((eventButtons and LEFTBUTtoN) <> 0) then
  810.                 left_button := buttonDown
  811.         else left_button := buttonUp;
  812.         if ((eventButtons and RIGHTBUTtoN) <> 0) then
  813.                 right_button := buttonDown
  814.         else right_button := buttonUp;
  815.         if ((eventButtons and MIDDLEBUTtoN) <> 0) then
  816.                 middle_button := buttonDown
  817.         else middle_button := buttonUp;
  818. end; {getLastEvent}
  819.  
  820. (******************************************************************************
  821.  
  822. *                              setDefaultHandler                              *
  823.  
  824. ******************************************************************************)
  825.  
  826. Procedure setDefaultHandler;
  827.  
  828. {get only event mask, and set event handler to defaultHandler}
  829.  
  830. begin
  831.         setEventHandler(mask,@defaultHandler);
  832. end; {setDefaultHandler}
  833.  
  834. (******************************************************************************
  835.  
  836. *                           enableLightPenEmulation                           *
  837.  
  838. ******************************************************************************)
  839.  
  840. Procedure enableLightPenEmulation;
  841.  
  842. begin
  843.         reg.ax := 13;
  844.         callMouse;
  845. end; {enableLightPenEmulation}
  846.  
  847. (******************************************************************************
  848.  
  849. *                          disableLightPenEmulation                           *
  850.  
  851. ******************************************************************************)
  852.  
  853. Procedure disableLightPenEmulation;
  854.  
  855. begin
  856.         reg.ax := 14;
  857.         callMouse;
  858. end;  {disableLightPenEmulation}
  859.  
  860. (******************************************************************************
  861.  
  862. *                              defineSensetivity                              *
  863.  
  864. ******************************************************************************)
  865.  
  866. Procedure defineSensetivity(x,y : Word);
  867.  
  868. begin
  869.         reg.ax := 15;
  870.         reg.cx := x; {# of mouse motions to horizontal 8 pixels}
  871.         reg.dx := y; {# of mouse motions to vertical 8 pixels}
  872.         callMouse;
  873.         XMotions := x;
  874.         YMotions := y; {update global Unit Variables}
  875. end; {defineSensetivity}
  876.  
  877. (******************************************************************************
  878.  
  879. *                              setHideCursorBox                               *
  880.  
  881. ******************************************************************************)
  882.  
  883. Procedure setHideCursorBox(left,top,right,bottom : Word);
  884.  
  885. begin
  886.         reg.ax := 16;
  887.         reg.es := seg(HideBox);
  888.         reg.dx := ofs(HideBox);
  889.         HideBox.left := left;
  890.         HideBox.right := right;
  891.         HideBox.top := top;
  892.         HideBox.bottom := bottom;
  893.         callMouse;
  894. end; {setHideCursorBox}
  895.  
  896. (******************************************************************************
  897.  
  898. *                         defineDoubleSpeedTreshHold                          *
  899.  
  900. ******************************************************************************)
  901.  
  902. Procedure defineDoubleSpeedTreshHold(treshHold : Word);
  903.  
  904. begin
  905.         reg.ax := 17;
  906.         reg.dx := treshHold;
  907.         callMouse;
  908. end; {defineDoubleSpeedTreshHold - from what speed to Double mouse movement}
  909.  
  910. (******************************************************************************
  911.  
  912. *                              disableTreshHold                               *
  913.  
  914. ******************************************************************************)
  915.  
  916. Procedure disableTreshHold;
  917.  
  918. begin
  919.         defineDoubleSpeedTreshHold($7FFF);
  920. end; {disableTreshHold}
  921.  
  922. (******************************************************************************
  923.  
  924. *                              defaultTreshHold                               *
  925.  
  926. ******************************************************************************)
  927.  
  928. Procedure defaultTreshHold;
  929.  
  930. begin
  931.         defineDoubleSpeedTreshHold(64);
  932. end; {defaultTreshHold}
  933.  
  934. (******************************************************************************
  935.  
  936. *                                setMouseGraph                                *
  937.  
  938. ******************************************************************************)
  939.  
  940. Procedure setMouseGraph;
  941.  
  942. begin
  943.         mouseGraph := True;
  944. end; {setMouseGraph}
  945.  
  946. (******************************************************************************
  947.  
  948. *                               resetMouseGraph                               *
  949.  
  950. ******************************************************************************)
  951.  
  952. Procedure resetMouseGraph;
  953.  
  954. begin
  955.         mouseGraph := False;
  956. end; {resetMouseGraph}
  957.  
  958.  
  959. (******************************************************************************
  960.  
  961. *                               waitForRelease                                *
  962.  
  963. * Wait Until button is release, or timeOut 1/100 seconds pass. (might miss a  *
  964.  
  965. * tenth (1/10) of a second.
  966.  
  967. ******************************************************************************)
  968.  
  969. Procedure waitForRelease;
  970. Var
  971.     sHour, sMinute, sSecond, sSec100 : Word;    { Time at start }
  972.     cHour, cMinute, cSecond, cSec100 : Word;    { Current time  }
  973.     stopSec                          : longInt;
  974.     currentSec                    : longInt;
  975.     Delta                            : longInt;
  976. begin
  977.     getTime(sHour, sMinute, sSecond, sSec100);
  978.     stopSec := (sHour*36000 + sMinute*600 + sSecond*10 + sSec100 + timeOut) mod
  979.  
  980.                     (24*360000);
  981.     Repeat
  982.            getTime(cHour, cMinute, cSecond, cSec100);
  983.            currentSec := (cHour*36000 + cMinute*600 + cSecond*10 + cSec100);
  984.            Delta := currentSec - stopSec;
  985.     Until (not ButtonPressed) or (Delta >=0) and (Delta < 36000);
  986. end; {waitForRelease}
  987.  
  988. (******************************************************************************
  989.  
  990. *                              swapEventHandler                               *
  991.  
  992. * handler is a Far routine.                                                   *
  993.  
  994. ******************************************************************************)
  995.  
  996. Procedure swapEventHandler;
  997. begin
  998.    reg.ax := $14;
  999.    reg.cx := mask;
  1000.         reg.es := seg(handler^);
  1001.         reg.dx := ofs(handler^);
  1002.         callMouse;
  1003.    lastMask := reg.cx;
  1004.    lastHandler := ptr(reg.es,reg.dx);
  1005. end; {swapEventHandler}
  1006.  
  1007. (******************************************************************************
  1008.  
  1009. *                            getMouseSaveStateSize                            *
  1010.  
  1011. ******************************************************************************)
  1012.  
  1013. Function getMouseSaveStateSize;
  1014. begin
  1015.    reg.ax := $15;
  1016.    callMouse;
  1017.    getMouseSaveStateSize := reg.bx;
  1018. end; {getMouseSaveStateSize}
  1019.  
  1020.  
  1021. (******************************************************************************
  1022.  
  1023. *                               interceptMouse                                *
  1024.  
  1025. ******************************************************************************)
  1026.  
  1027. Procedure interceptMouse;
  1028. begin
  1029.    With reg do begin
  1030.       ax := 3;
  1031.       callMouse; { get place .. }
  1032.       interceptX := cx;
  1033.       interceptY := dx;
  1034.       ax := 31;
  1035.       callMouse;
  1036.    end; { disable mouse driver .. }
  1037. end; {interceptMouse}
  1038.  
  1039. (******************************************************************************
  1040.  
  1041. *                                restoreMouse                                 *
  1042.  
  1043. ******************************************************************************)
  1044.  
  1045. Procedure restoreMouse;
  1046. begin
  1047.    With reg do begin
  1048.       ax := 32; { restore mouse driver .. }
  1049.       callMouse;
  1050.       ax := 4;
  1051.       cx := interceptX;
  1052.       dx := interceptY;
  1053.       callMouse;
  1054.    end; { With .. }
  1055. end; {restoreMouse}
  1056.  
  1057. Var
  1058.     OldExitProc : Pointer;
  1059.  
  1060. (******************************************************************************
  1061.  
  1062. *                                 MyExitProc                                  *
  1063.  
  1064. ******************************************************************************)
  1065.  
  1066. {$f+}Procedure MyExitProc;
  1067. begin
  1068.     ExitProc := OldExitProc;
  1069.     resetMouseGraph;
  1070.     initMouse;
  1071. end; { myExitProc }
  1072.  
  1073. { if this Unit is used With a Graphic Unit that is loaded and executed after
  1074.      this Unit in the Uses clause, the mouse initialization will not be
  1075.      correct, be sure to call initMouse in your Program start to work
  1076.      properly }
  1077.  
  1078. begin   {Unit initialization}
  1079.    eventX := 0;
  1080.    eventY := 0;
  1081.    eventHappened := False; { initialize ... }
  1082.         initMouse; {detect in global Variables}
  1083.         setArrowCursor; {start like that in Graphic mode}
  1084.         OldExitProc := ExitProc;
  1085.         ExitProc    := @MyExitProc;
  1086. end. {mouseLib}
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095. This is a demonstration of the previous Unit Robert.
  1096.  
  1097.  
  1098. (******************************************************************************
  1099.  
  1100. *                                  mouseTest                                  *
  1101.  
  1102. * This is a simple test Program that shows if the mouse is Functions, and
  1103.  
  1104. * demonstrates basic mouse Programming using the mouseLib Unit.
  1105.  
  1106. ******************************************************************************)
  1107.  
  1108. Program mouseTest;
  1109.  
  1110. Uses mouse,Crt,Graph;
  1111.  
  1112. Var
  1113.    grdriver,
  1114.    grmode,
  1115.    ErrCode : Integer;
  1116.  
  1117. Procedure Err(Msg: String);
  1118. begin
  1119.   Writeln(Msg);
  1120. end;
  1121.  
  1122. begin
  1123.      clrScr;
  1124.      if not (mouse_present) then begin
  1125.      { mouse_present was set by the mouseLib initialization code .. }
  1126.           Write('mouse not installed');
  1127.           Exit;
  1128.      end;
  1129.      Case mouse_buttons of
  1130.           twoButton : WriteLn('MicroSoft mouse Mode');
  1131.           threeButton : WriteLn('PC mouse Mode');
  1132.           else WriteLn('UnRecognized mouse mode');
  1133.      end; {Case}
  1134.      Writeln('MouseLib demo Program, (c) 1992, Ron Loewy.');
  1135.      Writeln;
  1136.      Writeln('Move Cursor, Press Right & Left buttons together to continue');
  1137.      Writeln('             Press any mouse button by itself to recognize');
  1138.      Window(10, 7, 70, 20);
  1139.      hardwareTextCursor(1,13); { "normal" Text cursor }
  1140.      showMouseCursor; { display the cursor }
  1141.      Repeat
  1142.            if getButton(leftButton) = buttonDown then
  1143.               WriteLn('Left Button Pressed');
  1144.            if getButton(rightButton) = buttonDown then
  1145.               WriteLn('right Button Pressed');
  1146.            if getButton(middleButton) = buttonDown then
  1147.               WriteLn('Middle Button Pressed');
  1148.      Until (getButton(leftButton) = buttonDown) and
  1149.            (getButton(RightButton) = buttonDown);
  1150.      hideMouseCursor; { we hide the cursor }
  1151.      grDriver := detect;
  1152.      initGraph(grDriver, grMode, 'D:\TP\BGI');
  1153.      ErrCode := GraphResult;
  1154.      if ErrCode <> grOK then Err('ERRor! not initializing:'+GraphErrorMsg(ErrCo
  1155.  
  1156.      setMouseGraph; { fix quircks in Herc. Graphic card }
  1157.      initMouse; { let the mouse sense it is in Graphic mode }
  1158.      outTextXY(10, 10, 'MouseLib demo Program, (c) 1992, Ron Loewy.');
  1159.      outTextXY(10, 30, 'Press the Right Button to end');
  1160.      showMouseCursor; { draw the Graphic default arrow cursor }
  1161.      Repeat Until getButton(rightButton) = buttonDown;
  1162.      hideMouseCursor;
  1163.      closeGraph;
  1164. end.
  1165.