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 >
Wrap
Text File
|
1993-02-27
|
10KB
|
323 lines
******************************************************************************
Mouse Utilities v1.1
by: Douglas Peterson aka Peter Piper
******************************************************************************
This release fixes the problems with PressData_mouse and ReleaseData_mouse
not working. Also note: I changed the order of arguments in both calls to
reflect consistency with the Get_mouse routine.
Here are some routines you can use for programming with the mouse. They
are written in assembly for use with Borland C/C++/Turbo C/C++. I am totally
unfamilier with Microsoft C so I don't know if they are compatible. If
Microsoft passes arguments the same way as Borland, I don't see why they
shouldn't be.
IF YOU FIND THIS USEFUL:
Please send a check or money order for $10 to:
Douglas Peterson
2425 Auburn Dr.
Victoria, MN 55386
You may also send comments, questions, or requests for improvments to this
address or by electronic mail on TSN, mailbox# 22332. All those who send me
money will be contacted on where to find any upgrades or new releases.
HOW TO:
Just put MOUSE.H in your Borland/Turbo C INCLUDE directory and put
MOUSELG.LIB and MOUSESM.LIB into the LIB directory and #include <mouse.h> in
your source, then link via a project or make or TLINK the .LIB file into your
code and your set!
MOUSELG.LIB is for use with Large memory module
MOUSESM.LIB is for use with Small memory module
FUNCTION PROTOTYPES:
Init_mouse
int Init_mouse(void)
This function initializes the mouse and displays the cursor on the
screen. You must call this AFTER initializing the graphics mode or it wont
work.
Returns: -1 if successfull (A 100% Microsoft compatable mouse driver is
loaded)
0 if not successfull
Mouse
void Mouse(int VIS)
VIS - 1 to show the mouse
2 to hide the mouse
SHOW and HIDE are predefined constants to make your code more legible.
This function hides and shows the mouse. You MUST hide the mouse before
doing anything that would alter the graphics page (ie drawing lines, etc)
or you will get 'mouse droppings' on your screen.
Returns: None
Move_mouse
void Move_mouse(int X, int Y)
X - xposition on screen
Y - yposition on screen
This function moves the mouse cursor to the X,Y coordinates you supply.
Returns: None
Get_mouse
void Get_mouse(int *X, int *Y, int *BUTTON)
X - xposition of mouse at time of call
Y - yposition of mouse at time of call
BUTTON - state of buttons:
0 bit - 1 if left button pressed
1 bit - 1 if right button pressed
3 bit - 1 if middle button pressed (Only if 3 button mouse)
This function returns the current status of the mouse. *X, *Y, *BUTTON
need to be refrences to integers to hold the return values
Example:
int mx, my, button;
Get_mouse(&mx, &my, &button);
Returns: None
Limit_mouse
void Limit_mouse(int LEFT, int TOP, int RIGHT, int BOTTOM)
LEFT,TOP - upperleft corner of box to limit mouse in
RIGHT,BOTTOM - lowerright corner of box to limit mouse in
This function defines a box to limit the mouse movement in. If the
mouse is outside the box before the call, it is moved into the nearest
boundary.
Returns: None
PixelsPer_mouse
void PixelsPer_mouse(int HORZ, int VERT)
HORZ - number of mickeys per 8 pixels horizontally (8 default)
VERT - number of mickeys per 8 pixels vertically (16 default)
What's a Mickey?? It's the unit of measurment defining the roller
under your mouse. Basically the higher the number, the 'slower' the
mouse moves. 1,1 will make the mouse almost uncontrollable :)
Returns: None
PressData_mouse
void PressData_mouse(int *X, int *Y, int *NUMBER)
On Call:
NUMBER - Which button do you want data on:
0 - Left
1 - Right
2 - Middle
On Return:
X - xposition of mouse at last button press
Y - yposition of mouse at last button press
NUMBER - Returns number of button presses for the selected button since
the last call to PressData or since the mouse was initialized.
The only thing to note of importance is how to call this routine.
You have to give referance to NUMBER, X, and Y so the routine can put
it's returns in those variables.
Example:
int x,y,number=0;
PressData_mouse(&x,&y,&number);
This returns the number of presses and last x, y for the left mouse
button in the variables number, x and y.
Returns: None
ReleaseData_mouse
void ReleaseData_mouse(int *X, int *Y int *NUMBER)
Same as PressData_mouse except it counts button realeases instead of
presses.
Change_mouse
void Change_mouse(int *ICON, int ROWS, int COLS)
ICON - 32 word bitmap array of Screen mask and Cursor mask (see below)
ROWS - (-16 to 16) x offset from upperleft of cursor for 'hot spot'
COLS - (-16 to 16) y offset from upperleft of cursor for 'hot spot'
This function lets you define your own mouse cursor. I'll do my best
to explain the Screen mask and the Cursor mask below.
screen mask cursor mask cursor
1001111111111111 9FFF 0000000000000000 0000 .**.............
1000111111111111 8FFF 0010000000000000 2200 .*X*............
1000011111111111 87FF 0011000000000000 3300 .*XX*...........
1000001111111111 83FF 0011100000000000 3800 .*XXX*..........
1000000111111111 81FF 0011110000000000 3C00 .*XXXX*.........
1000000011111111 80FF 0011111000000000 3E00 .*XXXXX*........
1000000001111111 807F 0011111100000000 3F00 .*XXXXXX*.......
1000000000111111 803F 0011111110000000 3F80 .*XXXXXXX*......
1000000000011111 801F 0011111111000000 3FC0 .*XXXXXXXX*.....
1000000000001111 800F 0011111000000000 3E00 .*XXXXX*****....
1000000011111111 80FF 0011011000000000 3600 .*XX*XX*........
1000100001111111 887F 0010001100000000 2300 .*X*.*XX*.......
1001100001111111 987F 0000001100000000 0300 .**..*XX*.......
1111110000111111 FC3F 0000000110000000 0180 ......*XX*......
1111110000111111 FC3F 0000000110000000 0180 ......*XX*......
1111111000111111 FE3F 0000000000000000 0000 .......***......
. - Unchanged screen
* - Black pixel
X - White pixel
screen mask cursor mask cursor
---------------------------------------
0 0 black
0 1 white
1 0 unchanged
1 1 inverted
---------------------------------------
Unchanged it n-k where n is the maximum color of the video mode and
k is the color to be replaced. So in 16 color mode if you inverted a
yellow (14) dot: maxcolor (15) the result would be blue (1) 15-14.
Once you have drawn out your 2 masks and converted the binary numbers
to hex (as shown above), assigned the 32 words to an int array:
int cursor[] = { 0x9FFF,0x8FFF,0x87FF,0x83FF,0x81FF,0x80FF,0x807F,0x803F,
0x801F,0x800F,0x80FF,0x887F,0x987F,0xFC3F,0xFC3F,0xFE3F,
0x0000,0x2200,0x3300,0x3800,0x3C00,0x3E00,0x3F00,0x3F80,
0x3FC0,0x3E00,0x3600,0x2300,0x0300,0x0180,0x0180,0X0000};
Now call Change_mouse:
Change_mouse(cursor,1,0);
The 1,0 is the 'hot spot' for which pixel you actually pressed on the
screen.
******************************************************************************
Here's an example that will show you some of the features:
******************************************************************************
#include <stdlib.h>
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <mouse.h>
int mousecur[] = {0xFFFF,0x871F,0x860F,0x8C0F,0x980F,0xF01F,0xE03F,0xC07F,
0x80FF,0x81FF,0x839F,0x876F,0xDEF7,0xEDFB,0xF3FD,0xFFFF,
0x0000,0x78E0,0x4910,0x5210,0x6410,0x0820,0x1040,0x3880,
0x4500,0x5600,0x6460,0x7890,0x2108,0x1204,0x0C02,0x0000};
void main(void)
{
int mx,my,button;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, ""); /* init graphics */
errorcode = graphresult();
if (errorcode != grOk) {
printf("\nGraphics error: %s", grapherrormsg(errorcode));
printf("\nPress any key to halt:\n");
exit(1);
}
if (!Init_mouse()) { /* init mouse */
closegraph();
printf("\nNot a Microsoft Compatable mouse driver");
printf("\nOr mouse driver not loaded\n");
exit(1);
}
Move_mouse(10,10); /* moves mouse to 10,10 */
Change_mouse(mousecur,1,1); /* changes mouse cursor to paint roller */
Mouse(HIDE); /* Remember to hide the mouse before drawing! */
setfillstyle(SOLID_FILL,WHITE);
setcolor(BLACK);
bar3d(100,100,300,199,0,0);
outtextxy(120,146,"Click Here to close");
Mouse(SHOW); /* And don't forget to show it again! */
do {
Get_mouse(&mx,&my,&button);
if (mx>100&&mx<300&&my>100&&my<199&&button) break;
}while(1); /* wait for click in box */
Limit_mouse(0,0,getmaxx(),100);
Mouse(HIDE);
setfillstyle(SOLID_FILL,BLACK);
setcolor(WHITE);
bar(100,100,300,199);
outtextxy(124,141,"Move mouse around");
outtextxy(120,151,"Press both buttons");
Mouse(SHOW);
do {
Get_mouse(&mx,&my,&button);
}while(button!=3); /* wait for bothbuttons pressed */
/* 3 = 00000011 bits 0 and 1 are set, indicating both buttons */
closegraph();
}
******************************************************************************
That's it, hope you enjoy!