Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File 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>

List of all members.

Public Member Functions

 ModifierButtons ()
 ModifierButtons (const ModifierButtons &copy)
 ~ModifierButtons ()
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.

bool operator!= (const ModifierButtons &other) const
bool operator< (const ModifierButtons &other) const
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 add_button (ButtonHandle button)
 Adds the indicated button to the set of buttons that will be monitored for upness and downness.

bool has_button (ButtonHandle button) const
 Returns true if the indicated button is in the set of buttons being monitored, false otherwise.

bool remove_button (ButtonHandle button)
 Removes the indicated button from the set of buttons being monitored.

int get_num_buttons () const
 Returns the number of buttons that the ModifierButtons object is monitoring (e.g.

ButtonHandle get_button (int index) const
 Returns the nth button that the ModifierButtons object is monitoring (the nth button passed to add_button()).

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.

bool add_event (const ButtonEvent &event)
 Calls button_down() or button_up(), as appropriate, according to the indicated ButtonEvent.

void all_buttons_up ()
 Marks all monitored buttons as being in the "up" state.

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.

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.

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.

void output (ostream &out) const
 Writes a one-line summary of the buttons known to be down.

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.


Private Types

typedef unsigned long BitmaskType

Private Member Functions

void modify_button_list ()
 Implements a poor-man's copy-on-write for the ModifierButtons class.


Private Attributes

PointerToArray< ButtonHandle_button_list
BitmaskType _state


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


Member Typedef Documentation

typedef unsigned long ModifierButtons::BitmaskType [private]
 

Definition at line 80 of file modifierButtons.h.

Referenced by has_button().


Constructor & Destructor Documentation

ModifierButtons::ModifierButtons  ) 
 

Definition at line 34 of file modifierButtons.cxx.

ModifierButtons::ModifierButtons const ModifierButtons &  copy  ) 
 

Definition at line 48 of file modifierButtons.cxx.

ModifierButtons::~ModifierButtons  ) 
 

Definition at line 62 of file modifierButtons.cxx.

References _button_list, and _state.


Member Function Documentation

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

References _button_list, PointerToArray< ButtonHandle >::begin(), PointerToArray< ButtonHandle >::end(), and PTA.

bool ModifierButtons::add_event const ButtonEvent event  )  [inline]
 

Calls button_down() or button_up(), as appropriate, according to the indicated ButtonEvent.

Definition at line 133 of file modifierButtons.I.

References _button_list, _state, nassertr, and PointerToArray< ButtonHandle >::size().

void ModifierButtons::all_buttons_up  )  [inline]
 

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

Definition at line 157 of file modifierButtons.I.

Referenced by DriveInterface::~DriveInterface().

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

References _button_list, _state, and PointerToArray< ButtonHandle >::size().

Referenced by get_num_buttons(), and ButtonThrower::has_throw_button().

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

References _button_list, _state, and PointerToArray< ButtonHandle >::size().

Referenced by get_num_buttons().

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

References _state, and INLINE.

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

References ButtonEvent::_button, ButtonEvent::_type, button_down(), button_up(), INLINE, ButtonEvent::T_down, and ButtonEvent::T_up.

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

References _button_list, PointerToArray< ButtonHandle >::get_ref_count(), nassertv, and PTA.

Referenced by ButtonThrower::has_throw_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 171 of file modifierButtons.cxx.

References _state, and BitmaskType.

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 188 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 172 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 294 of file modifierButtons.cxx.

References _button_list, _state, and PointerToArray< ButtonHandle >::size().

Referenced by Trackball::apply().

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

References _button_list.

void ModifierButtons::modify_button_list  )  [private]
 

Implements a poor-man's copy-on-write for the ModifierButtons class.

If any reference counts are held on our _button_list, besides ourselves, then allocates and copies a brand new copy of the _button_list. This should be done in preparation for any modifications to the _button_list, since multiple instances of the ModifierButtons object may share the same _button_list pointer.

Definition at line 397 of file modifierButtons.cxx.

bool ModifierButtons::operator!= const ModifierButtons &  other  )  const [inline]
 

Definition at line 66 of file modifierButtons.I.

References _state.

bool ModifierButtons::operator< const ModifierButtons &  other  )  const [inline]
 

Definition at line 78 of file modifierButtons.I.

References _button_list.

void ModifierButtons::operator= const ModifierButtons &  copy  )  [inline]
 

Definition at line 31 of file modifierButtons.I.

References _button_list, _state, and INLINE.

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

void ModifierButtons::output ostream &  out  )  const
 

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

Definition at line 340 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.

Definition at line 197 of file modifierButtons.cxx.

References _button_list, _state, and PointerToArray< ButtonHandle >::size().

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


Member Data Documentation

PointerToArray< ButtonHandle > ModifierButtons::_button_list [private]
 

Definition at line 79 of file modifierButtons.h.

Referenced by add_button(), add_event(), button_down(), button_up(), get_prefix(), is_down(), matches(), operator<(), operator=(), remove_button(), and ~ModifierButtons().

BitmaskType ModifierButtons::_state [private]
 

Definition at line 81 of file modifierButtons.h.

Referenced by add_event(), button_down(), button_up(), get_button(), has_button(), is_down(), operator!=(), operator=(), remove_button(), and ~ModifierButtons().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:52:16 2003 for Panda by doxygen1.3