Panda3D
 All Classes Functions Variables Enumerations
graphicsWindowInputDevice.I
1 // Filename: graphicsWindowInputDevice.I
2 // Created by: drose (24May00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 ////////////////////////////////////////////////////////////////////
16 // Function: GraphicsWindowInputDevice::Default Constructor
17 // Access: Public
18 // Description:
19 ////////////////////////////////////////////////////////////////////
20 INLINE GraphicsWindowInputDevice::
21 GraphicsWindowInputDevice() {
22  LightMutexHolder holder(_lock);
23  _flags = 0;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: GraphicsWindowInputDevice::get_name
28 // Access: Public
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 INLINE string GraphicsWindowInputDevice::
32 get_name() const {
33  LightMutexHolder holder(_lock);
34  return _name;
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: GraphicsWindowInputDevice::has_pointer
39 // Access: Public
40 // Description:
41 ////////////////////////////////////////////////////////////////////
42 INLINE bool GraphicsWindowInputDevice::
43 has_pointer() const {
44  LightMutexHolder holder(_lock);
45  return ((_flags & IDF_has_pointer) != 0);
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: GraphicsWindowInputDevice::has_keyboard
50 // Access: Public
51 // Description:
52 ////////////////////////////////////////////////////////////////////
53 INLINE bool GraphicsWindowInputDevice::
54 has_keyboard() const {
55  LightMutexHolder holder(_lock);
56  return ((_flags & IDF_has_keyboard) != 0);
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: GraphicsWindowInputDevice::get_pointer
61 // Access: Public
62 // Description: Returns the MouseData associated with the input
63 // device's pointer.
64 ////////////////////////////////////////////////////////////////////
66 get_pointer() const {
67  LightMutexHolder holder(_lock);
68  return _mouse_data;
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: GraphicsWindowInputDevice::get_raw_pointer
73 // Access: Public
74 // Description: Returns the MouseData associated with the input
75 // device's pointer, in raw form (ie, prior to any
76 // pointer_mode interpretation).
77 ////////////////////////////////////////////////////////////////////
79 get_raw_pointer() const {
80  LightMutexHolder holder(_lock);
81  return _true_mouse_data;
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: GraphicsWindowInputDevice::set_device_index
86 // Access: Public
87 // Description: Set the device index. This is reported in pointer
88 // events. The device index will be equal to the position
89 // of the GraphicsWindowInputDevice in the window's list.
90 ////////////////////////////////////////////////////////////////////
92 set_device_index(int index) {
93  LightMutexHolder holder(_lock);
94  _device_index = index;
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: GraphicsWindowInputDevice::enable_pointer_events
99 // Access: Public
100 // Description: Enables the generation of mouse-movement events.
101 ////////////////////////////////////////////////////////////////////
102 INLINE void GraphicsWindowInputDevice::
104  LightMutexHolder holder(_lock);
105  _enable_pointer_events = true;
106 }
107 
108 ////////////////////////////////////////////////////////////////////
109 // Function: GraphicsWindowInputDevice::disable_pointer_events
110 // Access: Public
111 // Description: Disables the generation of mouse-movement events.
112 ////////////////////////////////////////////////////////////////////
113 INLINE void GraphicsWindowInputDevice::
115  LightMutexHolder holder(_lock);
116  _enable_pointer_events = false;
117  _pointer_events.clear();
118 }
119 
120 ////////////////////////////////////////////////////////////////////
121 // Function: GraphicsWindowInputDevice::button_down
122 // Access: Published
123 // Description: Records that the indicated button has been depressed.
124 ////////////////////////////////////////////////////////////////////
125 INLINE void GraphicsWindowInputDevice::
127  button_down(button, ClockObject::get_global_clock()->get_frame_time());
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function: GraphicsWindowInputDevice::button_resume_down
132 // Access: Published
133 // Description: Records that the indicated button was depressed
134 // earlier, and we only just detected the event after
135 // the fact. This is mainly useful for tracking the
136 // state of modifier keys.
137 ////////////////////////////////////////////////////////////////////
138 INLINE void GraphicsWindowInputDevice::
140  button_resume_down(button, ClockObject::get_global_clock()->get_frame_time());
141 }
142 
143 ////////////////////////////////////////////////////////////////////
144 // Function: GraphicsWindowInputDevice::button_up
145 // Access: Published
146 // Description: Records that the indicated button has been released.
147 ////////////////////////////////////////////////////////////////////
148 INLINE void GraphicsWindowInputDevice::
150  button_up(button, ClockObject::get_global_clock()->get_frame_time());
151 }
152 
153 ////////////////////////////////////////////////////////////////////
154 // Function: GraphicsWindowInputDevice::keystroke
155 // Access: Published
156 // Description: Records that the indicated keystroke has been
157 // generated.
158 ////////////////////////////////////////////////////////////////////
159 INLINE void GraphicsWindowInputDevice::
160 keystroke(int keycode) {
161  keystroke(keycode, ClockObject::get_global_clock()->get_frame_time());
162 }
163 
164 ////////////////////////////////////////////////////////////////////
165 // Function: GraphicsWindowInputDevice::focus_lost
166 // Access: Published
167 // Description: This should be called when the window focus is lost,
168 // so that we may miss upcoming button events
169 // (especially "up" events) for the next period of time.
170 // It generates keyboard and mouse "up" events for those
171 // buttons that we previously sent unpaired "down"
172 // events, so that the Panda application will believe
173 // all buttons are now released.
174 ////////////////////////////////////////////////////////////////////
175 INLINE void GraphicsWindowInputDevice::
177  focus_lost(ClockObject::get_global_clock()->get_frame_time());
178 }
179 
180 ////////////////////////////////////////////////////////////////////
181 // Function: GraphicsWindowInputDevice::raw_button_down
182 // Access: Published
183 // Description: Records that the indicated button has been depressed.
184 ////////////////////////////////////////////////////////////////////
185 INLINE void GraphicsWindowInputDevice::
187  raw_button_down(button, ClockObject::get_global_clock()->get_frame_time());
188 }
189 
190 ////////////////////////////////////////////////////////////////////
191 // Function: GraphicsWindowInputDevice::raw_button_up
192 // Access: Published
193 // Description: Records that the indicated button has been released.
194 ////////////////////////////////////////////////////////////////////
195 INLINE void GraphicsWindowInputDevice::
197  raw_button_up(button, ClockObject::get_global_clock()->get_frame_time());
198 }
199 
200 ////////////////////////////////////////////////////////////////////
201 // Function: GraphicsWindowInputDevice::set_pointer_in_window
202 // Access: Published
203 // Description: To be called by a particular kind of GraphicsWindow
204 // to indicate that the pointer is within the window, at
205 // the given pixel coordinates.
206 ////////////////////////////////////////////////////////////////////
207 INLINE void GraphicsWindowInputDevice::
208 set_pointer_in_window(double x, double y) {
209  // mutex is handled in set pointer .. convience function
210  set_pointer(true, x, y, ClockObject::get_global_clock()->get_frame_time());
211 }
212 
213 ////////////////////////////////////////////////////////////////////
214 // Function: GraphicsWindowInputDevice::set_pointer_out_of_window
215 // Access: Published
216 // Description: To be called by a particular kind of GraphicsWindow
217 // to indicate that the pointer is no longer within the
218 // window.
219 ////////////////////////////////////////////////////////////////////
220 INLINE void GraphicsWindowInputDevice::
222  // mutex is handled in set pointer .. convience function
223  set_pointer(false, _mouse_data._xpos, _mouse_data._ypos,
225 }
226 
227 ////////////////////////////////////////////////////////////////////
228 // Function: GraphicsWindowInputDevice::set_pointer_in_window
229 // Access: Published
230 // Description: To be called by a particular kind of GraphicsWindow
231 // to indicate that the pointer is within the window, at
232 // the given pixel coordinates.
233 ////////////////////////////////////////////////////////////////////
234 INLINE void GraphicsWindowInputDevice::
235 set_pointer_in_window(double x, double y, double time) {
236  // mutex is handled in set pointer .. convience function
237  set_pointer(true, x, y, time);
238 }
239 
240 ////////////////////////////////////////////////////////////////////
241 // Function: GraphicsWindowInputDevice::set_pointer_out_of_window
242 // Access: Published
243 // Description: To be called by a particular kind of GraphicsWindow
244 // to indicate that the pointer is no longer within the
245 // window.
246 ////////////////////////////////////////////////////////////////////
247 INLINE void GraphicsWindowInputDevice::
249  // mutex is handled in set pointer .. convience function
250  set_pointer(false, _mouse_data._xpos, _mouse_data._ypos, time);
251 }
252 
253 ////////////////////////////////////////////////////////////////////
254 // Function: GraphicsWindowInputDevice::operator ==
255 // Access: Public
256 // Description:
257 ////////////////////////////////////////////////////////////////////
258 INLINE bool GraphicsWindowInputDevice::
259 operator == (const GraphicsWindowInputDevice &) const {
260  return true;
261 }
262 
263 ////////////////////////////////////////////////////////////////////
264 // Function: GraphicsWindowInputDevice::operator !=
265 // Access: Public
266 // Description:
267 ////////////////////////////////////////////////////////////////////
268 INLINE bool GraphicsWindowInputDevice::
269 operator != (const GraphicsWindowInputDevice &) const {
270  return false;
271 }
272 
273 ////////////////////////////////////////////////////////////////////
274 // Function: GraphicsWindowInputDevice::operator <
275 // Access: Public
276 // Description:
277 ////////////////////////////////////////////////////////////////////
278 INLINE bool GraphicsWindowInputDevice::
279 operator < (const GraphicsWindowInputDevice &) const {
280  return false;
281 }
void button_up(ButtonHandle button)
Records that the indicated button has been released.
void raw_button_up(ButtonHandle button)
Records that the indicated button has been released.
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
Definition: clockObject.I:271
void set_pointer_in_window(double x, double y)
To be called by a particular kind of GraphicsWindow to indicate that the pointer is within the window...
void button_down(ButtonHandle button)
Records that the indicated button has been depressed.
void set_pointer(bool inwin, double x, double y, double time)
Records that a mouse movement has taken place.
void set_device_index(int index)
Set the device index.
void focus_lost()
This should be called when the window focus is lost, so that we may miss upcoming button events (espe...
void button_resume_down(ButtonHandle button)
Records that the indicated button was depressed earlier, and we only just detected the event after th...
void disable_pointer_events()
Disables the generation of mouse-movement events.
void keystroke(int keycode)
Records that the indicated keystroke has been generated.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
double get_frame_time(Thread *current_thread=Thread::get_current_thread()) const
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
Definition: clockObject.I:48
Similar to MutexHolder, but for a light mutex.
void set_pointer_out_of_window()
To be called by a particular kind of GraphicsWindow to indicate that the pointer is no longer within ...
void enable_pointer_events()
Enables the generation of mouse-movement events.
This is a structure representing a single input device that may be associated with a window...
void raw_button_down(ButtonHandle button)
Records that the indicated button has been depressed.
MouseData get_raw_pointer() const
Returns the MouseData associated with the input device&#39;s pointer, in raw form (ie, prior to any pointer_mode interpretation).
Holds the data that might be generated by a 2-d pointer input device, such as the mouse in the Graphi...
Definition: mouseData.h:28
MouseData get_pointer() const
Returns the MouseData associated with the input device&#39;s pointer.