33 ButtonThrower(
const string &name) :
36 _button_events_input = define_input(
"button_events", ButtonEventList::get_class_type());
37 _button_events_output = define_output(
"button_events", ButtonEventList::get_class_type());
41 _specific_flag =
true;
43 _throw_buttons_active =
false;
60 _parameters.push_back(obj);
69 get_num_parameters()
const {
70 return _parameters.size();
79 nassertr(n >= 0 && n < (
int)_parameters.size(),
EventParameter(0));
80 return _parameters[n];
105 ThrowButtonDef::iterator di;
106 for (di = def.begin(); di != def.end(); ++di) {
125 ThrowButtons::iterator ti = _throw_buttons.find(button);
126 if (ti == _throw_buttons.end()) {
135 ThrowButtonDef::iterator di;
136 for (di = def.begin(); di != def.end(); ++di) {
140 _throw_buttons.erase(ti);
156 ThrowButtons::const_iterator ti = _throw_buttons.find(button);
157 if (ti == _throw_buttons.end()) {
166 ThrowButtonDef::const_iterator di;
167 for (di = def.begin(); di != def.end(); ++di) {
186 ThrowButtons::const_iterator ti = _throw_buttons.find(button);
187 if (ti == _throw_buttons.end()) {
202 _throw_buttons.clear();
209 write(std::ostream &out,
int indent_level)
const {
210 DataNode::write(out, indent_level);
211 if (_throw_buttons_active) {
213 <<
"Processing keys:\n";
215 ThrowButtons::const_iterator ti;
216 for (ti = _throw_buttons.begin(); ti != _throw_buttons.end(); ++ti) {
219 ThrowButtonDef::const_iterator di;
220 for (di = def.begin(); di != def.end(); ++di) {
221 indent(out, indent_level + 2)
222 << (*di).get_prefix() << button.
get_name() <<
"\n";
233 do_specific_event(
const string &event_name,
double time) {
234 if (_specific_flag) {
235 PT(
Event)
event =
new Event(_prefix + event_name);
238 event->add_parameter(time);
241 ParameterList::const_iterator pi;
242 for (pi = _parameters.begin(); pi != _parameters.end(); ++pi) {
243 event->add_parameter(*pi);
254 do_general_event(
const ButtonEvent &button_event,
const string &button_name) {
256 switch (button_event._type) {
257 case ButtonEvent::T_down:
258 event_name = _button_down_event;
261 case ButtonEvent::T_resume_down:
264 case ButtonEvent::T_up:
265 event_name = _button_up_event;
268 case ButtonEvent::T_repeat:
269 event_name = _button_repeat_event;
272 case ButtonEvent::T_keystroke:
273 event_name = _keystroke_event;
276 case ButtonEvent::T_candidate:
277 event_name = _candidate_event;
280 case ButtonEvent::T_move:
281 event_name = _move_event;
284 case ButtonEvent::T_raw_down:
285 event_name = _raw_button_down_event;
288 case ButtonEvent::T_raw_up:
289 event_name = _raw_button_up_event;
292 if (event_name.empty()) {
300 event->add_parameter(button_event._time);
304 switch (button_event._type) {
305 case ButtonEvent::T_down:
306 case ButtonEvent::T_resume_down:
307 case ButtonEvent::T_up:
308 case ButtonEvent::T_repeat:
309 case ButtonEvent::T_raw_down:
310 case ButtonEvent::T_raw_up:
311 event->add_parameter(button_name);
314 case ButtonEvent::T_keystroke:
315 event->add_parameter(std::wstring(1, button_event._keycode));
318 case ButtonEvent::T_candidate:
319 event->add_parameter(button_event._candidate_string);
322 case ButtonEvent::T_move:
323 event_name = _move_event;
327 ParameterList::const_iterator pi;
328 for (pi = _parameters.begin(); pi != _parameters.end(); ++pi) {
329 event->add_parameter(*pi);
348 _button_events->clear();
350 if (input.
has_data(_button_events_input)) {
352 DCAST_INTO_V(button_events, input.
get_data(_button_events_input).
get_ptr());
355 for (
int i = 0; i < num_events; i++) {
357 string event_name = be._button.
get_name();
359 if (be._type == ButtonEvent::T_down || be._type == ButtonEvent::T_repeat) {
369 if (be._type == ButtonEvent::T_repeat) {
370 do_specific_event(event_name +
"-repeat", be._time);
372 do_specific_event(event_name, be._time);
374 do_general_event(be, event_name);
379 _button_events->add_event(be);
382 }
else if (be._type == ButtonEvent::T_resume_down) {
389 }
else if (be._type == ButtonEvent::T_up) {
396 do_specific_event(event_name +
"-up", be._time);
397 do_general_event(be, event_name);
399 if (_throw_buttons_active) {
404 _button_events->add_event(be);
407 }
else if (be._type == ButtonEvent::T_raw_down) {
411 do_specific_event(
"raw-" + event_name, be._time);
412 do_general_event(be, event_name);
417 _button_events->add_event(be);
420 }
else if (be._type == ButtonEvent::T_raw_up) {
424 do_specific_event(
"raw-" + event_name +
"-up", be._time);
425 do_general_event(be, event_name);
427 if (_throw_buttons_active) {
432 _button_events->add_event(be);
438 _button_events->add_event(be);
439 do_general_event(be,
"");
The fundamental type of node for the data graph.
An optional parameter associated with an event.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool has_data(int index) const
Returns true if the indicated parameter has been stored, false otherwise.
This is our own Panda specialization on the default STL vector.
void set_data(int index, const EventParameter &data)
Sets the data for the indicated parameter.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
TypedWritableReferenceCount * get_ptr() const
Retrieves a pointer to the actual value stored in the parameter.
const EventParameter & get_data(int index) const
Extracts the data for the indicated index, if it has been stored, or the empty parameter if it has no...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A named event, possibly with parameters.
TypeHandle is the identifier used to differentiate C++ class types.
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...