Panda3D
 All Classes Functions Variables Enumerations
buttonMap.h
1 // Filename: buttonMap.h
2 // Created by: rdb (07Mar14)
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 #ifndef BUTTONMAP_H
16 #define BUTTONMAP_H
17 
18 #include "pandabase.h"
19 #include "typedReferenceCount.h"
20 #include "buttonHandle.h"
21 #include "buttonRegistry.h"
22 #include "pmap.h"
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : ButtonMap
26 // Description : This class represents a map containing all of the
27 // buttons of a (keyboard) device, though it can also
28 // be used as a generic mapping between ButtonHandles.
29 // It maps an underlying 'raw' button to a 'virtual'
30 // button, which may optionally be associated with an
31 // appropriate platform-specific name for the button.
32 ////////////////////////////////////////////////////////////////////
33 class EXPCL_PANDA_PUTIL ButtonMap : public TypedReferenceCount {
34 PUBLISHED:
35  INLINE int get_num_buttons() const;
36  INLINE ButtonHandle get_raw_button(int i) const;
37  INLINE ButtonHandle get_mapped_button(int i) const;
38  INLINE const string &get_mapped_button_label(int i) const;
39 
40  INLINE ButtonHandle get_mapped_button(ButtonHandle raw) const;
41  INLINE ButtonHandle get_mapped_button(const string &raw_name) const;
42  INLINE const string &get_mapped_button_label(ButtonHandle raw) const;
43  INLINE const string &get_mapped_button_label(const string &raw_name) const;
44 
45  void output(ostream &out) const;
46  void write(ostream &out, int indent_level = 0) const;
47 
48 public:
49  void map_button(ButtonHandle raw_button, ButtonHandle button, const string &label = "");
50 
51 private:
52  struct ButtonNode {
53  ButtonHandle _raw;
54  ButtonHandle _mapped;
55  string _label;
56  };
57 
58  pmap<int, ButtonNode> _button_map;
59  pvector<ButtonNode*> _buttons;
60 
61 public:
62  static TypeHandle get_class_type() {
63  return _type_handle;
64  }
65  static void init_type() {
66  TypedReferenceCount::init_type();
67  register_type(_type_handle, "ButtonMap",
68  TypedReferenceCount::get_class_type());
69  }
70  virtual TypeHandle get_type() const {
71  return get_class_type();
72  }
73  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
74 
75 private:
76  static TypeHandle _type_handle;
77 };
78 
79 #include "buttonMap.I"
80 
81 #endif
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:28
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This class represents a map containing all of the buttons of a (keyboard) device, though it can also ...
Definition: buttonMap.h:33