Panda3D

Loading...
Searching...
No Matches
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.
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
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.
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.
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 &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.
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 (std::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 (std::ostream &out) const
| Writes a multi-line summary including all of the buttons being monitored and which ones are known to be down.

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

## 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.

## Constructor & Destructor Documentation

## ◆ ModifierButtons() [1/2]

ModifierButtons::ModifierButtons | ( |  | ) |

Definition at line 21 of file modifierButtons.cxx.

## ◆ ModifierButtons() [2/2]

ModifierButtons::ModifierButtons | ( | const ModifierButtons & | copy | ) |

Definition at line 31 of file modifierButtons.cxx.

## ◆ ~ModifierButtons()

ModifierButtons::~ModifierButtons | ( |  | ) |

Definition at line 41 of file modifierButtons.cxx.

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

References has_button().

Referenced by WindowFramework::enable_keyboard(), and operator|=().

## ◆ all_buttons_up()

void ModifierButtons::all_buttons_up | ( |  | ) |
| inline

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

Definition at line 104 of file modifierButtons.I.

## ◆ 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 256 of file modifierButtons.cxx.

References ButtonHandle::matches().

Referenced by operator|=(), 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 274 of file modifierButtons.cxx.

References ButtonHandle::matches().

Referenced by 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 305 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 205 of file modifierButtons.cxx.

References ButtonHandle::matches().

Referenced by add_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 123 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 290 of file modifierButtons.cxx.

References ButtonHandle::matches().

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

## ◆ 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 113 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 133 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().

## ◆ operator!=()

bool ModifierButtons::operator!= | ( | const ModifierButtons & | other | ) | const
| inline

Definition at line 38 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 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 60 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 49 of file modifierButtons.cxx.

References get_button, get_num_buttons, and is_down().

## ◆ operator<()

bool ModifierButtons::operator< | ( | const ModifierButtons & | other | ) | const
| inline

Definition at line 46 of file modifierButtons.I.

## ◆ operator=()

void ModifierButtons::operator= | ( | const ModifierButtons & | copy | ) |
| inline

Definition at line 17 of file modifierButtons.I.

## ◆ 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 29 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 74 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 75 of file modifierButtons.cxx.

References add_button(), button_down(), get_button, get_num_buttons, and is_down().

## ◆ output()

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

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

Definition at line 321 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 225 of file modifierButtons.cxx.

## ◆ 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 106 of file modifierButtons.cxx.

References get_button, get_num_buttons, and is_down().

## ◆ 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 336 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.

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

## ◆ 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 matches(), operator&=(), operator|=(), and set_button_list().

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

- panda/src/putil/modifierButtons.h
- panda/src/putil/modifierButtons.cxx
- panda/src/putil/modifierButtons.I