0xc3 20 stundas atpakaļ
vecāks
revīzija
6b8fb98db0

BIN
res/fonts/InterRegular.ttf


BIN
res/fonts/ProggyClean.ttf


BIN
res/fonts/ProggyTiny.ttf


+ 3 - 0
scripts/build-debug.sh

@@ -3,5 +3,8 @@
 VCPKG_ROOT="$HOME/.local/share/vcpkg"
 PATH="$PATH:$VCPKG_ROOT"
 
+mkdir -p ./build/Debug
+ln -s $PWD/res $PWD/build/Debug/
+
 cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
 cmake --build build --config Debug -j $(nproc)

+ 3 - 0
scripts/build-release.sh

@@ -3,5 +3,8 @@
 VCPKG_ROOT="$HOME/.local/share/vcpkg"
 PATH="$PATH:$VCPKG_ROOT"
 
+mkdir -p ./build/Release
+ln -s $PWD/res $PWD/build/Release/
+
 cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
 cmake --build build --config Release -j $(nproc)

+ 1 - 1
src/saura/app/app.cpp

@@ -6,7 +6,7 @@ namespace saura {
 App::App() {
   is_running = true;
 
-  os_ctx = std::make_unique<OS>();
+  os_ctx = std::make_unique<os::Context>();
   os_ctx->set_root_window_title(get_app_base()->get_title());
 }
 

+ 1 - 1
src/saura/app/app.hpp

@@ -10,7 +10,7 @@
 namespace saura {
 class App {
 private:
-  std::unique_ptr<OS> os_ctx;
+  std::unique_ptr<os::Context> os_ctx;
 
   bool is_running;
 

+ 30 - 3
src/saura/cmd/sandbox/sandbox.cpp

@@ -12,19 +12,46 @@ struct SandboxApp : AppBase {
   std::shared_ptr<ServerAPI> server_api_ctx;
 
   void start() override {
-      spdlog::info("Sandbox start!");
+    spdlog::info("Sandbox start!");
 
-      server_api_ctx = std::make_shared<ServerAPI>();
+    server_api_ctx = std::make_shared<ServerAPI>();
   }
 
   void update(double dt) override {
     ImGui::SetNextWindowPos({0.0f, 0.0f});
     ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
-    ImGui::Begin("Demo", 0, ImGuiWindowFlags_NoDecoration);
 
+    ImGui::Begin("Demo", 0,
+                 ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
+                     ImGuiWindowFlags_NoFocusOnAppearing |
+                     ImGuiWindowFlags_NoSavedSettings);
     ImGui::Text("%s", this->get_title().c_str());
 
+    if (ImGui::BeginTabBar("Tabs")) {
+      // Tab 1
+      if (ImGui::BeginTabItem(u8"Главная")) {
+        ImGui::Text("Welcome to Tab 1 content!");
+        ImGui::Button("Click me in Tab 1");
+        ImGui::EndTabItem();
+      }
+
+      // Tab 2
+      if (ImGui::BeginTabItem(u8"Клиенты")) {
+        ImGui::Text("This is the content for Tab 2.");
+        ImGui::EndTabItem();
+      }
+
+      // Tab 3
+      if (ImGui::BeginTabItem(u8"Настройки")) {
+        ImGui::Text("Hello from the third tab.");
+        ImGui::EndTabItem();
+      }
+      ImGui::EndTabBar();
+    }
+
     ImGui::End();
+
+    ImGui::ShowDemoWindow();
   }
 
   void stop() override { spdlog::info("Sandbox stop!"); }

+ 4 - 1
src/saura/cmd/sandbox/server/server.hpp

@@ -1,4 +1,5 @@
-#pragma once
+#ifndef SAURA_SERVER_HPP_
+#define SAURA_SERVER_HPP_
 
 #include <atomic>
 #include <thread>
@@ -18,3 +19,5 @@ public:
   bool get_is_live();
 };
 }; // namespace saura
+
+#endif

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

@@ -1,4 +1,5 @@
-#pragma once
+#ifndef SAURA_APP_BASE_HPP_
+#define SAURA_APP_BASE_HPP_
 
 #include <spdlog/spdlog.h>
 
@@ -14,7 +15,9 @@ struct AppBase {
   virtual void start() {}
   virtual void update(double dt) {}
   virtual void stop() {}
-  virtual const std::string get_title() const { return g_app_base_instance->get_title(); }
+  virtual const std::string get_title() const {
+    return g_app_base_instance->get_title();
+  }
 };
 
 inline AppBase *get_app_base() {
@@ -25,3 +28,5 @@ inline AppBase *get_app_base() {
   return g_app_base_instance;
 }
 } // namespace saura
+
+#endif

+ 44 - 90
src/saura/core/os/os.cpp

@@ -1,23 +1,13 @@
 #include "os.hpp"
 
-#include <SDL3/SDL.h>
-#include <SDL3/SDL_oldnames.h>
-#include <SDL3/SDL_video.h>
+namespace saura::os {
+Context::Context() {
+  this->root_window_ctx = std::make_shared<os::Window_Context>();
+  this->root_window_ctx->title = "(Saura Studios) [Dev]";
+  this->root_window_ctx->w = 1280;
+  this->root_window_ctx->h = 720;
 
-#include <imgui.h>
-#include <imgui_impl_sdl3.h>
-#include <imgui_impl_sdlrenderer3.h>
-
-#include <filesystem>
-#include <locale>
-#include <string>
-
-namespace saura {
-OS::OS() {
-  root_window_ctx = std::make_unique<Window_Context>();
-  root_window_ctx->title = "(Saura Studios) [Dev]";
-  root_window_ctx->w = 1280;
-  root_window_ctx->h = 720;
+  ui_ctx = std::make_unique<ui::Context>(this->root_window_ctx);
 
   std::locale::global(std::locale("en_US.UTF-8"));
 
@@ -26,86 +16,50 @@ OS::OS() {
   }
 
   SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
-  root_window_ctx->handle =
-      SDL_CreateWindow(root_window_ctx->title.c_str(), root_window_ctx->w,
-                       root_window_ctx->h, window_flags);
-  if (root_window_ctx->handle == nullptr) {
+  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!");
   }
 
-  root_window_ctx->renderer =
-      SDL_CreateRenderer(root_window_ctx->handle, nullptr);
-  if (root_window_ctx->renderer == nullptr) {
+  this->root_window_ctx->renderer =
+      SDL_CreateRenderer(this->root_window_ctx->handle, nullptr);
+  if (this->root_window_ctx->renderer == nullptr) {
     throw std::runtime_error("Failed SDL_CreateRenderer!");
   }
-  SDL_SetRenderVSync(root_window_ctx->renderer, SDL_RENDERER_VSYNC_DISABLED);
-  SDL_SetWindowPosition(root_window_ctx->handle, SDL_WINDOWPOS_CENTERED,
+  SDL_SetRenderVSync(this->root_window_ctx->renderer, SDL_RENDERER_VSYNC_DISABLED);
+  SDL_SetWindowPosition(this->root_window_ctx->handle, SDL_WINDOWPOS_CENTERED,
                         SDL_WINDOWPOS_CENTERED);
-  SDL_ShowWindow(root_window_ctx->handle);
-
-  // Setup imgui
-  IMGUI_CHECKVERSION();
-  ImGui::CreateContext();
-  ImGuiIO &io = ImGui::GetIO();
-  (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(root_window_ctx->handle,
-                                    root_window_ctx->renderer);
-  ImGui_ImplSDLRenderer3_Init(root_window_ctx->renderer);
+
+  ui_ctx->init();
+
+  SDL_ShowWindow(this->root_window_ctx->handle);
 }
 
-OS::~OS() {
-  ImGui_ImplSDLRenderer3_Shutdown();
-  ImGui_ImplSDL3_Shutdown();
-  ImGui::DestroyContext();
+Context::~Context() {
+  ui_ctx->deinit();
 
-  SDL_DestroyRenderer(root_window_ctx->renderer);
-  SDL_DestroyWindow(root_window_ctx->handle);
+  SDL_DestroyRenderer(this->root_window_ctx->renderer);
+  SDL_DestroyWindow(this->root_window_ctx->handle);
   SDL_Quit();
 }
 
-void OS::draw_begin() {
-  ImGui_ImplSDLRenderer3_NewFrame();
-  ImGui_ImplSDL3_NewFrame();
-  ImGui::NewFrame();
-}
+void Context::draw_begin() { this->ui_ctx->begin(); }
 
-void OS::draw_end() {
-  ImVec4 clear_color = {0.15f, 0.15f, 0.15f, 0.0f};
-  ImGuiIO &io = ImGui::GetIO();
-  (void)io;
-  ImGui::Render();
-  SDL_SetRenderScale(root_window_ctx->renderer, io.DisplayFramebufferScale.x,
-                     io.DisplayFramebufferScale.y);
-  SDL_SetRenderDrawColorFloat(root_window_ctx->renderer, clear_color.x,
-                              clear_color.y, clear_color.z, clear_color.w);
-  SDL_RenderClear(root_window_ctx->renderer);
-  ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(),
-                                        root_window_ctx->renderer);
-
-  SDL_RenderPresent(root_window_ctx->renderer);
-}
+void Context::draw_end() { this->ui_ctx->end(); }
 
-void OS::update() {
+void Context::update() {
   int w, h = 0;
-  SDL_GetWindowSize(root_window_ctx->handle, &w, &h);
-  root_window_ctx->w = w;
-  root_window_ctx->h = h;
+  SDL_GetWindowSize(this->root_window_ctx->handle, &w, &h);
+  this->root_window_ctx->w = w;
+  this->root_window_ctx->h = h;
 }
 
-bool OS::update_events() {
+bool Context::update_events() {
   SDL_Event event = {};
   while (SDL_PollEvent(&event)) {
-
-    ImGui_ImplSDL3_ProcessEvent(&event);
+    ui_ctx->update_events(event);
 
     switch (event.type) {
     case SDL_EVENT_KEY_UP: {
@@ -118,7 +72,7 @@ bool OS::update_events() {
       return false;
     }
     case SDL_EVENT_WINDOW_CLOSE_REQUESTED: {
-      if (event.window.windowID == SDL_GetWindowID(root_window_ctx->handle)) {
+      if (event.window.windowID == SDL_GetWindowID(this->root_window_ctx->handle)) {
         return false;
       }
       break;
@@ -128,29 +82,29 @@ bool OS::update_events() {
   return true;
 }
 
-void OS::sleep(double ms) { SDL_Delay((Uint32)ms * 1000); }
+void Context::sleep(double ms) { SDL_Delay((Uint32)ms * 1000); }
 
-int OS::get_root_window_width() { return root_window_ctx->w; }
+int Context::get_root_window_width() { return this->root_window_ctx->w; }
 
-int OS::get_root_window_height() { return root_window_ctx->h; }
+int Context::get_root_window_height() { return this->root_window_ctx->h; }
 
-void OS::set_root_window_title(std::string title) {
-    SDL_SetWindowTitle(root_window_ctx.get()->handle, title.c_str());
+void Context::set_root_window_title(std::string title) {
+  SDL_SetWindowTitle(this->root_window_ctx.get()->handle, title.c_str());
 }
 
-double OS::get_performance_frequency() {
+double Context::get_performance_frequency() {
   return (double)SDL_GetPerformanceFrequency();
 }
 
-double OS::get_performance_counter() {
+double Context::get_performance_counter() {
   return (double)SDL_GetPerformanceCounter();
 }
 
-std::string OS::get_safe_getenv(const std::string key) {
+std::string Context::get_safe_getenv(const std::string key) {
   return SDL_getenv(key.c_str());
 }
 
-fs::path OS::get_home_config_path() {
+fs::path Context::get_home_config_path() {
   fs::path res = {};
 
 #if defined(_WIN32)
@@ -174,5 +128,5 @@ fs::path OS::get_home_config_path() {
   return res;
 }
 
-std::string OS::get_user_name() { return get_safe_getenv("USERNAME"); }
-} // namespace saura
+std::string Context::get_user_name() { return get_safe_getenv("USERNAME"); }
+} // namespace saura::os

+ 11 - 16
src/saura/core/os/os.hpp

@@ -1,29 +1,24 @@
 #ifndef SAURA_OS_HPP_
 #define SAURA_OS_HPP_
 
-#include <cstdint>
+#include <SDL3/SDL.h>
+
 #include <filesystem>
 
-#include <SDL3/SDL_render.h>
-#include <SDL3/SDL_video.h>
+#include "saura/core/os/os_types.hpp"
+#include "saura/core/ui/ui.hpp"
 
 namespace fs = std::filesystem;
 
-namespace saura {
-class OS {
-  struct Window_Context {
-    uint32_t w, h;
-    std::string title;
-    SDL_Window *handle;
-    SDL_Renderer *renderer;
-  };
-
+namespace saura::os {
+class Context {
 private:
-  std::unique_ptr<Window_Context> root_window_ctx;
+  std::shared_ptr<Window_Context> root_window_ctx;
+  std::unique_ptr<ui::Context> ui_ctx;
 
 public:
-  OS();
-  ~OS();
+  Context();
+  ~Context();
 
   void draw_begin();
   void draw_end();
@@ -44,6 +39,6 @@ public:
   static fs::path get_home_config_path();
   static std::string get_user_name();
 };
-} // namespace saura
+} // namespace saura::os
 
 #endif

+ 19 - 0
src/saura/core/os/os_types.hpp

@@ -0,0 +1,19 @@
+#ifndef SAURA_OS_TYPES_HPP_
+#define SAURA_OS_TYPES_HPP_
+
+#include <SDL3/SDL_render.h>
+#include <SDL3/SDL_video.h>
+
+#include <cstdint>
+#include <string>
+
+namespace saura::os {
+struct Window_Context {
+  uint32_t w, h;
+  std::string title;
+  SDL_Window *handle;
+  SDL_Renderer *renderer;
+};
+} // namespace saura
+
+#endif

+ 65 - 0
src/saura/core/ui/ui.cpp

@@ -0,0 +1,65 @@
+#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

+ 28 - 0
src/saura/core/ui/ui.hpp

@@ -0,0 +1,28 @@
+#ifndef SAURA_UI_HPP_
+#define SAURA_UI_HPP_
+
+#include <memory>
+
+#include <SDL3/SDL_events.h>
+
+#include "saura/core/os/os_types.hpp"
+
+namespace saura::ui {
+class Context {
+private:
+  std::weak_ptr<os::Window_Context> window_ctx;
+
+public:
+  Context(std::weak_ptr<os::Window_Context> window_ctx);
+
+  void init();
+  void deinit();
+
+  void update_events(SDL_Event &event);
+
+  void begin();
+  void end();
+};
+} // namespace saura::ui
+
+#endif