Panda3D
Loading...
Searching...
No Matches
modifierButtons.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file modifierButtons.h
10 * @author drose
11 * @date 2000-03-01
12 */
13
14#ifndef MODIFIERBUTTONS_H
15#define MODIFIERBUTTONS_H
16
17#include "pandabase.h"
18
19#include "buttonHandle.h"
20#include "pointerToArray.h"
21
22/**
23 * This class monitors the state of a number of individual buttons and tracks
24 * whether each button is known to be down or up.
25 */
26class EXPCL_PANDA_PUTIL ModifierButtons {
27PUBLISHED:
28 ModifierButtons();
29 ModifierButtons(const ModifierButtons &copy);
30 ~ModifierButtons();
31 INLINE void operator = (const ModifierButtons &copy);
32
33 INLINE bool operator == (const ModifierButtons &other) const;
34 INLINE bool operator != (const ModifierButtons &other) const;
35 INLINE bool operator < (const ModifierButtons &other) const;
36
37 INLINE ModifierButtons operator & (const ModifierButtons &other) const;
38 INLINE ModifierButtons operator | (const ModifierButtons &other) const;
39
40 void operator &= (const ModifierButtons &other);
41 void operator |= (const ModifierButtons &other);
42
43 void set_button_list(const ModifierButtons &other);
44
45 bool matches(const ModifierButtons &other) const;
46
47 bool add_button(ButtonHandle button);
48 bool has_button(ButtonHandle button) const;
49 bool remove_button(ButtonHandle button);
50
51 INLINE int get_num_buttons() const;
52 INLINE ButtonHandle get_button(int index) const;
53 MAKE_SEQ(get_buttons, get_num_buttons, get_button);
54 MAKE_SEQ_PROPERTY(buttons, get_num_buttons, get_button);
55
56 bool button_down(ButtonHandle button);
57 bool button_up(ButtonHandle button);
58 INLINE void all_buttons_up();
59
60 bool is_down(ButtonHandle button) const;
61 INLINE bool is_down(int index) const;
62 INLINE bool is_any_down() const;
63
64 std::string get_prefix() const;
65
66 void output(std::ostream &out) const;
67 void write(std::ostream &out) const;
68
69private:
70 void modify_button_list();
71
72 PTA(ButtonHandle) _button_list;
73 typedef unsigned long BitmaskType;
74 BitmaskType _state;
75};
76
77INLINE std::ostream &operator << (std::ostream &out, const ModifierButtons &mb) {
78 mb.output(out);
79 return out;
80}
81
82#include "modifierButtons.I"
83
84#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
This class monitors the state of a number of individual buttons and tracks whether each button is kno...
bool matches(const ModifierButtons &other) const
Returns true if the set of buttons indicated as down by this ModifierButtons object is the same set o...
bool add_button(ButtonHandle button)
Adds the indicated button to the set of buttons that will be monitored for upness and downness.
get_num_buttons
Returns the number of buttons that the ModifierButtons object is monitoring (e.g.
get_button
Returns the nth button that the ModifierButtons object is monitoring (the nth button passed to add_bu...
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 i...
bool remove_button(ButtonHandle button)
Removes the indicated button from the set of buttons being monitored.
bool button_up(ButtonHandle button)
Records that a particular button has been released.
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.
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 ...
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 mod...
bool has_button(ButtonHandle button) const
Returns true if the indicated button is in the set of buttons being monitored, false otherwise.
bool button_down(ButtonHandle button)
Records that a particular button has been pressed.
void all_buttons_up()
Marks all monitored buttons as being in the "up" state.
void output(std::ostream &out) const
Writes a one-line summary of the buttons known to be down.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.