mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Fix RGB returning wrong color and change it to RGBA (#1793)
* FIx RGB returning wrong color and change it to RGBA * Don't use the old RGB variable * Fix UIGlowPayload too * Add RGBA to ABGR helper and new method for glow/foreground to expose it directly * Move from Utils to ColorHelpers * Rename the function
This commit is contained in:
parent
d2a0c94ddd
commit
44a3c3a1ee
4 changed files with 44 additions and 21 deletions
|
|
@ -77,15 +77,21 @@ public class UIForegroundPayload : Payload
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the Red/Green/Blue values for this foreground color, encoded as a typical hex color.
|
/// Gets the Red/Green/Blue/Alpha values for this foreground color, encoded as a typical hex color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public uint RGB => this.UIColor.UIForeground & 0xFFFFFF;
|
public uint RGBA => this.UIColor.UIForeground;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the ABGR value for this foreground color, as ImGui requires it in PushColor.
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
public uint ABGR => Interface.ColorHelpers.SwapEndianness(this.UIColor.UIForeground);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{this.Type} - UIColor: {this.colorKey} color: {(this.IsEnabled ? this.RGB : 0)}";
|
return $"{this.Type} - UIColor: {this.colorKey} color: {(this.IsEnabled ? this.RGBA : 0)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|
|
||||||
|
|
@ -68,10 +68,16 @@ public class UIGlowPayload : Payload
|
||||||
public bool IsEnabled => this.ColorKey != 0;
|
public bool IsEnabled => this.ColorKey != 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the Red/Green/Blue values for this glow color, encoded as a typical hex color.
|
/// Gets the Red/Green/Blue/Alpha values for this glow color, encoded as a typical hex color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public uint RGB => this.UIColor.UIGlow & 0xFFFFFF;
|
public uint RGBA => this.UIColor.UIGlow;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the ABGR value for this glow color, as ImGui requires it in PushColor.
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
public uint ABGR => Interface.ColorHelpers.SwapEndianness(this.UIColor.UIGlow);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a Lumina UIColor object representing this payload. The actual color data is at UIColor.UIGlow.
|
/// Gets a Lumina UIColor object representing this payload. The actual color data is at UIColor.UIGlow.
|
||||||
|
|
@ -85,7 +91,7 @@ public class UIGlowPayload : Payload
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{this.Type} - UIColor: {this.colorKey} color: {(this.IsEnabled ? this.RGB : 0)}";
|
return $"{this.Type} - UIColor: {this.colorKey} color: {(this.IsEnabled ? this.RGBA : 0)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Buffers.Binary;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|
@ -159,6 +160,16 @@ public static class ColorHelpers
|
||||||
return new Vector4(r, g, b, hsv.A);
|
return new Vector4(r, g, b, hsv.A);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs a swap of endianness
|
||||||
|
/// Exmaple:
|
||||||
|
/// (FFXIV) RGBA to ABGR (ImGui)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rgba">Color value in byte order X Y Z W.</param>
|
||||||
|
/// <returns>Endian swapped color value with new byte order W Z Y X.</returns>
|
||||||
|
public static uint SwapEndianness(uint rgba)
|
||||||
|
=> BinaryPrimitives.ReverseEndianness(rgba);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lighten a color.
|
/// Lighten a color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -259,7 +270,7 @@ public static class ColorHelpers
|
||||||
hsv.A -= amount;
|
hsv.A -= amount;
|
||||||
return HsvToRgb(hsv);
|
return HsvToRgb(hsv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set alpha of a color.
|
/// Set alpha of a color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -299,10 +310,10 @@ public static class ColorHelpers
|
||||||
{
|
{
|
||||||
// If any components are out of range, return original value.
|
// If any components are out of range, return original value.
|
||||||
{ W: > 255.0f or < 0.0f } or { X: > 255.0f or < 0.0f } or { Y: > 255.0f or < 0.0f } or { Z: > 255.0f or < 0.0f } => color,
|
{ W: > 255.0f or < 0.0f } or { X: > 255.0f or < 0.0f } or { Y: > 255.0f or < 0.0f } or { Z: > 255.0f or < 0.0f } => color,
|
||||||
|
|
||||||
// If all components are already unit range, return original value.
|
// If all components are already unit range, return original value.
|
||||||
{ W: >= 0.0f and <= 1.0f, X: >= 0.0f and <= 1.0f, Y: >= 0.0f and <= 1.0f, Z: >= 0.0f and <= 1.0f } => color,
|
{ W: >= 0.0f and <= 1.0f, X: >= 0.0f and <= 1.0f, Y: >= 0.0f and <= 1.0f, Z: >= 0.0f and <= 1.0f } => color,
|
||||||
|
|
||||||
_ => color / 255.0f,
|
_ => color / 255.0f,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -476,12 +476,12 @@ public static class Util
|
||||||
case "MacOS": return OSPlatform.OSX;
|
case "MacOS": return OSPlatform.OSX;
|
||||||
case "Linux": return OSPlatform.Linux;
|
case "Linux": return OSPlatform.Linux;
|
||||||
}
|
}
|
||||||
|
|
||||||
// n.b. we had some fancy code here to check if the Wine host version returned "Darwin" but apparently
|
// n.b. we had some fancy code here to check if the Wine host version returned "Darwin" but apparently
|
||||||
// *all* our Wines report Darwin if exports aren't hidden. As such, it is effectively impossible (without some
|
// *all* our Wines report Darwin if exports aren't hidden. As such, it is effectively impossible (without some
|
||||||
// (very cursed and inaccurate heuristics) to determine if we're on macOS or Linux unless we're explicitly told
|
// (very cursed and inaccurate heuristics) to determine if we're on macOS or Linux unless we're explicitly told
|
||||||
// by our launcher. See commit a7aacb15e4603a367e2f980578271a9a639d8852 for the old check.
|
// by our launcher. See commit a7aacb15e4603a367e2f980578271a9a639d8852 for the old check.
|
||||||
|
|
||||||
return IsWine() ? OSPlatform.Linux : OSPlatform.Windows;
|
return IsWine() ? OSPlatform.Linux : OSPlatform.Windows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -544,7 +544,7 @@ public static class Util
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
foreach (var enumerator in enumerators)
|
foreach (var enumerator in enumerators)
|
||||||
|
|
@ -585,7 +585,7 @@ public static class Util
|
||||||
{
|
{
|
||||||
WriteAllTextSafe(path, text, Encoding.UTF8);
|
WriteAllTextSafe(path, text, Encoding.UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Overwrite text in a file by first writing it to a temporary file, and then
|
/// Overwrite text in a file by first writing it to a temporary file, and then
|
||||||
/// moving that file to the path specified.
|
/// moving that file to the path specified.
|
||||||
|
|
@ -597,7 +597,7 @@ public static class Util
|
||||||
{
|
{
|
||||||
WriteAllBytesSafe(path, encoding.GetBytes(text));
|
WriteAllBytesSafe(path, encoding.GetBytes(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Overwrite data in a file by first writing it to a temporary file, and then
|
/// Overwrite data in a file by first writing it to a temporary file, and then
|
||||||
/// moving that file to the path specified.
|
/// moving that file to the path specified.
|
||||||
|
|
@ -607,13 +607,13 @@ public static class Util
|
||||||
public static unsafe void WriteAllBytesSafe(string path, byte[] bytes)
|
public static unsafe void WriteAllBytesSafe(string path, byte[] bytes)
|
||||||
{
|
{
|
||||||
ArgumentException.ThrowIfNullOrEmpty(path);
|
ArgumentException.ThrowIfNullOrEmpty(path);
|
||||||
|
|
||||||
// Open the temp file
|
// Open the temp file
|
||||||
var tempPath = path + ".tmp";
|
var tempPath = path + ".tmp";
|
||||||
|
|
||||||
using var tempFile = Windows.Win32.PInvoke.CreateFile(
|
using var tempFile = Windows.Win32.PInvoke.CreateFile(
|
||||||
tempPath,
|
tempPath,
|
||||||
(uint)(FILE_ACCESS_RIGHTS.FILE_GENERIC_READ | FILE_ACCESS_RIGHTS.FILE_GENERIC_WRITE),
|
(uint)(FILE_ACCESS_RIGHTS.FILE_GENERIC_READ | FILE_ACCESS_RIGHTS.FILE_GENERIC_WRITE),
|
||||||
FILE_SHARE_MODE.FILE_SHARE_NONE,
|
FILE_SHARE_MODE.FILE_SHARE_NONE,
|
||||||
null,
|
null,
|
||||||
FILE_CREATION_DISPOSITION.CREATE_ALWAYS,
|
FILE_CREATION_DISPOSITION.CREATE_ALWAYS,
|
||||||
|
|
@ -622,7 +622,7 @@ public static class Util
|
||||||
|
|
||||||
if (tempFile.IsInvalid)
|
if (tempFile.IsInvalid)
|
||||||
throw new Win32Exception();
|
throw new Win32Exception();
|
||||||
|
|
||||||
// Write the data
|
// Write the data
|
||||||
uint bytesWritten = 0;
|
uint bytesWritten = 0;
|
||||||
if (!Windows.Win32.PInvoke.WriteFile(tempFile, new ReadOnlySpan<byte>(bytes), &bytesWritten, null))
|
if (!Windows.Win32.PInvoke.WriteFile(tempFile, new ReadOnlySpan<byte>(bytes), &bytesWritten, null))
|
||||||
|
|
@ -633,7 +633,7 @@ public static class Util
|
||||||
|
|
||||||
if (!Windows.Win32.PInvoke.FlushFileBuffers(tempFile))
|
if (!Windows.Win32.PInvoke.FlushFileBuffers(tempFile))
|
||||||
throw new Win32Exception();
|
throw new Win32Exception();
|
||||||
|
|
||||||
tempFile.Close();
|
tempFile.Close();
|
||||||
|
|
||||||
if (!Windows.Win32.PInvoke.MoveFileEx(tempPath, path, MOVE_FILE_FLAGS.MOVEFILE_REPLACE_EXISTING | MOVE_FILE_FLAGS.MOVEFILE_WRITE_THROUGH))
|
if (!Windows.Win32.PInvoke.MoveFileEx(tempPath, path, MOVE_FILE_FLAGS.MOVEFILE_REPLACE_EXISTING | MOVE_FILE_FLAGS.MOVEFILE_WRITE_THROUGH))
|
||||||
|
|
@ -750,7 +750,7 @@ public static class Util
|
||||||
"-",
|
"-",
|
||||||
MethodAttributes.Public | MethodAttributes.Static,
|
MethodAttributes.Public | MethodAttributes.Static,
|
||||||
CallingConventions.Standard,
|
CallingConventions.Standard,
|
||||||
null,
|
null,
|
||||||
new[] { typeof(object), typeof(IList<string>), typeof(ulong) },
|
new[] { typeof(object), typeof(IList<string>), typeof(ulong) },
|
||||||
obj.GetType(),
|
obj.GetType(),
|
||||||
true);
|
true);
|
||||||
|
|
@ -907,7 +907,7 @@ public static class Util
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Show a structure in an ImGui context.
|
/// Show a structure in an ImGui context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue