Panda3D
 All Classes Functions Variables Enumerations
buttonMap.I
1 // Filename: buttonMap.I
2 // Created by: rdb (09Mar14)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: ButtonMap::get_num_buttons
18 // Access: Published
19 // Description: Returns the number of buttons that this button
20 // mapping specifies.
21 ////////////////////////////////////////////////////////////////////
22 INLINE int ButtonMap::
23 get_num_buttons() const {
24  return _buttons.size();
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: ButtonMap::get_raw_button
29 // Access: Published
30 // Description: Returns the underlying raw button associated with
31 // the nth button.
32 ////////////////////////////////////////////////////////////////////
34 get_raw_button(int i) const {
35  return _buttons[i]->_raw;
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: ButtonMap::get_mapped_button
40 // Access: Published
41 // Description: Returns the nth mapped button, meaning the button
42 // that the nth raw button is mapped to.
43 ////////////////////////////////////////////////////////////////////
45 get_mapped_button(int i) const {
46  return _buttons[i]->_mapped;
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: ButtonMap::get_mapped_button_label
51 // Access: Published
52 // Description: Returns the label associated with the nth mapped
53 // button, meaning the button that the nth raw
54 // button is mapped to.
55 ////////////////////////////////////////////////////////////////////
56 INLINE const string &ButtonMap::
58  return _buttons[i]->_label;
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: ButtonMap::get_mapped_button
63 // Access: Published
64 // Description: Returns the button that the given button is mapped
65 // to, or ButtonHandle::none() if this map does not
66 // specify a mapped button for the given raw button.
67 ////////////////////////////////////////////////////////////////////
71  it = _button_map.find(raw.get_index());
72  if (it == _button_map.end()) {
73  return ButtonHandle::none();
74  } else {
75  return it->second._mapped;
76  }
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: ButtonMap::get_mapped_button
81 // Access: Published
82 // Description: Returns the button that the given button is mapped
83 // to, or ButtonHandle::none() if this map does not
84 // specify a mapped button for the given raw button.
85 ////////////////////////////////////////////////////////////////////
87 get_mapped_button(const string &raw_name) const {
88  ButtonHandle raw_button = ButtonRegistry::ptr()->find_button(raw_name);
89  if (raw_button == ButtonHandle::none()) {
90  return ButtonHandle::none();
91  } else {
92  return get_mapped_button(raw_button);
93  }
94 }
95 
96 ////////////////////////////////////////////////////////////////////
97 // Function: ButtoMap::get_mapped_button_label
98 // Access: Published
99 // Description: If the button map specifies a special name for the
100 // button (eg. if the operating system or keyboard
101 // device has a localized name describing the key),
102 // returns it, or the empty string otherwise.
103 //
104 // Note that this is not the same as
105 // get_mapped_button().get_name(), which returns the
106 // name of the Panda event associated with the button.
107 ////////////////////////////////////////////////////////////////////
108 INLINE const string &ButtonMap::
111  it = _button_map.find(raw.get_index());
112  if (it == _button_map.end()) {
113  static const string empty = "";
114  return empty;
115  } else {
116  return it->second._label;
117  }
118 }
119 
120 ////////////////////////////////////////////////////////////////////
121 // Function: ButtoMap::get_mapped_button_label
122 // Access: Published
123 // Description: If the button map specifies a special name for the
124 // button (eg. if the operating system or keyboard
125 // device has a localized name describing the key),
126 // returns it, or the empty string otherwise.
127 //
128 // Note that this is not the same as
129 // get_mapped_button().get_name(), which returns the
130 // name of the Panda event associated with the button.
131 ////////////////////////////////////////////////////////////////////
132 INLINE const string &ButtonMap::
133 get_mapped_button_label(const string &raw_name) const {
134  ButtonHandle raw_button = ButtonRegistry::ptr()->find_button(raw_name);
135  if (raw_button == ButtonHandle::none()) {
136  static const string empty = "";
137  return empty;
138  } else {
139  return get_mapped_button_label(raw_button);
140  }
141 }
static ButtonHandle none()
Returns a special zero-valued ButtonHandle that is used to indicate no button.
Definition: buttonHandle.I:205
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
int get_index() const
Returns the integer index associated with this ButtonHandle.
Definition: buttonHandle.I:184
const string & get_mapped_button_label(int i) const
Returns the label associated with the nth mapped button, meaning the button that the nth raw button i...
Definition: buttonMap.I:57
ButtonHandle get_raw_button(int i) const
Returns the underlying raw button associated with the nth button.
Definition: buttonMap.I:34
ButtonHandle find_button(const string &name)
Finds a ButtonHandle in the registry matching the indicated name.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
static ButtonRegistry * ptr()
Returns the pointer to the global ButtonRegistry object.
ButtonHandle get_mapped_button(int i) const
Returns the nth mapped button, meaning the button that the nth raw button is mapped to...
Definition: buttonMap.I:45
int get_num_buttons() const
Returns the number of buttons that this button mapping specifies.
Definition: buttonMap.I:23