extend ascii_key to accept a string as well as a character

This commit is contained in:
David Rose 2001-09-05 23:17:39 +00:00
parent d31a882b09
commit 2b080112c3
2 changed files with 18 additions and 0 deletions

View File

@ -33,6 +33,23 @@ ascii_key(char ascii_equivalent) {
return ButtonRegistry::ptr()->find_ascii_button(ascii_equivalent); return ButtonRegistry::ptr()->find_ascii_button(ascii_equivalent);
} }
////////////////////////////////////////////////////////////////////
// Function: KeyboardButton::ascii_key
// Access: Public, Static
// Description: Returns the ButtonHandle associated with the
// particular ASCII character (taken from the first
// character of the indicated string), if there is one,
// or ButtonHandle::none() if there is not.
////////////////////////////////////////////////////////////////////
ButtonHandle KeyboardButton::
ascii_key(const string &ascii_equivalent) {
if (ascii_equivalent.empty()) {
return ButtonHandle::none();
} else {
return ButtonRegistry::ptr()->find_ascii_button(ascii_equivalent[0]);
}
}
#define DEFINE_KEYBD_BUTTON_HANDLE(KeyName) \ #define DEFINE_KEYBD_BUTTON_HANDLE(KeyName) \
static ButtonHandle _##KeyName; \ static ButtonHandle _##KeyName; \
ButtonHandle KeyboardButton::KeyName() { return _##KeyName; } ButtonHandle KeyboardButton::KeyName() { return _##KeyName; }

View File

@ -32,6 +32,7 @@
class EXPCL_PANDA KeyboardButton { class EXPCL_PANDA KeyboardButton {
PUBLISHED: PUBLISHED:
static ButtonHandle ascii_key(char ascii_equivalent); static ButtonHandle ascii_key(char ascii_equivalent);
static ButtonHandle ascii_key(const string &ascii_equivalent);
static ButtonHandle space(); static ButtonHandle space();
static ButtonHandle backspace(); static ButtonHandle backspace();