Panda3D
buttonEvent.I
1 // Filename: buttonEvent.I
2 // Created by: drose (01Mar00)
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 ////////////////////////////////////////////////////////////////////
17 // Function: ButtonEvent::Default Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE ButtonEvent::
22 ButtonEvent() :
23  _button(ButtonHandle::none()),
24  _keycode(0),
25  _type(T_down),
26  _time(0.0)
27 {
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: ButtonEvent::Constructor
32 // Access: Public
33 // Description:
34 ////////////////////////////////////////////////////////////////////
35 INLINE ButtonEvent::
36 ButtonEvent(ButtonHandle button, ButtonEvent::Type type, double time) :
37  _button(button),
38  _keycode(0),
39  _highlight_start(0),
40  _highlight_end(0),
41  _type(type),
42  _time(time)
43 {
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: ButtonEvent::Constructor
48 // Access: Public
49 // Description:
50 ////////////////////////////////////////////////////////////////////
51 INLINE ButtonEvent::
52 ButtonEvent(short keycode, double time) :
53  _button(ButtonHandle::none()),
54  _keycode(keycode),
55  _highlight_start(0),
56  _highlight_end(0),
57  _type(T_keystroke),
58  _time(time)
59 {
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: ButtonEvent::Constructor
64 // Access: Public
65 // Description:
66 ////////////////////////////////////////////////////////////////////
67 INLINE ButtonEvent::
68 ButtonEvent(const wstring &candidate_string, size_t highlight_start,
69  size_t highlight_end, size_t cursor_pos) :
70  _button(ButtonHandle::none()),
71  _keycode(0),
72  _candidate_string(candidate_string),
73  _highlight_start(highlight_start),
74  _highlight_end(highlight_end),
75  _cursor_pos(cursor_pos),
76  _type(T_candidate),
77  _time(ClockObject::get_global_clock()->get_frame_time())
78 {
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: ButtonEvent::Copy Constructor
83 // Access: Public
84 // Description:
85 ////////////////////////////////////////////////////////////////////
86 INLINE ButtonEvent::
87 ButtonEvent(const ButtonEvent &copy) :
88  _button(copy._button),
89  _keycode(copy._keycode),
90  _candidate_string(copy._candidate_string),
91  _highlight_start(copy._highlight_start),
92  _highlight_end(copy._highlight_end),
93  _cursor_pos(copy._cursor_pos),
94  _type(copy._type),
95  _time(copy._time)
96 {
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: ButtonEvent::Copy Assignment Operator
101 // Access: Public
102 // Description:
103 ////////////////////////////////////////////////////////////////////
104 INLINE void ButtonEvent::
105 operator = (const ButtonEvent &copy) {
106  _button = copy._button;
107  _keycode = copy._keycode;
108  _candidate_string = copy._candidate_string;
109  _highlight_start = copy._highlight_start;
110  _highlight_end = copy._highlight_end;
111  _cursor_pos = copy._cursor_pos;
112  _type = copy._type;
113  _time = copy._time;
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: ButtonEvent::Equality Operator
118 // Access: Public
119 // Description: The equality operator does not consider time
120 // significant.
121 ////////////////////////////////////////////////////////////////////
122 INLINE bool ButtonEvent::
123 operator == (const ButtonEvent &other) const {
124  return (_button == other._button &&
125  _keycode == other._keycode &&
126  _type == other._type);
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: ButtonEvent::Inequality Operator
131 // Access: Public
132 // Description:
133 ////////////////////////////////////////////////////////////////////
134 INLINE bool ButtonEvent::
135 operator != (const ButtonEvent &other) const {
136  return !operator == (other);
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: ButtonEvent::Ordering Operator
141 // Access: Public
142 // Description:
143 ////////////////////////////////////////////////////////////////////
144 INLINE bool ButtonEvent::
145 operator < (const ButtonEvent &other) const {
146  if (_button != other._button) {
147  return _button < other._button;
148  }
149  if (_keycode != other._keycode) {
150  return _keycode < other._keycode;
151  }
152 
153  return _type < other._type;
154 }
155 
156 ////////////////////////////////////////////////////////////////////
157 // Function: ButtonEvent::update_mods
158 // Access: Published
159 // Description: Calls button_down() or button_up(), as appropriate,
160 // according to the ButtonEvent.
161 ////////////////////////////////////////////////////////////////////
162 INLINE bool ButtonEvent::
164  switch (_type) {
165  case T_down:
166  return mods.button_down(_button);
167 
168  case T_up:
169  return mods.button_up(_button);
170 
171  default:
172  return false;
173  }
174 }
bool button_down(ButtonHandle button)
Records that a particular button has been pressed.
This class monitors the state of a number of individual buttons and tracks whether each button is kno...
bool update_mods(ModifierButtons &mods) const
Calls button_down() or button_up(), as appropriate, according to the ButtonEvent. ...
Definition: buttonEvent.I:163
Records a button event of some kind.
Definition: buttonEvent.h:53
bool button_up(ButtonHandle button)
Records that a particular button has been released.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
A ClockObject keeps track of elapsed real time and discrete time.
Definition: clockObject.h:66
bool operator==(const ButtonEvent &other) const
The equality operator does not consider time significant.
Definition: buttonEvent.I:123