Panda3D
 All Classes Functions Variables Enumerations
buttonThrower.h
1 // Filename: buttonThrower.h
2 // Created by: drose (12Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef BUTTONTHROWER_H
16 #define BUTTONTHROWER_H
17 
18 #include "pandabase.h"
19 
20 #include "dataNode.h"
21 #include "modifierButtons.h"
22 #include "buttonEventList.h"
23 #include "pvector.h"
24 #include "pmap.h"
25 #include "eventParameter.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : ButtonThrower
29 // Description : Throws Panda Events for button down/up events
30 // generated within the data graph.
31 //
32 // This is a DataNode which is intended to be parented
33 // to the data graph below a device which is generating
34 // a sequence of button events, like a MouseAndKeyboard
35 // device. It simply takes each button it finds and
36 // throws a corresponding event based on the button name
37 // via the throw_event() call.
38 ////////////////////////////////////////////////////////////////////
39 class EXPCL_PANDA_TFORM ButtonThrower : public DataNode {
40 PUBLISHED:
41  ButtonThrower(const string &name);
42  ~ButtonThrower();
43 
44  INLINE void set_button_down_event(const string &button_down_event);
45  INLINE const string &get_button_down_event() const;
46  INLINE void set_button_up_event(const string &button_up_event);
47  INLINE const string &get_button_up_event() const;
48  INLINE void set_button_repeat_event(const string &button_repeat_event);
49  INLINE const string &get_button_repeat_event() const;
50  INLINE void set_keystroke_event(const string &keystroke_event);
51  INLINE const string &get_keystroke_event() const;
52  INLINE void set_candidate_event(const string &candidate_event);
53  INLINE const string &get_candidate_event() const;
54  INLINE void set_move_event(const string &move_event);
55  INLINE const string &get_move_event() const;
56  INLINE void set_raw_button_down_event(const string &raw_button_down_event);
57  INLINE const string &get_raw_button_down_event() const;
58  INLINE void set_raw_button_up_event(const string &raw_button_up_event);
59  INLINE const string &get_raw_button_up_event() const;
60 
61  INLINE void set_prefix(const string &prefix);
62  INLINE const string &get_prefix() const;
63  INLINE void set_specific_flag(bool specific_flag);
64  INLINE bool get_specific_flag() const;
65 
66  INLINE void set_time_flag(bool time_flag);
67  INLINE bool get_time_flag() const;
68 
69  void add_parameter(const EventParameter &obj);
70  int get_num_parameters() const;
71  EventParameter get_parameter(int n) const;
72  MAKE_SEQ(get_parameters, get_num_parameters, get_parameter);
73 
74  INLINE const ModifierButtons &get_modifier_buttons() const;
75  INLINE void set_modifier_buttons(const ModifierButtons &mods);
76 
77  INLINE void set_throw_buttons_active(bool flag);
78  INLINE bool get_throw_buttons_active() const;
79 
80  bool add_throw_button(const ModifierButtons &mods, const ButtonHandle &button);
81  bool remove_throw_button(const ModifierButtons &mods, const ButtonHandle &button);
82  bool has_throw_button(const ModifierButtons &mods, const ButtonHandle &button) const;
83  bool has_throw_button(const ButtonHandle &button) const;
84  void clear_throw_buttons();
85 
86 public:
87  virtual void write(ostream &out, int indent_level = 0) const;
88 
89 private:
90  void do_specific_event(const string &event_name, double time);
91  void do_general_event(const ButtonEvent &button_event,
92  const string &event_name);
93 
94 private:
95  string _button_down_event;
96  string _button_up_event;
97  string _button_repeat_event;
98  string _keystroke_event;
99  string _candidate_event;
100  string _move_event;
101  string _raw_button_up_event;
102  string _raw_button_down_event;
103  bool _specific_flag;
104  string _prefix;
105  bool _time_flag;
106  ModifierButtons _mods;
107 
109  ParameterList _parameters;
110 
113  ThrowButtons _throw_buttons;
114  bool _throw_buttons_active;
115 
116 protected:
117  // Inherited from DataNode
118  virtual void do_transmit_data(DataGraphTraverser *trav,
119  const DataNodeTransmit &input,
120  DataNodeTransmit &output);
121 
122 private:
123  // inputs
124  int _button_events_input;
125 
126  // outputs
127  int _button_events_output;
128  PT(ButtonEventList) _button_events;
129 
130 public:
131  static TypeHandle get_class_type() {
132  return _type_handle;
133  }
134  static void init_type() {
135  DataNode::init_type();
136  register_type(_type_handle, "ButtonThrower",
137  DataNode::get_class_type());
138  }
139  virtual TypeHandle get_type() const {
140  return get_class_type();
141  }
142  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
143 
144 private:
145  static TypeHandle _type_handle;
146 };
147 
148 #include "buttonThrower.I"
149 
150 #endif
The fundamental type of node for the data graph.
Definition: dataNode.h:64
This class monitors the state of a number of individual buttons and tracks whether each button is kno...
An optional parameter associated with an event.
Records a button event of some kind.
Definition: buttonEvent.h:53
Records a set of button events that happened recently.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
Throws Panda Events for button down/up events generated within the data graph.
Definition: buttonThrower.h:39
Encapsulates the data generated from (or sent into) any particular DataNode.
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...