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 */
26class 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
66private:
67 int _index;
68
69public:
70 static TypeHandle get_class_type() {
71 return _type_handle;
72 }
73 static void init_type() {
74 register_type(_type_handle, "ButtonHandle");
75 }
76
77private:
78 static TypeHandle _type_handle;
79
80friend 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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
The ButtonRegistry class maintains all the assigned ButtonHandles in a given system.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
An STL function object class, this is intended to be used on any ordered collection of class objects ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.