Skip to content

Commit 5739620

Browse files
committed
Merge branch 'main' into guitexture-resource
2 parents fd8d21c + ec01bc7 commit 5739620

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

src/window/gui/GameOverlay.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void GameOverlay::LoadFont(const std::string& name, const std::string& path, flo
2626
std::shared_ptr<Font> font = std::static_pointer_cast<Font>(
2727
Context::GetInstance()->GetResourceManager()->LoadResource(path, false, initData));
2828
if (font != nullptr) {
29-
mFonts[name] = io.Fonts->AddFontFromMemoryTTF(font->Data.data(), font->Data.size(), fontSize);
29+
mFonts[name] = io.Fonts->AddFontFromMemoryTTF(font->Data, font->DataSize, fontSize);
3030
}
3131
}
3232

src/window/gui/resource/Font.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ namespace LUS {
44
Font::Font() : Resource(std::shared_ptr<ResourceInitData>()) {
55
}
66

7+
Font::~Font() {
8+
if (Data != nullptr) {
9+
delete Data;
10+
}
11+
}
12+
713
void* Font::GetPointer() {
8-
return Data.data();
14+
return Data;
915
}
1016

1117
size_t Font::GetPointerSize() {
12-
return Data.size() * sizeof(char);
18+
return DataSize * sizeof(char);
1319
}
1420
} // namespace LUS

src/window/gui/resource/Font.h

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

55
namespace LUS {
6-
#define RESOURCE_TYPE_FONT 0x464F4E54
6+
#define RESOURCE_TYPE_FONT 0x464F4E54 // FONT
77

88
class Font : public Resource<void> {
99
public:
1010
using Resource::Resource;
1111

1212
Font();
13+
~Font();
1314

1415
void* GetPointer() override;
1516
size_t GetPointerSize() override;
1617

17-
std::vector<char> Data;
18+
char* Data = nullptr;
19+
size_t DataSize;
1820
};
1921
}; // namespace LUS

src/window/gui/resource/FontFactory.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ std::shared_ptr<IResource> ResourceFactoryBinaryFontV0::ReadResource(std::shared
1111
auto font = std::make_shared<Font>(file->InitData);
1212
auto reader = std::get<std::shared_ptr<BinaryReader>>(file->Reader);
1313

14-
uint32_t dataSize = file->Buffer->size();
14+
font->DataSize = file->Buffer->size();
1515

16-
font->Data.reserve(dataSize);
17-
18-
for (uint32_t i = 0; i < dataSize; i++) {
19-
font->Data.push_back(reader->ReadChar());
20-
}
16+
font->Data = new char[font->DataSize];
17+
reader->Read(font->Data, font->DataSize);
2118

2219
return font;
2320
}

0 commit comments

Comments
 (0)