Skip to content

Commit

Permalink
Add coloring options
Browse files Browse the repository at this point in the history
  • Loading branch information
Soreepeong committed Jul 29, 2024
1 parent 7369878 commit 6750eac
Show file tree
Hide file tree
Showing 20 changed files with 304 additions and 111 deletions.
8 changes: 4 additions & 4 deletions Dalamud/Dalamud.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Interface\Internal\ImGuiSeStringRenderer\TextProcessing\LineBreak.txt" LogicalName="LineBreak.txt" />
<EmbeddedResource Include="Interface\Internal\ImGuiSeStringRenderer\TextProcessing\EastAsianWidth.txt" LogicalName="EastAsianWidth.txt" />
<EmbeddedResource Include="Interface\Internal\ImGuiSeStringRenderer\TextProcessing\DerivedGeneralCategory.txt" LogicalName="DerivedGeneralCategory.txt" />
<EmbeddedResource Include="Interface\Internal\ImGuiSeStringRenderer\TextProcessing\emoji-data.txt" LogicalName="emoji-data.txt" />
<EmbeddedResource Include="Interface\ImGuiSeStringRenderer\Internal\TextProcessing\DerivedGeneralCategory.txt" LogicalName="DerivedGeneralCategory.txt" />
<EmbeddedResource Include="Interface\ImGuiSeStringRenderer\Internal\TextProcessing\EastAsianWidth.txt" LogicalName="EastAsianWidth.txt" />
<EmbeddedResource Include="Interface\ImGuiSeStringRenderer\Internal\TextProcessing\emoji-data.txt" LogicalName="emoji-data.txt" />
<EmbeddedResource Include="Interface\ImGuiSeStringRenderer\Internal\TextProcessing\LineBreak.txt" LogicalName="LineBreak.txt" />
</ItemGroup>

<Target Name="AddRuntimeDependenciesToContent" BeforeTargets="GetCopyToOutputDirectoryItems" DependsOnTargets="GenerateBuildDependencyFile;GenerateBuildRuntimeConfigurationFiles">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using Lumina.Data;

namespace Dalamud.Interface.Internal.ImGuiSeStringRenderer;
namespace Dalamud.Interface.ImGuiSeStringRenderer.Internal;

/// <summary>Game font data file.</summary>
internal sealed unsafe class GfdFile : FileResource
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

using static Dalamud.Interface.Internal.ImGuiSeStringRenderer.TextProcessing.UnicodeEastAsianWidthClass;
using static Dalamud.Interface.Internal.ImGuiSeStringRenderer.TextProcessing.UnicodeGeneralCategory;
using static Dalamud.Interface.Internal.ImGuiSeStringRenderer.TextProcessing.UnicodeLineBreakClass;
using static Dalamud.Interface.ImGuiSeStringRenderer.Internal.TextProcessing.UnicodeEastAsianWidthClass;
using static Dalamud.Interface.ImGuiSeStringRenderer.Internal.TextProcessing.UnicodeGeneralCategory;
using static Dalamud.Interface.ImGuiSeStringRenderer.Internal.TextProcessing.UnicodeLineBreakClass;

namespace Dalamud.Interface.Internal.ImGuiSeStringRenderer.TextProcessing;
namespace Dalamud.Interface.ImGuiSeStringRenderer.Internal.TextProcessing;

/// <summary>Enumerates line break offsets.</summary>
internal ref struct LineBreakEnumerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;

namespace Dalamud.Interface.Internal.ImGuiSeStringRenderer.TextProcessing;
namespace Dalamud.Interface.ImGuiSeStringRenderer.Internal.TextProcessing;

/// <summary>Stores unicode data.</summary>
internal static class UnicodeData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Dalamud.Interface.Internal.ImGuiSeStringRenderer.TextProcessing;
namespace Dalamud.Interface.ImGuiSeStringRenderer.Internal.TextProcessing;

/// <summary><a href="https://www.unicode.org/reports/tr11/">Unicode east asian width</a>.</summary>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Unicode Data")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Dalamud.Interface.Internal.ImGuiSeStringRenderer.TextProcessing;
namespace Dalamud.Interface.ImGuiSeStringRenderer.Internal.TextProcessing;

/// <summary><a href="https://www.unicode.org/reports/tr51/#Emoji_Characters">Unicode emoji property</a>.</summary>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Unicode Data")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Dalamud.Interface.Internal.ImGuiSeStringRenderer.TextProcessing;
namespace Dalamud.Interface.ImGuiSeStringRenderer.Internal.TextProcessing;

/// <summary><a href="https://www.unicode.org/reports/tr44/#General_Category_Values">Unicode general category.</a>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Dalamud.Interface.Internal.ImGuiSeStringRenderer.TextProcessing;
namespace Dalamud.Interface.ImGuiSeStringRenderer.Internal.TextProcessing;

/// <summary><a href="https://unicode.org/reports/tr14/#Table1">Unicode line break class</a>.</summary>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Unicode Data")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Lumina.Text.Payloads;
using Lumina.Text.ReadOnly;

namespace Dalamud.Interface.Internal.ImGuiSeStringRenderer.TextProcessing;
namespace Dalamud.Interface.ImGuiSeStringRenderer.Internal.TextProcessing;

/// <summary>Enumerates a UTF-N byte sequence by codepoint.</summary>
[DebuggerDisplay("{Current}/{data.Length} ({flags}, BE={isBigEndian})")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Dalamud.Interface.Internal.ImGuiSeStringRenderer.TextProcessing;
namespace Dalamud.Interface.ImGuiSeStringRenderer.Internal.TextProcessing;

/// <summary>Flags on enumerating a unicode sequence.</summary>
[Flags]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Runtime.InteropServices;
using System.Text;

namespace Dalamud.Interface.Internal.ImGuiSeStringRenderer.TextProcessing;
namespace Dalamud.Interface.ImGuiSeStringRenderer.Internal.TextProcessing;

/// <summary>Represents a single value to be used in a UTF-N byte sequence.</summary>
[StructLayout(LayoutKind.Explicit, Size = 4)]
Expand Down
54 changes: 54 additions & 0 deletions Dalamud/Interface/ImGuiSeStringRenderer/SeStringRenderStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using ImGuiNET;

using Lumina.Text.Payloads;

namespace Dalamud.Interface.ImGuiSeStringRenderer;

/// <summary>Render styles for a SeString.</summary>
public record struct SeStringRenderStyle
{
private uint color;
private uint edgeColor;
private uint shadowColor;
private bool hasValidColorValue;
private bool hasValidEdgeColorValue;
private bool hasValidShadowColorValue;

/// <summary>Gets or sets a value indicating whether to force the color of the rendered text edge.</summary>
/// <remarks>If not <c>null</c>, then <see cref="MacroCode.EdgeColor"/> and <see cref="MacroCode.EdgeColorType"/>
/// will be ignored.</remarks>
public bool ForceEdgeColor { get; set; }

/// <summary>Gets or sets a value indicating whether the text is rendered bold.</summary>
public bool Bold { get; set; }

/// <summary>Gets or sets a value indicating whether the text is rendered italic.</summary>
public bool Italic { get; set; }

/// <summary>Gets or sets a value indicating whether the text is rendered with edge.</summary>
public bool Edge { get; set; }

/// <summary>Gets or sets a value indicating whether the text is rendered with shadow.</summary>
public bool Shadow { get; set; }

/// <summary>Gets or sets the color of the rendered text.</summary>
public uint Color
{
readonly get => this.hasValidColorValue ? this.color : ImGui.GetColorU32(ImGuiCol.Text);
set => (this.hasValidColorValue, this.color) = (true, value);
}

/// <summary>Gets or sets the color of the rendered text edge.</summary>
public uint EdgeColor
{
readonly get => this.hasValidEdgeColorValue ? this.edgeColor : 0xFF000000;
set => (this.hasValidEdgeColorValue, this.edgeColor) = (true, value);
}

/// <summary>Gets or sets the color of the rendered text shadow.</summary>
public uint ShadowColor
{
readonly get => this.hasValidShadowColorValue ? this.shadowColor : 0xFF000000;
set => (this.hasValidShadowColorValue, this.shadowColor) = (true, value);
}
}
19 changes: 18 additions & 1 deletion Dalamud/Interface/Internal/UiDebug.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using System.Numerics;

using Dalamud.Game.Gui;
using Dalamud.Interface.Internal.ImGuiSeStringRenderer;
using Dalamud.Interface.ImGuiSeStringRenderer.Internal;
using Dalamud.Interface.Utility;
using Dalamud.Utility;

using FFXIVClientStructs.FFXIV.Client.System.String;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
using FFXIVClientStructs.FFXIV.Component.GUI;
using ImGuiNET;

using Lumina.Text.ReadOnly;

// Customised version of https://github.com/aers/FFXIVUIDebug

namespace Dalamud.Interface.Internal;
Expand Down Expand Up @@ -208,6 +213,18 @@ private void PrintSimpleNode(AtkResNode* node, string treePrefix)

ImGui.InputText($"Replace Text##{(ulong)textNode:X}", new IntPtr(textNode->NodeText.StringPtr), (uint)textNode->NodeText.BufSize);

ImGui.SameLine();
if (ImGui.Button($"Encode##{(ulong)textNode:X}"))
{
using var tmp = new Utf8String();
RaptureTextModule.Instance()->MacroEncoder.EncodeString(&tmp, textNode->NodeText.StringPtr);
textNode->NodeText.Copy(&tmp);
}

ImGui.SameLine();
if (ImGui.Button($"Decode##{(ulong)textNode:X}"))
textNode->NodeText.SetString(new ReadOnlySeStringSpan(textNode->NodeText.StringPtr).ToString());

ImGui.Text($"AlignmentType: {(AlignmentType)textNode->AlignmentFontType} FontSize: {textNode->FontSize}");
int b = textNode->AlignmentFontType;
if (ImGui.InputInt($"###setAlignment{(ulong)textNode:X}", ref b, 1))
Expand Down

Large diffs are not rendered by default.

36 changes: 28 additions & 8 deletions Dalamud/Interface/Utility/ImGuiHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@

using Dalamud.Configuration.Internal;
using Dalamud.Game.ClientState.Keys;
using Dalamud.Interface.ImGuiSeStringRenderer;
using Dalamud.Interface.ImGuiSeStringRenderer.Internal;
using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.ManagedFontAtlas.Internals;
using Dalamud.Interface.Utility.Raii;

using ImGuiNET;
using ImGuiScene;

using Lumina.Text.ReadOnly;

using SeStringRenderer = Dalamud.Interface.Internal.ImGuiSeStringRenderer.SeStringRenderer;

namespace Dalamud.Interface.Utility;

/// <summary>
Expand Down Expand Up @@ -181,13 +179,35 @@ public static void ClickToCopyText(string text, string? textCopy = null)
if (ImGui.IsItemClicked()) ImGui.SetClipboardText($"{textCopy}");
}

/// <inheritdoc cref="SeStringRenderer.DrawWrapped(ReadOnlySeStringSpan, float)"/>
/// <summary>Draws a SeString.</summary>
/// <param name="sss">SeString to draw.</param>
/// <param name="wrapWidth">Wrapping width. If a non-positive number is provided, then the remainder of the width
/// will be used.</param>
public static void SeStringWrapped(ReadOnlySpan<byte> sss, float wrapWidth = 0) =>
Service<SeStringRenderer>.Get().DrawWrapped(sss, wrapWidth);
Service<SeStringRenderer>.Get().DrawWrapped(sss, default, wrapWidth);

/// <inheritdoc cref="SeStringRenderer.CompileAndDrawWrapped"/>
/// <summary>Creates and caches a SeString from a text macro representation, and then draws it.</summary>
/// <param name="text">SeString text macro representation.</param>
/// <param name="wrapWidth">Wrapping width. If a non-positive number is provided, then the remainder of the width
/// will be used.</param>
public static void CompileSeStringWrapped(string text, float wrapWidth = 0) =>
Service<SeStringRenderer>.Get().CompileAndDrawWrapped(text, wrapWidth);
Service<SeStringRenderer>.Get().CompileAndDrawWrapped(text, default, wrapWidth);

/// <summary>Draws a SeString.</summary>
/// <param name="sss">SeString to draw.</param>
/// <param name="style">Initial rendering style.</param>
/// <param name="wrapWidth">Wrapping width. If a non-positive number is provided, then the remainder of the width
/// will be used.</param>
public static void SeStringWrapped(ReadOnlySpan<byte> sss, SeStringRenderStyle style, float wrapWidth = 0) =>
Service<SeStringRenderer>.Get().DrawWrapped(sss, style, wrapWidth);

/// <summary>Creates and caches a SeString from a text macro representation, and then draws it.</summary>
/// <param name="text">SeString text macro representation.</param>
/// <param name="style">Initial rendering style.</param>
/// <param name="wrapWidth">Wrapping width. If a non-positive number is provided, then the remainder of the width
/// will be used.</param>
public static void CompileSeStringWrapped(string text, SeStringRenderStyle style, float wrapWidth = 0) =>
Service<SeStringRenderer>.Get().CompileAndDrawWrapped(text, style, wrapWidth);

/// <summary>
/// Write unformatted text wrapped.
Expand Down

0 comments on commit 6750eac

Please sign in to comment.