Ver código fonte

Make string coercible into ButtonHandle

rdb 11 anos atrás
pai
commit
98ffa974ac
2 arquivos alterados com 17 adições e 0 exclusões
  1. 16 0
      panda/src/putil/buttonHandle.cxx
  2. 1 0
      panda/src/putil/buttonHandle.h

+ 16 - 0
panda/src/putil/buttonHandle.cxx

@@ -20,6 +20,22 @@ ButtonHandle ButtonHandle::_none;
 
 TypeHandle ButtonHandle::_type_handle;
 
+////////////////////////////////////////////////////////////////////
+//     Function: ButtonHandle::Constructor
+//       Access: Published
+//  Description: Constructs a ButtonHandle with the corresponding
+//               name, which is looked up in the ButtonRegistry.
+//               This exists for the purpose of being able to
+//               automatically coerce a string into a ButtonHandle;
+//               for most purposes, you should use either the static
+//               KeyboardButton/MouseButton getters or
+//               ButtonRegistry::register_button().
+////////////////////////////////////////////////////////////////////
+ButtonHandle::
+ButtonHandle(const string &name) {
+  _index = ButtonRegistry::ptr()->get_button(name)._index;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: ButtonHandle::get_name
 //       Access: Public

+ 1 - 0
panda/src/putil/buttonHandle.h

@@ -29,6 +29,7 @@ class EXPCL_PANDA_PUTIL ButtonHandle {
 PUBLISHED:
   INLINE ButtonHandle();
   INLINE ButtonHandle(int index);
+  ButtonHandle(const string &name);
 
 public:
   INLINE ButtonHandle(const ButtonHandle &copy);