From 98ffa974aca633aef0fca1e604d7007f592d3469 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 9 Mar 2014 17:32:59 +0000 Subject: [PATCH] Make string coercible into ButtonHandle --- panda/src/putil/buttonHandle.cxx | 16 ++++++++++++++++ panda/src/putil/buttonHandle.h | 1 + 2 files changed, 17 insertions(+) diff --git a/panda/src/putil/buttonHandle.cxx b/panda/src/putil/buttonHandle.cxx index e37f0f738d..49d17eeea3 100644 --- a/panda/src/putil/buttonHandle.cxx +++ b/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 diff --git a/panda/src/putil/buttonHandle.h b/panda/src/putil/buttonHandle.h index cd946bdfc3..909458c32c 100644 --- a/panda/src/putil/buttonHandle.h +++ b/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 ©);