home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / p / pmouse11.zip / MOUSE.DOC next >
Text File  |  1993-02-27  |  10KB  |  323 lines

  1. ******************************************************************************
  2.  
  3.                         
  4.                            Mouse Utilities v1.1
  5.  
  6.                    by:  Douglas Peterson  aka Peter Piper
  7.  
  8.  
  9. ******************************************************************************
  10.  
  11.  
  12.    This release fixes the problems with PressData_mouse and ReleaseData_mouse
  13. not working.  Also note:  I changed the order of arguments in both calls to
  14. reflect consistency with the Get_mouse routine.
  15.  
  16.    Here are some routines you can use for programming with the mouse.  They
  17. are written in assembly for use with Borland C/C++/Turbo C/C++.  I am totally 
  18. unfamilier with Microsoft C so I don't know if they are compatible.  If 
  19. Microsoft passes arguments the same way as Borland, I don't see why they 
  20. shouldn't be.
  21.  
  22.  
  23. IF YOU FIND THIS USEFUL:
  24.  
  25.    Please send a check or money order for $10 to:
  26.    
  27.    Douglas Peterson
  28.    2425 Auburn Dr.
  29.    Victoria, MN  55386
  30.  
  31.    You may also send comments, questions, or requests for improvments to this
  32. address or by electronic mail on TSN, mailbox# 22332.  All those who send me
  33. money will be contacted on where to find any upgrades or new releases.
  34.  
  35.  
  36. HOW TO:
  37.  
  38.    Just put MOUSE.H in your Borland/Turbo C INCLUDE directory and put
  39. MOUSELG.LIB and MOUSESM.LIB into the LIB directory and #include <mouse.h> in 
  40. your source, then link via a project or make or TLINK the .LIB file into your 
  41. code and your set!
  42.  
  43.    MOUSELG.LIB is for use with Large memory module
  44.    MOUSESM.LIB is for use with Small memory module
  45.  
  46.  
  47. FUNCTION PROTOTYPES:
  48.  
  49.  
  50. Init_mouse
  51.  
  52.    int  Init_mouse(void)
  53.  
  54.       This function initializes the mouse and displays the cursor on the 
  55.    screen.  You must call this AFTER initializing the graphics mode or it wont
  56.    work.  
  57.  
  58.    Returns: -1 if successfull (A 100% Microsoft compatable mouse driver is 
  59.                loaded)
  60.              0 if not successfull
  61.  
  62.  
  63. Mouse
  64.  
  65.    void Mouse(int VIS)
  66.  
  67.    VIS - 1 to show the mouse
  68.          2 to hide the mouse
  69.  
  70.    SHOW and HIDE are predefined constants to make your code more legible.
  71.  
  72.       This function hides and shows the mouse.  You MUST hide the mouse before
  73.    doing anything that would alter the graphics page (ie drawing lines, etc)
  74.    or you will get 'mouse droppings' on your screen.
  75.  
  76.  
  77.    Returns: None
  78.  
  79.  
  80. Move_mouse
  81.  
  82.    void Move_mouse(int X, int Y)
  83.  
  84.    X - xposition on screen
  85.    Y - yposition on screen
  86.  
  87.       This function moves the mouse cursor to the X,Y coordinates you supply.
  88.  
  89.    Returns: None
  90.  
  91.  
  92. Get_mouse
  93.  
  94.    void Get_mouse(int *X, int *Y, int *BUTTON)
  95.  
  96.    X - xposition of mouse at time of call
  97.    Y - yposition of mouse at time of call
  98.    BUTTON - state of buttons:
  99.  
  100.       0 bit - 1 if left button pressed
  101.       1 bit - 1 if right button pressed
  102.       3 bit - 1 if middle button pressed (Only if 3 button mouse)
  103.  
  104.       This function returns the current status of the mouse.  *X, *Y, *BUTTON
  105.    need to be refrences to integers to hold the return values
  106.    
  107.    Example:  
  108.       int mx, my, button;
  109.       Get_mouse(&mx, &my, &button);
  110.  
  111.    Returns: None
  112.  
  113.  
  114. Limit_mouse
  115.  
  116.    void Limit_mouse(int LEFT, int TOP, int RIGHT, int BOTTOM)
  117.  
  118.    LEFT,TOP - upperleft corner of box to limit mouse in
  119.    RIGHT,BOTTOM - lowerright corner of box to limit mouse in
  120.  
  121.       This function defines a box to limit the mouse movement in.  If the
  122.    mouse is outside the box before the call, it is moved into the nearest
  123.    boundary.
  124.  
  125.    Returns: None
  126.  
  127.  
  128. PixelsPer_mouse
  129.  
  130.    void PixelsPer_mouse(int HORZ, int VERT)
  131.  
  132.    HORZ - number of mickeys per 8 pixels horizontally (8 default)
  133.    VERT - number of mickeys per 8 pixels vertically (16 default)
  134.  
  135.       What's a Mickey??  It's the unit of measurment defining the roller 
  136.    under your mouse.  Basically the higher the number, the 'slower' the
  137.    mouse moves.  1,1 will make the mouse almost uncontrollable :)
  138.  
  139.    Returns: None
  140.  
  141.  
  142. PressData_mouse
  143.  
  144.    void PressData_mouse(int *X, int *Y, int *NUMBER)
  145.  
  146.    On Call:
  147.    NUMBER - Which button do you want data on:
  148.       0 - Left
  149.       1 - Right 
  150.       2 - Middle
  151.  
  152.    On Return:
  153.    X - xposition of mouse at last button press
  154.    Y - yposition of mouse at last button press
  155.    NUMBER - Returns number of button presses for the selected button since
  156.       the last call to PressData or since the mouse was initialized.
  157.  
  158.       The only thing to note of importance is how to call this routine.
  159.    You have to give referance to NUMBER, X, and Y so the routine can put
  160.    it's returns in those variables.
  161.  
  162.    Example:  
  163.       int x,y,number=0;
  164.       PressData_mouse(&x,&y,&number);
  165.  
  166.       This returns the number of presses and last x, y for the left mouse
  167.    button in the variables number, x and y.
  168.  
  169.    Returns: None
  170.  
  171.  
  172. ReleaseData_mouse
  173.  
  174.    void ReleaseData_mouse(int *X, int *Y int *NUMBER)
  175.  
  176.       Same as PressData_mouse except it counts button realeases instead of
  177.    presses.
  178.  
  179.  
  180. Change_mouse
  181.  
  182.    void Change_mouse(int *ICON, int ROWS, int COLS)
  183.  
  184.    ICON - 32 word bitmap array of Screen mask and Cursor mask (see below)
  185.    ROWS - (-16 to 16) x offset from upperleft of cursor for 'hot spot'
  186.    COLS - (-16 to 16) y offset from upperleft of cursor for 'hot spot'
  187.  
  188.       This function lets you define your own mouse cursor.  I'll do my best
  189.    to explain the Screen mask and the Cursor mask below.
  190.  
  191.      screen mask          cursor mask            cursor
  192.  
  193.    1001111111111111 9FFF   0000000000000000 0000   .**.............
  194.    1000111111111111 8FFF   0010000000000000 2200   .*X*............
  195.    1000011111111111 87FF   0011000000000000 3300   .*XX*...........
  196.    1000001111111111 83FF   0011100000000000 3800   .*XXX*..........
  197.    1000000111111111 81FF   0011110000000000 3C00   .*XXXX*.........
  198.    1000000011111111 80FF   0011111000000000 3E00   .*XXXXX*........
  199.    1000000001111111 807F   0011111100000000 3F00   .*XXXXXX*.......
  200.    1000000000111111 803F   0011111110000000 3F80   .*XXXXXXX*......
  201.    1000000000011111 801F   0011111111000000 3FC0   .*XXXXXXXX*.....
  202.    1000000000001111 800F   0011111000000000 3E00   .*XXXXX*****....
  203.    1000000011111111 80FF   0011011000000000 3600   .*XX*XX*........
  204.    1000100001111111 887F   0010001100000000 2300   .*X*.*XX*.......
  205.    1001100001111111 987F   0000001100000000 0300   .**..*XX*.......
  206.    1111110000111111 FC3F   0000000110000000 0180   ......*XX*......
  207.    1111110000111111 FC3F   0000000110000000 0180   ......*XX*......
  208.    1111111000111111 FE3F   0000000000000000 0000   .......***......
  209.  
  210.  
  211.       . - Unchanged screen
  212.       * - Black pixel
  213.       X - White pixel
  214.  
  215.    screen mask    cursor mask    cursor
  216.    ---------------------------------------
  217.       0              0           black
  218.       0              1           white
  219.       1              0           unchanged
  220.       1              1           inverted
  221.    ---------------------------------------
  222.  
  223.       Unchanged it n-k where n is the maximum color of the video mode and
  224.    k is the color to be replaced.  So in 16 color mode if you inverted a 
  225.    yellow (14) dot: maxcolor (15) the result would be blue (1) 15-14.
  226.  
  227.       Once you have drawn out your 2 masks and converted the binary numbers
  228.    to hex (as shown above), assigned the 32 words to an int array:
  229.  
  230.    int cursor[] = { 0x9FFF,0x8FFF,0x87FF,0x83FF,0x81FF,0x80FF,0x807F,0x803F,
  231.                     0x801F,0x800F,0x80FF,0x887F,0x987F,0xFC3F,0xFC3F,0xFE3F,
  232.                     0x0000,0x2200,0x3300,0x3800,0x3C00,0x3E00,0x3F00,0x3F80,
  233.                     0x3FC0,0x3E00,0x3600,0x2300,0x0300,0x0180,0x0180,0X0000};
  234.  
  235.       Now call Change_mouse:
  236.  
  237.    Change_mouse(cursor,1,0);
  238.  
  239.       The 1,0 is the 'hot spot' for which pixel you actually pressed on the
  240.    screen. 
  241.  
  242.  
  243.  
  244.  
  245. ******************************************************************************
  246.  
  247.    Here's an example that will show you some of the features:
  248.  
  249. ******************************************************************************
  250.  
  251. #include <stdlib.h>
  252. #include <stdio.h>
  253. #include <graphics.h>
  254. #include <conio.h>
  255. #include <mouse.h>
  256.  
  257. int mousecur[] = {0xFFFF,0x871F,0x860F,0x8C0F,0x980F,0xF01F,0xE03F,0xC07F,
  258.                   0x80FF,0x81FF,0x839F,0x876F,0xDEF7,0xEDFB,0xF3FD,0xFFFF,
  259.                   0x0000,0x78E0,0x4910,0x5210,0x6410,0x0820,0x1040,0x3880,
  260.                   0x4500,0x5600,0x6460,0x7890,0x2108,0x1204,0x0C02,0x0000};
  261.  
  262. void main(void)
  263. {
  264.  
  265.    int mx,my,button;
  266.    int gdriver = DETECT, gmode, errorcode;
  267.  
  268.    initgraph(&gdriver, &gmode, ""); /* init graphics */
  269.    errorcode = graphresult();
  270.    if (errorcode != grOk) {
  271.       printf("\nGraphics error: %s", grapherrormsg(errorcode));
  272.       printf("\nPress any key to halt:\n");
  273.       exit(1);
  274.    }
  275.  
  276.    if (!Init_mouse()) {  /* init mouse */
  277.       closegraph();
  278.       printf("\nNot a Microsoft Compatable mouse driver");
  279.       printf("\nOr mouse driver not loaded\n");
  280.       exit(1);
  281.    }
  282.  
  283.    Move_mouse(10,10);   /* moves mouse to 10,10 */
  284.    Change_mouse(mousecur,1,1);  /* changes mouse cursor to paint roller */
  285.  
  286.    Mouse(HIDE);  /*  Remember to hide the mouse before drawing!  */
  287.    setfillstyle(SOLID_FILL,WHITE);
  288.    setcolor(BLACK);
  289.    bar3d(100,100,300,199,0,0);
  290.    outtextxy(120,146,"Click Here to close");
  291.    Mouse(SHOW); /*  And don't forget to show it again!  */
  292.  
  293.    do {
  294.       Get_mouse(&mx,&my,&button);
  295.       if (mx>100&&mx<300&&my>100&&my<199&&button) break;
  296.    }while(1);  /* wait for click in box */
  297.  
  298.    Limit_mouse(0,0,getmaxx(),100);
  299.  
  300.    Mouse(HIDE);
  301.    setfillstyle(SOLID_FILL,BLACK);
  302.    setcolor(WHITE);
  303.    bar(100,100,300,199);
  304.    outtextxy(124,141,"Move mouse around");
  305.    outtextxy(120,151,"Press both buttons");
  306.    Mouse(SHOW);
  307.  
  308.    do { 
  309.       Get_mouse(&mx,&my,&button);
  310.    }while(button!=3);   /* wait for bothbuttons pressed */
  311.       /* 3 = 00000011 bits 0 and 1 are set, indicating both buttons */
  312.  
  313.    closegraph();
  314.  
  315. }
  316.  
  317. ******************************************************************************   
  318.    
  319.    
  320.    That's it, hope you enjoy!
  321.  
  322.  
  323.