Major cleanup.

Moved to namespace
Cleanup includes
This commit is contained in:
Antoine Pilote
2021-07-11 18:56:44 -04:00
parent f77bef6b28
commit 0c6ed48bbd
174 changed files with 11772 additions and 11296 deletions

View File

@@ -2,166 +2,170 @@
#include "../Window.h"
#include <GLFW/glfw3.h>
Input* Input::s_Instance;
std::map<int, bool> Input::m_Keys = std::map<int, bool>();
bool Input::m_MouseButtons[5] = { false, false, false, false, false };
namespace Nuake
{
Input* Input::s_Instance;
std::map<int, bool> Input::m_Keys = std::map<int, bool>();
bool Input::m_MouseButtons[5] = { false, false, false, false, false };
#pragma region Keys
// Only true if the key is currently being pressed
bool Input::IsKeyDown(int keycode)
{
auto window = Window::Get()->GetHandle();
int state = glfwGetKey(window, keycode);
bool result = state == GLFW_PRESS;
m_Keys[keycode] = state;
return result;
}
// Only true if the key is pressed for the first frame. no repeat.
bool Input::IsKeyPressed(int keycode)
{
auto window = Window::Get()->GetHandle();
int state = glfwGetKey(window, keycode);
bool result = state == GLFW_PRESS;
// First time pressed?
if (m_Keys.find(keycode) == m_Keys.end() || m_Keys[keycode] == true)
// Only true if the key is currently being pressed
bool Input::IsKeyDown(int keycode)
{
if (result)
m_Keys[keycode] = true;
auto window = Window::Get()->GetHandle();
int state = glfwGetKey(window, keycode);
bool result = state == GLFW_PRESS;
m_Keys[keycode] = state;
return result;
}
return false;
}
bool Input::IsKeyReleased(int keycode)
{
auto window = Window::Get()->GetHandle();
int state = glfwGetKey(window, keycode);
bool result = state == GLFW_RELEASE;
// First time pressed?
if (m_Keys.find(keycode) == m_Keys.end())
return result;
if (result && m_Keys[keycode] == true)
// Only true if the key is pressed for the first frame. no repeat.
bool Input::IsKeyPressed(int keycode)
{
return true;
}
auto window = Window::Get()->GetHandle();
int state = glfwGetKey(window, keycode);
bool result = state == GLFW_PRESS;
return false;
}
// First time pressed?
if (m_Keys.find(keycode) == m_Keys.end() || m_Keys[keycode] == true)
{
if (result)
m_Keys[keycode] = true;
return result;
}
return false;
}
bool Input::IsKeyReleased(int keycode)
{
auto window = Window::Get()->GetHandle();
int state = glfwGetKey(window, keycode);
bool result = state == GLFW_RELEASE;
// First time pressed?
if (m_Keys.find(keycode) == m_Keys.end())
return result;
if (result && m_Keys[keycode] == true)
{
return true;
}
return false;
}
#pragma endregion
#pragma region Mouse
// Visibility
void Input::HideMouse() {
auto window = Window::Get()->GetHandle();
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
}
bool Input::IsMouseHidden() {
auto window = Window::Get()->GetHandle();
return glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED;
}
void Input::ShowMouse() {
auto window = Window::Get()->GetHandle();
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
// Action
bool Input::IsMouseButtonDown(int button)
{
auto window = Window::Get()->GetHandle();
auto state = glfwGetMouseButton(window, button);
return state == GLFW_PRESS;
}
bool Input::IsMouseButtonPressed(int button)
{
auto window = Window::Get()->GetHandle();
auto state = glfwGetMouseButton(window, button);
if (m_MouseButtons[button] == false && state == GLFW_PRESS)
{
m_MouseButtons[button] = true;
return true;
// Visibility
void Input::HideMouse() {
auto window = Window::Get()->GetHandle();
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
}
return false;
}
bool Input::IsMouseHidden() {
auto window = Window::Get()->GetHandle();
return glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED;
}
bool Input::IsMouseButtonReleased(int button)
{
auto window = Window::Get()->GetHandle();
auto state = glfwGetMouseButton(window, button);
void Input::ShowMouse() {
auto window = Window::Get()->GetHandle();
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
return state == GLFW_RELEASE && m_MouseButtons[button] == true;
}
// Position
float Input::GetMouseX()
{
auto window = Window::Get()->GetHandle();
// Action
bool Input::IsMouseButtonDown(int button)
{
auto window = Window::Get()->GetHandle();
auto state = glfwGetMouseButton(window, button);
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
return state == GLFW_PRESS;
}
return (float)xpos;
}
bool Input::IsMouseButtonPressed(int button)
{
auto window = Window::Get()->GetHandle();
auto state = glfwGetMouseButton(window, button);
float Input::GetMouseY()
{
auto window = Window::Get()->GetHandle();
if (m_MouseButtons[button] == false && state == GLFW_PRESS)
{
m_MouseButtons[button] = true;
return true;
}
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
return false;
}
return (float)ypos;
}
bool Input::IsMouseButtonReleased(int button)
{
auto window = Window::Get()->GetHandle();
auto state = glfwGetMouseButton(window, button);
Vector2 Input::GetMousePosition()
{
auto window = Window::Get()->GetHandle();
return state == GLFW_RELEASE && m_MouseButtons[button] == true;
}
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
// Position
float Input::GetMouseX()
{
auto window = Window::Get()->GetHandle();
return Vector2(xpos, ypos);
}
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
return (float)xpos;
}
float Input::GetMouseY()
{
auto window = Window::Get()->GetHandle();
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
return (float)ypos;
}
Vector2 Input::GetMousePosition()
{
auto window = Window::Get()->GetHandle();
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
return Vector2(xpos, ypos);
}
#pragma endregion
bool Input::Init()
{
//auto window = Application::Get().GetWindow()->GetNative();
//glfwSetKeyCallback(window, Input::HandleInputCallback);
return false;
}
void Input::Update()
{
// Reset all input to false.
for (auto& k : m_Keys)
bool Input::Init()
{
if(!IsKeyDown(k.first))
k.second = false;
//auto window = Application::Get().GetWindow()->GetNative();
//glfwSetKeyCallback(window, Input::HandleInputCallback);
return false;
}
for (int i = 0; i < 5; i++)
void Input::Update()
{
if(!IsMouseButtonDown(i))
m_MouseButtons[i] = false;
// Reset all input to false.
for (auto& k : m_Keys)
{
if (!IsKeyDown(k.first))
k.second = false;
}
for (int i = 0; i < 5; i++)
{
if (!IsMouseButtonDown(i))
m_MouseButtons[i] = false;
}
}
}