Finish Classic 0.2 portability and release preparation (by Codex)
This commit is contained in:
1 parent
74ca973111
commit
6e5fa72ed5
13 files changed
+186
-25
No files matched your search
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "launch/launcher_ui.hpp"
|
||||
#include "launch/rml_path.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
#include "launch/process.hpp"
|
||||
#include "version.hpp"
|
||||
@@ -117,6 +118,7 @@ struct Video {
|
||||
};
|
||||
class RmlLauncher final : public LauncherUI, public Rml::EventListener {
|
||||
Video video_;
|
||||
rml::AssetFiles files_;
|
||||
SystemInterface_SDL system_{video_.window};
|
||||
RenderInterface_GL3 renderer_;
|
||||
TextInputMethodEditor_SDL ime_;
|
||||
@@ -215,6 +217,7 @@ class RmlLauncher final : public LauncherUI, public Rml::EventListener {
|
||||
answered_ = accepted_ = false;
|
||||
display("overlay", true);
|
||||
modal_visible_ = true;
|
||||
context_->Update();
|
||||
if (auto *input = document_->GetElementById("mod-name"))
|
||||
input->Focus(true);
|
||||
else
|
||||
@@ -391,6 +394,7 @@ class RmlLauncher final : public LauncherUI, public Rml::EventListener {
|
||||
throw std::runtime_error("RmlUI could not create the OpenGL renderer");
|
||||
try {
|
||||
Rml::SetSystemInterface(&system_);
|
||||
Rml::SetFileInterface(&files_);
|
||||
Rml::SetRenderInterface(&renderer_);
|
||||
Rml::SetTextInputHandler(&ime_);
|
||||
initialized_ = Rml::Initialise();
|
||||
@@ -398,12 +402,12 @@ class RmlLauncher final : public LauncherUI, public Rml::EventListener {
|
||||
throw std::runtime_error("RmlUI initialization failed");
|
||||
const auto assets = executable_path({}).parent_path() / "assets" / "launcher";
|
||||
for (const char *weight : {"Regular", "Bold"})
|
||||
if (!Rml::LoadFontFace(path_to_utf8(assets / (std::string("LatoLatin-") + weight + ".ttf"))))
|
||||
if (!Rml::LoadFontFace(rml::asset_path(assets / (std::string("LatoLatin-") + weight + ".ttf"))))
|
||||
throw std::runtime_error("Launcher font missing; extract the complete OpenBMH package");
|
||||
context_ = Rml::CreateContext("launcher", {1100, 688});
|
||||
if (!context_)
|
||||
throw std::runtime_error("RmlUI launcher context failed");
|
||||
document_ = context_->LoadDocument(path_to_utf8(assets / "launcher.rml"));
|
||||
document_ = context_->LoadDocument(rml::asset_path(assets / "launcher.rml"));
|
||||
if (!document_)
|
||||
throw std::runtime_error("Launcher layout missing; extract the complete OpenBMH package");
|
||||
document_->AddEventListener("click", this);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <RmlUi/Core/FileInterface.h>
|
||||
|
||||
namespace bmh::rml {
|
||||
// RmlUI parses document locations as URLs. Native Windows backslashes make
|
||||
// URL::GetPath() empty, so relative image sources lose their asset directory.
|
||||
inline std::string asset_path(const std::filesystem::path &path) {
|
||||
const auto utf8 = path.generic_u8string();
|
||||
return {utf8.begin(), utf8.end()};
|
||||
}
|
||||
// RmlUI paths are UTF-8. The Windows narrow fopen API uses the system code page.
|
||||
class AssetFiles : public Rml::FileInterface {
|
||||
public:
|
||||
Rml::FileHandle Open(const Rml::String &path) override {
|
||||
#ifdef _WIN32
|
||||
const std::u8string utf8(path.begin(), path.end());
|
||||
return reinterpret_cast<Rml::FileHandle>(_wfopen(std::filesystem::path(utf8).c_str(), L"rb"));
|
||||
#else
|
||||
return reinterpret_cast<Rml::FileHandle>(std::fopen(path.c_str(), "rb"));
|
||||
#endif
|
||||
}
|
||||
void Close(Rml::FileHandle file) override { std::fclose(reinterpret_cast<FILE *>(file)); }
|
||||
size_t Read(void *buffer, size_t size, Rml::FileHandle file) override {
|
||||
return std::fread(buffer, 1, size, reinterpret_cast<FILE *>(file));
|
||||
}
|
||||
bool Seek(Rml::FileHandle file, long offset, int origin) override {
|
||||
return std::fseek(reinterpret_cast<FILE *>(file), offset, origin) == 0;
|
||||
}
|
||||
size_t Tell(Rml::FileHandle file) override { return size_t(std::ftell(reinterpret_cast<FILE *>(file))); }
|
||||
};
|
||||
} // namespace bmh::rml
|
||||
Reference in new issue
Block a user