Revert "Show size appropriate fonts"

This reverts commit be65907beb.
This commit is contained in:
goaaats 2022-03-31 16:00:01 +02:00
parent 64e931f9ef
commit 04ec131b15
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
4 changed files with 97 additions and 320 deletions

View file

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using Dalamud.Configuration.Internal;
@ -21,18 +20,17 @@ namespace Dalamud.Interface.Internal.Windows
/// </summary>
internal class TitleScreenMenuWindow : Window, IDisposable
{
private const float TargetFontSizePt = 18f;
private const float TargetFontSizePx = TargetFontSizePt * 4 / 3;
private const float TargetFontSize = 16.2f;
private readonly TextureWrap shadeTexture;
private readonly Dictionary<Guid, InOutCubic> shadeEasings = new();
private readonly Dictionary<Guid, InOutQuint> moveEasings = new();
private readonly Dictionary<Guid, InOutCubic> logoEasings = new();
private readonly Dictionary<string, InterfaceManager.SpecialGlyphRequest> specialGlyphRequests = new();
private InOutCubic? fadeOutEasing;
private GameFontHandle? axisFontHandle;
private State state = State.Hide;
/// <summary>
@ -73,14 +71,19 @@ namespace Dalamud.Interface.Internal.Windows
/// <inheritdoc/>
public override void PreDraw()
{
this.SetAxisFonts();
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0));
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0, 0));
if (this.axisFontHandle?.Available ?? false)
ImGui.PushFont(this.axisFontHandle.ImFont);
base.PreDraw();
}
/// <inheritdoc/>
public override void PostDraw()
{
if (this.axisFontHandle?.Available ?? false)
ImGui.PopFont();
ImGui.PopStyleVar(2);
base.PostDraw();
}
@ -96,7 +99,7 @@ namespace Dalamud.Interface.Internal.Windows
/// <inheritdoc/>
public override void Draw()
{
var scale = ImGui.GetIO().FontGlobalScale;
ImGui.SetWindowFontScale(TargetFontSize / ImGui.GetFont().FontSize * 4 / 3);
var tsm = Service<TitleScreenMenu>.Get();
@ -126,7 +129,7 @@ namespace Dalamud.Interface.Internal.Windows
moveEasing.Update();
var finalPos = (i + 1) * this.shadeTexture.Height * scale;
var finalPos = (i + 1) * this.shadeTexture.Height;
var pos = moveEasing.Value * finalPos;
// FIXME(goat): Sometimes, easings can overshoot and bring things out of alignment.
@ -177,7 +180,7 @@ namespace Dalamud.Interface.Internal.Windows
{
var entry = tsm.Entries[i];
var finalPos = (i + 1) * this.shadeTexture.Height * scale;
var finalPos = (i + 1) * this.shadeTexture.Height;
this.DrawEntry(entry, i != 0, true, i == 0, false);
@ -219,35 +222,26 @@ namespace Dalamud.Interface.Internal.Windows
break;
}
}
}
var srcText = tsm.Entries.Select(e => e.Name).ToHashSet();
var keys = this.specialGlyphRequests.Keys.ToHashSet();
keys.RemoveWhere(x => srcText.Contains(x));
foreach (var key in keys)
private void SetAxisFonts()
{
var configuration = Service<DalamudConfiguration>.Get();
if (configuration.UseAxisFontsFromGame)
{
this.specialGlyphRequests[key].Dispose();
this.specialGlyphRequests.Remove(key);
if (this.axisFontHandle == null)
this.axisFontHandle = Service<GameFontManager>.Get().NewFontRef(new(GameFontFamily.Axis, TargetFontSize));
}
else
{
this.axisFontHandle?.Dispose();
this.axisFontHandle = null;
}
}
private bool DrawEntry(
TitleScreenMenu.TitleScreenMenuEntry entry, bool inhibitFadeout, bool showText, bool isFirst, bool overrideAlpha)
{
InterfaceManager.SpecialGlyphRequest fontHandle;
if (this.specialGlyphRequests.TryGetValue(entry.Name, out fontHandle) && fontHandle.Size != TargetFontSizePx)
{
fontHandle.Dispose();
this.specialGlyphRequests.Remove(entry.Name);
fontHandle = null;
}
if (fontHandle == null)
this.specialGlyphRequests[entry.Name] = fontHandle = Service<InterfaceManager>.Get().NewFontSizeRef(TargetFontSizePx, entry.Name);
ImGui.PushFont(fontHandle.Font);
var scale = ImGui.GetIO().FontGlobalScale;
if (!this.shadeEasings.TryGetValue(entry.Id, out var shadeEasing))
{
shadeEasing = new InOutCubic(TimeSpan.FromMilliseconds(350));
@ -257,7 +251,7 @@ namespace Dalamud.Interface.Internal.Windows
var initialCursor = ImGui.GetCursorPos();
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, (float)shadeEasing.Value);
ImGui.Image(this.shadeTexture.ImGuiHandle, new Vector2(this.shadeTexture.Width * scale, this.shadeTexture.Height * scale));
ImGui.Image(this.shadeTexture.ImGuiHandle, new Vector2(this.shadeTexture.Width, this.shadeTexture.Height));
ImGui.PopStyleVar();
var isHover = ImGui.IsItemHovered();
@ -311,7 +305,7 @@ namespace Dalamud.Interface.Internal.Windows
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 1f);
}
ImGui.Image(entry.Texture.ImGuiHandle, new Vector2(TitleScreenMenu.TextureSize * scale));
ImGui.Image(entry.Texture.ImGuiHandle, new Vector2(TitleScreenMenu.TextureSize));
if (overrideAlpha || isFirst)
{
ImGui.PopStyleVar();
@ -325,36 +319,23 @@ namespace Dalamud.Interface.Internal.Windows
var textHeight = ImGui.GetTextLineHeightWithSpacing();
var cursor = ImGui.GetCursorPos();
cursor.Y += (entry.Texture.Height * scale / 2) - (textHeight / 2);
cursor.Y += (entry.Texture.Height / 2) - (textHeight / 2);
ImGui.SetCursorPos(cursor);
if (overrideAlpha)
{
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, showText ? (float)logoEasing.Value : 0f);
}
// Drop shadow
ImGui.PushStyleColor(ImGuiCol.Text, 0xFF000000);
for (int i = 0, i_ = (int)Math.Ceiling(1 * scale); i < i_; i++)
{
ImGui.SetCursorPos(new Vector2(cursor.X, cursor.Y + i));
ImGui.Text(entry.Name);
}
ImGui.PopStyleColor();
ImGui.SetCursorPos(cursor);
ImGui.Text(entry.Name);
if (overrideAlpha)
{
ImGui.PopStyleVar();
}
initialCursor.Y += entry.Texture.Height * scale;
initialCursor.Y += entry.Texture.Height;
ImGui.SetCursorPos(initialCursor);
ImGui.PopFont();
return isHover;
}