Panda3D
Loading...
Searching...
No Matches
buttonMap.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 buttonMap.I
10 * @author rdb
11 * @date 2014-03-09
12 */
13
14/**
15 * Returns the number of buttons that this button mapping specifies.
16 */
17INLINE size_t ButtonMap::
18get_num_buttons() const {
19 return _buttons.size();
20}
21
22/**
23 * Returns the underlying raw button associated with the nth button.
24 */
26get_raw_button(size_t i) const {
27 return _buttons[i]->_raw;
28}
29
30/**
31 * Returns the nth mapped button, meaning the button that the nth raw button
32 * is mapped to.
33 */
35get_mapped_button(size_t i) const {
36 return _buttons[i]->_mapped;
37}
38
39/**
40 * Returns the label associated with the nth mapped button, meaning the button
41 * that the nth raw button is mapped to.
42 */
43INLINE const std::string &ButtonMap::
44get_mapped_button_label(size_t i) const {
45 return _buttons[i]->_label;
46}
47
48/**
49 * Returns the button that the given button is mapped to, or
50 * ButtonHandle::none() if this map does not specify a mapped button for the
51 * given raw button.
52 */
56 it = _button_map.find(raw.get_index());
57 if (it == _button_map.end()) {
58 return ButtonHandle::none();
59 } else {
60 return it->second._mapped;
61 }
62}
63
64/**
65 * Returns the button that the given button is mapped to, or
66 * ButtonHandle::none() if this map does not specify a mapped button for the
67 * given raw button.
68 */
70get_mapped_button(const std::string &raw_name) const {
71 ButtonHandle raw_button = ButtonRegistry::ptr()->find_button(raw_name);
72 if (raw_button == ButtonHandle::none()) {
73 return ButtonHandle::none();
74 } else {
75 return get_mapped_button(raw_button);
76 }
77}
78
79/**
80 * If the button map specifies a special name for the button (eg. if the
81 * operating system or keyboard device has a localized name describing the
82 * key), returns it, or the empty string otherwise.
83 *
84 * Note that this is not the same as get_mapped_button().get_name(), which
85 * returns the name of the Panda event associated with the button.
86 */
87INLINE const std::string &ButtonMap::
90 it = _button_map.find(raw.get_index());
91 if (it == _button_map.end()) {
92 static const std::string empty = "";
93 return empty;
94 } else {
95 return it->second._label;
96 }
97}
98
99/**
100 * If the button map specifies a special name for the button (eg. if the
101 * operating system or keyboard device has a localized name describing the
102 * key), returns it, or the empty string otherwise.
103 *
104 * Note that this is not the same as get_mapped_button().get_name(), which
105 * returns the name of the Panda event associated with the button.
106 */
107INLINE const std::string &ButtonMap::
108get_mapped_button_label(const std::string &raw_name) const {
109 ButtonHandle raw_button = ButtonRegistry::ptr()->find_button(raw_name);
110 if (raw_button == ButtonHandle::none()) {
111 static const std::string empty = "";
112 return empty;
113 } else {
114 return get_mapped_button_label(raw_button);
115 }
116}
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
get_index
Returns the integer index associated with this ButtonHandle.
const std::string & get_mapped_button_label(size_t i) const
Returns the label associated with the nth mapped button, meaning the button that the nth raw button i...
Definition buttonMap.I:44
ButtonHandle get_raw_button(size_t i) const
Returns the underlying raw button associated with the nth button.
Definition buttonMap.I:26
size_t get_num_buttons() const
Returns the number of buttons that this button mapping specifies.
Definition buttonMap.I:18
ButtonHandle get_mapped_button(size_t i) const
Returns the nth mapped button, meaning the button that the nth raw button is mapped to.
Definition buttonMap.I:35
ButtonHandle find_button(const std::string &name)
Finds a ButtonHandle in the registry matching the indicated name.
static ButtonRegistry * ptr()
Returns the pointer to the global ButtonRegistry object.
This is our own Panda specialization on the default STL map.
Definition pmap.h:49