|
|
@@ -1,5 +1,6 @@
|
|
|
#include "ui.hpp"
|
|
|
|
|
|
+#include <SDL3/SDL_video.h>
|
|
|
#include <imgui.h>
|
|
|
#include <imgui_impl_sdl3.h>
|
|
|
#include <imgui_impl_sdlrenderer3.h>
|
|
|
@@ -13,7 +14,11 @@ void Context::init() {
|
|
|
IMGUI_CHECKVERSION();
|
|
|
ImGui::CreateContext();
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
|
|
- io.Fonts->AddFontFromFileTTF("res/fonts/InterRegular.ttf", 18, nullptr,
|
|
|
+
|
|
|
+ float dpi_scale = SDL_GetWindowDisplayScale(window_ctx.lock()->handle);
|
|
|
+ float font_size = 16.0f;
|
|
|
+
|
|
|
+ io.Fonts->AddFontFromFileTTF("res/fonts/InterRegular.ttf", font_size * dpi_scale, nullptr,
|
|
|
io.Fonts->GetGlyphRangesCyrillic());
|
|
|
|
|
|
(void)io;
|
|
|
@@ -24,6 +29,7 @@ void Context::init() {
|
|
|
|
|
|
// Setup Dear ImGui style
|
|
|
ImGui::StyleColorsDark();
|
|
|
+ ImGui::GetStyle().ScaleAllSizes(dpi_scale);
|
|
|
|
|
|
// Setup Platform/Renderer backends
|
|
|
ImGui_ImplSDL3_InitForSDLRenderer(this->window_ctx.lock()->handle,
|
|
|
@@ -42,24 +48,27 @@ void Context::update_events(SDL_Event &event) {
|
|
|
}
|
|
|
|
|
|
void Context::begin() {
|
|
|
+ ImGuiIO *io = &ImGui::GetIO();
|
|
|
+
|
|
|
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);
|
|
|
+ ImGuiIO *io = &ImGui::GetIO();
|
|
|
+ ImVec4 clear_color = {0.15f, 0.15f, 0.15f, 0.0f};
|
|
|
+
|
|
|
+ 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);
|
|
|
+ SDL_RenderPresent(this->window_ctx.lock()->renderer);
|
|
|
}
|
|
|
} // namespace saura::ui
|