Panda3D
Loading...
Searching...
No Matches
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 */
35class EXPCL_PANDA_TFORM ButtonThrower : public DataNode {
36PUBLISHED:
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;
95
96public:
97 virtual void write(std::ostream &out, int indent_level = 0) const;
98
99private:
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
104private:
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
118 typedef pvector<EventParameter> ParameterList;
119 ParameterList _parameters;
120
121 typedef pvector<ModifierButtons> ThrowButtonDef;
122 typedef pmap<ButtonHandle, ThrowButtonDef> ThrowButtons;
123 ThrowButtons _throw_buttons;
124 bool _throw_buttons_active;
125
126protected:
127 // Inherited from DataNode
128 virtual void do_transmit_data(DataGraphTraverser *trav,
129 const DataNodeTransmit &input,
130 DataNodeTransmit &output);
131
132private:
133 // inputs
134 int _button_events_input;
135
136 // outputs
137 int _button_events_output;
138 PT(ButtonEventList) _button_events;
139
140public:
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
154private:
155 static TypeHandle _type_handle;
156};
157
158#include "buttonThrower.I"
159
160#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Records a set of button events that happened recently.
Records a button event of some kind.
Definition buttonEvent.h:49
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
get_time_flag
Returns the flag that indicates whether the time of the button event should be passed as a parameter.
set_time_flag
Sets the flag that indicates whether the time of the button event should be passed as a parameter or ...
get_specific_flag
Returns the flag that indicates whether specific events should be generated.
get_raw_button_down_event
Returns the raw_button_down_event that has been set on this ButtonThrower.
get_prefix
Returns the prefix that has been set on this ButtonThrower.
get_raw_button_up_event
Returns the raw_button_up_event that has been set on this ButtonThrower.
get_button_up_event
Returns the button_up_event that has been set on this ButtonThrower.
get_keystroke_event
Returns the keystroke_event that has been set on this ButtonThrower.
set_candidate_event
Specifies the event that is generated (if any) for each IME candidate string event received.
set_throw_buttons_active
Sets the flag that indicates whether the ButtonThrower will only process events for the explicitly na...
bool has_throw_button(const ModifierButtons &mods, const ButtonHandle &button) const
Returns true if the indicated button is on the set of buttons that will be processed by the ButtonThr...
get_num_parameters
Returns the number of parameters that have been added to the list of parameters to be passed with eac...
set_button_up_event
Specifies the generic event that is generated (if any) each time a key or button is released.
set_button_down_event
Specifies the generic event that is generated (if any) each time a key or button is depressed.
bool add_throw_button(const ModifierButtons &mods, const ButtonHandle &button)
Adds a new button to the set of buttons that the ButtonThrower explicitly processes.
get_button_repeat_event
Returns the button_repeat_event that has been set on this ButtonThrower.
set_modifier_buttons
Changes the set of ModifierButtons that the ButtonThrower will consider important enough to prepend t...
get_modifier_buttons
Returns the set of ModifierButtons that the ButtonThrower will consider important enough to prepend t...
set_specific_flag
Sets the flag that indicates whether specific events (events prefixed by set_prefix,...
set_raw_button_down_event
Like set_button_down_event, but uses the raw, untransformed scan key from the operating system.
set_move_event
Specifies the event that is generated (if any) each time the mouse is moved within the window.
get_throw_buttons_active
Returns the flag that indicates whether the ButtonThrower will only process events for the explicitly...
void clear_throw_buttons()
Empties the set of buttons that were added via add_throw_button().
set_button_repeat_event
Specifies the generic event that is generated (if any) repeatedly while a key or button is held down.
set_keystroke_event
Specifies the event that is generated (if any) for each keystroke that is received.
bool remove_throw_button(const ModifierButtons &mods, const ButtonHandle &button)
Removes the indicated button from the set of buttons that the ButtonThrower explicitly processes.
get_candidate_event
Returns the candidate_event that has been set on this ButtonThrower.
get_button_down_event
Returns the button_down_event that has been set on this ButtonThrower.
set_raw_button_up_event
Specifies the generic event that is generated (if any) each time a key or button is released.
set_prefix
Sets the prefix which is prepended to all specific event names (that is, event names generated from t...
virtual void write(std::ostream &out, int indent_level=0) const
Throw all events for button events found in the data element.
void add_parameter(const EventParameter &obj)
Adds the indicated parameter to the list of parameters that will be passed with each event generated ...
get_parameter
Returns the nth parameter that has been added to the list of parameters passed with each event genera...
get_move_event
Returns the move_event that has been set on this ButtonThrower.
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...
Encapsulates the data generated from (or sent into) any particular DataNode.
An optional parameter associated with an event.
This class monitors the state of a number of individual buttons and tracks whether each button is kno...
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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(),...