Panda3D

buttonEvent.I
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file buttonEvent.I
10 * @author drose
11 * @date 2000-03-01
12 */
13
14 /**
15 *
16 */
17 INLINE ButtonEvent::
18 ButtonEvent() :
19 _button(ButtonHandle::none()),
20 _keycode(0),
21 _type(T_down),
22 _time(0.0)
23 {
24 }
25
26 /**
27 *
28 */
29 INLINE ButtonEvent::
30 ButtonEvent(ButtonHandle button, ButtonEvent::Type type, double time) :
31 _button(button),
32 _keycode(0),
33 _highlight_start(0),
34 _highlight_end(0),
35 _type(type),
36 _time(time)
37 {
38 }
39
40 /**
41 *
42 */
43 INLINE ButtonEvent::
44 ButtonEvent(int keycode, double time) :
45 _button(ButtonHandle::none()),
46 _keycode(keycode),
47 _highlight_start(0),
48 _highlight_end(0),
49 _type(T_keystroke),
50 _time(time)
51 {
52 }
53
54 /**
55 *
56 */
57 INLINE ButtonEvent::
58 ButtonEvent(const std::wstring &candidate_string, size_t highlight_start,
59 size_t highlight_end, size_t cursor_pos) :
60 _button(ButtonHandle::none()),
61 _keycode(0),
62 _candidate_string(candidate_string),
63 _highlight_start(highlight_start),
64 _highlight_end(highlight_end),
65 _cursor_pos(cursor_pos),
66 _type(T_candidate),
67 _time(ClockObject::get_global_clock()->get_frame_time())
68 {
69 }
70
71 /**
72 *
73 */
74 INLINE ButtonEvent::
75 ButtonEvent(const ButtonEvent &copy) :
76 _button(copy._button),
77 _keycode(copy._keycode),
78 _candidate_string(copy._candidate_string),
79 _highlight_start(copy._highlight_start),
80 _highlight_end(copy._highlight_end),
81 _cursor_pos(copy._cursor_pos),
82 _type(copy._type),
83 _time(copy._time)
84 {
85 }
86
87 /**
88 *
89 */
90 INLINE void ButtonEvent::
91 operator = (const ButtonEvent &copy) {
92 _button = copy._button;
93 _keycode = copy._keycode;
94 _candidate_string = copy._candidate_string;
95 _highlight_start = copy._highlight_start;
96 _highlight_end = copy._highlight_end;
97 _cursor_pos = copy._cursor_pos;
98 _type = copy._type;
99 _time = copy._time;
100 }
101
102 /**
103 * The equality operator does not consider time significant.
104 */
105 INLINE bool ButtonEvent::
106 operator == (const ButtonEvent &other) const {
107 return (_button == other._button &&
108 _keycode == other._keycode &&
109 _type == other._type);
110 }
111
112 /**
113 *
114 */
115 INLINE bool ButtonEvent::
116 operator != (const ButtonEvent &other) const {
117 return !operator == (other);
118 }
119
120 /**
121 *
122 */
123 INLINE bool ButtonEvent::
124 operator < (const ButtonEvent &other) const {
125 if (_button != other._button) {
126 return _button < other._button;
127 }
128 if (_keycode != other._keycode) {
129 return _keycode < other._keycode;
130 }
131
132 return _type < other._type;
133 }
134
135 /**
136 * Calls button_down() or button_up(), as appropriate, according to the
137 * ButtonEvent.
138 */
139 INLINE bool ButtonEvent::
140 update_mods(ModifierButtons &mods) const {
141 switch (_type) {
142 case T_down:
143 return mods.button_down(_button);
144
145 case T_up:
146 return mods.button_up(_button);
147
148 default:
149 return false;
150 }
151 }
ButtonEvent
Records a button event of some kind.
Definition: buttonEvent.h:46
ButtonEvent::operator==
bool operator==(const ButtonEvent &other) const
The equality operator does not consider time significant.
Definition: buttonEvent.I:106
ButtonEvent::update_mods
bool update_mods(ModifierButtons &mods) const
Calls button_down() or button_up(), as appropriate, according to the ButtonEvent.
Definition: buttonEvent.I:140
ButtonHandle
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26
ClockObject
A ClockObject keeps track of elapsed real time and discrete time.
Definition: clockObject.h:58
ModifierButtons
This class monitors the state of a number of individual buttons and tracks whether each button is kno...
Definition: modifierButtons.h:26
ModifierButtons::button_up
bool button_up(ButtonHandle button)
Records that a particular button has been released.
Definition: modifierButtons.cxx:275
ModifierButtons::button_down
bool button_down(ButtonHandle button)
Records that a particular button has been pressed.
Definition: modifierButtons.cxx:257