Panda3D
buttonThrower.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 buttonThrower.h
10  * @author drose
11  * @date 2002-03-12
12  */
13 
14 #ifndef BUTTONTHROWER_H
15 #define BUTTONTHROWER_H
16 
17 #include "pandabase.h"
18 
19 #include "dataNode.h"
20 #include "modifierButtons.h"
21 #include "buttonEventList.h"
22 #include "pvector.h"
23 #include "pmap.h"
24 #include "eventParameter.h"
25 
26 /**
27  * Throws Panda Events for button down/up events generated within the data
28  * graph.
29  *
30  * This is a DataNode which is intended to be parented to the data graph below
31  * a device which is generating a sequence of button events, like a
32  * MouseAndKeyboard device. It simply takes each button it finds and throws a
33  * corresponding event based on the button name via the throw_event() call.
34  */
35 class EXPCL_PANDA_TFORM ButtonThrower : public DataNode {
36 PUBLISHED:
37  explicit ButtonThrower(const std::string &name);
38  ~ButtonThrower();
39 
40  INLINE void set_button_down_event(const std::string &button_down_event);
41  INLINE const std::string &get_button_down_event() const;
42  INLINE void set_button_up_event(const std::string &button_up_event);
43  INLINE const std::string &get_button_up_event() const;
44  INLINE void set_button_repeat_event(const std::string &button_repeat_event);
45  INLINE const std::string &get_button_repeat_event() const;
46  INLINE void set_keystroke_event(const std::string &keystroke_event);
47  INLINE const std::string &get_keystroke_event() const;
48  INLINE void set_candidate_event(const std::string &candidate_event);
49  INLINE const std::string &get_candidate_event() const;
50  INLINE void set_move_event(const std::string &move_event);
51  INLINE const std::string &get_move_event() const;
52  INLINE void set_raw_button_down_event(const std::string &raw_button_down_event);
53  INLINE const std::string &get_raw_button_down_event() const;
54  INLINE void set_raw_button_up_event(const std::string &raw_button_up_event);
55  INLINE const std::string &get_raw_button_up_event() const;
56  MAKE_PROPERTY(button_down_event, get_button_down_event, set_button_down_event);
57  MAKE_PROPERTY(button_up_event, get_button_up_event, set_button_up_event);
58  MAKE_PROPERTY(button_repeat_event, get_button_repeat_event, set_button_repeat_event);
59  MAKE_PROPERTY(keystroke_event, get_keystroke_event, set_keystroke_event);
60  MAKE_PROPERTY(candidate_event, get_candidate_event, set_candidate_event);
61  MAKE_PROPERTY(move_event, get_move_event, set_move_event);
62  MAKE_PROPERTY(raw_button_down_event, get_raw_button_down_event, set_raw_button_down_event);
63  MAKE_PROPERTY(raw_button_up_event, get_raw_button_up_event, set_raw_button_up_event);
64 
65  INLINE void set_prefix(const std::string &prefix);
66  INLINE const std::string &get_prefix() const;
67  INLINE void set_specific_flag(bool specific_flag);
68  INLINE bool get_specific_flag() const;
69  MAKE_PROPERTY(prefix, get_prefix, set_prefix);
70  MAKE_PROPERTY(specific_flag, get_specific_flag, set_specific_flag);
71 
72  INLINE void set_time_flag(bool time_flag);
73  INLINE bool get_time_flag() const;
74  MAKE_PROPERTY(time_flag, get_time_flag, set_time_flag);
75 
76  void add_parameter(const EventParameter &obj);
77  int get_num_parameters() const;
78  EventParameter get_parameter(int n) const;
79  MAKE_SEQ(get_parameters, get_num_parameters, get_parameter);
80  MAKE_SEQ_PROPERTY(parameters, get_num_parameters, get_parameter);
81 
82  INLINE const ModifierButtons &get_modifier_buttons() const;
83  INLINE void set_modifier_buttons(const ModifierButtons &mods);
84  MAKE_PROPERTY(modifier_buttons, get_modifier_buttons, set_modifier_buttons);
85 
86  INLINE void set_throw_buttons_active(bool flag);
87  INLINE bool get_throw_buttons_active() const;
88  MAKE_PROPERTY(throw_buttons_active, get_throw_buttons_active, set_throw_buttons_active);
89 
90  bool add_throw_button(const ModifierButtons &mods, const ButtonHandle &button);
91  bool remove_throw_button(const ModifierButtons &mods, const ButtonHandle &button);
92  bool has_throw_button(const ModifierButtons &mods, const ButtonHandle &button) const;
93  bool has_throw_button(const ButtonHandle &button) const;
94  void clear_throw_buttons();
95 
96 public:
97  virtual void write(std::ostream &out, int indent_level = 0) const;
98 
99 private:
100  void do_specific_event(const std::string &event_name, double time);
101  void do_general_event(const ButtonEvent &button_event,
102  const std::string &event_name);
103 
104 private:
105  std::string _button_down_event;
106  std::string _button_up_event;
107  std::string _button_repeat_event;
108  std::string _keystroke_event;
109  std::string _candidate_event;
110  std::string _move_event;
111  std::string _raw_button_up_event;
112  std::string _raw_button_down_event;
113  bool _specific_flag;
114  std::string _prefix;
115  bool _time_flag;
116  ModifierButtons _mods;
117 
119  ParameterList _parameters;
120 
123  ThrowButtons _throw_buttons;
124  bool _throw_buttons_active;
125 
126 protected:
127  // Inherited from DataNode
128  virtual void do_transmit_data(DataGraphTraverser *trav,
129  const DataNodeTransmit &input,
130  DataNodeTransmit &output);
131 
132 private:
133  // inputs
134  int _button_events_input;
135 
136  // outputs
137  int _button_events_output;
138  PT(ButtonEventList) _button_events;
139 
140 public:
141  static TypeHandle get_class_type() {
142  return _type_handle;
143  }
144  static void init_type() {
145  DataNode::init_type();
146  register_type(_type_handle, "ButtonThrower",
147  DataNode::get_class_type());
148  }
149  virtual TypeHandle get_type() const {
150  return get_class_type();
151  }
152  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
153 
154 private:
155  static TypeHandle _type_handle;
156 };
157 
158 #include "buttonThrower.I"
159 
160 #endif
The fundamental type of node for the data graph.
Definition: dataNode.h:52
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Records a button event of some kind.
Definition: buttonEvent.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:26
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
Throws Panda Events for button down/up events generated within the data graph.
Definition: buttonThrower.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...