InputManager class
This commit is contained in:
parent
7d3ccdb15f
commit
e74a21b365
26
core/input/manager.cpp
Normal file
26
core/input/manager.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include "manager.hpp"
|
||||
|
||||
namespace hibis {
|
||||
InputManager::InputManager() {}
|
||||
InputManager::~InputManager() {}
|
||||
|
||||
bool InputManager::isKeyPressed(int scancode) {
|
||||
if (mKeyScancodes.find(scancode) != mKeyScancodes.end()) return (mKeyScancodes[scancode] == Pressed || mKeyScancodes[scancode] == Held);
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool InputManager::isKeyJustPressed(int scancode) {
|
||||
if (mKeyScancodes.find(scancode) != mKeyScancodes.end()) return mKeyScancodes[scancode] == Pressed;
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool InputManager::isKeyJustReleased(int scancode) {
|
||||
if (mKeyScancodes.find(scancode) != mKeyScancodes.end()) return mKeyScancodes[scancode] == Released;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
void InputManager::setKeyPressState(int scancode, PressTypes type) {
|
||||
mKeyScancodes[scancode] = type;
|
||||
}
|
||||
}
|
21
core/input/manager.hpp
Normal file
21
core/input/manager.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "presstypes.hpp"
|
||||
|
||||
namespace hibis {
|
||||
class InputManager final {
|
||||
public:
|
||||
InputManager();
|
||||
~InputManager();
|
||||
|
||||
bool isKeyPressed(int scancode);
|
||||
bool isKeyJustPressed(int scancode);
|
||||
bool isKeyJustReleased(int scancode);
|
||||
|
||||
void setKeyPressState(int scancode, PressTypes type);
|
||||
private:
|
||||
std::map<int, PressTypes> mKeyScancodes;
|
||||
};
|
||||
}
|
11
core/input/presstypes.hpp
Normal file
11
core/input/presstypes.hpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
namespace hibis {
|
||||
enum PressTypes {
|
||||
Unpressed,
|
||||
Pressed,
|
||||
Held,
|
||||
Released,
|
||||
Unknown = __INT32_MAX__
|
||||
};
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
#include "renderer.hpp"
|
||||
|
||||
namespace hibis {
|
||||
Renderer::Renderer(LoggerCallback logger) : mLogger(logger) {}
|
||||
Renderer::Renderer(LoggerCallback logger) : mLogger(logger), mInputManager() {}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "../input/manager.hpp"
|
||||
#include "../math/types.hpp"
|
||||
#include "../resources/resource.hpp"
|
||||
#include "../resources/shader.hpp"
|
||||
|
@ -36,6 +37,7 @@ namespace hibis {
|
|||
|
||||
bool mKeepOpen = true;
|
||||
LoggerCallback mLogger;
|
||||
InputManager mInputManager;
|
||||
protected:
|
||||
bool mIsWireframeMode = false;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue