First commit.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <hdk/sdl.hpp>
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_sdl3.h>
|
||||
#include <imgui_impl_sdlrenderer3.h>
|
||||
|
||||
#include <hdk/sdl/Application.hpp>
|
||||
|
||||
namespace hdk::is3r {
|
||||
class Is3rWindowContext;
|
||||
class Is3rApp : public sdl::ProtectedApp {
|
||||
public:
|
||||
virtual SDL_AppResult Event(SDL_Event* event) override {
|
||||
ImGui_ImplSDL3_ProcessEvent(event);
|
||||
return ProtectedApp::Event(event);
|
||||
}
|
||||
|
||||
Is3rWindowContext CreateWindow(const char* title, int width, int height, SDL_WindowFlags flags);
|
||||
};
|
||||
|
||||
struct Is3rWindowData {
|
||||
sdl::Window window { nullptr };
|
||||
sdl::Renderer renderer { nullptr };
|
||||
sdl::evt::WindowEvents window_events;
|
||||
grid::eps::Conduit<> on_iterate;
|
||||
grid::eps::Conduit<> on_frame;
|
||||
grid::eps::TapScope taps;
|
||||
};
|
||||
|
||||
class Is3rWindowContext : public grid::SharedPtrWrapper<Is3rWindowData> {
|
||||
public:
|
||||
using SharedPtrWrapper<Is3rWindowData>::SharedPtrWrapper;
|
||||
|
||||
static Is3rWindowContext Create(const char* title, int width, int height, SDL_WindowFlags flags) {
|
||||
auto [window, renderer] = sdl::CreateWindowAndRenderer(title, width, height, flags);
|
||||
if (!window || !renderer) {
|
||||
SDL_Log("Failed to create window or renderer: %s", SDL_GetError());
|
||||
return Is3rWindowContext(nullptr);
|
||||
}
|
||||
auto* data = new Is3rWindowData{.window = window, .renderer = renderer};
|
||||
auto context = Is3rWindowContext(get_or_cache(data, [](Is3rWindowData* data) { delete data; }));
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
inline Is3rWindowContext Is3rApp::CreateWindow(const char* title, int width, int height, SDL_WindowFlags flags) {
|
||||
auto ctx = Is3rWindowContext::Create(title, width, height, flags);
|
||||
auto wid = ctx->window.GetID();
|
||||
ctx->taps << events.Window[wid] % ctx->window_events;
|
||||
ctx->taps << OnIterate % ctx->on_iterate;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user