mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
Adding pointer events (ie, mouse movement)
This commit is contained in:
parent
5e149d9694
commit
14b7dd6d25
@ -2,4 +2,6 @@
|
||||
#include "asyncTaskManager.cxx"
|
||||
#include "buttonEvent.cxx"
|
||||
#include "buttonEventList.cxx"
|
||||
#include "pointerEvent.cxx"
|
||||
#include "pointerEventList.cxx"
|
||||
#include "config_event.cxx"
|
||||
|
112
panda/src/event/pointerEvent.I
Normal file
112
panda/src/event/pointerEvent.I
Normal file
@ -0,0 +1,112 @@
|
||||
// Filename: pointerEvent.I
|
||||
// Created by: jyelon (20Sep2007)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEvent::Default Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PointerEvent::
|
||||
PointerEvent() :
|
||||
_pointer(-1),
|
||||
_time(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEvent::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PointerEvent::
|
||||
PointerEvent(int pointer, const MouseData &data, double time) :
|
||||
_pointer(pointer),
|
||||
_data(data),
|
||||
_time(time)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEvent::Copy Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PointerEvent::
|
||||
PointerEvent(const PointerEvent ©) :
|
||||
_pointer(copy._pointer),
|
||||
_data(copy._data),
|
||||
_time(copy._time)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEvent::Copy Assignment Operator
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PointerEvent::
|
||||
operator = (const PointerEvent ©) {
|
||||
_pointer = copy._pointer;
|
||||
_data = copy._data;
|
||||
_time = copy._time;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEvent::Equality Operator
|
||||
// Access: Public
|
||||
// Description: The equality operator does not consider time
|
||||
// significant.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool PointerEvent::
|
||||
operator == (const PointerEvent &other) const {
|
||||
return (_pointer == other._pointer &&
|
||||
_data._xpos == other._data._xpos &&
|
||||
_data._ypos == other._data._ypos &&
|
||||
_data._in_window == other._data._in_window);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEvent::Inequality Operator
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool PointerEvent::
|
||||
operator != (const PointerEvent &other) const {
|
||||
return !operator == (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEvent::Ordering Operator
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool PointerEvent::
|
||||
operator < (const PointerEvent &other) const {
|
||||
if (_pointer != other._pointer) {
|
||||
return _pointer < other._pointer;
|
||||
}
|
||||
if (_data._xpos != other._data._xpos) {
|
||||
return _data._xpos < other._data._xpos;
|
||||
}
|
||||
if (_data._ypos != other._data._ypos) {
|
||||
return _data._ypos < other._data._ypos;
|
||||
}
|
||||
return _data._in_window < other._data._in_window;
|
||||
}
|
||||
|
60
panda/src/event/pointerEvent.cxx
Normal file
60
panda/src/event/pointerEvent.cxx
Normal file
@ -0,0 +1,60 @@
|
||||
// Filename: pointerEvent.cxx
|
||||
// Created by: drose (01Mar00)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "pointerEvent.h"
|
||||
#include "datagram.h"
|
||||
#include "datagramIterator.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEvent::output
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PointerEvent::
|
||||
output(ostream &out) const {
|
||||
out << "pointer " << _pointer << " to "
|
||||
<< _data._xpos << "," << _data._ypos
|
||||
<< (_data._in_window ? " in" : " out");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEvent::write_datagram
|
||||
// Access: Public
|
||||
// Description: Writes the event into a datagram.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PointerEvent::
|
||||
write_datagram(Datagram &dg) const {
|
||||
dg.add_int8(_pointer);
|
||||
dg.add_bool(_data._in_window);
|
||||
dg.add_int32(_data._xpos);
|
||||
dg.add_int32(_data._ypos);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEvent::read_datagram
|
||||
// Access: Public
|
||||
// Description: Restores the event from the datagram.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PointerEvent::
|
||||
read_datagram(DatagramIterator &scan) {
|
||||
_pointer = scan.get_int8();
|
||||
_data._in_window = scan.get_bool();
|
||||
_data._xpos = scan.get_int32();
|
||||
_data._ypos = scan.get_int32();
|
||||
_time = 0.0;
|
||||
}
|
63
panda/src/event/pointerEvent.h
Normal file
63
panda/src/event/pointerEvent.h
Normal file
@ -0,0 +1,63 @@
|
||||
// Filename: pointerEvent.h
|
||||
// Created by: jyelon (20Sep2007)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef POINTEREVENT_H
|
||||
#define POINTEREVENT_H
|
||||
|
||||
#include "pandabase.h"
|
||||
#include "mouseData.h"
|
||||
|
||||
class Datagram;
|
||||
class DatagramIterator;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : PointerEvent
|
||||
// Description : Records a pointer movement event.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA_EVENT PointerEvent {
|
||||
public:
|
||||
|
||||
INLINE PointerEvent();
|
||||
INLINE PointerEvent(const PointerEvent ©);
|
||||
INLINE PointerEvent(int pointer, const MouseData &data, double time);
|
||||
INLINE void operator = (const PointerEvent ©);
|
||||
|
||||
INLINE bool operator == (const PointerEvent &other) const;
|
||||
INLINE bool operator != (const PointerEvent &other) const;
|
||||
INLINE bool operator < (const PointerEvent &other) const;
|
||||
|
||||
void output(ostream &out) const;
|
||||
|
||||
void write_datagram(Datagram &dg) const;
|
||||
void read_datagram(DatagramIterator &scan);
|
||||
|
||||
public:
|
||||
int _pointer;
|
||||
MouseData _data;
|
||||
double _time;
|
||||
};
|
||||
|
||||
INLINE ostream &operator << (ostream &out, const PointerEvent &pe) {
|
||||
pe.output(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
#include "pointerEvent.I"
|
||||
|
||||
#endif
|
||||
|
95
panda/src/event/pointerEventList.I
Normal file
95
panda/src/event/pointerEventList.I
Normal file
@ -0,0 +1,95 @@
|
||||
// Filename: pointerEventList.I
|
||||
// Created by: jyelon (20Sep2007)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PointerEventList::
|
||||
PointerEventList() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::Copy Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PointerEventList::
|
||||
PointerEventList(const PointerEventList ©) :
|
||||
_events(copy._events)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::Copy Assignment Operator
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PointerEventList::
|
||||
operator = (const PointerEventList ©) {
|
||||
_events = copy._events;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::add_event
|
||||
// Access: Public
|
||||
// Description: Adds a new event to the end of the list.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PointerEventList::
|
||||
add_event(const PointerEvent &event) {
|
||||
_events.push_back(event);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::get_num_events
|
||||
// Access: Public
|
||||
// Description: Returns the number of events in the list.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int PointerEventList::
|
||||
get_num_events() const {
|
||||
return _events.size();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::get_event
|
||||
// Access: Public
|
||||
// Description: Returns the nth event in the list. This does not
|
||||
// remove the event from the list; the only way to
|
||||
// remove events is to empty the whole list with
|
||||
// clear().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const PointerEvent &PointerEventList::
|
||||
get_event(int n) const {
|
||||
#ifndef NDEBUG
|
||||
static PointerEvent empty_event;
|
||||
nassertr(n >= 0 && n < (int)_events.size(), empty_event);
|
||||
#endif // NDEBUG
|
||||
return _events[n];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::clear
|
||||
// Access: Public
|
||||
// Description: Empties all the events from the list.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PointerEventList::
|
||||
clear() {
|
||||
_events.clear();
|
||||
}
|
147
panda/src/event/pointerEventList.cxx
Normal file
147
panda/src/event/pointerEventList.cxx
Normal file
@ -0,0 +1,147 @@
|
||||
// Filename: pointerEventList.cxx
|
||||
// Created by: jyelon (20Sep2007)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "pointerEventList.h"
|
||||
#include "indent.h"
|
||||
|
||||
TypeHandle PointerEventList::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::add_events
|
||||
// Access: Public
|
||||
// Description: Appends the events from the other list onto the end
|
||||
// of this one.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PointerEventList::
|
||||
add_events(const PointerEventList &other) {
|
||||
_events.reserve(_events.size() + other._events.size());
|
||||
Events::const_iterator ei;
|
||||
for (ei = other._events.begin(); ei != other._events.end(); ++ei) {
|
||||
_events.push_back(*ei);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::output
|
||||
// Access: Public, Virtual
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PointerEventList::
|
||||
output(ostream &out) const {
|
||||
if (_events.empty()) {
|
||||
out << "(no pointers)";
|
||||
} else {
|
||||
Events::const_iterator ei;
|
||||
ei = _events.begin();
|
||||
out << "(" << (*ei);
|
||||
++ei;
|
||||
while (ei != _events.end()) {
|
||||
out << " " << (*ei);
|
||||
++ei;
|
||||
}
|
||||
out << ")";
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::write
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PointerEventList::
|
||||
write(ostream &out, int indent_level) const {
|
||||
indent(out, indent_level) << _events.size() << " events:\n";
|
||||
Events::const_iterator ei;
|
||||
for (ei = _events.begin(); ei != _events.end(); ++ei) {
|
||||
indent(out, indent_level + 2) << (*ei) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::register_with_read_factory
|
||||
// Access: Public, Static
|
||||
// Description: Tells the BamReader how to create objects of type
|
||||
// Lens.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PointerEventList::
|
||||
register_with_read_factory() {
|
||||
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::write_datagram
|
||||
// Access: Public, Virtual
|
||||
// Description: Writes the contents of this object to the datagram
|
||||
// for shipping out to a Bam file.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PointerEventList::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
TypedWritable::write_datagram(manager, dg);
|
||||
|
||||
dg.add_uint16(_events.size());
|
||||
Events::const_iterator ei;
|
||||
for (ei = _events.begin(); ei != _events.end(); ++ei) {
|
||||
(*ei).write_datagram(dg);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::make_from_bam
|
||||
// Access: Protected, Static
|
||||
// Description: This function is called by the BamReader's factory
|
||||
// when a new object of type Lens is encountered
|
||||
// in the Bam file. It should create the Lens
|
||||
// and extract its information from the file.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
TypedWritable *PointerEventList::
|
||||
make_from_bam(const FactoryParams ¶ms) {
|
||||
PointerEventList *list = new PointerEventList;
|
||||
DatagramIterator scan;
|
||||
BamReader *manager;
|
||||
|
||||
parse_params(params, scan, manager);
|
||||
list->fillin(scan, manager);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerEventList::fillin
|
||||
// Access: Public
|
||||
// Description: This internal function is called by make_from_bam to
|
||||
// read in all of the relevant data from the BamFile for
|
||||
// the new PointerEventList.
|
||||
//
|
||||
// This function is normally protected, but it is
|
||||
// declared public in this case so that MouseRecorder
|
||||
// may call it to read a PointerEventList from the middle
|
||||
// of a datagram.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PointerEventList::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
TypedWritable::fillin(scan, manager);
|
||||
|
||||
int num_events = scan.get_uint16();
|
||||
_events.clear();
|
||||
_events.reserve(num_events);
|
||||
for (int i = 0; i < num_events; i++) {
|
||||
PointerEvent event;
|
||||
event.read_datagram(scan);
|
||||
_events.push_back(event);
|
||||
}
|
||||
}
|
97
panda/src/event/pointerEventList.h
Normal file
97
panda/src/event/pointerEventList.h
Normal file
@ -0,0 +1,97 @@
|
||||
// Filename: pointerEventList.h
|
||||
// Created by: drose (12Mar02)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef POINTEREVENTLIST_H
|
||||
#define POINTEREVENTLIST_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "pointerEvent.h"
|
||||
#include "typedReferenceCount.h"
|
||||
#include "eventParameter.h"
|
||||
#include "pvector.h"
|
||||
|
||||
class ModifierPointers;
|
||||
class Datagram;
|
||||
class DatagramIterator;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : PointerEventList
|
||||
// Description : Records a set of pointer events that happened
|
||||
// recently. This class is usually used only in the
|
||||
// data graph, to transmit the recent pointer presses,
|
||||
// but it may be used anywhere a list of PointerEvents
|
||||
// is desired.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA_EVENT PointerEventList : public EventStoreValueBase {
|
||||
public:
|
||||
INLINE PointerEventList();
|
||||
INLINE PointerEventList(const PointerEventList ©);
|
||||
INLINE void operator = (const PointerEventList ©);
|
||||
|
||||
INLINE void add_event(const PointerEvent &event);
|
||||
INLINE int get_num_events() const;
|
||||
INLINE const PointerEvent &get_event(int n) const;
|
||||
INLINE void clear();
|
||||
|
||||
void add_events(const PointerEventList &other);
|
||||
|
||||
virtual void output(ostream &out) const;
|
||||
void write(ostream &out, int indent_level = 0) const;
|
||||
|
||||
private:
|
||||
typedef pvector<PointerEvent> Events;
|
||||
Events _events;
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &dg);
|
||||
|
||||
protected:
|
||||
static TypedWritable *make_from_bam(const FactoryParams ¶ms);
|
||||
|
||||
public:
|
||||
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
EventStoreValueBase::init_type();
|
||||
register_type(_type_handle, "PointerEventList",
|
||||
EventStoreValueBase::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
INLINE ostream &operator << (ostream &out, const PointerEventList &pointerlist) {
|
||||
pointerlist.output(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
#include "pointerEventList.I"
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user