Panda3D
buttonHandle.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 buttonHandle.cxx
10  * @author drose
11  * @date 2000-03-01
12  */
13 
14 #include "buttonHandle.h"
15 #include "buttonRegistry.h"
16 
17 TypeHandle ButtonHandle::_type_handle;
18 
19 /**
20  * Constructs a ButtonHandle with the corresponding name, which is looked up
21  * in the ButtonRegistry. This exists for the purpose of being able to
22  * automatically coerce a string into a ButtonHandle; for most purposes, you
23  * should use either the static KeyboardButton/MouseButton getters or
24  * ButtonRegistry::register_button().
25  */
26 ButtonHandle::
27 ButtonHandle(const std::string &name) {
28  _index = ButtonRegistry::ptr()->get_button(name)._index;
29 }
30 
31 /**
32  * Returns the name of the button.
33  */
34 std::string ButtonHandle::
35 get_name() const {
36  if ((*this) == ButtonHandle::none()) {
37  return "none";
38  } else {
39  return ButtonRegistry::ptr()->get_name(*this);
40  }
41 }
42 
43 /**
44  * Returns the alias (alternate name) associated with the button, if any, or
45  * ButtonHandle::none() if the button has no alias.
46  *
47  * Each button is allowed to have one alias, and multiple different buttons
48  * can refer to the same alias. The alias should be the more general name for
49  * the button, for instance, shift is an alias for lshift, but not vice-versa.
50  */
51 ButtonHandle ButtonHandle::
52 get_alias() const {
53  if ((*this) == ButtonHandle::none()) {
54  return ButtonHandle::none();
55  } else {
56  return ButtonRegistry::ptr()->get_alias(*this);
57  }
58 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::string get_name(ButtonHandle button) const
Returns the name of the indicated button.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26
ButtonHandle get_button(const std::string &name)
Finds a ButtonHandle in the registry matching the indicated name.
static ButtonRegistry * ptr()
Returns the pointer to the global ButtonRegistry object.
ButtonHandle get_alias(ButtonHandle button) const
Returns the alias for the indicated button, or ButtonHandle::none() if the button has no specified al...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.