Panda3D
buttonMap.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 buttonMap.h
10  * @author rdb
11  * @date 2014-03-07
12  */
13 
14 #ifndef BUTTONMAP_H
15 #define BUTTONMAP_H
16 
17 #include "pandabase.h"
18 #include "typedReferenceCount.h"
19 #include "buttonHandle.h"
20 #include "buttonRegistry.h"
21 #include "pmap.h"
22 
23 /**
24  * This class represents a map containing all of the buttons of a (keyboard)
25  * device, though it can also be used as a generic mapping between
26  * ButtonHandles. It maps an underlying 'raw' button to a 'virtual' button,
27  * which may optionally be associated with an appropriate platform-specific
28  * name for the button.
29  */
30 class EXPCL_PANDA_PUTIL ButtonMap : public TypedReferenceCount {
31 PUBLISHED:
32  INLINE size_t get_num_buttons() const;
33  INLINE ButtonHandle get_raw_button(size_t i) const;
34  INLINE ButtonHandle get_mapped_button(size_t i) const;
35  INLINE const std::string &get_mapped_button_label(size_t i) const;
36 
37  INLINE ButtonHandle get_mapped_button(ButtonHandle raw) const;
38  INLINE ButtonHandle get_mapped_button(const std::string &raw_name) const;
39  INLINE const std::string &get_mapped_button_label(ButtonHandle raw) const;
40  INLINE const std::string &get_mapped_button_label(const std::string &raw_name) const;
41 
42  void output(std::ostream &out) const;
43  void write(std::ostream &out, int indent_level = 0) const;
44 
45 public:
46  void map_button(ButtonHandle raw_button, ButtonHandle button, const std::string &label = "");
47 
48 private:
49  struct ButtonNode {
50  ButtonHandle _raw;
51  ButtonHandle _mapped;
52  std::string _label;
53  };
54 
55  pmap<int, ButtonNode> _button_map;
56  pvector<ButtonNode*> _buttons;
57 
58 public:
59  static TypeHandle get_class_type() {
60  return _type_handle;
61  }
62  static void init_type() {
63  TypedReferenceCount::init_type();
64  register_type(_type_handle, "ButtonMap",
65  TypedReferenceCount::get_class_type());
66  }
67  virtual TypeHandle get_type() const {
68  return get_class_type();
69  }
70  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
71 
72 private:
73  static TypeHandle _type_handle;
74 };
75 
76 #include "buttonMap.I"
77 
78 #endif
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(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This class represents a map containing all of the buttons of a (keyboard) device, though it can also ...
Definition: buttonMap.h:30
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.