feat: add jank hover highlight for links

This commit is contained in:
Anna 2022-02-15 18:36:16 -05:00
parent 1c22fe16b3
commit 1c1fd5d6d5
3 changed files with 45 additions and 3 deletions

View File

@ -164,7 +164,7 @@ internal sealed class ChatLog : IUiComponent {
if (parts.Length < 2 || parts[0] != "chat") {
return;
}
switch (parts[1]) {
case "hide":
this._hideState = HideState.User;
@ -988,7 +988,7 @@ internal sealed class ChatLog : IUiComponent {
}
if (wrap) {
ImGuiUtil.WrapText(content, chunk, handler);
ImGuiUtil.WrapText(content, chunk, handler, this.Ui.DefaultText);
} else {
ImGui.TextUnformatted(content);
ImGuiUtil.PostPayload(chunk, handler);

View File

@ -29,6 +29,15 @@ internal static class ColourUtil {
);
}
internal static uint Vector4ToAbgr(Vector4 col) {
return RgbaToAbgr(ComponentsToRgba(
(byte) Math.Round(col.X * 255),
(byte) Math.Round(col.Y * 255),
(byte) Math.Round(col.Z * 255),
(byte) Math.Round(col.W * 255)
));
}
internal static uint ComponentsToRgba(byte red, byte green, byte blue, byte alpha = 0xFF) => alpha
| (uint) (red << 24)
| (uint) (green << 16)

View File

@ -1,4 +1,6 @@
using System.Numerics;
using System.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Interface;
using Dalamud.Interface.Style;
using ImGuiNET;
@ -12,11 +14,18 @@ internal static class ImGuiUtil {
ImGuiMouseButton.Right,
};
private static Payload? _hovered;
private static Payload? _lastLink;
private static readonly List<(Vector2, Vector2)> _payloadBounds = new();
internal static void PostPayload(Chunk chunk, PayloadHandler? handler) {
var payload = chunk.Link;
if (payload != null && ImGui.IsItemHovered()) {
_hovered = payload;
ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
handler?.Hover(payload);
} else if (!ReferenceEquals(_hovered, payload)) {
_hovered = null;
}
if (handler == null) {
@ -30,10 +39,34 @@ internal static class ImGuiUtil {
}
}
internal static unsafe void WrapText(string csText, Chunk chunk, PayloadHandler? handler) {
internal static unsafe void WrapText(string csText, Chunk chunk, PayloadHandler? handler, Vector4 defaultText) {
void Text(byte* text, byte* textEnd) {
var oldPos = ImGui.GetCursorScreenPos();
ImGuiNative.igTextUnformatted(text, textEnd);
PostPayload(chunk, handler);
if (!ReferenceEquals(_lastLink, chunk.Link)) {
_payloadBounds.Clear();
}
_lastLink = chunk.Link;
if (_hovered != null && ReferenceEquals(_hovered, chunk.Link)) {
defaultText.W = 0.25f;
var actualCol = ColourUtil.Vector4ToAbgr(defaultText);
ImGui.GetWindowDrawList().AddRectFilled(oldPos, oldPos + ImGui.GetItemRectSize(), actualCol);
foreach (var (start, size) in _payloadBounds) {
ImGui.GetWindowDrawList().AddRectFilled(start, start + size, actualCol);
}
_payloadBounds.Clear();
}
if (_hovered == null && chunk.Link != null) {
_payloadBounds.Add((oldPos, ImGui.GetItemRectSize()));
}
}
if (csText.Length == 0) {