| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include "ui.hpp"
- #include <imgui.h>
- #include <imgui_impl_sdl3.h>
- #include <imgui_impl_sdlrenderer3.h>
- namespace saura::ui {
- Context::Context(std::weak_ptr<os::Window_Context> window_ctx) {
- this->window_ctx = window_ctx;
- }
- void Context::init() {
- IMGUI_CHECKVERSION();
- ImGui::CreateContext();
- ImGuiIO &io = ImGui::GetIO();
- io.Fonts->AddFontFromFileTTF("res/fonts/InterRegular.ttf", 18, nullptr,
- io.Fonts->GetGlyphRangesCyrillic());
- (void)io;
- io.ConfigFlags |=
- ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
- io.ConfigFlags |=
- ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
- // Setup Dear ImGui style
- ImGui::StyleColorsDark();
- // Setup Platform/Renderer backends
- ImGui_ImplSDL3_InitForSDLRenderer(this->window_ctx.lock()->handle,
- this->window_ctx.lock()->renderer);
- ImGui_ImplSDLRenderer3_Init(this->window_ctx.lock()->renderer);
- }
- void Context::deinit() {
- ImGui_ImplSDLRenderer3_Shutdown();
- ImGui_ImplSDL3_Shutdown();
- ImGui::DestroyContext();
- }
- void Context::update_events(SDL_Event &event) {
- ImGui_ImplSDL3_ProcessEvent(&event);
- }
- void Context::begin() {
- ImGui_ImplSDLRenderer3_NewFrame();
- ImGui_ImplSDL3_NewFrame();
- ImGui::NewFrame();
- }
- void Context::end() {
- ImVec4 clear_color = {0.15f, 0.15f, 0.15f, 0.0f};
- ImGuiIO &io = ImGui::GetIO();
- (void)io;
- ImGui::Render();
- SDL_SetRenderScale(this->window_ctx.lock()->renderer, io.DisplayFramebufferScale.x,
- io.DisplayFramebufferScale.y);
- SDL_SetRenderDrawColorFloat(this->window_ctx.lock()->renderer, clear_color.x,
- clear_color.y, clear_color.z, clear_color.w);
- SDL_RenderClear(this->window_ctx.lock()->renderer);
- ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(),
- this->window_ctx.lock()->renderer);
- SDL_RenderPresent(this->window_ctx.lock()->renderer);
- }
- } // namespace saura::ui
|