Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 19, 2009, 5:31:02 PM (15 years ago)
Author:
rgrieder
Message:

Merged all remaining revisions from core4 back to the trunk.

Location:
code/trunk
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/input/InputHandler.h

    r3276 r3327  
    2727 */
    2828
    29 /**
    30 @file
    31 @brief
    32     Declarations of various interface classes for the input management.
    33 */
    34 
    3529#ifndef _InputHandler_H__
    3630#define _InputHandler_H__
     
    4135namespace orxonox
    4236{
     37    namespace ButtonEvent
     38    {
     39        //! Helper enum to deploy events with the help of templates
     40        enum Value
     41        {
     42            Press,
     43            Release,
     44            Hold
     45        };
     46
     47        //! Enables function overloading with integer values
     48        template <ButtonEvent::Value Event>
     49        struct EnumToType { };
     50        typedef EnumToType<Press>   TPress;
     51        typedef EnumToType<Release> TRelease;
     52        typedef EnumToType<Hold>    THold;
     53    }
     54
     55    namespace KeyboardModifier
     56    {
     57        //! Keyboard modifiers (shift, ctrl and alt)
     58        enum Enum
     59        {
     60            Shift = 0x0000001,
     61            Ctrl  = 0x0000010,
     62            Alt   = 0x0000100
     63        };
     64    }
     65
     66    //! Event argument for key events
     67    class _CoreExport KeyEvent
     68    {
     69    public:
     70        KeyEvent(const OIS::KeyEvent& evt)
     71            : key_(static_cast<KeyCode::ByEnum>(evt.key))
     72            , text_(evt.text)
     73            , modifiers_(0)
     74        { }
     75        bool operator==(const KeyEvent& rhs) const
     76            { return rhs.key_ == key_; }
     77        bool operator!=(const KeyEvent& rhs) const
     78            { return rhs.key_ != key_; }
     79        void setModifiers(int modifiers)
     80            { modifiers_ = modifiers; }
     81
     82        bool isModifierDown(KeyboardModifier::Enum modifier) const
     83            { return static_cast<KeyboardModifier::Enum>(modifier & modifiers_); }
     84        KeyCode::ByEnum getKeyCode() const
     85            { return key_; }
     86        unsigned int getText() const { return text_; }
     87
     88    private:
     89        KeyCode::ByEnum key_;
     90        unsigned int text_;
     91        int modifiers_;
     92    };
     93
    4394    /**
    4495    @brief
     96        Base class for all input handlers like KeyBinder, InputBuffer, etc.
     97
     98        Derive from this class if you wish to receive input events.
     99        But keep in mind that this is pointless wihtout first having an InputState.
     100    @note
     101        The definitions for the button events with the weird arguments are simply
     102        to avoid redunant code in the input devices.
    45103    */
    46104    class _CoreExport InputHandler
     
    83141        virtual void allDevicesUpdated(float dt) { }
    84142
     143        //! Use this input handler if you want to occupy a device in an input state.
    85144        static InputHandler EMPTY;
    86145    };
Note: See TracChangeset for help on using the changeset viewer.