0xc3 4 days ago
parent
commit
380633dbc3

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

@@ -7,8 +7,9 @@ App::App() {
   is_running = true;
 
   os_ctx = std::make_unique<OS>();
+  os_ctx->set_root_window_title(get_app_base()->get_title());
+
   server_api_ctx = std::make_shared<ServerAPI>();
-  ui_ctx = std::make_unique<UI>(server_api_ctx);
 }
 
 App::~App() {}

+ 0 - 2
front/src/saura/app/app.hpp

@@ -3,7 +3,6 @@
 
 #include "saura/core/os/os.hpp"
 #include "saura/core/server/server.hpp"
-#include "saura/core/ui/ui.hpp"
 
 #include <SDL3/SDL_render.h>
 #include <SDL3/SDL_video.h>
@@ -13,7 +12,6 @@ namespace saura {
 class App {
 private:
   std::unique_ptr<OS> os_ctx;
-  std::unique_ptr<UI> ui_ctx;
   std::shared_ptr<ServerAPI> server_api_ctx;
 
   bool is_running;

+ 11 - 5
front/src/saura/cmd/sandbox/sandbox.cpp

@@ -2,20 +2,26 @@
 
 #include <spdlog/spdlog.h>
 
+#include <imgui.h>
+#include <imgui_internal.h>
+
 namespace saura {
 struct SandboxApp : AppBase {
   void start() override { spdlog::info("Sandbox start!"); }
 
   void update(double dt) override {
-    // static float t = 0;
-    // t += dt;
-    // if (int(t) % 3 == 0)
-    //   spdlog::info("tick {}", t);
+      ImGui::SetNextWindowPos({0.0f, 0.0f});
+      ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
+      ImGui::Begin("Demo", 0, ImGuiWindowFlags_NoDecoration);
+
+      ImGui::Text("%s", this->get_title().c_str());
+
+      ImGui::End();
   }
 
   void stop() override { spdlog::info("Sandbox stop!"); }
 
-  const char *name() const override { return "Cool Sandbox"; }
+  const std::string get_title() const override { return "Sandbox (Dev)"; }
 };
 
 AppBase *g_app_base_instance = new SandboxApp();

+ 8 - 7
front/src/saura/core/app_base/app_base.hpp

@@ -3,22 +3,23 @@
 #include <spdlog/spdlog.h>
 
 namespace saura {
+struct AppBase;
+
+// Эта глобальная переменная будет переопределена линковщиком в каждом
+// cmd-проекте
+extern AppBase *g_app_base_instance;
+
 struct AppBase {
   virtual ~AppBase() = default;
   virtual void start() {}
   virtual void update(double dt) {}
   virtual void stop() {}
-  virtual const char *name() const { return "Unnamed App"; }
+  virtual const std::string get_title() const { return g_app_base_instance->get_title(); }
 };
 
-// Эта глобальная переменная будет переопределена линковщиком в каждом
-// cmd-проекте
-extern AppBase *g_app_base_instance;
-
 inline AppBase *get_app_base() {
   if (!g_app_base_instance) {
-    spdlog::error(
-        "g_app_instance не определён!");
+    spdlog::error("g_app_instance не определён!");
     std::terminate();
   }
   return g_app_base_instance;

+ 5 - 0
front/src/saura/core/os/os.cpp

@@ -1,6 +1,7 @@
 #include "os.hpp"
 
 #include <SDL3/SDL.h>
+#include <SDL3/SDL_oldnames.h>
 #include <SDL3/SDL_video.h>
 
 #include <imgui.h>
@@ -133,6 +134,10 @@ int OS::get_root_window_width() { return root_window_ctx->w; }
 
 int OS::get_root_window_height() { return root_window_ctx->h; }
 
+void OS::set_root_window_title(std::string title) {
+    SDL_SetWindowTitle(root_window_ctx.get()->handle, title.c_str());
+}
+
 double OS::get_performance_frequency() {
   return (double)SDL_GetPerformanceFrequency();
 }

+ 2 - 0
front/src/saura/core/os/os.hpp

@@ -35,6 +35,8 @@ public:
   int get_root_window_width();
   int get_root_window_height();
 
+  void set_root_window_title(std::string title);
+
   double get_performance_frequency();
   double get_performance_counter();
 

+ 0 - 105
front/src/saura/core/ui/ui.cpp

@@ -1,105 +0,0 @@
-#include "ui.hpp"
-
-#include <imgui.h>
-#include <imgui_internal.h>
-
-#include <cstdint>
-#include <vector>
-
-#include "saura/core/server/server.hpp"
-
-namespace saura {
-UI::UI(std::shared_ptr<ServerAPI> server_api_ctx) {
-  current_ent = nullptr;
-  server_info = {};
-  deps.server_api_ctx = server_api_ctx;
-
-  auto items = std::vector<Entity>{
-      {
-          .uuid = "0",
-          .title = "Talltale Online",
-          .url = "https://talltale.online/",
-      },
-      {
-          .uuid = "1",
-          .title = "Google",
-          .url = "https://google.com/",
-      },
-      {
-          .uuid = "2",
-          .title = "Arch Linux",
-          .url = "https://archlinux.org/",
-      },
-      {
-          .uuid = "3",
-          .title = "GitHub",
-          .url = "https://github.com/",
-      },
-  };
-
-  for (uint32_t i = 0; i < items.size(); i += 1) {
-    entities.push_back(items[i]);
-  }
-}
-
-UI::~UI() {}
-
-void UI::draw() {
-  server_info.is_connect = deps.server_api_ctx.lock()->get_is_live();
-
-  ImGui::SetNextWindowPos({0.0f, 0.0f});
-  ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
-  ImGui::Begin("Drag & Drop List", 0, ImGuiWindowFlags_NoDecoration);
-
-  {
-    ImGui::Text("server.is_connect:");
-    ImVec2 text_pos = ImGui::GetItemRectMax();
-    float spacing = 5.0f;
-    ImVec2 center = ImVec2(text_pos.x + spacing + 4.0f,
-                           text_pos.y - ImGui::GetTextLineHeight() * 0.5f);
-    float radius = 4.0f;
-    ImU32 color = IM_COL32(255, 0, 0, 255);
-    if (server_info.is_connect == true) {
-      color = IM_COL32(0, 255, 0, 255);
-    }
-    ImDrawList *draw_list = ImGui::GetWindowDrawList();
-    draw_list->AddCircleFilled(center, radius, color, 16);
-  }
-
-  ImGui::Text("ent.count: %d", (int)entities.size());
-  if (current_ent != nullptr) {
-    ImGui::Text("current_ent_uuid: %s", current_ent->uuid.c_str());
-  } else {
-    ImGui::Text("current_ent_uuid: None");
-  }
-
-  ImVec2 mouse = ImGui::GetMousePos();
-  uint32_t rect_count = 0;
-
-  // --- Render ---
-  for (auto &ent : entities) {
-    ImGui::PushID(ent.uuid.c_str());
-    ImGui::Button(ent.title.c_str(), {150, 22});
-    ent.local_tmp_id = ImGui::GetItemID();
-    ent.rect.min = ImGui::GetItemRectMin();
-    ent.rect.max = ImGui::GetItemRectMax();
-    ImGui::PopID();
-  }
-
-  // --- Logic ---
-  for (auto &ent : entities) {
-    ImGuiID ent_hovered_id = ImGui::GetCurrentContext()->HoveredId;
-
-    // --- Handle drag start ---
-    if (ImGui::IsMouseDown(ImGuiMouseButton_Left) &&
-        ent.local_tmp_id == ent_hovered_id) {
-      current_ent = &ent;
-    } else if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
-      current_ent = nullptr;
-    }
-  }
-
-  ImGui::End();
-}
-
-} // namespace saura

+ 0 - 41
front/src/saura/core/ui/ui.hpp

@@ -1,41 +0,0 @@
-#pragma once
-
-#include "saura/core/server/server.hpp"
-#include <cstdint>
-#include <imgui.h>
-#include <memory>
-#include <string>
-#include <vector>
-
-namespace saura {
-struct Entity {
-  std::string uuid;
-  uint32_t local_tmp_id;
-  std::string title;
-  std::string url;
-  struct {
-    ImVec2 min;
-    ImVec2 max;
-  } rect;
-};
-
-struct ServerInfo {
-  bool is_connect;
-};
-
-class UI {
-private:
-  Entity *current_ent;
-  std::vector<Entity> entities;
-  ServerInfo server_info;
-
-  struct {
-    std::weak_ptr<ServerAPI> server_api_ctx;
-  } deps;
-
-public:
-  UI(std::shared_ptr<ServerAPI> server_api_ctx);
-  ~UI();
-  void draw();
-};
-} // namespace saura