
#ifndef __WFX_INPUT_INPUTHANDLER_H__
#define __WFX_INPUT_INPUTHANDLER_H__

#include <WFX/WFXIncludes.h>

#include <WFX/lang/Singleton.h>
#include <WFX/kernel/Task.h>
#include <WFX/input/KeyboardListener.h>
#include <WFX/input/MouseListener.h>
#include <WFX/input/JoystickListener.h>

namespace WFX {

    namespace input {

        /**
         * Inputhandler interface
         * An InputHandler must be able to provide 
         * eventlisteners with the necessary events
         */
        class InputHandler : public WFX::kernel::Task, public WFX::lang::Singleton<InputHandler> {
            public:

                /**
                 * Ctor
                 */
                InputHandler() {
                    NumSticks = 0;
                }
                
                /** adds a Keyboardlistener */
                void addKeyboardListener(KeyboardListener* l) {
                    KeyboardListeners.push_back(l);
                }
                 
                /** adds a Mouselistener */
                void addMouseListener(MouseListener* l) {
                    MouseListeners.push_back(l);
                }
                 
                /** adds a Joysticklistener */
                void addJoystickListener(JoystickListener* l) {
                    JoystickListeners.push_back(l);
                }

                /** returns the number of joysticks present */
                Int getNumSticks() {
                    return NumSticks;
                }

                /** causes all pending Events to be flushed */
                virtual void flushEvents() = 0;

                /** stores the X and Y pos in the given vars */
                virtual void getMousePos(Int* x, Int* y) = 0;

            protected:
                /** event listeners */
                std::list<KeyboardListener*> KeyboardListeners;
                std::list<MouseListener*> MouseListeners;
                std::list<JoystickListener*> JoystickListeners;

                /** the number of joysticks */
                Int NumSticks;

                /**
                 * KeyPress
                 * notifies all KeyBoardListeners
                 */
                void keyPressed(KeyEvent k);
                /**
                 * KeyRelease
                 * notifies all KeyBoardListeners
                 */
                void keyReleased(KeyEvent k);
                /**
                 * Joystick button press
                 * notifies all JoystickListeners
                 */
                void buttonPressed(JoystickButtonEvent j);
                /**
                 * Joystick button release
                 * notifies all JoystickListeners
                 */
                void buttonReleased(JoystickButtonEvent j);
                /**
                 * Joystick Axis Event
                 * notifies all JoystickListeners
                 */
                void axisEvent(JoystickAxisEvent j);
                /**
                 * Mouse moeved event
                 * notifies all JoystickListeners
                 */
                void mouseMoved(MouseMotionEvent e);
                /**
                 * Mouse Button pressed
                 * notifies all JoystickListeners
                 */
                void mouseButtonPressed(MouseButtonEvent e);
                /**
                 * Mouse Button pressed
                 * notifies all JoystickListeners
                 */
                void mouseButtonReleased(MouseButtonEvent e);

            private:

        };

    }

}


#endif //include guard


