Panda3D
mouseRecorder.h
1 // Filename: mouseRecorder.h
2 // Created by: drose (25Jan04)
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 MOUSERECORDER_H
16 #define MOUSERECORDER_H
17 
18 #include "recorderBase.h"
19 #include "dataNode.h"
20 #include "dataNodeTransmit.h"
21 #include "linmath_events.h"
22 #include "buttonEventList.h"
23 
24 class FactoryParams;
25 class BamReader;
26 class BamWriter;
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : MouseRecorder
30 // Description : This object records any data generated by a
31 // particular MouseAndKeyboard node on the datagraph for
32 // a session for eventual playback via a
33 // DataGraphPlayback (and a PlaybackController). To use
34 // it, make it a child of the node you wish to record.
35 // It also serves as a pass-through, so that additional
36 // child nodes may be parented directly to it.
37 ////////////////////////////////////////////////////////////////////
38 class EXPCL_PANDA_RECORDER MouseRecorder : public DataNode, public RecorderBase {
39 PUBLISHED:
40  MouseRecorder(const string &name);
41  virtual ~MouseRecorder();
42 
43 public:
44  virtual void record_frame(BamWriter *manager, Datagram &dg);
45  virtual void play_frame(DatagramIterator &scan, BamReader *manager);
46 
47 public:
48  virtual void output(ostream &out) const;
49  virtual void write(ostream &out, int indent_level = 0) const;
50 
51 protected:
52  // Inherited from DataNode
53  virtual void do_transmit_data(DataGraphTraverser *trav,
54  const DataNodeTransmit &input,
55  DataNodeTransmit &output);
56 
57 private:
58  // inputs
59  int _pixel_xy_input;
60  int _pixel_size_input;
61  int _xy_input;
62  int _button_events_input;
63 
64  // outputs
65  int _pixel_xy_output;
66  int _pixel_size_output;
67  int _xy_output;
68  int _button_events_output;
69 
70  bool _has_mouse;
71  LPoint2 _mouse_xy;
72  LPoint2 _mouse_pixel_xy;
73  PT(ButtonEventList) _live_button_events;
74  PT(ButtonEventList) _save_button_events;
75 
76  PT(EventStoreVec2) _pixel_xy;
77  PT(EventStoreVec2) _xy;
78 
79 public:
80  static void register_with_read_factory();
81  virtual void write_datagram(BamWriter *manager, Datagram &dg);
82  virtual void write_recorder(BamWriter *manager, Datagram &dg);
83 
84  INLINE virtual void ref() const FINAL { ReferenceCount::ref(); };
85  INLINE virtual bool unref() const FINAL { return ReferenceCount::unref(); };
86 
87 protected:
88  static TypedWritable *make_from_bam(const FactoryParams &params);
89  static RecorderBase *make_recorder(const FactoryParams &params);
90  void fillin(DatagramIterator &scan, BamReader *manager);
91  void fillin_recorder(DatagramIterator &scan, BamReader *manager);
92 
93 public:
94  static TypeHandle get_class_type() {
95  return _type_handle;
96  }
97  static void init_type() {
98  DataNode::init_type();
99  RecorderBase::init_type();
100  register_type(_type_handle, "MouseRecorder",
101  DataNode::get_class_type(),
102  RecorderBase::get_class_type());
103  }
104  virtual TypeHandle get_type() const {
105  return get_class_type();
106  }
107  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
108 
109 private:
110  static TypeHandle _type_handle;
111 };
112 
113 #endif
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: dataNode.cxx:347
The fundamental type of node for the data graph.
Definition: dataNode.h:64
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
void write_recorder(BamWriter *manager, Datagram &dg)
This method is provided for the benefit of classes (like MouseRecorder) that inherit from PandaMode a...
Definition: pandaNode.cxx:4201
virtual void play_frame(DatagramIterator &scan, BamReader *manager)
Reloads the most recent data collected from the indicated datagram.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
Definition: pandaNode.cxx:4153
A handy class object for storing simple values (like integers or strings) passed along with an Event ...
Definition: paramValue.h:109
Records a set of button events that happened recently.
This describes the structure of a single array within a Geom data.
virtual void record_frame(BamWriter *manager, Datagram &dg)
Records the most recent data collected into the indicated datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This is the base class to a number of objects that record particular kinds of user input (like a Mous...
Definition: recorderBase.h:55
void ref() const
Explicitly increments the reference count.
This object records any data generated by a particular MouseAndKeyboard node on the datagraph for a s...
Definition: mouseRecorder.h:38
A class to retrieve the individual data elements previously stored in a Datagram. ...
This is a two-component point in space.
Definition: lpoint2.h:92
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
Encapsulates the data generated from (or sent into) any particular DataNode.
virtual bool unref() const
Explicitly decrements the reference count.
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...