Panda3D
Loading...
Searching...
No Matches
buttonRegistry.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 buttonRegistry.h
10 * @author drose
11 * @date 2000-03-01
12 */
13
14#ifndef BUTTONREGISTRY_H
15#define BUTTONREGISTRY_H
16
17#include "pandabase.h"
18
19#include "buttonHandle.h"
20
21#include "pvector.h"
22#include "pmap.h"
23
24/**
25 * The ButtonRegistry class maintains all the assigned ButtonHandles in a
26 * given system. There should be only one ButtonRegistry class during the
27 * lifetime of the application.
28 */
29class EXPCL_PANDA_PUTIL ButtonRegistry {
30protected:
31 class EXPCL_PANDA_PUTIL RegistryNode {
32 public:
33 INLINE RegistryNode(ButtonHandle handle, ButtonHandle alias,
34 const std::string &name);
35
36 ButtonHandle _handle;
37 ButtonHandle _alias;
38 std::string _name;
39 };
40
41public:
42 bool register_button(ButtonHandle &button_handle, const std::string &name,
43 ButtonHandle alias = ButtonHandle::none(),
44 char ascii_equivalent = '\0');
45
46PUBLISHED:
47 ButtonHandle get_button(const std::string &name);
48 ButtonHandle find_button(const std::string &name);
49 ButtonHandle find_ascii_button(char ascii_equivalent) const;
50
51 void write(std::ostream &out) const;
52
53 // ptr() returns the pointer to the global ButtonRegistry object.
54 INLINE static ButtonRegistry *ptr();
55
56public:
57 INLINE std::string get_name(ButtonHandle button) const;
58 INLINE ButtonHandle get_alias(ButtonHandle button) const;
59
60private:
61 // The ButtonRegistry class should never be constructed by user code. There
62 // is only one in the universe, and it constructs itself!
63 ButtonRegistry();
64
65 static void init_global_pointer();
66
67 RegistryNode *look_up(ButtonHandle button) const;
68
69 typedef pvector<RegistryNode *> HandleRegistry;
70 HandleRegistry _handle_registry;
71
72 typedef pmap<std::string, RegistryNode *> NameRegistry;
73 NameRegistry _name_registry;
74
75 static ButtonRegistry *_global_pointer;
76};
77
78#include "buttonRegistry.I"
79
80#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
ButtonHandle find_ascii_button(char ascii_equivalent) const
Finds a ButtonHandle in the registry matching the indicated ASCII equivalent character.
ButtonHandle find_button(const std::string &name)
Finds a ButtonHandle in the registry matching the indicated name.
std::string get_name(ButtonHandle button) const
Returns the name of the indicated button.
bool register_button(ButtonHandle &button_handle, const std::string &name, ButtonHandle alias=ButtonHandle::none(), char ascii_equivalent='\0')
Registers a new ButtonHandle with the indicated name, and if specified, the indicated ASCII equivalen...
ButtonHandle get_button(const std::string &name)
Finds a ButtonHandle in the registry matching the indicated name.
ButtonHandle get_alias(ButtonHandle button) const
Returns the alias for the indicated button, or ButtonHandle::none() if the button has no specified al...
static ButtonRegistry * ptr()
Returns the pointer to the global ButtonRegistry object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.