Panda3D
 All Classes Functions Variables Enumerations
buttonMap.cxx
1 // Filename: buttonMap.cxx
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 #include "buttonMap.h"
16 #include "indent.h"
17 
18 TypeHandle ButtonMap::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: ButtonMap::map_button
22 // Access: Public
23 // Description: Registers a new button mapping.
24 ////////////////////////////////////////////////////////////////////
25 void ButtonMap::
26 map_button(ButtonHandle raw_button, ButtonHandle button, const string &label) {
27  int index = raw_button.get_index();
28  if (_button_map.find(index) != _button_map.end()) {
29  // A button with this index was already mapped.
30  return;
31  }
32 
33  ButtonNode bnode;
34  bnode._raw = raw_button;
35  bnode._mapped = button;
36  bnode._label = label;
37  _button_map[index] = bnode;
38  _buttons.push_back(&_button_map[index]);
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: ButtonMap::output
43 // Access: Published
44 // Description:
45 ////////////////////////////////////////////////////////////////////
46 void ButtonMap::
47 output(ostream &out) const {
48  out << "ButtonMap (" << get_num_buttons() << " buttons)";
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: ButtonMap::write
53 // Access: Published
54 // Description:
55 ////////////////////////////////////////////////////////////////////
56 void ButtonMap::
57 write(ostream &out, int indent_level) const {
58  indent(out, indent_level)
59  << "ButtonMap, " << get_num_buttons() << " buttons:\n";
60 
62  for (it = _buttons.begin(); it != _buttons.end(); ++it) {
63  const ButtonNode *bn = *it;
64 
65  indent(out, indent_level + 2)
66  << bn->_raw << " -> " << bn->_mapped << " \"" << bn->_label << "\"\n";
67  }
68 }
This is the primary interface to on/off button devices associated with a ClientBase.
Definition: buttonNode.h:41
int get_index() const
Returns the integer index associated with this ButtonHandle.
Definition: buttonHandle.I:184
void map_button(ButtonHandle raw_button, ButtonHandle button, const string &label="")
Registers a new button mapping.
Definition: buttonMap.cxx:26
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
int get_num_buttons() const
Returns the number of buttons that this button mapping specifies.
Definition: buttonMap.I:23