Panda3D
buttonMap.cxx
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.cxx
10  * @author rdb
11  * @date 2014-03-09
12  */
13 
14 #include "buttonMap.h"
15 #include "indent.h"
16 
17 TypeHandle ButtonMap::_type_handle;
18 
19 /**
20  * Registers a new button mapping.
21  */
22 void ButtonMap::
23 map_button(ButtonHandle raw_button, ButtonHandle button, const std::string &label) {
24  int index = raw_button.get_index();
25  if (_button_map.find(index) != _button_map.end()) {
26  // A button with this index was already mapped.
27  return;
28  }
29 
30  ButtonNode bnode;
31  bnode._raw = raw_button;
32  bnode._mapped = button;
33  bnode._label = label;
34  _button_map[index] = bnode;
35  _buttons.push_back(&_button_map[index]);
36 }
37 
38 /**
39  *
40  */
41 void ButtonMap::
42 output(std::ostream &out) const {
43  out << "ButtonMap (" << get_num_buttons() << " buttons)";
44 }
45 
46 /**
47  *
48  */
49 void ButtonMap::
50 write(std::ostream &out, int indent_level) const {
51  indent(out, indent_level)
52  << "ButtonMap, " << get_num_buttons() << " buttons:\n";
53 
55  for (it = _buttons.begin(); it != _buttons.end(); ++it) {
56  const ButtonNode *bn = *it;
57 
58  indent(out, indent_level + 2)
59  << bn->_raw << " -> " << bn->_mapped << " \"" << bn->_label << "\"\n";
60  }
61 }
This is the primary interface to on/off button devices associated with a ClientBase.
Definition: buttonNode.h:33
get_index
Returns the integer index associated with this ButtonHandle.
Definition: buttonHandle.h:60
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
size_t get_num_buttons() const
Returns the number of buttons that this button mapping specifies.
Definition: buttonMap.I:18
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
void map_button(ButtonHandle raw_button, ButtonHandle button, const std::string &label="")
Registers a new button mapping.
Definition: buttonMap.cxx:23
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.