Sirikata
libogre/include/sirikata/ogre/input/InputEvents.hpp
Go to the documentation of this file.
00001 /*  Sirikata libproxyobject -- Ogre Graphics Plugin
00002  *  InputEvents.hpp
00003  *
00004  *  Copyright (c) 2009, Daniel Reiter Horn
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions are
00009  *  met:
00010  *  * Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  *  * Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in
00014  *    the documentation and/or other materials provided with the
00015  *    distribution.
00016  *  * Neither the name of Sirikata nor the names of its contributors may
00017  *    be used to endorse or promote products derived from this software
00018  *    without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00021  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00022  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00023  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00024  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00026  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  */
00032 
00033 #ifndef SIRIKATA_INPUT_InputEvents_HPP__
00034 #define SIRIKATA_INPUT_InputEvents_HPP__
00035 
00036 #include <sirikata/ogre/input/InputDevice.hpp>
00037 
00038 namespace Sirikata {
00039 
00040 namespace Graphics {
00041 class WebView;
00042 }
00043 
00044 namespace Input {
00045 
00046 using Graphics::WebView;
00047 
00052 class SIRIKATA_OGRE_EXPORT InputEvent {
00053     InputDeviceWPtr mDevice;
00054 
00055 public:
00056     InputEvent(const InputDeviceWPtr &dev)
00057         : mDevice(dev)
00058     {
00059     }
00060     virtual ~InputEvent() {}
00061 
00062     InputDevicePtr getDevice() const {
00063         return mDevice.lock();
00064     }
00065 };
00066 typedef std::tr1::shared_ptr<InputEvent> InputEventPtr;
00067 
00069 class SIRIKATA_OGRE_EXPORT ButtonEvent : public InputEvent {
00070 public:
00071     KeyEvent mEvent; 
00072     KeyButton mButton; 
00073     Modifier mModifier; 
00074 
00075     virtual ~ButtonEvent(){}
00076     ButtonEvent(const InputDevicePtr &dev,
00077         KeyEvent event, unsigned int key, Modifier mod)
00078         : InputEvent(dev),
00079         mEvent(event),
00080         mButton(key),
00081         mModifier(mod)
00082         {
00083     }
00084 
00085     // Indicates if the button was in the depressed state.
00086     bool pressed() {
00087         return ( (mEvent == KEY_PRESSED) || (mEvent == KEY_DOWN) || (mEvent == KEY_REPEATED) );
00088     }
00089     // Indicates if the button was actively pressed, i.e. was pushed down
00090     // instead of just held down
00091     bool activelyPressed() {
00092         return ( (mEvent == KEY_PRESSED) || (mEvent == KEY_DOWN) );
00093     }
00094 };
00095 typedef std::tr1::shared_ptr<ButtonEvent> ButtonEventPtr;
00096 
00100 class SIRIKATA_OGRE_EXPORT ButtonPressed :public ButtonEvent {
00101 public:
00102     ButtonPressed(const InputDevicePtr &dev, unsigned int key, Modifier mod)
00103         : ButtonEvent(dev, KEY_PRESSED, key, mod) {
00104     }
00105     virtual ~ButtonPressed(){}
00106 };
00107 typedef std::tr1::shared_ptr<ButtonPressed> ButtonPressedEventPtr;
00108 
00112 class SIRIKATA_OGRE_EXPORT ButtonRepeated :public ButtonEvent {
00113 public:
00114     ButtonRepeated(const InputDevicePtr &dev, unsigned int key, Modifier mod)
00115         : ButtonEvent(dev, KEY_REPEATED, key, mod) {
00116     }
00117     virtual ~ButtonRepeated(){}
00118 };
00119 typedef std::tr1::shared_ptr<ButtonRepeated> ButtonRepeatedEventPtr;
00120 
00122 class SIRIKATA_OGRE_EXPORT ButtonReleased :public ButtonEvent {
00123 public:
00124     ButtonReleased(const InputDevicePtr &dev, unsigned int key, Modifier mod)
00125         : ButtonEvent(dev, KEY_RELEASED, key, mod) {
00126     }
00127     virtual ~ButtonReleased(){}
00128 };
00129 typedef std::tr1::shared_ptr<ButtonReleased> ButtonReleasedEventPtr;
00130 
00136 class SIRIKATA_OGRE_EXPORT ButtonDown :public ButtonEvent {
00137 public:
00138     ButtonDown(const InputDevicePtr &dev, unsigned int key, Modifier mod)
00139         : ButtonEvent(dev, KEY_DOWN, key, mod) {
00140     }
00141     virtual ~ButtonDown(){}
00142 };
00143 typedef std::tr1::shared_ptr<ButtonDown> ButtonDownEventPtr;
00144 
00150 class SIRIKATA_OGRE_EXPORT AxisEvent: public InputEvent {
00151 public:
00152     AxisIndex mAxis;
00153     AxisValue mValue;
00154 
00155     AxisEvent(const InputDevicePtr &dev, unsigned int axis, AxisValue value)
00156         : InputEvent(dev),
00157         mAxis(axis),
00158         mValue(value)
00159     {
00160     }
00161 };
00162 typedef std::tr1::shared_ptr<AxisEvent> AxisEventPtr;
00163 
00176 class SIRIKATA_OGRE_EXPORT TextInputEvent: public InputEvent {
00177 public:
00178     std::string mText; 
00179 
00180     TextInputEvent(const InputDevicePtr &dev, char *text)
00181         : InputEvent(dev),
00182                                  mText(text) {
00183     }
00184 };
00185 typedef std::tr1::shared_ptr<TextInputEvent> TextInputEventPtr;
00186 
00188 class SIRIKATA_OGRE_EXPORT MouseEvent: public InputEvent {
00189 public:
00190     float mX; 
00191     float mY; 
00192     int mCursorType; 
00193 
00194     MouseEvent(const PointerDevicePtr &dev,
00195                float x, float y, int cursorType)
00196         : InputEvent(dev) {
00197         mX = x;
00198         mY = y;
00199         mCursorType = cursorType;
00200     }
00201 
00202     PointerDevicePtr getDevice() const {
00203         return std::tr1::static_pointer_cast<PointerDevice>(
00204             InputEvent::getDevice());
00205     }
00206 };
00207 typedef std::tr1::shared_ptr<MouseEvent> MouseEventPtr;
00208 
00210 class SIRIKATA_OGRE_EXPORT MouseHoverEvent: public MouseEvent {
00211 public:
00212     MouseHoverEvent(const PointerDevicePtr &dev,
00213                float x, float y, int cursorType)
00214         : MouseEvent(dev, x, y, cursorType) {
00215     }
00216 };
00217 typedef std::tr1::shared_ptr<MouseHoverEvent> MouseHoverEventPtr;
00218 
00220 class SIRIKATA_OGRE_EXPORT MouseDownEvent: public MouseEvent {
00221 public:
00222     MouseButton mButton; 
00223     float mXStart; 
00224     float mYStart; 
00225     float mLastX;
00226     float mLastY;
00227     int mPressure; 
00228     int mPressureMax;
00229     int mPressureMin;
00230 
00232     float deltaX() const {
00233         return (mX - mXStart)/2.0f;
00234     }
00235 
00237     float deltaY() const {
00238         return (mY - mYStart)/2.0f;
00239     }
00240 
00241     float deltaLastY() const {
00242         return (mY - mLastY)/2.0f;
00243     }
00244 
00245     float deltaLastX() const {
00246         return (mX - mLastX)/2.0f;
00247     }
00248 
00249     MouseDownEvent(const PointerDevicePtr &dev,
00250                     float xstart, float ystart, float xend, float yend,
00251                     float lastx, float lasty,
00252                     int cursorType, int button,
00253                     int pressure, int pressureMin, int pressureMax)
00254         : MouseEvent(dev, xend, yend, cursorType) {
00255         mButton = button;
00256         mXStart = xstart;
00257         mYStart = ystart;
00258         mLastX = lastx;
00259         mLastY = lasty;
00260         mPressure = pressure;
00261         mPressureMin = pressureMin;
00262         mPressureMax = pressureMax;
00263     }
00264 };
00265 typedef std::tr1::shared_ptr<MouseDownEvent> MouseDownEventPtr;
00266 
00269 class SIRIKATA_OGRE_EXPORT MouseClickEvent: public MouseDownEvent {
00270 public:
00271     MouseClickEvent(const PointerDevicePtr &dev,
00272                     float x, float y,
00273                     int cursorType, int button)
00274         : MouseDownEvent(dev, x, y, x, y, x, y,
00275                          cursorType, button, 0, 0, 0) {
00276     }
00277 };
00278 typedef std::tr1::shared_ptr<MouseClickEvent> MouseClickEventPtr;
00279 
00281 class SIRIKATA_OGRE_EXPORT MousePressedEvent: public MouseDownEvent {
00282 public:
00283     MousePressedEvent(const PointerDevicePtr &dev,
00284                     float x, float y,
00285                     int cursorType, int button)
00286         : MouseDownEvent(dev, x, y, x, y, x, y,
00287                          cursorType, button, 0, 0, 0) {
00288     }
00289 };
00290 typedef std::tr1::shared_ptr<MousePressedEvent> MousePressedEventPtr;
00291 
00293 class SIRIKATA_OGRE_EXPORT MouseReleasedEvent: public MouseDownEvent {
00294 public:
00295     MouseReleasedEvent(const PointerDevicePtr &dev,
00296                     float x, float y,
00297                     int cursorType, int button)
00298         : MouseDownEvent(dev, x, y, x, y, x, y,
00299                          cursorType, button, 0, 0, 0) {
00300     }
00301 };
00302 typedef std::tr1::shared_ptr<MouseReleasedEvent> MouseReleasedEventPtr;
00303 
00306 class SIRIKATA_OGRE_EXPORT MouseDragEvent: public MouseDownEvent {
00307 public:
00308     MouseDragType mType;
00309     MouseDragEvent(const PointerDevicePtr &dev,
00310                    MouseDragType type,
00311                    float xstart, float ystart, float xend, float yend,
00312                    float lastx, float lasty,
00313                    int cursorType, int button,
00314                    int pressure, int pressureMin, int pressureMax)
00315         : MouseDownEvent(dev, xstart, ystart,
00316                          xend, yend, lastx, lasty, cursorType, button,
00317                          pressure, pressureMin, pressureMax) {
00318         mType = type;
00319     }
00320 };
00321 typedef std::tr1::shared_ptr<MouseDragEvent> MouseDragEventPtr;
00322 
00325 class SIRIKATA_OGRE_EXPORT WindowEvent {
00326 public:
00327     enum WindowEventName {
00328         WindowShown,
00329         WindowExposed,
00330         WindowHidden,
00331         WindowMoved,
00332         WindowResized,
00333         WindowMinimized,
00334         WindowMaximized,
00335         WindowRestored,
00336         WindowMouseEnter,
00337         WindowMouseLeave,
00338         WindowFocused,
00339         WindowUnfocused,
00340         WindowQuit,
00341         Unknown
00342     };
00343 
00344     WindowEventName mName;
00345     int mData1;
00346     int mData2;
00347 
00348     WindowEvent(WindowEventName name, int data1, int data2)
00349         : mName(name), mData1(data1), mData2(data2)
00350     {
00351     }
00352 
00353     WindowEventName name() const { return mName; }
00354 
00355     int getX() const {
00356         return mData1;
00357     }
00358     int getY() const {
00359         return mData2;
00360     }
00361 
00362 };
00363 typedef std::tr1::shared_ptr<WindowEvent> WindowEventPtr;
00364 
00365 class SIRIKATA_OGRE_EXPORT DragAndDropEvent {
00366 public:
00367     int mXCoord;
00368     int mYCoord;
00369     std::vector<std::string> mFilenames;
00370     DragAndDropEvent(const std::vector<std::string>&files, int x=0, int y=0)
00371         : mXCoord(x), mYCoord(y), mFilenames(files) {
00372     }
00373 };
00374 typedef std::tr1::shared_ptr<DragAndDropEvent> DragAndDropEventPtr;
00375 
00376 
00378 class SIRIKATA_OGRE_EXPORT WebViewEvent : public InputEvent {
00379 public:
00380     Graphics::WebView* wv;
00381     String webview;
00382     String name;
00383     std::vector<String> args; // The pointer here is annoying, but necessary to avoid having to include the defintion here, which in turn causes circular includes
00384 
00385     WebViewEvent(const String &wvName, const String& name, const std::vector<String>& args);
00386     WebViewEvent(const String &wvName, const std::vector<DataReference<const char*> >& args);
00387     virtual ~WebViewEvent();
00388 };
00389 typedef std::tr1::shared_ptr<WebViewEvent> WebViewEventPtr;
00390 
00391 
00392 }
00393 }
00394 
00395 #endif