home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PASCAL / MOUSTL55.ZIP / MOUSTOOL.DOC < prev    next >
Text File  |  1989-09-13  |  22KB  |  494 lines

  1. ╔═══════════════════════════════════════════════════════════════════════════╗
  2. ║                                                                           ║
  3. ║                               MouseTools                                  ║
  4. ║                     Version 1.1    September 13, 1989                     ║
  5. ║                                                                           ║
  6. ║                              Nels Anderson                                ║
  7. ║                             92 Bishop Drive                               ║
  8. ║                          Framingham, MA  01701                            ║
  9. ║                                                                           ║
  10. ╚═══════════════════════════════════════════════════════════════════════════╝
  11.  
  12. The use of a mouse as an input device is becoming increasingly common in
  13. many types of programs.  While this (usually) makes life easier for the
  14. user, it certainly does make the programmer's job harder.  Several things
  15. I've worked on seemed to demand a mouse interface, so I ended up writing
  16. my own utilities to use a mouse and I present them in this package for
  17. you to use in your own Turbo Pascal 5.5 programs.
  18.  
  19. This set of utilities provides most of the necessary procedures to use
  20. a mouse in your own programs, including:
  21.  
  22.   o  display the mouse cursor
  23.   o  read mouse and button positions
  24.   o  display various prompts with "push buttons"
  25.   o  select filenames
  26.  
  27. To use these tools you will need Turbo Pascal 5.5 and you must have the
  28. TP5.5 units Crt, Dos, Drivers, Fonts and Graph available.  I've provided
  29. you with two sample programs (mapedit.pas, cgaexp.pas) along with the .tpu
  30. files for all the mouse tools.  This should give you enough to get started
  31. writing mouse programs in Turbo Pascal.  The source code for the units is
  32. not included.
  33.  
  34. New in v1.1 is support for MCGA graphics mode.  You'll need the driver
  35. that Borland has made available in the BGIKIT to be able to use this mode
  36. since it was not included in the standard Turbo Pascal package.
  37.  
  38. MouseTools is provided as Shareware.  You may use it, copy it for friends,
  39. upload it to BBS's, etc.  If you continue to use MouseTools and would like
  40. to reward me for my work, you can send a donation ($10 suggested) to me
  41. at:
  42.  
  43.                              Nels Anderson
  44.                             92 Bishop Drive
  45.                          Framingham, MA  01701
  46.  
  47. Registered users will get the latest updates on the tools as well as the
  48. source code for all the mouse units.  Support is also available through
  49. my BBS, )(evious, at 508-875-3618 or 617-449-7322, 300/1200/2400/9600HST.
  50. I'd love to see anything you create using these tools; if you can either
  51. mail me a copy or upload it to the BBS.
  52.  
  53. If you're connected to one of the minicomputer nets (InterNet, uucp...)
  54. you can try reaching me at one of these addresses:
  55.  
  56.                 ima!primerd!en-m32.prime.com!nja
  57.                 uunet!en-m32.prime.com!nja
  58.                 csnet-relay!en-m32.prime.com!nja
  59.                 nja%en-m32.prime.com@relay.cs.net
  60.                 nja@en-m32.prime.com
  61.  
  62.  
  63. ╔═══════════════════════════════════════════════════════════════════════════╗
  64. ║                            Using MouseTools                               ║
  65. ╚═══════════════════════════════════════════════════════════════════════════╝
  66.  
  67. Probably the best way to understand how the tools work is to examine the
  68. sample programs, mapedit.pas and cgaexp.pas.  You should refer to them for
  69. actual examples of how things are used as they are described here.
  70.  
  71. First, some basic concepts.  Most of your interface to the mouse is
  72. actually done by the mouse driver that is supplied by the mouse manu-
  73. facturer.  The interface to the mouse driver is done through interrupts
  74. similar to the way MS-DOS or BIOS functions are accessed.  If you've
  75. never used MS-DOS/BIOS functions, don't worry.  MouseTools handles all
  76. the messy details for you.
  77.  
  78. Once the mouse is activated and you can read positions from it, your
  79. program needs to display something on the screen to echo the mouse's
  80. actions.  MouseTools allows you to use any shape as a mouse cursor,
  81. and comes with an arrow, finger and hand cursor already drawn.  With
  82. the registered version you can add your own cursor shapes.  Tools are
  83. provided for displaying and moving the cursor around the screen.
  84.  
  85. In addition to movement, you need to determine when the user wants to
  86. do something either by just being over a particular part of the screen
  87. or by using the mouse buttons.  These are the basic tools of the mouse
  88. interface.
  89.  
  90. In addition to the basics, tools are provided to display prompts of
  91. several types and return the selections the user made.  One of the most
  92. sophisticated prompts is the file selection tool, which allows the user
  93. to select files through a scrolling list and includes the ability to
  94. change directories and drives.
  95.  
  96. OK, so all these tools are available.  Now you're probably wondering
  97. exactly how to use them.  Let's go through that step by step.
  98.  
  99. INITIALIZATION
  100.  
  101. First, you must enter graphics mode as you would in any Turbo Pascal
  102. program.   Then the mouse itself must be initialized.  The functions
  103. to do this are:
  104.  
  105. MReset -- resets the mouse and returns -1 if a mouse driver is installed
  106. MLimit (x1,x2,y1,y2) -- sets the limits of the mouse coordinates
  107. MPut(x,y) -- positions the mouse at coordinates x,y
  108.  
  109. If MReset doesn't return a value of -1 there is no mouse driver installed
  110. and your program won't be able to do any mouse functions.  MLimit is used
  111. to control the range of values the mouse returns to you.  These limits
  112. will probably be equal to the size of the screen (i.e., x=0 thru 639,
  113. y=0 thru 349 for EGA graphics mode).  MPut sets the mouse coordinates to
  114. start from.  You'll probably want to either put the mouse in a corner or
  115. in the middle of the screen.
  116.  
  117. Several Pascal variables are used to keep track of what the mouse has
  118. been doing.  These are:
  119.  
  120. Mx -- last mouse x coordinate        \
  121. My -- last mouse y coordinate         >  all are in mouse.tpu
  122. Button -- last mouse button value    /
  123.  
  124. Initially, you should set Mx and My to the values you used in MPut(x,y),
  125. and you should initialize Button to 0.
  126.  
  127. You'll also need some memory on the heap to save the screen that's under
  128. the mouse cursor.  The variable MCurs (in mouse.tpu) is used to point to
  129. this memory.  Set it up by using:
  130.  
  131. GetMem(MCurs,ImageSize(0,0,MW,MH));    {reserve memory for mouse cursor}
  132.  
  133. There's still no visible indication on the screen that there's a mouse
  134. in use.  You can now turn on the mouse cursor using the procedure:
  135.  
  136. MouseCursorOn(Mx,My,HAND);        {display a hand cursor}
  137.  
  138. The first two parameters determine where the mouse cursor will be.
  139. The third parameter determines the shape of the mouse cursor.  The
  140. available cursor shapes are HAND, FINGER and ARROW.
  141.  
  142. Now everything is set, and you can start the main body of your program.
  143.  
  144.  
  145. USING THE MOUSE IN YOUR MAIN PROGRAM
  146.  
  147. The main body of your program will need a loop where the mouse is
  148. polled allowing its displayed position to be updated and to check
  149. for command requests from the user.
  150.  
  151. The main procedure in this loop is:
  152.  
  153. MStatus(NewButton,NewX,NewY);            {get mouse status}
  154.  
  155. This returns the current position of the mouse buttons followed by the
  156. x and y mouse coordinates.  There are several things you can then do
  157. with this information:
  158.  
  159.  *  Compare NewX vs. Mx and NewY vs. My to see if the mouse has moved.
  160.     If it has, use:
  161.     
  162.     MouseCursor(NewX,NewY,Mx,My,HAND);        {move mouse cursor}
  163.     
  164.     to move the mouse cursor to its new position.  After moving, save NewX
  165.     into Mx and NewY into My.
  166.  
  167.  *  See if the mouse is over something significant by using:
  168.  
  169.     MouseLocate(NewX,NewY,18,@mt)
  170.  
  171.     This function uses a table ("mt" in this case, containing 18 items)
  172.     of coordinates and returns a value indicating which if any sets of
  173.     coordinates NewX/NewY are within.  MouseLocate() is further described
  174.     later.
  175.  
  176.  *  See if a button is being pushed by comparing NewButton with
  177.     Button.  Detecting a button push will usually mean a call to
  178.     MouseLocate() to find what item the user is selecting.  Then
  179.     a case statement can be used to call the appropriate procedure.
  180.  
  181. Believe it or not, that's basically it!  The remainder of this file will
  182. describe in detail what all the available functions and procedures do.
  183.  
  184.  
  185. MOUSETOOLS DETAILED DESCRIPTIONS
  186.  
  187. Once you understand the basics of initializing the mouse and detecting
  188. what it's doing in the body of the program, you'll need to know what
  189. tools are available for using it further.  This section describes in
  190. detail all the available mouse functions and procedures, in order by
  191. the unit they are in.
  192.  
  193. MOUSE.TPU
  194.  
  195. This unit provides the interface to the mouse driver, plus the basic
  196. routines for displaying the mouse cursor and determining what the
  197. mouse is pointing to.
  198.  
  199. function MReset:  INTEGER;
  200.  
  201.   This function initializes the mouse.  It returns an integer value of
  202.   -1 if a mouse is detected.  If MReset does not return -1, you cannot
  203.   use mouse functions in the remainder of the program.
  204.   
  205. procedure MPut(mx,my:  INTEGER);
  206.  
  207.   This procedure sets the current mouse position to mx,my.  That is, if
  208.   you were to immediately read the mouse position using MStatus() before
  209.   the user had a chance to move it, the values you'd receive back would
  210.   be mx,my.
  211.  
  212. procedure MStatus(var button,xpos,ypos:  INTEGER);
  213.  
  214.   This procedure returns the current state of the mouse.  "Button" is a
  215.   bit mapped value indicating which buttons are pressed (i.e., Button is
  216.   1 if button 1 is pressed, 2 if button 2 is pressed, 3 if both buttons
  217.   1 and 2 are pressed).  xpos,ypos are the current position of the mouse.
  218.  
  219. procedure MLimit(xmin,xmax,ymin,ymax:  INTEGER);
  220.  
  221.   You can limit the coordinate values returned by MStatus using this
  222.   procedure.  To prevent the mouse from going off the screen in EGA
  223.   640x350 mode, you could set xmin=0, xmax=639, ymin=0, ymax=349.
  224.   Smaller values can be used to limit mouse travel to only a portion
  225.   of the screen.
  226.  
  227. procedure MouseCursor(x,y,Oldx,Oldy,Num:  INTEGER);
  228.  
  229.   This procedure moves the displayed mouse cursor from one position, 
  230.   Oldx,Oldy to a new position, x,y.  Make sure the mouse cursor is
  231.   actually being displayed when you call this function, otherwise you
  232.   will leave blocks of garbage on the screen.
  233.  
  234. procedure MouseCursorOn(x,y,Num:  INTEGER);
  235.  
  236.   This procedure is basically one half of MouseCursor().  Use it when
  237.   the mouse cursor is not currently being displayed but now should be,
  238.   such as at the beginning of the program.  MouseCursorOn() must be
  239.   used before MouseCursor() is first called.
  240.  
  241. procedure MouseCursorOff(Oldx,Oldy:  INTEGER);
  242.  
  243.   This procedure removes the mouse cursor from the screen and restores
  244.   whatever was under it to view.
  245.  
  246. function MouseLocate(x,y,size:  INTEGER; mt:  mtptr):  INTEGER;
  247.  
  248.   This function is the key to making the mouse do useful things within
  249.   your program.  It uses a table "mt" with "size" entries in it to
  250.   determine what the user is pointing to.  "x" and "y" should be the
  251.   current mouse coordinates (Mx and My).
  252.   
  253.   To use MouseLocate you must set up a table of integers, 4 numbers
  254.   per entry, which describe rectangles on the screen.  Here is a sample
  255.   table:
  256.   
  257.   Const
  258.     mt: array[1..2,1..4] of INTEGER = (
  259.     (400,620,68,81),            {save}
  260.     (400,620,82,95) );            {read}
  261.   
  262.   The sample shows two possible functions, save and read, that the user
  263.   can select.  If the x coordinate of the mouse is between 400 and 620,
  264.   and the y coordinate is between 68 and 81 then "save" is being
  265.   selected.  MouseLocate will check all entries in the table and will
  266.   return the number of the first table entry found that contains the
  267.   specified coordinates.
  268.   
  269.   Note that when calling MouseLocate you must actually pass a pointer
  270.   to the table rather than the table itself, so a sample call to
  271.   MouseLocate might look like this:
  272.   
  273.   i := MouseLocate(Mx,My,18,@mt);
  274.  
  275. MOUSERS2.TPU
  276.  
  277. This unit provides several ways of prompting the user for input and
  278. using the mouse to get his response.
  279.  
  280. function MGetFile(FileSpec,Heading:  STRING): STRING;
  281.  
  282.   This is a very sophisticated routine for allowing the user to select
  283.   file names.  A box is popped up containing a list of files that the
  284.   user can select from.  The list can be scrolled if all valid files
  285.   do not fit and the user can switch between directories and disks.
  286.   "FileSpec" specifies what file names will be shown.  You'd use "*.*"
  287.   to show all files, but if you only wanted files with the suffix "pic"
  288.   you could set FileSpec to "*.pic".  Many possibilities are available
  289.   for FileSpec.  "Heading" is a prompt to the user that will be at the
  290.   top of the box showing the file names.  MGetFile returns a string
  291.   containing the filename that was selected.  If character 0 of the
  292.   returned string is equal to #255 however the user aborted the file
  293.   selection.
  294.  
  295. function MouseYN(x,y: INTEGER; Heading:  STRING):  BOOLEAN;
  296.  
  297.   This function displays a question contained in "Heading" along with
  298.   a yes and no button.  If the user selects the yes button, the
  299.   function returns a TRUE value, otherwise it returns false.
  300.   
  301. function MouseQuestion(Size: INTEGER;Heading: STRING;Ques: QTable): INTEGER;
  302.  
  303.   This function displays a question and a list of answers for the user
  304.   to choose from, returning the number of the user's choice.  "Size"
  305.   is the number of possible answers.  "Ques" is an array of strings
  306.   containing the possible responses.  A sample "Ques" might look like:
  307.   
  308.   PalQues: array[1..5] of STRING = (    {palette questions}
  309.   'Save','Load','Change','Rotate','Default');
  310.   
  311.   Note that when calling MouseQuestion you must actually pass a pointer
  312.   to the table rather than the table itself, so a sample call to
  313.   MouseQuestion might look like this:
  314.   
  315.   case MouseQuestion(5,'Select a palette function',@PalQues) of
  316.  
  317. function MouseReadKey(Heading: STRING): CHAR;
  318.  
  319.   This function displays a heading (actually, the heading is optional)
  320.   and waits for the user to hit a single key or click the mouse.  If
  321.   a key is hit, its value is returned; otherwise if the mouse is
  322.   clicked a value of #0 is returned.
  323.  
  324. BOX.TPU
  325.  
  326. This unit has a couple of tools used for popup boxes and other things.
  327.  
  328. procedure OutlineBox(x1,y1,x2,y2,boxcolor,rectcolor:  INTEGER);
  329.  
  330.   This procedure draws a box using "boxcolor" as the background color
  331.   of the box, and using a single pixel wide outline of color "rectcolor"
  332.   around the edge.  This is the standard box used for mouse prompts.
  333.  
  334. procedure XPutPixel(x,y,color:  INTEGER);
  335.  
  336.   Plot a pixel at x,y by XOR'ing its current color with "color".
  337.  
  338. procedure XLine(x1,y1,x2,y2,color:  INTEGER);
  339.  
  340.   Draw a line from x1,y1 to x2,y2 by XOR'ing its current color
  341.   with "color".
  342.  
  343. procedure Input(var temp:  STRING);
  344.  
  345.   String input routine for graphics mode.  Handles echoing of the
  346.   string using the currently selected font as well as displaying a
  347.   cursor and backspacing.
  348.  
  349. PALETTE.TPU
  350.  
  351. This unit is not strictly part of the mouse tools, but is needed to
  352. use EGA graphics mode.  Its only procedure is one to initialize graphics
  353. mode.
  354.  
  355. procedure Initialize;
  356.  
  357.   As currently set up, Initialize sets up EGA 640x350 mode graphics.
  358.   This routine is right out of the Turbo Pascal sample programs, so if
  359.   you need other modes you should be able to make your own version of
  360.   it.
  361.  
  362. CONVERT.TPU
  363.  
  364. This unit isn't really necessary for a mouse interface either, but
  365. contains some functions that I use in mapedit.pas and which you might
  366. find useful.
  367.  
  368. function RtoI(number:  REAL): INTEGER;
  369.  
  370.   Takes the real variable "number" and returns it as an integer.
  371.  
  372. function ItoS(number:  LONGINT): STRING;
  373.  
  374.   Takes the integer variable "number" and returns it as a string.
  375.  
  376. function ItoFS(number:  LONGINT;  a:  INTEGER; fill:  CHAR): STRING;
  377.  
  378.   Takes the integer variable "number" and returns it as a formatted
  379.   string, exactly "a" characters long with unneeded character positions
  380.   set to the character "fill".
  381.  
  382. function RtoS(number:  REAL; a,b:  INTEGER): STRING;
  383.  
  384.   Takes the real variable "number" and returns it as a formatted
  385.   string, exactly "a" characters long with "b" characters after the
  386.   decimal point.
  387.  
  388. function NoSpace(s: STRING): STRING;
  389.  
  390.   Takes the string "s" and returns it with leading spaces removed.
  391.  
  392. function GetVal(s: STRING): REAL;
  393.  
  394.   Takes the string "s" and returns it as a real number.
  395.  
  396.  
  397. ╔═══════════════════════════════════════════════════════════════════════════╗
  398. ║                            Sample Programs                                ║
  399. ╚═══════════════════════════════════════════════════════════════════════════╝
  400.  
  401. MapEdit, one sample program used to demonstrate MouseTools, is actually
  402. a utility I wrote for a friend who needed to be able to draw icons that
  403. would be combined to create a map display in a program he was writing.
  404. Another friend has since used MapEdit to draw the keys for a calculator
  405. program he is writing.  I haven't used any MapEdit icons in any released
  406. programs *yet* but I'm working on an adventure game that will use maps
  407. and creatures created with MapEdit.  So, in addition to a sample of the
  408. mouse tools you're getting a potentially useful program since there are
  409. lots of possible uses for graphical icons.
  410.  
  411. I've included a sample icon file called ccmap.pic for you to play around
  412. with.  This is some of the icons for my future adventure game.  Try using
  413. the various functions of MapEdit to see what the mouse tools actually 
  414. look like on the screen.
  415.  
  416. By the way, if you want to see an actual program that used MapEdit, look
  417. for BassTour by Dick Olsen, currently available on BBS's as BASSTR26.ZIP.
  418.  
  419. CGAExp, the other sample program, doesn't actually do anything useful but
  420. demonstrates that the MouseTools can be used in CGA graphics as well as
  421. EGA.  Since there's less actual program surrounding the tools, you might
  422. find it more useful for understanding the tools than MapEdit.
  423.  
  424. ╔═══════════════════════════════════════════════════════════════════════════╗
  425. ║                             Included Files                                ║
  426. ╚═══════════════════════════════════════════════════════════════════════════╝
  427.  
  428. The following files are included in MouseTools:
  429.  
  430. MOUSE.TPU       Mouse driver interface and other basic mouse tools
  431. MOUSERS2.TPU    Mouse response tools
  432. CONVERT.TPU     Some conversion tools used by mapedit.pas
  433. PALETTE.TPU     Graphics initialization used by mapedit.pas
  434. BOX.TPU         Graphics utilities for popup boxes
  435. CGAEXP.PAS      Sample program using MouseTools (CGA)
  436. CGAEXP.EXE      Run-able version of sample program
  437. MAPEDIT.PAS     Sample program using MouseTools (EGA)
  438. MAPEDIT.EXE     Run-able version of sample program
  439. CCMAP.PIC       Sample data for mapedit.exe
  440. SHAREWRE.TXT    Explaination of shareware distribution
  441. MOUSTOOL.DOC    This file, the MouseTools documentation
  442.  
  443. ╔═══════════════════════════════════════════════════════════════════════════╗
  444. ║                           Available Software                              ║
  445. ╚═══════════════════════════════════════════════════════════════════════════╝
  446.  
  447. Other software which I've either written or contributed to:
  448.  
  449. EGATREK:   Space strategy battle game, using full EGA graphics,
  450.            based on the classic minicomputer game.  Winner of
  451.            Public Brand Software's 1988 software contest.
  452.  
  453. MAHJONGG:  Solitaire game played with Chinese tiles.  Supports
  454.            EGA and Hercules graphics; mouse optional.  See reviews
  455.            in December 1988 "PCWorld" and April 1989 "Compute!".
  456.  
  457. MOUSTOOL:  A collection of utilities for Turbo Pascal programmers
  458.            wishing to incorporate mouse input in their programs.
  459.            Sample programs included for both EGA and CGA graphics.
  460.  
  461. SOUNDPAS:  A collection of utilities for Turbo Pascal programmers
  462.            to add music and sound effects to their programs.  Includes
  463.            units for interrupt and real time sounds.
  464.  
  465. BASSTOUR:  (Written by Dick Olsen).  Game that simulates a fishing
  466.            tournament, including rod and lure selection.  Runs in
  467.            EGA/CGA/Hercules graphics modes.  Uses many of the
  468.            utilities from MOUSTOOL.
  469.  
  470. BASSMAP:   Companion program for BassTour which allows lakes to be
  471.            created or modified.
  472.  
  473. CALLDOOR:  A PCBoard 14.x door that lets users view the system caller
  474.            log.  Logs for any node can be viewed in reverse order
  475.            (i.e., most recent caller back) or the logs can be searched
  476.            for any string.
  477.  
  478. TOPPERS:   A PCBoard 14.x sysop utility that generates a formatted
  479.            list of the board's top users (by number of calls,
  480.            downloads and uploads).  The output file has three columns,
  481.            one for each category.  Graphics and non-graphics output
  482.            is available.
  483.  
  484. TOPTALK:   A PCBoard 14.x sysop utility that tracks user activity in
  485.            conferences based on number of messages posted.  Included
  486.            is a complete record of all user activity plus a bulletin
  487.            file of the top ten most active message posters.
  488.  
  489. GROUPERS:  A PCBoard 14.x game door.  Players gamble on the outcome
  490.            of the next card drawn from the deck.  The game is set up
  491.            to run as a monthly contest and keeps track of current
  492.            scores, generates a current scores bulletin and an end of
  493.            month final scores bulletin.
  494.