feat: add system font selection

This commit is contained in:
Anna
2022-02-04 23:00:16 -05:00
parent 38cdb98f2d
commit 45c7d85e33
13 changed files with 280 additions and 19 deletions
+77 -1
View File
@@ -1,4 +1,6 @@
using ChatTwo.Resources;
using System.Drawing;
using System.Drawing.Text;
using ChatTwo.Resources;
using ChatTwo.Util;
using ImGuiNET;
@@ -6,14 +8,32 @@ namespace ChatTwo.Ui.SettingsTabs;
internal sealed class Display : ISettingsTab {
private Configuration Mutable { get; }
private List<FontFamily> Fonts { get; } = new();
private List<string> JpFonts { get; set; } = new();
public string Name => Language.Options_Display_Tab + "###tabs-display";
internal Display(Configuration mutable) {
this.Mutable = mutable;
this.UpdateFonts();
}
private void UpdateFonts() {
this.Fonts.Clear();
var fonts = new InstalledFontCollection();
foreach (var font in fonts.Families) {
this.Fonts.Add(font);
}
this.JpFonts = Ui.Fonts.GetJpFonts();
}
public void Draw() {
if (ImGui.IsWindowAppearing()) {
this.UpdateFonts();
}
ImGuiUtil.OptionCheckbox(ref this.Mutable.HideChat, Language.Options_HideChat_Name, Language.Options_HideChat_Description);
ImGuiUtil.OptionCheckbox(ref this.Mutable.HideDuringCutscenes, Language.Options_HideDuringCutscenes_Name, Language.Options_HideDuringCutscenes_Description);
ImGuiUtil.OptionCheckbox(ref this.Mutable.NativeItemTooltips, Language.Options_NativeItemTooltips_Name, Language.Options_NativeItemTooltips_Description);
@@ -28,6 +48,62 @@ internal sealed class Display : ISettingsTab {
ImGuiUtil.OptionCheckbox(ref this.Mutable.ShowNoviceNetwork, Language.Options_ShowNoviceNetwork_Name, Language.Options_ShowNoviceNetwork_Description);
if (ImGui.BeginCombo("Font", this.Mutable.GlobalFont)) {
foreach (var font in Ui.Fonts.GlobalFonts) {
if (ImGui.Selectable(font.Name, this.Mutable.GlobalFont == font.Name)) {
this.Mutable.GlobalFont = font.Name;
}
if (ImGui.IsWindowAppearing() && this.Mutable.GlobalFont == font.Name) {
ImGui.SetScrollHereY(0.5f);
}
}
ImGui.Separator();
foreach (var family in this.Fonts) {
if (!family.IsStyleAvailable(FontStyle.Italic)) {
continue;
}
if (ImGui.Selectable(family.Name, this.Mutable.GlobalFont == family.Name)) {
this.Mutable.GlobalFont = family.Name;
}
if (ImGui.IsWindowAppearing() && this.Mutable.GlobalFont == family.Name) {
ImGui.SetScrollHereY(0.5f);
}
}
ImGui.EndCombo();
}
if (ImGui.BeginCombo("Japanese font", this.Mutable.JapaneseFont)) {
foreach (var (name, _) in Ui.Fonts.JapaneseFonts) {
if (ImGui.Selectable(name, this.Mutable.JapaneseFont == name)) {
this.Mutable.JapaneseFont = name;
}
if (ImGui.IsWindowAppearing() && this.Mutable.JapaneseFont == name) {
ImGui.SetScrollHereY(0.5f);
}
}
// ImGui.Separator();
//
// foreach (var family in this.JpFonts) {
// if (ImGui.Selectable(family, this.Mutable.JapaneseFont == family)) {
// this.Mutable.JapaneseFont = family;
// }
//
// if (ImGui.IsWindowAppearing() && this.Mutable.JapaneseFont == family) {
// ImGui.SetScrollHereY(0.5f);
// }
// }
ImGui.EndCombo();
}
ImGui.DragFloat(Language.Options_FontSize_Name, ref this.Mutable.FontSize, .0125f, 12f, 36f, $"{this.Mutable.FontSize:N1}");
if (ImGui.DragFloat(Language.Options_WindowOpacity_Name, ref this.Mutable.WindowAlpha, .0025f, 0f, 1f, $"{this.Mutable.WindowAlpha * 100f:N2}%%")) {
switch (this.Mutable.WindowAlpha) {