Added controller support

This commit is contained in:
Lauchmelder 2022-03-01 18:13:47 +01:00
parent e5cc1565fd
commit f4e6198a99
No known key found for this signature in database
GPG key ID: C2403C69D78F011D
15 changed files with 310 additions and 6 deletions

9
src/gfx/Input.cpp Normal file
View file

@ -0,0 +1,9 @@
#include "Window.hpp"
#include "Input.hpp"
Window* Input::window = nullptr;
bool Input::IsKeyDown(int key)
{
return (glfwGetKey(window->GetNativeWindow(), key) == GLFW_PRESS);
}

16
src/gfx/Input.hpp Normal file
View file

@ -0,0 +1,16 @@
#pragma once
#include <memory>
#include <GLFW/glfw3.h>
class Window;
class Input
{
public:
static inline void SetWindow(Window* source) { window = source; }
static bool IsKeyDown(int key);
private:
static Window* window;
};

View file

@ -5,6 +5,8 @@
#include <imgui/backends/imgui_impl_opengl3.h>
#include <imgui/imgui.h>
#include "Input.hpp"
Window::Window(uint16_t width, uint16_t height, const std::string& title) :
handle(nullptr)
{
@ -17,6 +19,7 @@ Window::Window(uint16_t width, uint16_t height, const std::string& title) :
}
glfwMakeContextCurrent(handle);
Input::SetWindow(this);
}
Window::~Window()