mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 13:55:38 +00:00
CommonHostInterface: Move fonts/logo to resources directory
This commit is contained in:
parent
c4f0dafb1f
commit
4f190aa902
BIN
data/resources/roboto-regular.ttf
Normal file
BIN
data/resources/roboto-regular.ttf
Normal file
Binary file not shown.
|
@ -556,10 +556,40 @@ bool CommonHostInterface::CreateHostDisplayResources()
|
|||
|
||||
if (!m_display->CreateImGuiContext())
|
||||
{
|
||||
Log_ErrorPrintf("Failed to create ImGui device context");
|
||||
ReportError("Failed to create ImGui device context");
|
||||
return false;
|
||||
}
|
||||
|
||||
// load text font
|
||||
{
|
||||
std::unique_ptr<ByteStream> stream = OpenPackageFile("resources" FS_OSPATH_SEPARATOR_STR "roboto-regular.ttf",
|
||||
BYTESTREAM_OPEN_READ | BYTESTREAM_OPEN_STREAMED);
|
||||
std::vector<u8> font_data;
|
||||
if (!stream || (font_data = FileSystem::ReadBinaryStream(stream.get()), font_data.empty()))
|
||||
{
|
||||
ReportError("Failed to load text font");
|
||||
m_display->DestroyImGuiContext();
|
||||
return false;
|
||||
}
|
||||
|
||||
ImGuiFullscreen::SetFontData(std::move(font_data));
|
||||
}
|
||||
|
||||
// load icon font
|
||||
{
|
||||
std::unique_ptr<ByteStream> stream = OpenPackageFile("resources" FS_OSPATH_SEPARATOR_STR "fa-solid-900.ttf",
|
||||
BYTESTREAM_OPEN_READ | BYTESTREAM_OPEN_STREAMED);
|
||||
std::vector<u8> font_data;
|
||||
if (!stream || (font_data = FileSystem::ReadBinaryStream(stream.get()), font_data.empty()))
|
||||
{
|
||||
ReportError("Failed to load icon font");
|
||||
m_display->DestroyImGuiContext();
|
||||
return false;
|
||||
}
|
||||
|
||||
ImGuiFullscreen::SetIconFontData(std::move(font_data));
|
||||
}
|
||||
|
||||
if (m_fullscreen_ui_enabled)
|
||||
{
|
||||
if (!FullscreenUI::Initialize(this))
|
||||
|
@ -572,9 +602,7 @@ bool CommonHostInterface::CreateHostDisplayResources()
|
|||
if (!m_fullscreen_ui_enabled)
|
||||
ImGuiFullscreen::ResetFonts();
|
||||
|
||||
m_logo_texture = m_display->CreateTexture(APP_ICON_WIDTH, APP_ICON_HEIGHT, 1, 1, 1, HostDisplayPixelFormat::RGBA8,
|
||||
APP_ICON_DATA, sizeof(u32) * APP_ICON_WIDTH, false);
|
||||
if (!m_logo_texture || !m_display->UpdateImGuiFontTexture())
|
||||
if (!m_display->UpdateImGuiFontTexture())
|
||||
{
|
||||
Log_ErrorPrintf("Failed to create ImGui font text");
|
||||
if (m_fullscreen_ui_enabled)
|
||||
|
@ -585,6 +613,10 @@ bool CommonHostInterface::CreateHostDisplayResources()
|
|||
return false;
|
||||
}
|
||||
|
||||
m_logo_texture = FullscreenUI::LoadTextureResource("logo.png", false);
|
||||
if (!m_logo_texture)
|
||||
m_logo_texture = FullscreenUI::LoadTextureResource("duck.png", true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3314,8 +3346,8 @@ void CommonHostInterface::DisplayLoadingScreen(const char* message, int progress
|
|||
// eat the last imgui frame, it might've been partially rendered by the caller.
|
||||
ImGui::NewFrame();
|
||||
|
||||
const float logo_width = static_cast<float>(APP_ICON_WIDTH) * scale;
|
||||
const float logo_height = static_cast<float>(APP_ICON_HEIGHT) * scale;
|
||||
const float logo_width = 260.0f * scale;
|
||||
const float logo_height = 260.0f * scale;
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(logo_width, logo_height), ImGuiCond_Always);
|
||||
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, (io.DisplaySize.y * 0.5f) - (50.0f * scale)),
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -123,7 +123,6 @@ static std::optional<u32> s_open_leaderboard_id;
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
// Resources
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
static std::unique_ptr<HostDisplayTexture> LoadTextureResource(const char* name, bool allow_fallback = true);
|
||||
static bool LoadResources();
|
||||
static void DestroyResources();
|
||||
|
||||
|
@ -462,19 +461,6 @@ bool LoadResources()
|
|||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<ByteStream> stream = s_host_interface->OpenPackageFile(
|
||||
"resources" FS_OSPATH_SEPARATOR_STR "fa-solid-900.ttf", BYTESTREAM_OPEN_READ | BYTESTREAM_OPEN_STREAMED);
|
||||
if (!stream)
|
||||
return false;
|
||||
|
||||
std::vector<u8> font_data = FileSystem::ReadBinaryStream(stream.get());
|
||||
if (font_data.empty())
|
||||
return false;
|
||||
|
||||
ImGuiFullscreen::SetIconFontData(std::move(font_data));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -497,7 +483,7 @@ static std::unique_ptr<HostDisplayTexture> LoadTexture(const char* path, bool fr
|
|||
{
|
||||
std::unique_ptr<ByteStream> stream;
|
||||
if (from_package)
|
||||
stream = s_host_interface->OpenPackageFile(path, BYTESTREAM_OPEN_READ);
|
||||
stream = g_host_interface->OpenPackageFile(path, BYTESTREAM_OPEN_READ);
|
||||
else
|
||||
stream = FileSystem::OpenFile(path, BYTESTREAM_OPEN_READ);
|
||||
if (!stream)
|
||||
|
@ -513,7 +499,7 @@ static std::unique_ptr<HostDisplayTexture> LoadTexture(const char* path, bool fr
|
|||
return {};
|
||||
}
|
||||
|
||||
std::unique_ptr<HostDisplayTexture> texture = s_host_interface->GetDisplay()->CreateTexture(
|
||||
std::unique_ptr<HostDisplayTexture> texture = g_host_interface->GetDisplay()->CreateTexture(
|
||||
image.GetWidth(), image.GetHeight(), 1, 1, 1, HostDisplayPixelFormat::RGBA8, image.GetPixels(),
|
||||
image.GetByteStride());
|
||||
if (!texture)
|
||||
|
@ -538,7 +524,7 @@ std::unique_ptr<HostDisplayTexture> LoadTextureResource(const char* name, bool a
|
|||
|
||||
Log_ErrorPrintf("Missing resource '%s', using fallback", name);
|
||||
|
||||
texture = s_host_interface->GetDisplay()->CreateTexture(PLACEHOLDER_ICON_WIDTH, PLACEHOLDER_ICON_HEIGHT, 1, 1, 1,
|
||||
texture = g_host_interface->GetDisplay()->CreateTexture(PLACEHOLDER_ICON_WIDTH, PLACEHOLDER_ICON_HEIGHT, 1, 1, 1,
|
||||
HostDisplayPixelFormat::RGBA8, PLACEHOLDER_ICON_DATA,
|
||||
sizeof(u32) * PLACEHOLDER_ICON_WIDTH, false);
|
||||
if (!texture)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#pragma once
|
||||
#include "common/types.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
class HostDisplayTexture;
|
||||
class CommonHostInterface;
|
||||
class SettingsInterface;
|
||||
struct Settings;
|
||||
|
@ -60,6 +62,7 @@ void Render();
|
|||
bool IsBindingInput();
|
||||
bool HandleKeyboardBinding(const char* keyName, bool pressed);
|
||||
|
||||
std::unique_ptr<HostDisplayTexture> LoadTextureResource(const char* name, bool allow_fallback = true);
|
||||
bool InvalidateCachedTexture(const std::string& path);
|
||||
|
||||
// Returns true if the message has been dismissed.
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -4,10 +4,6 @@ constexpr int WINDOW_ICON_WIDTH = 64;
|
|||
constexpr int WINDOW_ICON_HEIGHT = 64;
|
||||
extern unsigned int WINDOW_ICON_DATA[WINDOW_ICON_WIDTH * WINDOW_ICON_HEIGHT];
|
||||
|
||||
constexpr int APP_ICON_WIDTH = 260;
|
||||
constexpr int APP_ICON_HEIGHT = 260;
|
||||
extern unsigned int APP_ICON_DATA[APP_ICON_WIDTH * APP_ICON_HEIGHT];
|
||||
|
||||
constexpr int PLACEHOLDER_ICON_WIDTH = 128;
|
||||
constexpr int PLACEHOLDER_ICON_HEIGHT = 96;
|
||||
extern unsigned int PLACEHOLDER_ICON_DATA[PLACEHOLDER_ICON_WIDTH * PLACEHOLDER_ICON_HEIGHT];
|
|
@ -33,6 +33,7 @@ float g_menu_bar_size = 0.0f;
|
|||
|
||||
static std::string s_font_filename;
|
||||
static std::string s_icon_font_filename;
|
||||
static std::vector<u8> s_text_font_data;
|
||||
static std::vector<u8> s_icon_font_data;
|
||||
static float s_font_size = 15.0f;
|
||||
static const ImWchar* s_font_glyph_range = nullptr;
|
||||
|
@ -56,6 +57,11 @@ void SetFontFilename(std::string filename)
|
|||
std::string().swap(s_font_filename);
|
||||
}
|
||||
|
||||
void SetFontData(std::vector<u8> data)
|
||||
{
|
||||
s_text_font_data = std::move(data);
|
||||
}
|
||||
|
||||
void SetIconFontFilename(std::string icon_font_filename)
|
||||
{
|
||||
if (!icon_font_filename.empty())
|
||||
|
@ -92,6 +98,49 @@ void SetResolveTextureFunction(ResolveTextureHandleCallback callback)
|
|||
s_resolve_texture_handle = callback;
|
||||
}
|
||||
|
||||
static ImFont* AddTextFont(float size /*= 15.0f*/)
|
||||
{
|
||||
static const ImWchar default_ranges[] = {
|
||||
// Basic Latin + Latin Supplement + Central European diacritics
|
||||
0x0020,
|
||||
0x017F,
|
||||
|
||||
// Cyrillic + Cyrillic Supplement
|
||||
0x0400,
|
||||
0x052F,
|
||||
|
||||
// Cyrillic Extended-A
|
||||
0x2DE0,
|
||||
0x2DFF,
|
||||
|
||||
// Cyrillic Extended-B
|
||||
0xA640,
|
||||
0xA69F,
|
||||
|
||||
0,
|
||||
};
|
||||
|
||||
ImFontConfig cfg;
|
||||
|
||||
if (!s_font_filename.empty())
|
||||
{
|
||||
return ImGui::GetIO().Fonts->AddFontFromFileTTF(s_font_filename.c_str(), size, &cfg,
|
||||
s_font_glyph_range ? s_font_glyph_range : default_ranges);
|
||||
}
|
||||
else if (!s_text_font_data.empty())
|
||||
{
|
||||
cfg.FontDataOwnedByAtlas = false;
|
||||
return ImGui::GetIO().Fonts->AddFontFromMemoryTTF(s_text_font_data.data(),
|
||||
static_cast<int>(s_text_font_data.size()), size, &cfg,
|
||||
s_font_glyph_range ? s_font_glyph_range : default_ranges);
|
||||
}
|
||||
else
|
||||
{
|
||||
Panic("No text font provided");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void AddIconFonts(float size)
|
||||
{
|
||||
static const ImWchar range_fa[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
|
||||
|
@ -102,7 +151,11 @@ static void AddIconFonts(float size)
|
|||
cfg.GlyphMinAdvanceX = size * 0.75f;
|
||||
cfg.GlyphMaxAdvanceX = size * 0.75f;
|
||||
|
||||
if (!s_icon_font_data.empty())
|
||||
if (!s_icon_font_filename.empty())
|
||||
{
|
||||
ImGui::GetIO().Fonts->AddFontFromFileTTF(s_icon_font_filename.c_str(), size * 0.75f, &cfg, range_fa);
|
||||
}
|
||||
else if (!s_icon_font_data.empty())
|
||||
{
|
||||
cfg.FontDataOwnedByAtlas = false;
|
||||
ImGui::GetIO().Fonts->AddFontFromMemoryTTF(s_icon_font_data.data(), static_cast<int>(s_icon_font_data.size()),
|
||||
|
@ -110,7 +163,7 @@ static void AddIconFonts(float size)
|
|||
}
|
||||
else
|
||||
{
|
||||
ImGui::GetIO().Fonts->AddFontFromFileTTF(s_icon_font_filename.c_str(), size * 0.75f, &cfg, range_fa);
|
||||
Panic("No icon font provided");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,26 +182,12 @@ bool UpdateFonts()
|
|||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.Fonts->Clear();
|
||||
|
||||
if (s_font_filename.empty())
|
||||
{
|
||||
g_standard_font = ImGui::AddRobotoRegularFont(standard_font_size);
|
||||
AddIconFonts(standard_font_size);
|
||||
g_medium_font = ImGui::AddRobotoRegularFont(medium_font_size);
|
||||
AddIconFonts(medium_font_size);
|
||||
g_large_font = ImGui::AddRobotoRegularFont(large_font_size);
|
||||
AddIconFonts(large_font_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_standard_font =
|
||||
io.Fonts->AddFontFromFileTTF(s_font_filename.c_str(), standard_font_size, nullptr, s_font_glyph_range);
|
||||
AddIconFonts(standard_font_size);
|
||||
g_medium_font =
|
||||
io.Fonts->AddFontFromFileTTF(s_font_filename.c_str(), medium_font_size, nullptr, s_font_glyph_range);
|
||||
AddIconFonts(medium_font_size);
|
||||
g_large_font = io.Fonts->AddFontFromFileTTF(s_font_filename.c_str(), large_font_size, nullptr, s_font_glyph_range);
|
||||
AddIconFonts(large_font_size);
|
||||
}
|
||||
g_standard_font = AddTextFont(standard_font_size);
|
||||
AddIconFonts(standard_font_size);
|
||||
g_medium_font = AddTextFont(medium_font_size);
|
||||
AddIconFonts(medium_font_size);
|
||||
g_large_font = AddTextFont(large_font_size);
|
||||
AddIconFonts(large_font_size);
|
||||
|
||||
if (!io.Fonts->Build())
|
||||
Panic("Failed to rebuild font atlas");
|
||||
|
@ -163,15 +202,8 @@ void ResetFonts()
|
|||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.Fonts->Clear();
|
||||
|
||||
if (s_font_filename.empty())
|
||||
{
|
||||
g_standard_font = ImGui::AddRobotoRegularFont(standard_font_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_standard_font =
|
||||
io.Fonts->AddFontFromFileTTF(s_font_filename.c_str(), standard_font_size, nullptr, s_font_glyph_range);
|
||||
}
|
||||
g_standard_font = AddTextFont(standard_font_size);
|
||||
AddIconFonts(standard_font_size);
|
||||
|
||||
g_medium_font = nullptr;
|
||||
g_large_font = nullptr;
|
||||
|
|
|
@ -133,6 +133,7 @@ static ALWAYS_INLINE ImVec4 UISecondaryTextColor()
|
|||
}
|
||||
|
||||
void SetFontFilename(std::string filename);
|
||||
void SetFontData(std::vector<u8> data);
|
||||
void SetIconFontFilename(std::string icon_font_filename);
|
||||
void SetIconFontData(std::vector<u8> data);
|
||||
void SetFontSize(float size_pixels);
|
||||
|
|
|
@ -54,31 +54,3 @@ void ImGui::StyleColorsDarker(ImGuiStyle* dst)
|
|||
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
|
||||
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
|
||||
}
|
||||
|
||||
#include "font_roboto_regular.inl"
|
||||
|
||||
ImFont* ImGui::AddRobotoRegularFont(float size /*= 15.0f*/)
|
||||
{
|
||||
static const ImWchar ranges[] = {
|
||||
// Basic Latin + Latin Supplement + Central European diacritics
|
||||
0x0020,
|
||||
0x017F,
|
||||
|
||||
// Cyrillic + Cyrillic Supplement
|
||||
0x0400,
|
||||
0x052F,
|
||||
|
||||
// Cyrillic Extended-A
|
||||
0x2DE0,
|
||||
0x2DFF,
|
||||
|
||||
// Cyrillic Extended-B
|
||||
0xA640,
|
||||
0xA69F,
|
||||
|
||||
0,
|
||||
};
|
||||
|
||||
return ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(
|
||||
s_font_roboto_regular_compressed_data, s_font_roboto_regular_compressed_size, size, nullptr, ranges);
|
||||
}
|
||||
|
|
|
@ -3,5 +3,4 @@
|
|||
|
||||
namespace ImGui {
|
||||
void StyleColorsDarker(ImGuiStyle* dst = nullptr);
|
||||
ImFont* AddRobotoRegularFont(float size = 15.0f);
|
||||
} // namespace ImGui
|
||||
|
|
Loading…
Reference in a new issue