Wider glyph ranges for custom font; media player text scaling with `font_scale_media_player` param

pull/197/head
jackun 4 years ago
parent c254347688
commit c04658456a
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -42,6 +42,7 @@ frame_timing
### Change the hud font size (default is 24)
font_size=24
# font_scale_media_player = 0.55
### Change the hud position (default is top-left)
position=top-left

@ -131,21 +131,7 @@ void imgui_create(void *ctx)
GLint current_texture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &current_texture);
int font_size = params.font_size;
if (!font_size)
font_size = 24;
if (!params.font_file.empty() && file_exists(params.font_file)) {
state.font = io.Fonts->AddFontFromFileTTF(params.font_file.c_str(), font_size);
state.font1 = io.Fonts->AddFontFromFileTTF(params.font_file.c_str(), font_size * 0.55f);
} else {
ImFontConfig font_cfg = ImFontConfig();
const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85();
const ImWchar* glyph_ranges = io.Fonts->GetGlyphRangesDefault();
state.font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, font_size, &font_cfg, glyph_ranges);
state.font1 = io.Fonts->AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, font_size * 0.55, &font_cfg, glyph_ranges);
}
create_fonts(params, state.font, state.font1);
sw_stats.font1 = state.font1;
// Restore global context or ours might clash with apps that use Dear ImGui

@ -253,6 +253,41 @@ static void unmap_object(uint64_t obj)
/**/
void create_fonts(const overlay_params& params, ImFont*& default_font, ImFont*& small_font)
{
auto& io = ImGui::GetIO();
int font_size = params.font_size;
if (!font_size)
font_size = 24;
static const ImWchar glyph_ranges[] =
{
0x0020, 0x00FF, // Basic Latin + Latin Supplement
0x0100, 0x017f, // Latin Extended-A
0x0400, 0x052F, // Cyrillic + Cyrillic Supplement
0x2DE0, 0x2DFF, // Cyrillic Extended-A
0xA640, 0xA69F, // Cyrillic Extended-B
0,
};
// ImGui takes ownership of the data, no need to free it
if (!params.font_file.empty() && file_exists(params.font_file)) {
default_font = io.Fonts->AddFontFromFileTTF(params.font_file.c_str(), font_size, nullptr, glyph_ranges);
small_font = io.Fonts->AddFontFromFileTTF(params.font_file.c_str(), font_size * 0.55f, nullptr, io.Fonts->GetGlyphRangesDefault());
} else {
const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85();
default_font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, font_size, nullptr, io.Fonts->GetGlyphRangesDefault());
small_font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, font_size * 0.55, nullptr, io.Fonts->GetGlyphRangesDefault());
}
}
// FIXME "temporary" hack until Dear ImGui has an actual API for this
void scale_default_font(ImFont& scaled_font, float scale)
{
scaled_font = *ImGui::GetIO().Fonts->Fonts[0];
scaled_font.Scale = scale;
}
static VkLayerInstanceCreateInfo *get_instance_chain_info(const VkInstanceCreateInfo *pCreateInfo,
VkLayerFunction func)
{
@ -1127,7 +1162,7 @@ void render_mpris_metadata(swapchain_stats& data, const ImVec4& color, metadata&
if (meta.valid) {
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(8,0));
ImGui::Dummy(ImVec2(0.0f, 20.0f));
ImGui::PushFont(data.font1);
//ImGui::PushFont(data.font1);
if (meta.ticker.needs_recalc) {
meta.ticker.tw0 = ImGui::CalcTextSize(meta.title.c_str()).x;
@ -1171,7 +1206,7 @@ void render_mpris_metadata(swapchain_stats& data, const ImVec4& color, metadata&
ImGui::TextColored(color, "(paused)");
}
ImGui::PopFont();
//ImGui::PopFont();
ImGui::PopStyleVar();
}
}
@ -1496,9 +1531,13 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
}
#ifdef HAVE_DBUS
ImFont scaled_font;
scale_default_font(scaled_font, params.font_scale_media_player);
ImGui::PushFont(&scaled_font);
auto media_color = ImGui::ColorConvertU32ToFloat4(params.media_player_color);
render_mpris_metadata(data, media_color, main_metadata, frame_timing, true);
render_mpris_metadata(data, media_color, generic_mpris, frame_timing, false);
ImGui::PopFont();
#endif
if(loggingOn)
@ -2137,22 +2176,7 @@ static void setup_swapchain_data_pipeline(struct swapchain_data *data)
device_data->vtable.DestroyShaderModule(device_data->device, frag_module, NULL);
ImGuiIO& io = ImGui::GetIO();
int font_size = device_data->instance->params.font_size;
if (!font_size)
font_size = 24;
// ImGui takes ownership of the data, no need to free it
if (!device_data->instance->params.font_file.empty() && file_exists(device_data->instance->params.font_file)) {
data->font = io.Fonts->AddFontFromFileTTF(device_data->instance->params.font_file.c_str(), font_size);
data->sw_stats.font1 = io.Fonts->AddFontFromFileTTF(device_data->instance->params.font_file.c_str(), font_size * 0.55f);
} else {
ImFontConfig font_cfg = ImFontConfig();
const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85();
const ImWchar* glyph_ranges = io.Fonts->GetGlyphRangesDefault();
data->font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, font_size, &font_cfg, glyph_ranges);
data->sw_stats.font1 = io.Fonts->AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, font_size * 0.55, &font_cfg, glyph_ranges);
}
create_fonts(device_data->instance->params, data->font, data->sw_stats.font1);
unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);

@ -74,4 +74,5 @@ void init_system_info(void);
void FpsLimiter(struct fps_limit& stats);
void imgui_custom_style(struct overlay_params& params);
void get_device_name(int32_t vendorID, int32_t deviceID, struct swapchain_stats& sw_stats);
void calculate_benchmark_data(void);
void calculate_benchmark_data(void);
void create_fonts(const overlay_params& params, ImFont*& default_font, ImFont*& small_font);

@ -196,6 +196,7 @@ parse_path(const char *str)
#define parse_io_write(s) parse_unsigned(s)
#define parse_pci_dev(s) parse_str(s)
#define parse_media_player_name(s) parse_str(s)
#define parse_font_scale_media_player(s) parse_font_size(s)
#define parse_cpu_color(s) parse_color(s)
#define parse_gpu_color(s) parse_color(s)
@ -360,6 +361,7 @@ parse_overlay_config(struct overlay_params *params,
params->text_color = 0xffffff;
params->media_player_color = 0xffffff;
params->media_player_name = "spotify";
params->font_scale_media_player = 0.55f;
#ifdef HAVE_X11
params->toggle_hud = { XK_F12 };

@ -60,6 +60,7 @@ typedef unsigned long KeySym;
OVERLAY_PARAM_CUSTOM(vsync) \
OVERLAY_PARAM_CUSTOM(gl_vsync) \
OVERLAY_PARAM_CUSTOM(font_size) \
OVERLAY_PARAM_CUSTOM(font_scale_media_player) \
OVERLAY_PARAM_CUSTOM(toggle_hud) \
OVERLAY_PARAM_CUSTOM(toggle_logging) \
OVERLAY_PARAM_CUSTOM(reload_cfg) \
@ -127,6 +128,7 @@ struct overlay_params {
unsigned media_player_color;
unsigned tableCols;
float font_size;
float font_scale_media_player;
float background_alpha, alpha;
std::vector<KeySym> toggle_hud;
std::vector<KeySym> toggle_logging;

Loading…
Cancel
Save