root/juggler/branches/2.2/modules/gadgeteer/gadget/Type/KeyboardMouse/Event.h
| Revision 19841, 4.0 kB (checked in by patrick, 2 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /*************** <auto-copyright.pl BEGIN do not edit this line> ************** |
| 2 | * |
| 3 | * VR Juggler is (C) Copyright 1998-2007 by Iowa State University |
| 4 | * |
| 5 | * Original Authors: |
| 6 | * Allen Bierbaum, Christopher Just, |
| 7 | * Patrick Hartling, Kevin Meinert, |
| 8 | * Carolina Cruz-Neira, Albert Baker |
| 9 | * |
| 10 | * This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Library General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Library General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Library General Public |
| 21 | * License along with this library; if not, write to the |
| 22 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | * Boston, MA 02111-1307, USA. |
| 24 | * |
| 25 | *************** <auto-copyright.pl END do not edit this line> ***************/ |
| 26 | |
| 27 | #ifndef _GADGET_EVENT_H_ |
| 28 | #define _GADGET_EVENT_H_ |
| 29 | |
| 30 | #include <gadget/gadgetConfig.h> |
| 31 | #include <vpr/IO/SerializableObject.h> |
| 32 | |
| 33 | #include <gadget/Type/KeyboardMouse/EventPtr.h> |
| 34 | |
| 35 | namespace gadget |
| 36 | { |
| 37 | |
| 38 | /** Possible event types. */ |
| 39 | enum EventType |
| 40 | { |
| 41 | NoEvent = 0, /**< No event */ |
| 42 | KeyPressEvent = 1, /**< Key press event */ |
| 43 | KeyReleaseEvent = 2, /**< Key release event */ |
| 44 | MouseButtonPressEvent = 3, /**< Mouse button press event */ |
| 45 | MouseButtonReleaseEvent = 4, /**< Mouse button release event */ |
| 46 | MouseMoveEvent = 5 /**< Mouse move event */ |
| 47 | }; |
| 48 | |
| 49 | /** \class Event Event.h gadget/Type/KeyboardMouse/Event.h |
| 50 | * |
| 51 | * Base event type that an event source may generate. This class cannot be |
| 52 | * instantiated directly, and instead, subclasses must be used. |
| 53 | */ |
| 54 | class GADGET_CLASS_API Event : public vpr::SerializableObject |
| 55 | { |
| 56 | public: |
| 57 | /** |
| 58 | * Returns the type of this event. This can be used for dynamic casting |
| 59 | * to more specific event types. |
| 60 | */ |
| 61 | const EventType type() const |
| 62 | { |
| 63 | return mType; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Sets the type of this event. This is needed because, while using an |
| 68 | * object reader to de-serialize an Event object, we cannot set the type |
| 69 | * during construction. We must set the event type after creating |
| 70 | * this event using the EventFactory. This could later be removed if |
| 71 | * the EventFactory is chaged to take care of this. |
| 72 | */ |
| 73 | void setType(const EventType type) |
| 74 | { |
| 75 | mType = type; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Returns the time at which the event occurred. |
| 80 | */ |
| 81 | const unsigned long time() const |
| 82 | { |
| 83 | return mTime; |
| 84 | } |
| 85 | |
| 86 | virtual ~Event() |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Serializes this object into the given object writer. |
| 92 | * |
| 93 | * @param writer The object writer to which this object will be serialized. |
| 94 | * |
| 95 | * @throw vpr::IOException is thrown if serialization fails. |
| 96 | */ |
| 97 | virtual void writeObject(vpr::ObjectWriter* writer); |
| 98 | |
| 99 | /** |
| 100 | * De-serializes this object. |
| 101 | * |
| 102 | * @param reader The object reader from which this object will be |
| 103 | * de-serialized. |
| 104 | * |
| 105 | * @throw vpr::IOException is thrown if de-serialization fails. |
| 106 | */ |
| 107 | virtual void readObject(vpr::ObjectReader* reader); |
| 108 | |
| 109 | protected: |
| 110 | /** |
| 111 | * Initializes data members. |
| 112 | * |
| 113 | * @param type The type of this event from the Event::Type enumeration. |
| 114 | * @param time The time at which this event occurred. This should be as |
| 115 | * accurate as possible, preferabbly acquired from the |
| 116 | * operating system or windowing system event data structure. |
| 117 | * The time at which the event was processed is not an |
| 118 | * acceptable value. |
| 119 | */ |
| 120 | Event(const EventType type, const unsigned long time) |
| 121 | : mType(type), mTime(time) |
| 122 | { |
| 123 | } |
| 124 | |
| 125 | EventType mType; /**< The event type. */ |
| 126 | unsigned long mTime; /**< Time at which the event occurred. */ |
| 127 | }; |
| 128 | |
| 129 | } |
| 130 | |
| 131 | |
| 132 | #endif /* _GADGET_EVENT_H_ */ |
Note: See TracBrowser for help on using the browser.
