Panda3D
Public Member Functions | Public Attributes | List of all members
ModifierButtons Class Reference

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 &copy)
 
bool add_button (ButtonHandle button)
 Adds the indicated button to the set of buttons that will be monitored for upness and downness. More...
 
void all_buttons_up ()
 Marks all monitored buttons as being in the "up" state. More...
 
bool button_down (ButtonHandle button)
 Records that a particular button has been pressed. More...
 
bool button_up (ButtonHandle button)
 Records that a particular button has been released. More...
 
ButtonHandle get_button (int index) const
 
int get_num_buttons () const
 
std::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. More...
 
bool has_button (ButtonHandle button) const
 Returns true if the indicated button is in the set of buttons being monitored, false otherwise. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void operator &= (const ModifierButtons &other)
 Sets is_down() true for any button that is already true for this object and the other object. More...
 
bool operator< (const ModifierButtons &other) const
 
void operator= (const ModifierButtons &copy)
 
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. More...
 
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. More...
 
void operator|= (const ModifierButtons &other)
 Sets is_down() true for any button that is already true for this object and the other object. More...
 
void output (std::ostream &out) const
 Writes a one-line summary of the buttons known to be down. More...
 
bool remove_button (ButtonHandle button)
 Removes the indicated button from the set of buttons being monitored. More...
 
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. More...
 
void write (std::ostream &out) const
 Writes a multi-line summary including all of the buttons being monitored and which ones are known to be down. More...
 

Public Attributes

 get_button
 Returns the nth button that the ModifierButtons object is monitoring (the nth button passed to add_button()). More...
 
 get_num_buttons
 Returns the number of buttons that the ModifierButtons object is monitoring (e.g. More...
 

Detailed Description

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 26 of file modifierButtons.h.

Member Function Documentation

◆ add_button()

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 180 of file modifierButtons.cxx.

Referenced by MouseInterfaceNode::require_button().

◆ all_buttons_up()

void ModifierButtons::all_buttons_up ( )
inline

Marks all monitored buttons as being in the "up" state.

Definition at line 105 of file modifierButtons.I.

Referenced by MouseInterfaceNode::clear_all_buttons().

◆ button_down()

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 257 of file modifierButtons.cxx.

Referenced by MouseInterfaceNode::require_button(), and ButtonEvent::update_mods().

◆ button_up()

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 275 of file modifierButtons.cxx.

Referenced by MouseInterfaceNode::clear_button(), MouseInterfaceNode::require_button(), and ButtonEvent::update_mods().

◆ get_prefix()

std::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 306 of file modifierButtons.cxx.

◆ has_button()

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 206 of file modifierButtons.cxx.

References ButtonHandle::matches().

Referenced by MouseInterfaceNode::clear_button().

◆ is_any_down()

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 124 of file modifierButtons.I.

◆ is_down() [1/2]

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 291 of file modifierButtons.cxx.

◆ is_down() [2/2]

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 114 of file modifierButtons.I.

◆ matches()

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 134 of file modifierButtons.cxx.

Referenced by ButtonThrower::add_throw_button(), ButtonThrower::has_throw_button(), and ButtonThrower::remove_throw_button().

◆ operator &()

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 61 of file modifierButtons.I.

◆ operator &=()

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 50 of file modifierButtons.cxx.

References get_num_buttons.

◆ operator==()

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 30 of file modifierButtons.I.

◆ operator|()

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 75 of file modifierButtons.I.

◆ operator|=()

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 76 of file modifierButtons.cxx.

References get_num_buttons.

◆ output()

void ModifierButtons::output ( std::ostream &  out) const

Writes a one-line summary of the buttons known to be down.

Definition at line 322 of file modifierButtons.cxx.

◆ remove_button()

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 226 of file modifierButtons.cxx.

Referenced by MouseInterfaceNode::clear_button().

◆ set_button_list()

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 107 of file modifierButtons.cxx.

References get_num_buttons.

Referenced by MouseInterfaceNode::clear_all_buttons(), MouseInterfaceNode::clear_button(), and MouseInterfaceNode::require_button().

◆ write()

void ModifierButtons::write ( std::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 337 of file modifierButtons.cxx.

Member Data Documentation

◆ get_button

ButtonHandle ModifierButtons::get_button
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 53 of file modifierButtons.h.

◆ get_num_buttons

int ModifierButtons::get_num_buttons
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 53 of file modifierButtons.h.

Referenced by operator &=(), operator|=(), and set_button_list().


The documentation for this class was generated from the following files: