Skip to content

Commit e5294c9

Browse files
committed
fonts loading
1 parent da077e8 commit e5294c9

File tree

8 files changed

+13
-6
lines changed

8 files changed

+13
-6
lines changed

src/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ set(Source_Files__Window__Gui
247247
${CMAKE_CURRENT_SOURCE_DIR}/window/gui/GuiElement.cpp
248248
${CMAKE_CURRENT_SOURCE_DIR}/window/gui/GuiMenuBar.h
249249
${CMAKE_CURRENT_SOURCE_DIR}/window/gui/GuiMenuBar.cpp
250+
${CMAKE_CURRENT_SOURCE_DIR}/window/gui/resource/Font.h
251+
${CMAKE_CURRENT_SOURCE_DIR}/window/gui/resource/Font.cpp
252+
${CMAKE_CURRENT_SOURCE_DIR}/window/gui/resource/FontFactory.h
253+
${CMAKE_CURRENT_SOURCE_DIR}/window/gui/resource/FontFactory.cpp
250254
)
251255

252256
source_group("window/gui" FILES ${Source_Files__Window__Gui})

src/resource/ResourceManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ std::shared_future<std::shared_ptr<IResource>> ResourceManager::LoadResourceAsyn
174174
}
175175

176176
std::shared_ptr<IResource> ResourceManager::LoadResource(const std::string& filePath, bool loadExact, std::shared_ptr<ResourceInitData> initData) {
177-
auto resource = LoadResourceAsync(filePath, loadExact, true).get();
177+
auto resource = LoadResourceAsync(filePath, loadExact, true, initData).get();
178178
if (resource == nullptr) {
179179
SPDLOG_ERROR("Failed to load resource file at path {}", filePath);
180180
}

src/resource/ResourceType.h

-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ enum class ResourceType {
1414
Array = 0x4F415252, // OARR
1515
Blob = 0x4F424C42, // OBLB
1616
Texture = 0x4F544558, // OTEX
17-
Font = 0x464F4E54 // FONT
1817
};
1918
} // namespace LUS

src/window/gui/GameOverlay.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
#include "public/bridge/consolevariablebridge.h"
44
#include "resource/File.h"
5-
#include "resource/type/Font.h"
5+
#include "window/gui/resource/Font.h"
6+
#include "window/gui/resource/FontFactory.h"
67
#include "resource/archive/Archive.h"
78
#include "resource/ResourceManager.h"
89
#include "Context.h"
@@ -21,7 +22,7 @@ void GameOverlay::LoadFont(const std::string& name, const std::string& path, flo
2122
ImGuiIO& io = ImGui::GetIO();
2223
auto initData = std::make_shared<ResourceInitData>();
2324
initData->Format = RESOURCE_FORMAT_BINARY;
24-
initData->Type = static_cast<uint32_t>(ResourceType::Font);
25+
initData->Type = static_cast<uint32_t>(RESOURCE_TYPE_FONT);
2526
initData->ResourceVersion = 0;
2627
std::shared_ptr<Font> font = std::static_pointer_cast<Font>(Context::GetInstance()->GetResourceManager()->LoadResource(path, false, initData));
2728
if (font != nullptr) {
@@ -137,6 +138,7 @@ ImVec2 GameOverlay::CalculateTextSize(const char* text, const char* textEnd, boo
137138
}
138139

139140
void GameOverlay::Init() {
141+
Context::GetInstance()->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(std::make_shared<ResourceFactoryBinaryFontV0>(), RESOURCE_FORMAT_BINARY, "Font", static_cast<uint32_t>(RESOURCE_TYPE_FONT), 0);
140142
LoadFont("Press Start 2P", "fonts/PressStart2P-Regular.ttf", 12.0f);
141143
LoadFont("Fipps", "fonts/Fipps-Regular.otf", 32.0f);
142144
const std::string defaultFont = mFonts.begin()->first;
File renamed without changes.

src/resource/type/Font.h src/window/gui/resource/Font.h

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "resource/Resource.h"
44

55
namespace LUS {
6+
#define RESOURCE_TYPE_FONT 0x464F4E54
7+
68
class Font : public Resource<void> {
79
public:
810
using Resource::Resource;

src/resource/factory/FontFactory.cpp src/window/gui/resource/FontFactory.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "resource/factory/FontFactory.h"
2-
#include "resource/type/Font.h"
1+
#include "window/gui/resource/FontFactory.h"
2+
#include "window/gui/resource/Font.h"
33
#include "spdlog/spdlog.h"
44

55
namespace LUS {
File renamed without changes.

0 commit comments

Comments
 (0)