📄 moustrap.prn
字号:
- Page 18 -
MouseTrap Library
September 21, 1988
DeActivate_Mouse_Page
GSyntax:H
#include <moustrap.h>
mouse_t DeActivate_Mouse_Page(Page_ID);
mouse_t Page_ID;
GH
GDescription:H
Deactivates the referenced mouse page. Button and Hot Spot
definitions linked to that page will no longer function until
restarted with Activate_Mouse_Page. On Single page mode, this is
done automatically when another page is activated.
GReturn Value:H
MNOERROR if there was no problem; otherwise
MERROR with the specific error given in M_Error
GSee Also:H
M_Error Activate_Mouse_Page, Clear_Mouse_Pages
GExample:H
See Chapter 4.
- Page 19 -
MouseTrap Library
September 21, 1988
Define_Mouse_System
GSyntax:H
#include <moustrap.h>
mouse_t Define_Mouse_System(Page_Type);
mouse_t Page_type;
GDescription:H
Define_Mouse_System declares how mouse pages are to be used
through the program. Page_Type must be either M_Overlaid_Pages or
M_Single_Pages. Automatically initializes mouse by executing
Check_Mouse. Can only be done once in a program unless reset with
Clear_All_Mouse_Definitions.
GReturn Value:H
MNOERROR if there was no problem; otherwise
MERROR with the specific error given in M_Error
GH
GH
GSee Also:H
M_Error, Clear_All_Mouse_Definitions, Check_Mouse
GExample:H
See Chapter 4.
- Page 20 -
MouseTrap Library
September 21, 1988
Delete_Mouse_Button
Delete_Mouse_Hot_Spot
Delete_Mouse_Page
GSyntax:H
#include <moustrap.h>
mouse_t Delete_Mouse_Button(mouse_t Page_ID, mouse_t Button);
mouse_t Delete_Mouse_Hot_Spot(mouse_t HS_ID);
mouse_t Delete_Mouse_Page(mouse_t Page_ID);
GDescription:H
Removes the indicated item from the system.
GReturn Value:H
MNOERROR if there was no problem; otherwise
MERROR with the specific error given in M_Error
GH
GH
GSee Also:H
M_Error
GExample:H
See Chapter 4.
- Page 21 -
MouseTrap Library
September 21, 1988
Get_Char_Mouse_Kbd
GSyntax:H
#include <moustrap.h>
mouse_t Get_Char_Mouse_Kbd(void);
GDescription:H
Get_Char_Mouse_Kbd acts much like the standard library
function GETCH, but will accept input from either the keyboard or
the mouse. Will return only when some input is received from the
keyboard or mouse.
GH
GReturn Value:H
The value inputted if there was no problem; otherwise
MERROR with the specific error given in M_Error
GH
GH
GSee Also:H
M_Error, Read_Mouse
GExample:H
See Chapter 4.
- Page 22 -
MouseTrap Library
September 21, 1988
Read_Mouse
GSyntax:H
#include <moustrap.h>
mouse_t Read_Mouse(void)
GH
GDescription:H
Checks mouse for input.
GReturn Value:H
the Return_value assigned to a Button or Hot Spot, if that
item was "clicked" on, or
0 if no button was pressed.
GSee Also:H
M_Error, Get_Char_Mouse_Kbd
GExample:H
See Chapter 4.
- Page 23 -
MouseTrap Library
September 21, 1988
Chapter 4
G Using the MouseTrap LibraryH
The basic concept of the MouseTrap is the "Mouse Page". A
Mouse Page is one set of button and "Hot spot" definitions. Any
character can be assigned to a button or hot spot. Pages can be
used in either of two ways: You can have up ot 65,000 single pages,
which can only be used one at a time, or up to 16 page "overlaid"
pages, any combination of which can be active at once. You choose
this by using the Define_Mouse_System function, with either
M_Single_Pages or M_Overlaid_Pages.
The next step is to define a page, by using the
Add_Mouse_Page function, passing to it the "type" of page it is,
either M_Graphic_Coord or M_Text_Coord; and the 4 corner points for
that page using the appropriate set of coordinates (either 80x25 or
640x200). Using "0" for each corner will have it using the entire
screen. Add_Mouse_Page will return a ID number for the page, which
you will be using in all future references to this page.
Next, you must define the buttons you will be using. This
is done with Add_Mouse_Button. You tell it which for which page and
button this definition is to apply, and the value to return if that
button was clicked while that page was active. If you use "0" for
the Page ID, this definition will apply to all pages. If you use
"0" for the return value, you can have that button return different
values for being clicked at different "hot spots" within the page.
If you are using hot spots in a page, you must next call
Add_Mouse_Hot_Spot, passing to it the page ID and button code, the
corner points, and the return value for the spot.
Now, we get to the fun part. Choose a page using the
Activate_Mouse_Page function. Using overlaid page, you can have
several pages active at once; remove them with the
DeActivate_Mouse_Page or Clear_Mouse_Pages function. In single page
mode, activating a new page automatically deactivates the last one.
Finally, simply call Read_Mouse(). It will return either
the value for the button or Hot spot clicked or 0 if no button was
clicked. Or simpler still, use Get_Char_Mouse_Kbd(), which waits
until some input is entered by either keyboard or mouse.
- Page 24 -
MouseTrap Library
September 21, 1988
To further exemplify the process let's examine the sample
program MICETEST.C:
#include <stdio.h>
#include "moustrap.h"
#include <graph.h>
main ()
{
mouse_t y,z,c;
The data type "mouse_t" is defined in MOUSTRAP.H. All variables
used with the MouseTrap library should be define as this type.
The first group of lines setup the screen so it's easier to
understand what's happening with the mouse. But by themselves they
do nothing of interest to this discussion. Ignore them and skip
down a bit.
Define_Mouse_System(M_Single_Pages);
For the first step, we going to be using single pages; only one of
the pages we're about the define can be active at only given time.
y=Add_Mouse_Page(M_Text_Coord,15,20,24,40);
z=Add_Mouse_Page(M_Text_Coord,5,10,15,20);
Next, we define two mouse pages, Y & Z. Y is limited to the
rectangle from row 15, column 20 to row 24, column 40. Similarly, Z
is the area from (5,10) to (15,20).
Set_Mouse_Text_Cursor(0,0,TC(' ',4,4));
Now, we describe how we the mouse cursor to look. We start with
something simple. We'll use a software cursor, with no screen mask.
We use the macro TC(), defined in MOUSTRAP.H, to build a cursor
which is just a space, with a red foreground (color 4) on a red
background.
Add_Mouse_Button(0,M_Middle,'2');
For our first button definition, we'll say that anytime the Middle
button is pressed, Read_Mouse will return an ASCII character '2',
regardless of what page is active (provided at least one page IS
active).
Add_Mouse_Button(z,M_Left,'1');
Next we'll have pressing the Left button return an ASCII '1'
whenever page Z is active.
- Page 25 -
MouseTrap Library
September 21, 1988
Add_Mouse_Button(z,M_Right,0);
Add_Mouse_Hot_Spot(z,M_Right,7,13,13,18,'C');
Now, we add our first Hot Spot. Here, we must first declare the
Right button in Page Z, then we declare the area in the rectangle
(7,13) - (13,18) as a hot spot returning the character 'C' when that
button is pressed while page Z is active. Since no other hot spot
is defined, clicking the right button outside that area will return
0, just as if no click had occurred.
Add_Mouse_Button(y,M_Left,0);
Add_Mouse_Hot_Spot(y,M_Left,15,20,24,30,'L');
Add_Mouse_Hot_Spot(y,M_Left,15,30,24,40,'R');
Continuing in a similar vein, we define two hot spots in page Y.
When the Left button is pressed, if the cursor is in the left side
we'll get the character 'L', while the right side return the
character 'R'
do {
Activate_Mouse_Page(z);
As we enter the loop, we activate page Z. The mouse cursor is
"turned on" with it's movement limited to the edges of the page.
c=Get_Char_Mouse_Kbd();
printf("Page Z: Character \"%c\"",c);
We stop, and get a character from either the keyboard (which is not
much fun), or via the mouse; and print it.
Activate_Mouse_Page(y);
c=Get_Char_Mouse_Kbd();
printf("Page Y: Character \"%c\"",c);
Now, we activate page Y (which automatically deactivates page Z).
The mouse cursor moves into the new area, and it's motion is limited
to that range. We get another character and print it.
} while (c!='2');
Clear_All_Mouse_Definitions();
Define_Mouse_System(M_Overlaid_Pages);
Now, we want to start over, so we clear all of the old definitions,
and restart, but this time using overlaid pages.
- Page 26 -
MouseTrap Library
September 21, 1988
y=Add_Mouse_Page(M_Text_Coord,15,20,24,40);
z=Add_Mouse_Page(M_Text_Coord,5,10,15,20);
Add_Mouse_Button(0,M_Middle,'2');
Add_Mouse_Button(z,M_Left,'1');
Add_Mouse_Button(z,M_Right,0);
Add_Mouse_Hot_Spot(z,M_Right,7,13,13,18,'C');
Add_Mouse_Button(y,M_Left,0);
Add_Mouse_Hot_Spot(y,M_Left,15,20,24,30,'L');
Add_Mouse_Hot_Spot(y,M_Left,15,30,24,40,'R');
Set_Mouse_Text_Cursor(0,0,TC('+',4,2));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -