[turbine] Cleanup
This commit is contained in:
parent
81d092e967
commit
f6d2d96ff9
@ -15,15 +15,24 @@
|
|||||||
|
|
||||||
namespace turbine {
|
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 {
|
namespace gl {
|
||||||
|
|
||||||
void addDrawer(Context &ctx, Drawer *cd) noexcept {
|
void addDrawer(Context &ctx, Drawer *cd) noexcept {
|
||||||
auto &gctx = static_cast<GlfwContext&>(ctx);
|
auto &gctx = glctx(ctx);
|
||||||
gctx.drawers.emplace_back(cd);
|
gctx.drawers.emplace_back(cd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeDrawer(Context &ctx, Drawer *cd) noexcept {
|
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) {
|
for (auto i = 0u; i < gctx.drawers.size(); ++i) {
|
||||||
if (gctx.drawers[i] == cd) {
|
if (gctx.drawers[i] == cd) {
|
||||||
oxIgnoreError(gctx.drawers.erase(i));
|
oxIgnoreError(gctx.drawers.erase(i));
|
||||||
@ -65,7 +74,7 @@ static void handleKeyPress(Context *ctx, int key, bool down) noexcept {
|
|||||||
return map;
|
return map;
|
||||||
}();
|
}();
|
||||||
const auto eventHandler = keyEventHandler(*ctx);
|
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)];
|
const auto k = keyMap[static_cast<std::size_t>(key)];
|
||||||
setKeyDownStatus(&gctx, k, down);
|
setKeyDownStatus(&gctx, k, down);
|
||||||
if (eventHandler) {
|
if (eventHandler) {
|
||||||
@ -200,7 +209,7 @@ static void themeImgui() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error initGfx(Context &ctx) noexcept {
|
ox::Error initGfx(Context &ctx) noexcept {
|
||||||
auto &gctx = static_cast<GlfwContext&>(ctx);
|
auto &gctx = glctx(ctx);
|
||||||
glfwSetErrorCallback(handleGlfwError);
|
glfwSetErrorCallback(handleGlfwError);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 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 {
|
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);
|
auto cstr = ox_malloca(title.bytes() + 1, char);
|
||||||
ox_strncpy(cstr.get(), title.data(), title.bytes());
|
ox_strncpy(cstr.get(), title.data(), title.bytes());
|
||||||
glfwSetWindowTitle(gctx.window, cstr);
|
glfwSetWindowTitle(gctx.window, cstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void focusWindow(Context &ctx) noexcept {
|
void focusWindow(Context &ctx) noexcept {
|
||||||
auto &gctx = static_cast<GlfwContext&>(ctx);
|
auto &gctx = glctx(ctx);
|
||||||
glfwFocusWindow(gctx.window);
|
glfwFocusWindow(gctx.window);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getScreenWidth(Context &ctx) noexcept {
|
int getScreenWidth(Context &ctx) noexcept {
|
||||||
auto &gctx = static_cast<GlfwContext&>(ctx);
|
auto &gctx = glctx(ctx);
|
||||||
int w = 0, h = 0;
|
int w = 0, h = 0;
|
||||||
glfwGetFramebufferSize(gctx.window, &w, &h);
|
glfwGetFramebufferSize(gctx.window, &w, &h);
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getScreenHeight(Context &ctx) noexcept {
|
int getScreenHeight(Context &ctx) noexcept {
|
||||||
auto &gctx = static_cast<GlfwContext&>(ctx);
|
auto &gctx = glctx(ctx);
|
||||||
int w = 0, h = 0;
|
int w = 0, h = 0;
|
||||||
glfwGetFramebufferSize(gctx.window, &w, &h);
|
glfwGetFramebufferSize(gctx.window, &w, &h);
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Size getScreenSize(Context &ctx) noexcept {
|
ox::Size getScreenSize(Context &ctx) noexcept {
|
||||||
auto &gctx = static_cast<GlfwContext&>(ctx);
|
auto &gctx = glctx(ctx);
|
||||||
int w = 0, h = 0;
|
int w = 0, h = 0;
|
||||||
glfwGetFramebufferSize(gctx.window, &w, &h);
|
glfwGetFramebufferSize(gctx.window, &w, &h);
|
||||||
return {w, h};
|
return {w, h};
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Bounds getWindowBounds(Context &ctx) noexcept {
|
ox::Bounds getWindowBounds(Context &ctx) noexcept {
|
||||||
auto &gctx = static_cast<GlfwContext&>(ctx);
|
auto &gctx = glctx(ctx);
|
||||||
ox::Bounds bnds;
|
ox::Bounds bnds;
|
||||||
glfwGetWindowPos(gctx.window, &bnds.x, &bnds.y);
|
glfwGetWindowPos(gctx.window, &bnds.x, &bnds.y);
|
||||||
glfwGetWindowSize(gctx.window, &bnds.width, &bnds.height);
|
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 {
|
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);
|
glfwSetWindowPos(gctx.window, bnds.x, bnds.y);
|
||||||
glfwSetWindowSize(gctx.window, bnds.width, bnds.height);
|
glfwSetWindowSize(gctx.window, bnds.width, bnds.height);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void setConstantRefresh(Context &ctx, bool r) noexcept {
|
void setConstantRefresh(Context &ctx, bool r) noexcept {
|
||||||
auto &gctx = static_cast<GlfwContext&>(ctx);
|
auto &gctx = glctx(ctx);
|
||||||
gctx.constantRefresh = r;
|
gctx.constantRefresh = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user