0xc3 пре 1 месец
родитељ
комит
24d32e4c62

+ 1 - 1
README.md

@@ -1,4 +1,4 @@
 ```
-cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=/home/deck/.local/share/vcpkg/scripts/buildsystems/vcpkg.cmake
+cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=$HOME/.local/share/vcpkg/scripts/buildsystems/vcpkg.cmake
 cmake --build build --config Debug -j $(nproc)
 ```

+ 15 - 2
src/saura/cmd/sandbox/sandbox.cpp

@@ -2,7 +2,6 @@
 #include <cstring>
 #include <fmt/format.h>
 #include <memory>
-#include <saura/core/app_base/app_base.hpp>
 
 #include <spdlog/spdlog.h>
 
@@ -17,6 +16,8 @@
 #include "saura/core/base/types.hpp"
 #include "saura/core/memory/arena.hpp"
 #include "server/server.hpp"
+#include <saura/core/app_base/app_base.hpp>
+#include <saura/core/os/os.hpp>
 
 namespace saura {
 static bool req_open_ppm = false;
@@ -31,13 +32,18 @@ struct SandboxApp : AppBase {
   std::unique_ptr<MemoryArena> def_mem_arena;
   std::unique_ptr<MemoryArenaTemp> mem_arena_temp;
 
+  ClientInfo *tmp_client;
+
   void start() override {
     spdlog::info("Sandbox start!");
 
+    spdlog::info("DPI scale: {}", os_ctx->get_dpi_scale());
+
     this->def_mem_arena = std::make_unique<MemoryArena>();
     this->mem_arena_temp = std::make_unique<MemoryArenaTemp>();
 
-    this->def_mem_arena->push_zero(Kilobytes(1024));
+    this->tmp_client =
+        (ClientInfo *)this->def_mem_arena->push_zero(Kilobytes(1));
 
     this->server_api_ctx = std::make_shared<ServerAPI>();
     this->clients = server_api_ctx->fetch_clients(10, 0);
@@ -509,6 +515,13 @@ struct SandboxApp : AppBase {
     ImGui::End();
 
     ImGui::ShowDemoWindow();
+
+    // ImGui::SetNextWindowPos(ImGui::GetMousePos());
+    // ImGui::Begin("X", 0,
+    //              ImGuiWindowFlags_NoDecoration |
+    //                  ImGuiWindowFlags_NoMouseInputs |
+    //                  ImGuiWindowFlags_NoSavedSettings);
+    // ImGui::End();
   }
 
   void stop() override { spdlog::info("Sandbox stop!"); }

+ 0 - 12
src/saura/cmd/tests/tests.cpp

@@ -1,17 +1,5 @@
 #include <gtest/gtest.h>
 
-// Function to be tested
-int add(int a, int b) { return a + b; }
-
-// Define a test case (suite name) and a specific test name
-TEST(AdditionTest, PositiveNumbers) {
-  ASSERT_EQ(3, add(1, 2)); // Assertion to check for equality
-}
-
-TEST(AdditionTest, NegativeNumbers) { ASSERT_EQ(-3, add(-1, -2)); }
-
-// Main function to run all tests (often handled by the test framework in modern
-// IDE setups)
 int main(int argc, char **argv) {
   ::testing::InitGoogleTest(&argc, argv);
   return RUN_ALL_TESTS();

+ 2 - 0
src/saura/core/app_base/app_base.hpp

@@ -15,6 +15,8 @@ struct AppBase {
 private:
   std::string title;
   bool is_quit;
+
+public:
   std::unique_ptr<os::Context> os_ctx;
 
 public:

+ 17 - 8
src/saura/core/os/os.cpp

@@ -1,5 +1,7 @@
 #include "os.hpp"
 
+#include <spdlog/spdlog.h>
+
 namespace saura::os {
 Context::Context() {
   this->root_window_ctx = std::make_shared<os::Window_Context>();
@@ -15,10 +17,12 @@ Context::Context() {
     throw std::runtime_error("Failed SDL_Init!");
   }
 
-  SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
-  this->root_window_ctx->handle =
-      SDL_CreateWindow(this->root_window_ctx->title.c_str(), this->root_window_ctx->w,
-                       this->root_window_ctx->h, window_flags);
+  SDL_WindowFlags window_flags =
+      SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY;
+
+  this->root_window_ctx->handle = SDL_CreateWindow(
+      this->root_window_ctx->title.c_str(), this->root_window_ctx->w,
+      this->root_window_ctx->h, window_flags);
   if (this->root_window_ctx->handle == nullptr) {
     throw std::runtime_error("Failed SDL_CreateWindow!");
   }
@@ -28,7 +32,8 @@ Context::Context() {
   if (this->root_window_ctx->renderer == nullptr) {
     throw std::runtime_error("Failed SDL_CreateRenderer!");
   }
-  SDL_SetRenderVSync(this->root_window_ctx->renderer, SDL_RENDERER_VSYNC_DISABLED);
+  SDL_SetRenderVSync(this->root_window_ctx->renderer,
+                     SDL_RENDERER_VSYNC_DISABLED);
   SDL_SetWindowPosition(this->root_window_ctx->handle, SDL_WINDOWPOS_CENTERED,
                         SDL_WINDOWPOS_CENTERED);
 
@@ -59,8 +64,6 @@ void Context::update() {
 bool Context::update_events() {
   SDL_Event event = {};
   while (SDL_PollEvent(&event)) {
-    ui_ctx->update_events(event);
-
     switch (event.type) {
     case SDL_EVENT_KEY_UP: {
       if (event.key.key == SDLK_ESCAPE) {
@@ -72,12 +75,14 @@ bool Context::update_events() {
       return false;
     }
     case SDL_EVENT_WINDOW_CLOSE_REQUESTED: {
-      if (event.window.windowID == SDL_GetWindowID(this->root_window_ctx->handle)) {
+      if (event.window.windowID ==
+          SDL_GetWindowID(this->root_window_ctx->handle)) {
         return false;
       }
       break;
     }
     }
+    ui_ctx->update_events(event);
   }
   return true;
 }
@@ -100,6 +105,10 @@ double Context::get_performance_counter() {
   return (double)SDL_GetPerformanceCounter();
 }
 
+uint32_t Context::get_dpi_scale() {
+  return SDL_GetWindowDisplayScale(this->root_window_ctx.get()->handle);
+}
+
 std::string Context::get_safe_getenv(const std::string key) {
   return SDL_getenv(key.c_str());
 }

+ 3 - 0
src/saura/core/os/os.hpp

@@ -4,6 +4,7 @@
 #include <SDL3/SDL.h>
 
 #include <filesystem>
+#include <memory>
 
 #include "saura/core/os/os_types.hpp"
 #include "saura/core/ui/ui.hpp"
@@ -35,6 +36,8 @@ public:
   double get_performance_frequency();
   double get_performance_counter();
 
+  uint32_t get_dpi_scale();
+
   static std::string get_safe_getenv(const std::string key);
   static fs::path get_home_config_path();
   static std::string get_user_name();

+ 22 - 13
src/saura/core/ui/ui.cpp

@@ -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

+ 15 - 15
vcpkg.json

@@ -1,17 +1,17 @@
 {
- "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
- "name": "bookmarks",
- "version": "0.1.0",
- "dependencies": [
-  {
-   "name": "imgui",
-   "features": ["sdl3-binding", "sdl3-renderer-binding"]
-  },
-  "spdlog",
-  "sdl3",
-  "glm",
-  "cpr",
-  "nlohmann-json",
-  "gtest"
- ]
+  "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
+  "name": "bookmarks",
+  "version": "0.1.0",
+  "dependencies": [
+    {
+      "name": "imgui",
+      "features": ["sdl3-binding", "sdl3-renderer-binding"]
+    },
+    "spdlog",
+    "sdl3",
+    "glm",
+    "cpr",
+    "nlohmann-json",
+    "gtest"
+  ]
 }