Added accept_failed callback hooks to provide feedback when the user attempts to submit a disabled field--this lets us do things like flash the text field red to get their attention.

This commit is contained in:
M. Ian Graham 2007-07-19 00:41:35 +00:00
parent 3b985045cb
commit 4429b66c8d
3 changed files with 44 additions and 0 deletions

View File

@ -413,6 +413,18 @@ get_accept_prefix() {
return "accept-";
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_accept_failed_prefix
// Access: Published, Static
// Description: Returns the prefix that is used to define the accept
// failed event for all PGEntries. This event is the
// concatenation of this string followed by get_id().
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_accept_failed_prefix() {
return "acceptfailed-";
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_overflow_prefix
// Access: Published, Static
@ -460,6 +472,17 @@ get_accept_event(const ButtonHandle &button) const {
return "accept-" + button.get_name() + "-" + get_id();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_accept_failed_event
// Access: Published
// Description: Returns the event name that will be thrown when the
// entry cannot accept an input
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_accept_failed_event(const ButtonHandle &button) const {
return "acceptfailed-" + button.get_name() + "-" + get_id();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_overflow_event
// Access: Published

View File

@ -215,6 +215,9 @@ press(const MouseWatcherParameter &param, bool background) {
if (_accept_enabled) {
accept(param);
}
else {
accept_failed(param);
}
} else if (button == KeyboardButton::backspace()) {
// Backspace. Remove the character to the left of the cursor.
@ -410,6 +413,21 @@ accept(const MouseWatcherParameter &param) {
set_focus(false);
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::accept_failed
// Access: Public, Virtual
// Description: This is a callback hook function, called whenever the
// user presses Enter but we can't accept the input.
////////////////////////////////////////////////////////////////////
void PGEntry::
accept_failed(const MouseWatcherParameter &param) {
PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param);
string event = get_accept_failed_event(param.get_button());
play_sound(event);
throw_event(event, EventParameter(ep));
//set_focus(false);
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::overflow
// Access: Public, Virtual

View File

@ -61,6 +61,7 @@ public:
virtual void candidate(const MouseWatcherParameter &param, bool background);
virtual void accept(const MouseWatcherParameter &param);
virtual void accept_failed(const MouseWatcherParameter &param);
virtual void overflow(const MouseWatcherParameter &param);
virtual void type(const MouseWatcherParameter &param);
virtual void erase(const MouseWatcherParameter &param);
@ -118,11 +119,13 @@ PUBLISHED:
virtual void set_focus(bool focus);
INLINE static string get_accept_prefix();
INLINE static string get_accept_failed_prefix();
INLINE static string get_overflow_prefix();
INLINE static string get_type_prefix();
INLINE static string get_erase_prefix();
INLINE string get_accept_event(const ButtonHandle &button) const;
INLINE string get_accept_failed_event(const ButtonHandle &button) const;
INLINE string get_overflow_event() const;
INLINE string get_type_event() const;
INLINE string get_erase_event() const;