Compare commits
1 Commits
main
...
feat/filesystem
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ca2c82718 |
+53
-2
@@ -10,6 +10,7 @@
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
#include <climits>
|
||||
#include <entt.hpp>
|
||||
#include "log.h"
|
||||
#include "Application.h"
|
||||
@@ -17,9 +18,56 @@
|
||||
#include "SceneGraph.h"
|
||||
#include "SceneLoader.h"
|
||||
#include "PhysFSManager.h"
|
||||
#include "physfs.h"
|
||||
#define IMVIEWGUIZMO_IMPLEMENTATION
|
||||
#include "ImViewGuizmoRaymath.h"
|
||||
|
||||
static ImFont* AddFontFromPhysFS(ImFontAtlas* atlas, const char* path, float size,
|
||||
ImFontConfig* config = nullptr, const ImWchar* ranges = nullptr)
|
||||
{
|
||||
if (!atlas || !path) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PHYSFS_File* file = PhysFSManager::OpenRead(path);
|
||||
if (!file) {
|
||||
log_warn("ImGui font missing: %s", path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PHYSFS_sint64 length = PHYSFS_fileLength(file);
|
||||
if (length <= 0 || length > static_cast<PHYSFS_sint64>(INT32_MAX)) {
|
||||
PhysFSManager::Close(file);
|
||||
log_warn("ImGui font invalid size: %s", path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
unsigned char* data = static_cast<unsigned char*>(IM_ALLOC(static_cast<size_t>(length)));
|
||||
if (!data) {
|
||||
PhysFSManager::Close(file);
|
||||
log_warn("ImGui font alloc failed: %s", path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PHYSFS_sint64 read = PHYSFS_readBytes(file, data, length);
|
||||
PhysFSManager::Close(file);
|
||||
if (read != length) {
|
||||
IM_FREE(data);
|
||||
log_warn("ImGui font read failed: %s", path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ImFontConfig localConfig;
|
||||
if (!config) {
|
||||
localConfig.FontDataOwnedByAtlas = true;
|
||||
config = &localConfig;
|
||||
} else {
|
||||
config->FontDataOwnedByAtlas = true;
|
||||
}
|
||||
|
||||
return atlas->AddFontFromMemoryTTF(data, static_cast<int>(length), size, config, ranges);
|
||||
}
|
||||
|
||||
GuiManager::GuiManager() {}
|
||||
|
||||
GuiManager::~GuiManager() {}
|
||||
@@ -2126,7 +2174,10 @@ void GuiManager::SetTheme()
|
||||
io.Fonts->Clear();
|
||||
|
||||
// Don't clear; just add new fonts and rebuild
|
||||
io.Fonts->AddFontFromFileTTF("fonts/Inter-Regular.ttf", 16); // index 0 (replaces default)
|
||||
ImFont* baseFont = AddFontFromPhysFS(io.Fonts, "fonts/Inter-Regular.ttf", 16);
|
||||
if (!baseFont) {
|
||||
baseFont = io.Fonts->AddFontDefault();
|
||||
}
|
||||
|
||||
// Re-add FontAwesome as merge into default (index 0)
|
||||
float iconFontSize = 16.0f * 2.0f / 3.0f;
|
||||
@@ -2138,7 +2189,7 @@ void GuiManager::SetTheme()
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(fa_solid_900_compressed_data,
|
||||
fa_solid_900_compressed_size,
|
||||
iconFontSize, &iconsConfig, iconsRanges);
|
||||
io.Fonts->AddFontFromFileTTF("fonts/JetBrainsMono-Regular.ttf", 16);
|
||||
AddFontFromPhysFS(io.Fonts, "fonts/JetBrainsMono-Regular.ttf", 16);
|
||||
io.Fonts->Build();
|
||||
|
||||
ImVec4 *colors = ImGui::GetStyle().Colors;
|
||||
|
||||
Reference in New Issue
Block a user