Panda3D
 All Classes Functions Variables Enumerations
graphicsWindowInputDevice.h
1 // Filename: graphicsWindowInputDevice.h
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 #ifndef GRAPHICSWINDOWINPUTDEVICE_H
16 #define GRAPHICSWINDOWINPUTDEVICE_H
17 
18 #include "pandabase.h"
19 
20 #include "buttonEvent.h"
21 #include "pointerEvent.h"
22 #include "pointerEventList.h"
23 #include "mouseData.h"
24 #include "clockObject.h"
25 
26 #include "pdeque.h"
27 #include "pvector.h"
28 #include "lightMutex.h"
29 #include "lightMutexHolder.h"
30 
31 // Forward declarations
32 class GraphicsWindow;
33 
34 ////////////////////////////////////////////////////////////////////
35 // Class : GraphicsWindowInputDevice
36 // Description : This is a structure representing a single input
37 // device that may be associated with a window.
38 // Typically this will be a keyboard/mouse pair, and
39 // there will be exactly one of these associated with
40 // each window, but other variants are possible.
41 ////////////////////////////////////////////////////////////////////
42 class EXPCL_PANDA_DISPLAY GraphicsWindowInputDevice {
43 private:
44  GraphicsWindowInputDevice(GraphicsWindow *host, const string &name, int flags);
45 
46 public:
47  static GraphicsWindowInputDevice pointer_only(GraphicsWindow *host, const string &name);
48  static GraphicsWindowInputDevice keyboard_only(GraphicsWindow *host, const string &name);
49  static GraphicsWindowInputDevice pointer_and_keyboard(GraphicsWindow *host, const string &name);
50 
52  GraphicsWindowInputDevice(const GraphicsWindowInputDevice &copy);
53  void operator = (const GraphicsWindowInputDevice &copy);
54  ~GraphicsWindowInputDevice();
55 
56  INLINE string get_name() const;
57  INLINE bool has_pointer() const;
58  INLINE bool has_keyboard() const;
59 
60  INLINE void set_device_index(int index);
61 
62  INLINE MouseData get_pointer() const;
63  INLINE MouseData get_raw_pointer() const;
64 
65  INLINE void enable_pointer_events();
66  INLINE void disable_pointer_events();
67 
68  void enable_pointer_mode(double speed);
69  void disable_pointer_mode();
70 
71  bool has_button_event() const;
72  ButtonEvent get_button_event();
73  bool has_pointer_event() const;
74  PT(PointerEventList) get_pointer_events();
75 
76 PUBLISHED:
77  // The following interface is for the various kinds of
78  // GraphicsWindows to record the data incoming on the device.
79  INLINE void button_down(ButtonHandle button);
80  INLINE void button_resume_down(ButtonHandle button);
81  INLINE void button_up(ButtonHandle button);
82  INLINE void keystroke(int keycode);
83  INLINE void focus_lost();
84  INLINE void raw_button_down(ButtonHandle button);
85  INLINE void raw_button_up(ButtonHandle button);
86  INLINE void set_pointer_in_window(double x, double y);
87  INLINE void set_pointer_out_of_window();
88 
89  void button_down(ButtonHandle button, double time);
90  void button_resume_down(ButtonHandle button, double time);
91  void button_up(ButtonHandle button, double time);
92  void keystroke(int keycode, double time);
93  void candidate(const wstring &candidate_string, size_t highlight_start,
94  size_t highlight_end, size_t cursor_pos);
95  void focus_lost(double time);
96  void raw_button_down(ButtonHandle button, double time);
97  void raw_button_up(ButtonHandle button, double time);
98 
99  INLINE void set_pointer_in_window(double x, double y, double time);
100  INLINE void set_pointer_out_of_window(double time);
101  void set_pointer(bool inwin, double x, double y, double time);
102 
103 public:
104  // We need these methods to make VC++ happy when we try to
105  // instantiate a pvector<GraphicsWindowInputDevice>. They don't do
106  // anything useful.
107  INLINE bool operator == (const GraphicsWindowInputDevice &other) const;
108  INLINE bool operator != (const GraphicsWindowInputDevice &other) const;
109  INLINE bool operator < (const GraphicsWindowInputDevice &other) const;
110 
111 private:
112  enum InputDeviceFlags {
113  IDF_has_pointer = 0x01,
114  IDF_has_keyboard = 0x02
115  };
117 
118  LightMutex _lock;
119 
120  GraphicsWindow *_host;
121 
122  string _name;
123  int _flags;
124  int _device_index;
125  int _event_sequence;
126 
127  bool _pointer_mode_enable;
128  double _pointer_speed;
129 
130  bool _enable_pointer_events;
131  MouseData _mouse_data;
132  MouseData _true_mouse_data;
133  ButtonEvents _button_events;
134  PT(PointerEventList) _pointer_events;
135 
137  ButtonsHeld _buttons_held;
138 };
139 
140 #include "graphicsWindowInputDevice.I"
141 
142 #define EXPCL EXPCL_PANDA_DISPLAY
143 #define EXPTP EXPTP_PANDA_DISPLAY
144 #define TYPE GraphicsWindowInputDevice
145 #define NAME vector_GraphicsWindowInputDevice
146 
147 #include "vector_src.h"
148 
149 // Tell GCC that we'll take care of the instantiation explicitly here.
150 #ifdef __GNUC__
151 #pragma interface
152 #endif
153 
154 #endif
Records a set of pointer events that happened recently.
Records a button event of some kind.
Definition: buttonEvent.h:53
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
This is a structure representing a single input device that may be associated with a window...
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
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:45