84 lines
2.3 KiB
C++
84 lines
2.3 KiB
C++
/**
|
|
* @author: Thomas Brandého
|
|
*/
|
|
|
|
#ifndef INPUT_H
|
|
#define INPUT_H
|
|
#include "keybindings.h"
|
|
#include <queue>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#include "textbuffer.h"
|
|
#include "glm/vec2.hpp"
|
|
|
|
class Input{
|
|
private:
|
|
/* window-related variables */
|
|
sf::Window* m_window;
|
|
bool m_closeRequested;
|
|
bool m_hasBeenResized;
|
|
|
|
/* general action-mapping variables */
|
|
IKeysMap m_keysmap;
|
|
std::vector<int> m_actions;
|
|
int nb_actions;
|
|
|
|
/* context-related variables */
|
|
std::string m_current_context;
|
|
std::vector<Context> m_contexts;
|
|
std::unordered_map<std::string,KeyBindings> m_keybindings;
|
|
|
|
/* keyboard-related variables */
|
|
std::vector<sf::Keyboard::Key> m_heldkeys;
|
|
void releaseHeldKeys(sf::Keyboard::Key keycode);
|
|
|
|
/* mouse-related variables */
|
|
sf::Vector2i m_mouse_position;
|
|
sf::Vector2i m_last_mouse_position;
|
|
float m_delta_vertical_scroll;
|
|
bool m_mouseGrabbed;
|
|
|
|
/* text-related variable */
|
|
std::wstring m_buffer;
|
|
public:
|
|
/* Constructors */
|
|
Input(sf::Window *w);
|
|
|
|
/* general action-mapping functions */
|
|
void setKeysMap(IKeysMap km); //set bindings
|
|
void updateEvents(); //handle the input and put the associated event in the file
|
|
std::vector<int> getActions(); //get the first action in the file of event
|
|
|
|
/* context-related functions */
|
|
void addContext(Context context){m_contexts.push_back(context);}
|
|
std::string getCurrentContext(){return m_current_context;}
|
|
void setCurrentContext(std::string context_name){m_current_context = context_name;}
|
|
void updateKeyBindings();
|
|
|
|
/* window-related function */
|
|
bool isCloseRequested() const;
|
|
bool isResized() const;
|
|
|
|
/* keyboard-related functions */
|
|
bool isKeyPressed(int key) const;
|
|
|
|
/* mouse-related function */
|
|
//sf::Vector2i getPosition() const;
|
|
glm::vec2 getPosition() const;
|
|
//sf::Vector2i getDeltaPosition() const;
|
|
glm::vec2 getDeltaPosition() const;
|
|
float getDeltaVerticalScroll() const;
|
|
|
|
/* Mouse grabbing */
|
|
void setMouseGrabbed(bool isGrabbed);
|
|
void toggleMouseGrab() { setMouseGrabbed(!m_mouseGrabbed); }
|
|
bool isMouseGrabbed() const { return m_mouseGrabbed; }
|
|
|
|
/* text-related function */
|
|
std::wstring getText();
|
|
|
|
void test();
|
|
};
|
|
|
|
#endif //INPUT_H
|