Name | Executed | Routines | % | Executed | Lines | % | Unexecuted |
/home/matt/eu/rds/include/std/mouse.e | 0 | 3 | 0.00% | 12 | 20 | 60.00% | 8 |
Routine | Executed | Lines | Unexecuted | |
mouse_events() | 0 | 3 | 0.00% | 3 |
mouse_pointer() | 0 | 3 | 0.00% | 3 |
get_mouse() | 0 | 2 | 0.00% | 2 |
# | Executed | |
1 | -- (c) Copyright - See License.txt | |
2 | -- | |
3 | namespace mouse | |
4 | ||
5 | --**** | |
6 | -- == Mouse | |
7 | -- | |
8 | -- < | |
9 | -- | |
10 | -- === Requirements | |
11 | -- | |
12 | -- * //Linux// ~-- you need GPM server to be running | |
13 | -- * //Windows// ~-- not implemented yet for the text console | |
14 | -- * //FreeBSD// ~-- not implemented | |
15 | -- * //OS X// ~-- not implemented | |
16 | -- | |
17 | ||
18 | --**** | |
19 | -- === Constants | |
20 | -- | |
21 | -- The following constants can be used to identify and specify mouse events. | |
22 | -- | |
23 | ||
24 | public integer MOVE, LEFT_DOWN, LEFT_UP, RIGHT_DOWN, RIGHT_UP, | |
25 | MIDDLE_DOWN, MIDDLE_UP, ANY_UP | |
26 | ||
27 | 1 | ifdef UNIX then |
28 | 1 | MOVE = 0 |
29 | 1 | LEFT_DOWN = 4 |
30 | 1 | LEFT_UP = 4 |
31 | 1 | RIGHT_DOWN = 1 |
32 | 1 | RIGHT_UP = 1 |
33 | 1 | MIDDLE_DOWN = 2 |
34 | 1 | MIDDLE_UP = 2 |
35 | 1 | ANY_UP = 35 -- LEFT, RIGHT or MIDDLE up (best you can do under xterm) |
36 | elsedef | |
37 | MOVE = 1 | |
38 | LEFT_DOWN = 2 | |
39 | LEFT_UP = 4 | |
40 | RIGHT_DOWN = 8 | |
41 | RIGHT_UP = 16 | |
42 | MIDDLE_DOWN = 32 | |
43 | MIDDLE_UP = 64 | |
44 | end ifdef | |
45 | ||
46 | 1 | constant M_GET_MOUSE = 14, |
47 | 1 | M_MOUSE_EVENTS = 15, |
48 | 1 | M_MOUSE_POINTER = 24 |
49 | ||
50 | --**** | |
51 | -- === Routines | |
52 | ||
53 | --** | |
54 | -- Queries the last mouse event. | |
55 | -- | |
56 | -- Returns: | |
57 | -- An **object**, either -1 if there has not | |
58 | -- been a mouse event since the last time ##get_mouse##() was called. | |
59 | -- Otherwise, returns a triple ##{event, x, y}##. | |
60 | -- | |
61 | -- Constants have been defined in mouse.e for the possible mouse events (the values for ##event##): | |
62 | -- | |
63 | -- public constant | |
64 | -- MOVE = 1, | |
65 | -- LEFT_DOWN = 2, | |
66 | -- LEFT_UP = 4, | |
67 | -- RIGHT_DOWN = 8, | |
68 | -- RIGHT_UP = 16, | |
69 | -- MIDDLE_DOWN = 32, | |
70 | -- MIDDLE_UP = 64 | |
71 | -- | |
72 | -- | |
73 | -- x and y are the coordinates of the mouse pointer at the time that the event occurred. | |
74 | -- Comments: | |
75 | -- ##get_mouse##() returns immediately with either a -1 or a mouse event, without waiting for an event to occur. So, you must check it frequently enough to avoid missing an event: | |
76 | -- when the next event occurs, the current event will be lost, if you haven't read it. | |
77 | -- In practice it is not hard to catch almost all events. Losing a MOVE event is generally | |
78 | -- not too serious, as the next MOVE will tell you where the mouse pointer is. | |
79 | -- | |
80 | -- Sometimes multiple events will be reported. For example, if the mouse is moving when the | |
81 | -- left button is clicked, ##get_mouse##() will report an event value of LEFT_DOWN+MOVE, i.e. | |
82 | -- 2+1 or 3. For this reason you should test for a particular event using [[:and_bits]](). See | |
83 | -- examples below. Further, you can determine which events will be reported using [[:mouse_events]]. | |
84 | -- | |
85 | -- In //Linux//, no scaling is required - x and y correspond to the line and column on the screen, | |
86 | -- with (1,1) at the top left. | |
87 | -- | |
88 | -- In //Linux//, mouse movement events are not reported in an xterm window, only in the text console. | |
89 | -- | |
90 | -- In //Linux//, LEFT_UP, RIGHT_UP and MIDDLE_UP are not distinguishable from one another. | |
91 | -- | |
92 | -- The first call that you make to ##get_mouse##() will turn on a mouse pointer, or a highlighted character. | |
93 | -- | |
94 | -- The x,y coordinate returned could be that of the very tip of the mouse pointer or might refer to | |
95 | -- the pixel pointed-to by the mouse pointer. | |
96 | -- | |
97 | -- Example 1: | |
98 | -- a return value of: | |
99 | -- ##{2, 100, 50}## | |
100 | -- would indicate that the left button was pressed down when the | |
101 | -- mouse pointer was at location x=100, y=50 on the screen. | |
102 | -- | |
103 | -- Example 2: | |
104 | -- To test for LEFT_DOWN, write something like the following: | |
105 | -- | |
106 | -- | |
107 | -- while 1 do | |
108 | -- object event = get_mouse() | |
109 | -- if sequence(event) then | |
110 | -- if and_bits(event[1], LEFT_DOWN) then | |
111 | -- -- left button was pressed | |
112 | -- exit | |
113 | -- end if | |
114 | -- end if | |
115 | -- end while | |
116 | -- | |
117 | -- | |
118 | -- See Also: | |
119 | -- [[:mouse_events]], [[: mouse_pointer]] | |
120 | ||
121 | 0 | |
122 | 0 | return machine_func(M_GET_MOUSE, 0) |
123 | end function | |
124 | ||
125 | --** | |
126 | -- Select the mouse events [[:get_mouse]]() is to report. | |
127 | -- | |
128 | -- Parameters: | |
129 | -- # ##events##: an integer, all requested event codes or'ed together. | |
130 | -- | |
131 | -- Comments: | |
132 | -- By default, [[:get_mouse]]() will report all events. ##mouse_events##() can be called at various stages of the | |
133 | -- execution of your program, as the need to detect events changes. Under //Unix//, ##mouse_events##() currently has no effect. | |
134 | -- | |
135 | -- It is good practice to ignore events that you are not interested in, particularly the very | |
136 | -- frequent MOVE event, in order to reduce the chance that you will miss a significant event. | |
137 | -- | |
138 | -- The first call that you make to ##mouse_events##() will turn on a mouse pointer, or a highlighted character. | |
139 | -- | |
140 | -- Example 1: | |
141 | -- | |
142 | -- mouse_events(LEFT_DOWN + LEFT_UP + RIGHT_DOWN) | |
143 | -- | |
144 | -- | |
145 | -- will restrict get_mouse() to reporting the left button | |
146 | -- being pressed down or released, and the right button | |
147 | -- being pressed down. All other events will be ignored. | |
148 | -- | |
149 | -- See Also: | |
150 | -- [[:get_mouse]], [[: mouse_pointer]] | |
151 | ||
152 | 0 | |
153 | 0 | machine_proc(M_MOUSE_EVENTS, events) |
154 | 0 | end procedure |
155 | ||
156 | --** | |
157 | -- Turn mouse pointer on or off. | |
158 | -- | |
159 | -- Parameters: | |
160 | -- # ##show_it## : an integer, 0 to hide and 1 to show. | |
161 | -- | |
162 | -- Comments: | |
163 | -- Multiple calls to hide | |
164 | -- the pointer will require multiple calls to turn it back on. The | |
165 | -- first call to either [[:get_mouse]]() or [[:mouse_events]]() will | |
166 | -- also turn the pointer on (once). | |
167 | -- | |
168 | -- Under //Linux//, [[:mouse_pointer]]() currently has no effect | |
169 | -- | |
170 | -- It may be necessary to hide the mouse pointer temporarily when you | |
171 | -- update the screen. | |
172 | -- | |
173 | -- After a call to [[:text_rows]]() you may have to call [[:mouse_pointer]](1) | |
174 | -- to see the mouse pointer again. | |
175 | -- | |
176 | -- See Also: | |
177 | -- [[:get_mouse]], [[:mouse_pointer]] | |
178 | ||
179 | 0 | |
180 | 0 | machine_proc(M_MOUSE_POINTER, show_it) |
181 | 0 | end procedure |