[nostalgia/core] Add focusWindow, cleanup GLFW leak into Userland, change shutdown to stop main loop

This commit is contained in:
2021-07-23 21:52:26 -05:00
parent 7dfa2f5713
commit 32ac497a0e
8 changed files with 50 additions and 19 deletions
+13 -2
View File
@@ -11,6 +11,7 @@
#include <nostalgia/core/config.hpp>
#include <nostalgia/core/gfx.hpp>
#include <nostalgia/core/input.hpp>
#include <nostalgia/core/userland/gfx.hpp>
#include "core.hpp"
@@ -19,11 +20,10 @@ namespace nostalgia::core {
void draw(Context *ctx) noexcept;
static void handleKeyPress(Context *ctx, int key) {
const auto id = ctx->windowerData<GlfwImplData>();
switch (key) {
case GLFW_KEY_ESCAPE:
case GLFW_KEY_Q:
glfwSetWindowShouldClose(id->window, true);
shutdown(ctx);
break;
default:
break;
@@ -66,6 +66,11 @@ ox::Error run(Context *ctx) noexcept {
draw(ctx);
glfwSwapBuffers(id->window);
}
// destroy GLFW window
oxReturnError(renderer::shutdown(ctx));
glfwDestroyWindow(id->window);
ctx->setWindowerData(nullptr);
delete id;
return OxError(0);
}
@@ -85,4 +90,10 @@ bool buttonDown(Key) noexcept {
return false;
}
void shutdown(Context *ctx) noexcept {
const auto id = ctx->windowerData<GlfwImplData>();
glfwSetWindowShouldClose(id->window, true);
}
}