[turbine] Cleanup

This commit is contained in:
Gary Talent 2023-11-05 15:42:49 -06:00
parent 81d092e967
commit f6d2d96ff9

View File

@ -15,15 +15,24 @@
namespace turbine {
[[nodiscard]]
inline GlfwContext &glctx(Context &ctx) noexcept {
if constexpr(ox::defines::Debug) {
return dynamic_cast<GlfwContext&>(ctx);
} else {
return static_cast<GlfwContext&>(ctx);
}
}
namespace gl {
void addDrawer(Context &ctx, Drawer *cd) noexcept {
auto &gctx = static_cast<GlfwContext&>(ctx);
auto &gctx = glctx(ctx);
gctx.drawers.emplace_back(cd);
}
void removeDrawer(Context &ctx, Drawer *cd) noexcept {
auto &gctx = static_cast<GlfwContext&>(ctx);
auto &gctx = glctx(ctx);
for (auto i = 0u; i < gctx.drawers.size(); ++i) {
if (gctx.drawers[i] == cd) {
oxIgnoreError(gctx.drawers.erase(i));
@ -65,7 +74,7 @@ static void handleKeyPress(Context *ctx, int key, bool down) noexcept {
return map;
}();
const auto eventHandler = keyEventHandler(*ctx);
auto &gctx = static_cast<GlfwContext&>(*ctx);
auto &gctx = glctx(*ctx);
const auto k = keyMap[static_cast<std::size_t>(key)];
setKeyDownStatus(&gctx, k, down);
if (eventHandler) {
@ -200,7 +209,7 @@ static void themeImgui() noexcept {
}
ox::Error initGfx(Context &ctx) noexcept {
auto &gctx = static_cast<GlfwContext&>(ctx);
auto &gctx = glctx(ctx);
glfwSetErrorCallback(handleGlfwError);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
@ -238,40 +247,40 @@ ox::Error initGfx(Context &ctx) noexcept {
}
void setWindowTitle(Context &ctx, ox::CRStringView title) noexcept {
auto &gctx = static_cast<GlfwContext&>(ctx);
auto &gctx = glctx(ctx);
auto cstr = ox_malloca(title.bytes() + 1, char);
ox_strncpy(cstr.get(), title.data(), title.bytes());
glfwSetWindowTitle(gctx.window, cstr);
}
void focusWindow(Context &ctx) noexcept {
auto &gctx = static_cast<GlfwContext&>(ctx);
auto &gctx = glctx(ctx);
glfwFocusWindow(gctx.window);
}
int getScreenWidth(Context &ctx) noexcept {
auto &gctx = static_cast<GlfwContext&>(ctx);
auto &gctx = glctx(ctx);
int w = 0, h = 0;
glfwGetFramebufferSize(gctx.window, &w, &h);
return w;
}
int getScreenHeight(Context &ctx) noexcept {
auto &gctx = static_cast<GlfwContext&>(ctx);
auto &gctx = glctx(ctx);
int w = 0, h = 0;
glfwGetFramebufferSize(gctx.window, &w, &h);
return h;
}
ox::Size getScreenSize(Context &ctx) noexcept {
auto &gctx = static_cast<GlfwContext&>(ctx);
auto &gctx = glctx(ctx);
int w = 0, h = 0;
glfwGetFramebufferSize(gctx.window, &w, &h);
return {w, h};
}
ox::Bounds getWindowBounds(Context &ctx) noexcept {
auto &gctx = static_cast<GlfwContext&>(ctx);
auto &gctx = glctx(ctx);
ox::Bounds bnds;
glfwGetWindowPos(gctx.window, &bnds.x, &bnds.y);
glfwGetWindowSize(gctx.window, &bnds.width, &bnds.height);
@ -279,14 +288,14 @@ ox::Bounds getWindowBounds(Context &ctx) noexcept {
}
ox::Error setWindowBounds(Context &ctx, const ox::Bounds &bnds) noexcept {
auto &gctx = static_cast<GlfwContext&>(ctx);
auto &gctx = glctx(ctx);
glfwSetWindowPos(gctx.window, bnds.x, bnds.y);
glfwSetWindowSize(gctx.window, bnds.width, bnds.height);
return {};
}
void setConstantRefresh(Context &ctx, bool r) noexcept {
auto &gctx = static_cast<GlfwContext&>(ctx);
auto &gctx = glctx(ctx);
gctx.constantRefresh = r;
}