Add mouse catching and escape systems to app
This commit is contained in:
@@ -1,19 +1,48 @@
|
||||
#include <flecs.h>
|
||||
#include <input/input.h>
|
||||
#include <iostream>
|
||||
#include <log/log.h>
|
||||
#include <window/window.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
Log::initialize();
|
||||
|
||||
flecs::world world;
|
||||
|
||||
world.import <Window::WindowModule>();
|
||||
world.import <Input::InputModule>();
|
||||
|
||||
auto window = Window::spawn_window(world);
|
||||
auto glfw_window = window.get<std::shared_ptr<GLFWwindow>>();
|
||||
|
||||
world.import <Input::InputModule>();
|
||||
world.system<Window::Window, Input::ButtonInput<Input::KeyCode> const>().each(
|
||||
[](flecs::entity e,
|
||||
Window::Window,
|
||||
Input::ButtonInput<Input::KeyCode> const& button_input) {
|
||||
if (button_input.just_pressed(Input::KeyCode(GLFW_KEY_LEFT_CONTROL))) {
|
||||
auto glfw_window = e.get<std::shared_ptr<GLFWwindow>>();
|
||||
auto input_mode = glfwGetInputMode(glfw_window->get(), GLFW_CURSOR);
|
||||
|
||||
if (input_mode == GLFW_CURSOR_NORMAL) {
|
||||
glfwSetInputMode(glfw_window->get(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
} else {
|
||||
glfwSetInputMode(glfw_window->get(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
world.system<Window::Window, Input::ButtonInput<Input::KeyCode> const>().each(
|
||||
[](flecs::entity e,
|
||||
Window::Window,
|
||||
Input::ButtonInput<Input::KeyCode> const& button_input) {
|
||||
if (button_input.just_pressed(Input::KeyCode(GLFW_KEY_ESCAPE))) {
|
||||
auto glfw_window = e.get<std::shared_ptr<GLFWwindow>>();
|
||||
glfwSetWindowShouldClose(glfw_window->get(), GLFW_TRUE);
|
||||
}
|
||||
});
|
||||
|
||||
while (glfwWindowShouldClose(glfw_window->get()) == GLFW_FALSE) {
|
||||
glfwPollEvents();
|
||||
|
||||
Reference in New Issue
Block a user