Panda3D

Loading...
Searching...
No Matches
buttonHandle.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 buttonHandle.h
10 * @author drose
11 * @date 2000-03-01
12 */
13
14#ifndef BUTTONHANDLE_H
15#define BUTTONHANDLE_H
16
17#include "pandabase.h"
18#include "typeHandle.h"
19#include "register_type.h"
20
21/**
22 * A ButtonHandle represents a single button from any device, including
23 * keyboard buttons and mouse buttons (but see KeyboardButton and
24 * MouseButton).
25 */
26 class EXPCL_PANDA_PUTIL ButtonHandle final {
27PUBLISHED:
28 // The default constructor must do nothing, because we can't guarantee
29 // ordering of static initializers. If the constructor tried to initialize
30 // its value, it might happen after the value had already been set
31 // previously by another static initializer!
32 INLINE ButtonHandle() = default;
33 constexpr ButtonHandle(int index);
34 ButtonHandle(const std::string &name);
35
36PUBLISHED:
37 INLINE bool operator == (const ButtonHandle &other) const;
38 INLINE bool operator != (const ButtonHandle &other) const;
39 INLINE bool operator < (const ButtonHandle &other) const;
40 INLINE bool operator <= (const ButtonHandle &other) const;
41 INLINE bool operator > (const ButtonHandle &other) const;
42 INLINE bool operator >= (const ButtonHandle &other) const;
43 INLINE int compare_to(const ButtonHandle &other) const;
44 INLINE size_t get_hash() const;
45
46 std::string get_name() const;
47 INLINE bool has_ascii_equivalent() const;
48 INLINE char get_ascii_equivalent() const;
49
50 ButtonHandle get_alias() const;
51
52 INLINE bool matches(const ButtonHandle &other) const;
53
54 constexpr int get_index() const;
55 INLINE void output(std::ostream &out) const;
56 constexpr static ButtonHandle none() { return ButtonHandle(0); }
57
58 INLINE operator bool () const;
59
60 MAKE_PROPERTY(index, get_index);
61 MAKE_PROPERTY(name, get_name);
62 MAKE_PROPERTY2(ascii_equivalent, has_ascii_equivalent,
63 get_ascii_equivalent);
64 MAKE_PROPERTY(alias, get_alias);
65
66 private:
67 int _index;
68
69 public:
70 static TypeHandle get_class_type() {
71 return _type_handle;
72 }
73 static void init_type() {
74 register_type(_type_handle, "ButtonHandle");
75 }
76
77 private:
78 static TypeHandle _type_handle;
79
80 friend class ButtonRegistry;
81};
82
83// It's handy to be able to output a ButtonHandle directly, and see the button
84// name.
85INLINE std::ostream &operator << (std::ostream &out, ButtonHandle button) {
86 button.output(out);
87 return out;
88}
89
90#include "buttonHandle.I"
91
92#endif
buttonHandle.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ButtonHandle
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition buttonHandle.h:26
ButtonHandle::get_ascii_equivalent
get_ascii_equivalent
Returns the character code associated with the button, or '\0' if no ASCII code was associated.
Definition buttonHandle.h:63
ButtonHandle::has_ascii_equivalent
has_ascii_equivalent
Returns true if the button was created with an ASCII equivalent code (e.g.
Definition buttonHandle.h:63
ButtonHandle::get_name
get_name
Returns the name of the button.
Definition buttonHandle.h:61
ButtonHandle::compare_to
int compare_to(const ButtonHandle &other) const
Sorts ButtonHandles arbitrarily (according to <, >, etc.).
Definition buttonHandle.I:76
ButtonHandle::get_alias
get_alias
Returns the alias (alternate name) associated with the button, if any, or ButtonHandle::none() if the...
Definition buttonHandle.h:64
ButtonHandle::get_index
get_index
Returns the integer index associated with this ButtonHandle.
Definition buttonHandle.h:60
ButtonHandle::get_hash
size_t get_hash() const
Returns a hash code suitable for phash_map.
Definition buttonHandle.I:84
ButtonHandle::matches
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...
Definition buttonHandle.I:114
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition register_type.I:22
typeHandle.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.