Panda3D
Loading...
Searching...
No Matches
buttonHandle.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 buttonHandle.I
10 * @author drose
11 * @date 2000-03-01
12 */
13
14/**
15 * Constructs a ButtonHandle with the corresponding index number, which may
16 * have been returned by an earlier call to ButtonHandle::get_index().
17 */
18constexpr ButtonHandle::
19ButtonHandle(int index) : _index(index) {
20}
21
22/**
23 *
24 */
25INLINE bool ButtonHandle::
26operator == (const ButtonHandle &other) const {
27 return (_index == other._index);
28}
29
30/**
31 *
32 */
33INLINE bool ButtonHandle::
34operator != (const ButtonHandle &other) const {
35 return (_index != other._index);
36}
37
38/**
39 *
40 */
41INLINE bool ButtonHandle::
42operator < (const ButtonHandle &other) const {
43 return (_index < other._index);
44}
45
46/**
47 *
48 */
49INLINE bool ButtonHandle::
50operator <= (const ButtonHandle &other) const {
51 return (_index <= other._index);
52}
53
54/**
55 *
56 */
57INLINE bool ButtonHandle::
58operator > (const ButtonHandle &other) const {
59 return (_index > other._index);
60}
61
62/**
63 *
64 */
65INLINE bool ButtonHandle::
66operator >= (const ButtonHandle &other) const {
67 return (_index >= other._index);
68}
69
70/**
71 * Sorts ButtonHandles arbitrarily (according to <, >, etc.). Returns a
72 * number less than 0 if this type sorts before the other one, greater than
73 * zero if it sorts after, 0 if they are equivalent.
74 */
76compare_to(const ButtonHandle &other) const {
77 return _index - other._index;
78}
79
80/**
81 * Returns a hash code suitable for phash_map.
82 */
83INLINE size_t ButtonHandle::
84get_hash() const {
85 return (size_t)_index;
86}
87
88/**
89 * Returns true if the button was created with an ASCII equivalent code (e.g.
90 * for a standard keyboard button).
91 */
92INLINE bool ButtonHandle::
94 return (_index > 0 && _index < 128);
95}
96
97/**
98 * Returns the character code associated with the button, or '\0' if no ASCII
99 * code was associated.
100 */
101INLINE char ButtonHandle::
102get_ascii_equivalent() const {
103 return has_ascii_equivalent() ? (char)_index : '\0';
104}
105
106/**
107 * Returns true if this ButtonHandle is the same as the other one, or if the
108 * other one is an alias for this one. (Does not return true if this button
109 * is an alias for the other one, however.)
110 *
111 * This is a more general comparison than operator ==.
112 */
113INLINE bool ButtonHandle::
114matches(const ButtonHandle &other) const {
115 return ((*this) == other ||
116 (other != ButtonHandle::none() &&
117 get_alias() == other));
118}
119
120/**
121 * Returns the integer index associated with this ButtonHandle. Each
122 * different ButtonHandle will have a different index. However, you probably
123 * shouldn't be using this method; you should just treat the ButtonHandles as
124 * opaque classes. This is provided for the convenience of non-C++ scripting
125 * languages to build a hashtable of ButtonHandles.
126 */
127constexpr int ButtonHandle::
128get_index() const {
129 return _index;
130}
131
132/**
133 *
134 */
135INLINE void ButtonHandle::
136output(std::ostream &out) const {
137 out << get_name();
138}
139
140/**
141 * ButtonHandle::none() evaluates to false, everything else evaluates to true.
142 */
143INLINE ButtonHandle::
144operator bool () const {
145 return (_index != 0);
146}
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
get_ascii_equivalent
Returns the character code associated with the button, or '\0' if no ASCII code was associated.
has_ascii_equivalent
Returns true if the button was created with an ASCII equivalent code (e.g.
get_name
Returns the name of the button.
int compare_to(const ButtonHandle &other) const
Sorts ButtonHandles arbitrarily (according to <, >, etc.).
get_alias
Returns the alias (alternate name) associated with the button, if any, or ButtonHandle::none() if the...
get_index
Returns the integer index associated with this ButtonHandle.
size_t get_hash() const
Returns a hash code suitable for phash_map.
bool matches(const ButtonHandle &other) const
Returns true if this ButtonHandle is the same as the other one, or if the other one is an alias for t...