//
// Created by trotfunky on 07/10/2019.
//

#ifndef TESTS_OPENGL_KEYSTATEMANAGER_H
#define TESTS_OPENGL_KEYSTATEMANAGER_H

#include <map>
#include <GL/glut.h>


/// Handles the key events from glut and keep the status of keys up to date.
/// "Static class"
class KeyStateManager {
public:
    KeyStateManager() = delete;

    static void register_glut_callbacks();

    // FIXME: Not happy with having two functions : char auto promoted to int if same name
    static bool is_key_pressed(unsigned char key);
    static bool is_special_key_pressed(int key);

    // Glut callbacks for input events
    static void key_press(unsigned char event_key, int mouse_x, int mouse_y);
    static void key_up(unsigned char event_key, int mouse_x, int mouse_y);
    static void special_key_press(int event_key, int mouse_x, int mouse_y);
    static void special_key_up(int event_key, int mouse_x, int mouse_y);

private:
    // The maps are used to keep track of the keys which were pressed or released during runtime.
    static std::map<unsigned char,bool> ascii_keys_status;
    static std::map<int,bool> special_keys_status;

    // These functions are called by *_press and *_up to update their values
    static void update_key(unsigned char event_key, bool new_status);
    static void update_special_key(int event_key, bool new_status);
};


#endif //TESTS_OPENGL_KEYSTATEMANAGER_H
