Panda3D
Loading...
Searching...
No Matches
buttonEvent.h
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.h
10 * @author drose
11 * @date 2000-03-01
12 */
13
14#ifndef BUTTONEVENT_H
15#define BUTTONEVENT_H
16
17#include "pandabase.h"
18
19#include "buttonHandle.h"
20#include "clockObject.h"
21#include "modifierButtons.h"
22
23class Datagram;
25
26/**
27 * Records a button event of some kind. This is either a keyboard or mouse
28 * button (or some other kind of button) changing state from up to down, or
29 * vice-versa, or it is a single "keystroke".
30 *
31 * A keystroke is different than a button event in that (a) it does not
32 * necessarily correspond to a physical button on a keyboard, but might be the
33 * result of a combination of buttons (e.g. "A" is the result of shift +
34 * "a"); and (b) it does not manage separate "up" and "down" events, but is
35 * itself an instantaneous event.
36 *
37 * Normal up/down button events can be used to track the state of a particular
38 * button on the keyboard, while keystroke events are best used to monitor
39 * what a user is attempting to type.
40 *
41 * Button up/down events are defined across all the physical keys on the
42 * keyboard (and other buttons for which there is a corresponding ButtonHandle
43 * object), while keystroke events are defined across the entire Unicode
44 * character set.
45 *
46 * This API should not be considered stable and may change in a future version
47 * of Panda3D.
48 */
49class EXPCL_PANDA_EVENT ButtonEvent {
50PUBLISHED:
51 enum Type {
52 // T_down is sent when a button was just pressed.
53 T_down,
54
55 // T_resume_down is a special event that is only thrown when focus is
56 // returned to a window and a button is detected as being held down at that
57 // point; it indicates that the button should be considered down now (if it
58 // wasn't already), but it didn't just get pressed down at this moment, it
59 // was depressed some time ago. It's mainly used for correct tracking of
60 // modifier keys like shift and control, and can be ignored for other keys.
61 T_resume_down,
62
63 // T_down is sent when a button is released.
64 T_up,
65
66 // T_repeat is sent for each a keyrepeat event generated by the system,
67 // for a button that is continually held down. If you want to respect
68 // keyrepeat, treat T_down and T_repeat equivalently.
69 T_repeat,
70
71 // T_keystroke is a special keystroke event, and is sent along with a
72 // Unicode keycode value, not a ButtonHandle.
73 T_keystroke,
74
75 // T_candidate is used to indicate that the user is using the IME and has
76 // in the process of selecting some possible text to type from a menu.
77 T_candidate,
78
79 // T_move is used to indicate that the mouse has moved within the current
80 // region. Button drag mode needs this, others may ignore this event
81 T_move,
82
83 // T_raw_down is usually sent together with T_down, except that this is
84 // the original, untransformed scan key sent by the keyboard. It is not
85 // altered by modifier keys and acts as if the user is using the US
86 // (qwerty) keyboard layout.
87 T_raw_down,
88 T_raw_up,
89 };
90
91public:
92 INLINE ButtonEvent();
93 INLINE ButtonEvent(ButtonHandle button, Type type, double time = ClockObject::get_global_clock()->get_frame_time());
94 INLINE ButtonEvent(int keycode, double time = ClockObject::get_global_clock()->get_frame_time());
95 INLINE ButtonEvent(const std::wstring &candidate_string, size_t highlight_start,
96 size_t highlight_end, size_t cursor_pos);
97 INLINE ButtonEvent(const ButtonEvent &copy);
98 INLINE void operator = (const ButtonEvent &copy);
99
100PUBLISHED:
101 INLINE bool operator == (const ButtonEvent &other) const;
102 INLINE bool operator != (const ButtonEvent &other) const;
103 INLINE bool operator < (const ButtonEvent &other) const;
104
105public:
106 INLINE bool update_mods(ModifierButtons &mods) const;
107
108 INLINE ButtonHandle get_button() const;
109 INLINE int get_keycode() const;
110 INLINE Type get_type() const;
111 INLINE double get_time() const;
112
113 void output(std::ostream &out) const;
114
115 void write_datagram(Datagram &dg) const;
116 void read_datagram(DatagramIterator &scan);
117
118PUBLISHED:
119 MAKE_PROPERTY(button, get_button);
120 MAKE_PROPERTY(keycode, get_keycode);
121 MAKE_PROPERTY(type, get_type);
122 MAKE_PROPERTY(time, get_time);
123
124public:
125 // _button will be filled in if type is T_down, T_resume_down, or T_up.
126 ButtonHandle _button;
127
128 // _keycode will be filled in if type is T_keystroke. It will be the
129 // Unicode character that was typed.
130 int _keycode;
131
132 // _candidate_string will be filled in if type is T_candidate.
133 std::wstring _candidate_string;
134 size_t _highlight_start;
135 size_t _highlight_end;
136 size_t _cursor_pos;
137
138 // This is the type of the button event (see above).
139 Type _type;
140
141 // This is the time the event occurred, as recorded from the OS if that
142 // information is available. It is in seconds elapsed from an arbitrary
143 // epoch, and it matches the time reported by
144 // ClockObject::get_global_clock().
145 double _time;
146};
147
148INLINE std::ostream &operator << (std::ostream &out, const ButtonEvent &be) {
149 be.output(out);
150 return out;
151}
152
153#include "buttonEvent.I"
154
155#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Records a button event of some kind.
Definition buttonEvent.h:49
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
This class monitors the state of a number of individual buttons and tracks whether each button is kno...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.