Panda3D
|
This class monitors the state of a number of individual buttons and tracks whether each button is known to be down or up. More...
#include "modifierButtons.h"
Public Member Functions | |
ModifierButtons (const ModifierButtons ©) | |
bool | add_button (ButtonHandle button) |
Adds the indicated button to the set of buttons that will be monitored for upness and downness. | |
void | all_buttons_up () |
Marks all monitored buttons as being in the "up" state. | |
bool | button_down (ButtonHandle button) |
Records that a particular button has been pressed. | |
bool | button_up (ButtonHandle button) |
Records that a particular button has been released. | |
ButtonHandle | get_button (int index) const |
Returns the nth button that the ModifierButtons object is monitoring (the nth button passed to add_button()). | |
int | get_num_buttons () const |
Returns the number of buttons that the ModifierButtons object is monitoring (e.g. | |
string | get_prefix () const |
Returns a string which can be used to prefix any button name or event name with the unique set of modifier buttons currently being held. | |
bool | has_button (ButtonHandle button) const |
Returns true if the indicated button is in the set of buttons being monitored, false otherwise. | |
bool | is_any_down () const |
Returns true if any of the tracked button are known to be down, or false if all of them are up. | |
bool | is_down (ButtonHandle button) const |
Returns true if the indicated button is known to be down, or false if it is known to be up or if it is not in the set of buttons being tracked. | |
bool | is_down (int index) const |
Returns true if the indicated button is known to be down, or false if it is known to be up. | |
MAKE_SEQ (get_buttons, get_num_buttons, get_button) | |
bool | matches (const ModifierButtons &other) const |
Returns true if the set of buttons indicated as down by this ModifierButtons object is the same set of buttons indicated as down by the other ModifierButtons object. | |
bool | operator!= (const ModifierButtons &other) const |
ModifierButtons | operator& (const ModifierButtons &other) const |
Returns a new ModifierButtons object for which is_down() will be true only if it is true on both source objects. | |
void | operator&= (const ModifierButtons &other) |
Sets is_down() true for any button that is already true for this object and the other object. | |
bool | operator< (const ModifierButtons &other) const |
void | operator= (const ModifierButtons ©) |
bool | operator== (const ModifierButtons &other) const |
The equality operator is an exact comparision: the two ModifierButtons are equal if they share the same button list--indeed, the same pointer--and they all the buttons have the same state. | |
ModifierButtons | operator| (const ModifierButtons &other) const |
Returns a new ModifierButtons object for which is_down() will be true if it is true on either of the source objects. | |
void | operator|= (const ModifierButtons &other) |
Sets is_down() true for any button that is already true for this object and the other object. | |
void | output (ostream &out) const |
Writes a one-line summary of the buttons known to be down. | |
bool | remove_button (ButtonHandle button) |
Removes the indicated button from the set of buttons being monitored. | |
void | set_button_list (const ModifierButtons &other) |
Sets the list of buttons to watch to be the same as that of the other ModifierButtons object. | |
void | write (ostream &out) const |
Writes a multi-line summary including all of the buttons being monitored and which ones are known to be down. |
This class monitors the state of a number of individual buttons and tracks whether each button is known to be down or up.
Definition at line 29 of file modifierButtons.h.
bool ModifierButtons::add_button | ( | ButtonHandle | button | ) |
Adds the indicated button to the set of buttons that will be monitored for upness and downness.
Returns true if the button was added, false if it was already being monitored or if too many buttons are currently being monitored.
Definition at line 203 of file modifierButtons.cxx.
References has_button(), and ButtonHandle::none().
Referenced by operator|=(), MouseInterfaceNode::require_button(), and MouseInterfaceNode::watch_button().
void ModifierButtons::all_buttons_up | ( | ) | [inline] |
Marks all monitored buttons as being in the "up" state.
Definition at line 131 of file modifierButtons.I.
Referenced by MouseInterfaceNode::clear_all_buttons().
bool ModifierButtons::button_down | ( | ButtonHandle | button | ) |
Records that a particular button has been pressed.
If the given button is one of the buttons that is currently being monitored, this will update the internal state appropriately; otherwise, it will do nothing. Returns true if the button is one that was monitored, or false otherwise.
Definition at line 290 of file modifierButtons.cxx.
References ButtonHandle::matches().
Referenced by ButtonThrower::do_transmit_data(), operator|=(), MouseInterfaceNode::require_button(), and ButtonEvent::update_mods().
bool ModifierButtons::button_up | ( | ButtonHandle | button | ) |
Records that a particular button has been released.
If the given button is one of the buttons that is currently being monitored, this will update the internal state appropriately; otherwise, it will do nothing. Returns true if the button is one that was monitored, or false otherwise.
Definition at line 312 of file modifierButtons.cxx.
References ButtonHandle::matches().
Referenced by MouseInterfaceNode::clear_button(), ButtonThrower::do_transmit_data(), MouseInterfaceNode::require_button(), and ButtonEvent::update_mods().
ButtonHandle ModifierButtons::get_button | ( | int | index | ) | const [inline] |
Returns the nth button that the ModifierButtons object is monitoring (the nth button passed to add_button()).
This must be in the range 0 <= index < get_num_buttons().
Definition at line 119 of file modifierButtons.I.
References ButtonHandle::none().
Referenced by operator&=(), operator|=(), and set_button_list().
int ModifierButtons::get_num_buttons | ( | ) | const [inline] |
Returns the number of buttons that the ModifierButtons object is monitoring (e.g.
the number of buttons passed to add_button()).
Definition at line 106 of file modifierButtons.I.
Referenced by matches(), operator&=(), operator|=(), and set_button_list().
string ModifierButtons::get_prefix | ( | ) | const |
Returns a string which can be used to prefix any button name or event name with the unique set of modifier buttons currently being held.
Definition at line 349 of file modifierButtons.cxx.
Referenced by ButtonThrower::do_transmit_data(), and MouseWatcher::throw_event_pattern().
bool ModifierButtons::has_button | ( | ButtonHandle | button | ) | const |
Returns true if the indicated button is in the set of buttons being monitored, false otherwise.
Definition at line 231 of file modifierButtons.cxx.
References ButtonHandle::matches().
Referenced by add_button(), MouseInterfaceNode::clear_button(), and MouseWatcher::throw_event_pattern().
bool ModifierButtons::is_any_down | ( | ) | const [inline] |
Returns true if any of the tracked button are known to be down, or false if all of them are up.
Definition at line 154 of file modifierButtons.I.
bool ModifierButtons::is_down | ( | int | index | ) | const [inline] |
Returns true if the indicated button is known to be down, or false if it is known to be up.
Definition at line 142 of file modifierButtons.I.
bool ModifierButtons::is_down | ( | ButtonHandle | button | ) | const |
Returns true if the indicated button is known to be down, or false if it is known to be up or if it is not in the set of buttons being tracked.
Definition at line 331 of file modifierButtons.cxx.
References ButtonHandle::matches().
Referenced by MouseInterfaceNode::is_down(), matches(), operator&=(), operator|=(), and set_button_list().
bool ModifierButtons::matches | ( | const ModifierButtons & | other | ) | const |
Returns true if the set of buttons indicated as down by this ModifierButtons object is the same set of buttons indicated as down by the other ModifierButtons object.
The buttons indicated as up are not relevant.
Definition at line 153 of file modifierButtons.cxx.
References get_num_buttons(), and is_down().
Referenced by ButtonThrower::add_throw_button(), ButtonThrower::has_throw_button(), and ButtonThrower::remove_throw_button().
ModifierButtons ModifierButtons::operator& | ( | const ModifierButtons & | other | ) | const [inline] |
Returns a new ModifierButtons object for which is_down() will be true only if it is true on both source objects.
The set of buttons reported by has_button() is not completely defined if both source objects have a different set.
Definition at line 75 of file modifierButtons.I.
void ModifierButtons::operator&= | ( | const ModifierButtons & | other | ) |
Sets is_down() true for any button that is already true for this object and the other object.
Definition at line 59 of file modifierButtons.cxx.
References get_button(), get_num_buttons(), and is_down().
bool ModifierButtons::operator== | ( | const ModifierButtons & | other | ) | const [inline] |
The equality operator is an exact comparision: the two ModifierButtons are equal if they share the same button list--indeed, the same pointer--and they all the buttons have the same state.
Use matches() if a less exact equality test is needed.
Definition at line 37 of file modifierButtons.I.
ModifierButtons ModifierButtons::operator| | ( | const ModifierButtons & | other | ) | const [inline] |
Returns a new ModifierButtons object for which is_down() will be true if it is true on either of the source objects.
The set of buttons reported by has_button() is not completely defined if both source objects have a different set.
Definition at line 92 of file modifierButtons.I.
void ModifierButtons::operator|= | ( | const ModifierButtons & | other | ) |
Sets is_down() true for any button that is already true for this object and the other object.
Adds whatever buttons are necessary to the list to make this so
Definition at line 88 of file modifierButtons.cxx.
References add_button(), button_down(), get_button(), get_num_buttons(), and is_down().
void ModifierButtons::output | ( | ostream & | out | ) | const |
Writes a one-line summary of the buttons known to be down.
Definition at line 368 of file modifierButtons.cxx.
bool ModifierButtons::remove_button | ( | ButtonHandle | button | ) |
Removes the indicated button from the set of buttons being monitored.
Returns true if the button was removed, false if it was not being monitored in the first place.
Unlike the other methods, you cannot remove a button by removing its alias; you have to remove exactly the button itself.
Definition at line 255 of file modifierButtons.cxx.
Referenced by MouseInterfaceNode::clear_button().
void ModifierButtons::set_button_list | ( | const ModifierButtons & | other | ) |
Sets the list of buttons to watch to be the same as that of the other ModifierButtons object.
This makes the lists pointer equivalent (until one or the other is later modified).
This will preserve the state of any button that was on the original list and is also on the new lists. Any other buttons will get reset to the default state of "up".
Definition at line 123 of file modifierButtons.cxx.
References get_button(), get_num_buttons(), and is_down().
Referenced by MouseInterfaceNode::clear_all_buttons(), MouseInterfaceNode::clear_button(), MouseInterfaceNode::require_button(), and MouseInterfaceNode::watch_button().
void ModifierButtons::write | ( | ostream & | out | ) | const |
Writes a multi-line summary including all of the buttons being monitored and which ones are known to be down.
Definition at line 386 of file modifierButtons.cxx.