Panda3D
 All Classes Functions Variables Enumerations
buttonHandle.cxx
1 // Filename: buttonHandle.cxx
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 #include "buttonHandle.h"
16 #include "buttonRegistry.h"
17 
18 // This is initialized to zero by static initialization.
19 ButtonHandle ButtonHandle::_none;
20 
21 TypeHandle ButtonHandle::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: ButtonHandle::Constructor
25 // Access: Published
26 // Description: Constructs a ButtonHandle with the corresponding
27 // name, which is looked up in the ButtonRegistry.
28 // This exists for the purpose of being able to
29 // automatically coerce a string into a ButtonHandle;
30 // for most purposes, you should use either the static
31 // KeyboardButton/MouseButton getters or
32 // ButtonRegistry::register_button().
33 ////////////////////////////////////////////////////////////////////
35 ButtonHandle(const string &name) {
36  _index = ButtonRegistry::ptr()->get_button(name)._index;
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: ButtonHandle::get_name
41 // Access: Public
42 // Description: Returns the name of the button.
43 ////////////////////////////////////////////////////////////////////
44 string ButtonHandle::
45 get_name() const {
46  if ((*this) == ButtonHandle::none()) {
47  return "none";
48  } else {
49  return ButtonRegistry::ptr()->get_name(*this);
50  }
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: ButtonHandle::get_alias
55 // Access: Published
56 // Description: Returns the alias (alternate name) associated with
57 // the button, if any, or ButtonHandle::none() if the
58 // button has no alias.
59 //
60 // Each button is allowed to have one alias, and
61 // multiple different buttons can refer to the same
62 // alias. The alias should be the more general name for
63 // the button, for instance, shift is an alias for
64 // lshift, but not vice-versa.
65 ////////////////////////////////////////////////////////////////////
67 get_alias() const {
68  if ((*this) == ButtonHandle::none()) {
69  return ButtonHandle::none();
70  } else {
71  return ButtonRegistry::ptr()->get_alias(*this);
72  }
73 }
ButtonHandle get_button(const string &name)
Finds a ButtonHandle in the registry matching the indicated name.
static ButtonHandle none()
Returns a special zero-valued ButtonHandle that is used to indicate no button.
Definition: buttonHandle.I:205
ButtonHandle get_alias() const
Returns the alias (alternate name) associated with the button, if any, or ButtonHandle::none() if the...
ButtonHandle()
The default constructor must do nothing, because we can't guarantee ordering of static initializers...
Definition: buttonHandle.I:26
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
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.
string get_name() const
Returns the name of the button.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
string get_name(ButtonHandle button) const
Returns the name of the indicated button.