Panda3D
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  */
26 class EXPCL_PANDA_PUTIL ModifierButtons {
27 PUBLISHED:
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 
69 private:
70  void modify_button_list();
71 
72  PTA(ButtonHandle) _button_list;
73  typedef unsigned long BitmaskType;
74  BitmaskType _state;
75 };
76 
77 INLINE 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
ModifierButtons
This class monitors the state of a number of individual buttons and tracks whether each button is kno...
Definition: modifierButtons.h:26
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ButtonHandle
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26
modifierButtons.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
buttonHandle.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerToArray.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ModifierButtons::output
void output(std::ostream &out) const
Writes a one-line summary of the buttons known to be down.
Definition: modifierButtons.cxx:322