//
//  Controls.hpp
//  Meteor
//
//  Created by Cesar Parent on 30/08/2015.
//  Copyright © 2015 Cesar Parent. All rights reserved.
//

#ifndef Controls_hpp
#define Controls_hpp

#include "../defines.h"
#include "Key.h"
#include <map>

NS_BEGIN

class ControlsDelegate;

/*!
 * @class           Controls
 * @ingroup         Management
 * @brief           The class responsible for handling Keyboard, Mouse and Game Controller states
 *                  and forward them to the current delegate.
 * @details         Controls are polled automatically by the game engine. If you wish to receive
 *                  Keyboard, Mouse and Controller events, you should implement the ControlsDelegate
 *                  protocol, and register yourself as the Controls's delegate using setDelegate().
 */
class Controls {
    
public:
    
    /*!
     * @internal
     * @brief       Polls the event queue and dispatch control events.
     */
    static void
    poll();
    
    /*!
     * @internal
     * @brief       Returns a bitmask
     *
     */
    static Modifier
    modifiers() { return _modifiers; }
    
    /*!
     * @brief       Sets the delegate object that will receive controls events.
     * @details     There can only be one Controls Delegate at a time. If you register an object at
     *              delegate, the previous delegate will not receive events anymore.
     * @param       delegate    An object that implements ControlsDelegate and will receive controls
     *                          events.
     */
    static void
    setDelegate(ControlsDelegate* delegate);
    
    /*!
     * @brief       Returns wether a quit event was sent to the game.
     * @return      Wether a quit event was sent to the game.
     */
    static bool
    quit() { return _quit; }
    
private:
    
    static Modifier
    _modifiers;
    
    static ControlsDelegate*
    _delegate;
    
    static bool
    _quit;
    
    static std::map<int, void*>
    _controllers;
    
};

NS_END

#endif /* Controls_hpp */
