Sirikata
libogre/include/sirikata/ogre/input/InputListener.hpp
Go to the documentation of this file.
00001 // Copyright (c) 2011 Sirikata Authors. All rights reserved.
00002 // Use of this source code is governed by a BSD-style license that can
00003 // be found in the LICENSE file.
00004 
00005 #ifndef _SIRIKATA_OGRE_INPUT_LISTENER_HPP_
00006 #define _SIRIKATA_OGRE_INPUT_LISTENER_HPP_
00007 
00008 #include <sirikata/ogre/Platform.hpp>
00009 
00010 namespace Sirikata {
00011 namespace Input {
00012 
00013 // Event types
00014 class InputDeviceEvent;
00015 typedef std::tr1::shared_ptr<InputDeviceEvent> InputDeviceEventPtr;
00016 class ButtonPressed;
00017 typedef std::tr1::shared_ptr<ButtonPressed> ButtonPressedPtr;
00018 class ButtonRepeated;
00019 typedef std::tr1::shared_ptr<ButtonRepeated> ButtonRepeatedPtr;
00020 class ButtonReleased;
00021 typedef std::tr1::shared_ptr<ButtonReleased> ButtonReleasedPtr;
00022 class ButtonDown;
00023 typedef std::tr1::shared_ptr<ButtonDown> ButtonDownPtr;
00024 class AxisEvent;
00025 typedef std::tr1::shared_ptr<AxisEvent> AxisEventPtr;
00026 class TextInputEvent;
00027 typedef std::tr1::shared_ptr<TextInputEvent> TextInputEventPtr;
00028 class MouseHoverEvent;
00029 typedef std::tr1::shared_ptr<MouseHoverEvent> MouseHoverEventPtr;
00030 class MousePressedEvent;
00031 typedef std::tr1::shared_ptr<MousePressedEvent> MousePressedEventPtr;
00032 class MouseReleasedEvent;
00033 typedef std::tr1::shared_ptr<MouseReleasedEvent> MouseReleasedEventPtr;
00034 class MouseClickEvent;
00035 typedef std::tr1::shared_ptr<MouseClickEvent> MouseClickEventPtr;
00036 class MouseDragEvent;
00037 typedef std::tr1::shared_ptr<MouseDragEvent> MouseDragEventPtr;
00038 class DragAndDropEvent;
00039 typedef std::tr1::shared_ptr<DragAndDropEvent> DragAndDropEventPtr;
00040 class WebViewEvent;
00041 typedef std::tr1::shared_ptr<WebViewEvent> WebViewEventPtr;
00042 class WindowEvent;
00043 typedef std::tr1::shared_ptr<WindowEvent> WindowEventPtr;
00044 
00045 
00050 class SIRIKATA_OGRE_EXPORT EventResponse {
00051     enum {
00052         NOP,
00053         DELETE_LISTENER=1,
00054         CANCEL_EVENT=2,
00055         DELETE_LISTENER_AND_CANCEL_EVENT = DELETE_LISTENER | CANCEL_EVENT,
00056     } mResp;
00057 
00058     template <class Ev> friend class EventManager;
00059 
00060   public:
00062     static EventResponse nop() {
00063         EventResponse retval;
00064         retval.mResp=NOP;
00065         return retval;
00066     }
00068     static EventResponse del() {
00069         EventResponse retval;
00070         retval.mResp=DELETE_LISTENER;
00071         return retval;
00072     }
00074     static EventResponse cancel() {
00075         EventResponse retval;
00076         retval.mResp=CANCEL_EVENT;
00077         return retval;
00078     }
00080     static EventResponse cancelAndDel() {
00081         EventResponse retval;
00082         retval.mResp=DELETE_LISTENER_AND_CANCEL_EVENT;
00083         return retval;
00084     }
00085 
00086     bool operator==(const EventResponse& other) {
00087         return (mResp == other.mResp);
00088     }
00089     bool operator!=(const EventResponse& other) {
00090         return (mResp != other.mResp);
00091     }
00092 };
00093 
00095 class SIRIKATA_OGRE_EXPORT InputListener {
00096   public:
00097 
00098     virtual ~InputListener() {}
00099 
00100     virtual EventResponse onInputDeviceEvent(InputDeviceEventPtr ev) { return EventResponse::nop(); }
00101 
00102     virtual EventResponse onKeyPressedEvent(ButtonPressedPtr ev) { return EventResponse::nop(); }
00103     virtual EventResponse onKeyRepeatedEvent(ButtonRepeatedPtr ev) { return EventResponse::nop(); }
00104     virtual EventResponse onKeyReleasedEvent(ButtonReleasedPtr ev) { return EventResponse::nop(); }
00105     virtual EventResponse onKeyDownEvent(ButtonDownPtr ev) { return EventResponse::nop(); }
00106 
00107     virtual EventResponse onAxisEvent(AxisEventPtr ev) { return EventResponse::nop(); }
00108     virtual EventResponse onTextInputEvent(TextInputEventPtr ev) { return EventResponse::nop(); }
00109     virtual EventResponse onMouseHoverEvent(MouseHoverEventPtr ev) { return EventResponse::nop(); }
00110     virtual EventResponse onMousePressedEvent(MousePressedEventPtr ev) { return EventResponse::nop(); }
00111     virtual EventResponse onMouseReleasedEvent(MouseReleasedEventPtr ev) { return EventResponse::nop(); }
00112     virtual EventResponse onMouseClickEvent(MouseClickEventPtr ev) { return EventResponse::nop(); }
00113     virtual EventResponse onMouseDragEvent(MouseDragEventPtr ev) { return EventResponse::nop(); }
00114     virtual EventResponse onDragAndDropEvent(DragAndDropEventPtr ev) { return EventResponse::nop(); }
00115     virtual EventResponse onWebViewEvent(WebViewEventPtr ev) { return EventResponse::nop(); }
00116     virtual EventResponse onWindowEvent(WindowEventPtr ev) { return EventResponse::nop(); }
00117 
00118 }; // class InputListener
00119 
00120 } // namespace Input
00121 } // namespace Sirikata
00122 
00123 #endif //_SIRIKATA_OGRE_INPUT_LISTENER_HPP_