Panda3D
AwMouseAndKeyboard.cxx
1 // Filename: AwMouseAndKeyboard.cxx
2 // Created by: Bei Yang (Mar2010)
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 #include "config_awesomium.h"
16 #include "AwMouseAndKeyboard.h"
17 #include "dataNodeTransmit.h"
18 
19 TypeHandle AwMouseAndKeyboard::_type_handle;
20 
21 AwMouseAndKeyboard::AwMouseAndKeyboard(const string &name):
22 DataNode(name)
23 {
24  _button_events_input = define_input("button_events", ButtonEventList::get_class_type());
25  _button_events_output = define_output("button_events", ButtonEventList::get_class_type());
26 }
27 
28 
29 void AwMouseAndKeyboard::do_transmit_data(DataGraphTraverser *trav, const DataNodeTransmit &input, DataNodeTransmit &output){
30 
31  if (input.has_data(_button_events_input)) {
32  const ButtonEventList *button_events;
33  DCAST_INTO_V(button_events, input.get_data(_button_events_input).get_ptr());
34 
35  int num_events = button_events->get_num_events();
36  for (int i = 0; i < num_events; i++) {
37  const ButtonEvent &be = button_events->get_event(i);
38  string event_name = be._button.get_name();
39  printf("Button Event! : %s with code %i and index %i ", event_name.c_str(), be._keycode, be._button.get_index());
40  if(be._type == ButtonEvent::T_down) printf("down");
41  if(be._type == ButtonEvent::T_repeat) printf("repeat");
42  if(be._type == ButtonEvent::T_up) printf("up");
43  if(be._type == ButtonEvent::T_resume_down) printf("T_resume_down");
44  printf("\n");
45  }
46  }
47 
48 }
The fundamental type of node for the data graph.
Definition: dataNode.h:64
int get_num_events() const
Returns the number of events in the list.
Records a button event of some kind.
Definition: buttonEvent.h:53
bool has_data(int index) const
Returns true if the indicated parameter has been stored, false otherwise.
Records a set of button events that happened recently.
int get_index() const
Returns the integer index associated with this ButtonHandle.
Definition: buttonHandle.I:184
string get_name() const
Returns the name of the button.
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...
const ButtonEvent & get_event(int n) const
Returns the nth event in the list.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
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...