Panda3D
buttonRegistry.h
1 // Filename: buttonRegistry.h
2 // Created by: drose (01Mar00)
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 BUTTONREGISTRY_H
16 #define BUTTONREGISTRY_H
17 
18 #include "pandabase.h"
19 
20 #include "buttonHandle.h"
21 
22 #include "pvector.h"
23 #include "pmap.h"
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : ButtonRegistry
27 // Description : The ButtonRegistry class maintains all the assigned
28 // ButtonHandles in a given system. There should be only
29 // one ButtonRegistry class during the lifetime of the
30 // application.
31 ////////////////////////////////////////////////////////////////////
32 class EXPCL_PANDA_PUTIL ButtonRegistry {
33 protected:
34  class EXPCL_PANDA_PUTIL RegistryNode {
35  public:
36  INLINE RegistryNode(ButtonHandle handle, ButtonHandle alias,
37  const string &name);
38 
39  ButtonHandle _handle;
40  ButtonHandle _alias;
41  string _name;
42  };
43 
44 public:
45  bool register_button(ButtonHandle &button_handle, const string &name,
47  char ascii_equivalent = '\0');
48 
49 PUBLISHED:
50  ButtonHandle get_button(const string &name);
51  ButtonHandle find_button(const string &name);
52  ButtonHandle find_ascii_button(char ascii_equivalent) const;
53 
54  void write(ostream &out) const;
55 
56  // ptr() returns the pointer to the global ButtonRegistry object.
57  INLINE static ButtonRegistry *ptr();
58 
59 public:
60  INLINE string get_name(ButtonHandle button) const;
61  INLINE ButtonHandle get_alias(ButtonHandle button) const;
62 
63 private:
64  // The ButtonRegistry class should never be constructed by user code.
65  // There is only one in the universe, and it constructs itself!
67 
68  static void init_global_pointer();
69 
70  RegistryNode *look_up(ButtonHandle button) const;
71 
73  HandleRegistry _handle_registry;
74 
76  NameRegistry _name_registry;
77 
78  static ButtonRegistry *_global_pointer;
79 };
80 
81 #include "buttonRegistry.I"
82 
83 #endif
static ButtonHandle none()
Returns a special zero-valued ButtonHandle that is used to indicate no button.
Definition: buttonHandle.I:205
The ButtonRegistry class maintains all the assigned ButtonHandles in a given system.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28