Make Color and TextStyle serializable

This commit is contained in:
Yoshi Askharoun
2023-05-24 15:32:09 -05:00
parent bcf9b83f54
commit 30cf50b55e
3 changed files with 47 additions and 7 deletions
@@ -62,6 +62,6 @@ public class OpCodeArgument : ISerializable
info.AddValue(nameof(Name), Name);
info.AddValue(nameof(Type), Type.FullName);
info.AddValue(nameof(CanSerializeValue), CanSerializeValue);
info.AddValue(nameof(Value), CanSerializeValue ? Value : Value.ToString());
info.AddValue(nameof(Value), CanSerializeValue ? Value : Value?.ToString());
}
}
+17 -5
View File
@@ -6,11 +6,13 @@
using Microsoft.Iris.Render;
using System;
using System.Runtime.Serialization;
using System.Text;
namespace Microsoft.Iris.Drawing
{
public struct Color
[Serializable]
public struct Color : ISerializable
{
private const int ARGBAlphaShift = 24;
private const int ARGBRedShift = 16;
@@ -28,6 +30,11 @@ namespace Microsoft.Iris.Drawing
internal Color(uint value) => this.value = value;
internal Color(SerializationInfo info, StreamingContext context)
{
value = info.GetUInt32(nameof(Value));
}
public byte R
{
get => (byte)(Value >> 16 & byte.MaxValue);
@@ -192,7 +199,7 @@ namespace Microsoft.Iris.Drawing
internal int ToArgb() => (int)Value;
internal ColorF RenderConvert() => new ColorF(A, R, G, B);
internal ColorF RenderConvert() => new(A, R, G, B);
public override string ToString()
{
@@ -218,10 +225,15 @@ namespace Microsoft.Iris.Drawing
public override int GetHashCode() => value.GetHashCode();
internal static Color Transparent => new Color(0U);
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(nameof(Value), Value);
}
internal static Color Black => new Color(4278190080U);
internal static Color Transparent => new(0U);
internal static Color White => new Color(uint.MaxValue);
internal static Color Black => new(0xFF00_0000U);
internal static Color White => new(uint.MaxValue);
}
}
+29 -1
View File
@@ -6,11 +6,13 @@
using System;
using System.Collections.Specialized;
using System.Runtime.Serialization;
using System.Text;
namespace Microsoft.Iris.Drawing
{
internal class TextStyle
[Serializable]
internal class TextStyle : ISerializable
{
private BitVector32 _flags;
private string _fontFace;
@@ -21,6 +23,18 @@ namespace Microsoft.Iris.Drawing
private Color _textColor;
private bool _fragment;
public TextStyle() { }
protected TextStyle(SerializationInfo info, StreamingContext context)
{
FontFace = info.GetString(nameof(FontFace));
FontSize = info.GetSingle(nameof(FontSize));
LineSpacing = info.GetSingle(nameof(LineSpacing));
Color = (Color)info.GetValue(nameof(Color), typeof(Color));
_flags = new(info.GetInt32("flags"));
}
public bool IsInitialized() => _flags.Data != 0;
public string FontFace
@@ -201,6 +215,20 @@ namespace Microsoft.Iris.Drawing
return stringBuilder.ToString();
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (_flags[1])
info.AddValue(nameof(FontFace), FontFace);
if (_flags[2])
info.AddValue(nameof(FontSize), FontSize);
if (_flags[32])
info.AddValue(nameof(LineSpacing), LineSpacing);
if (_flags[64])
info.AddValue(nameof(Color), Color);
info.AddValue("flags", _flags.Data);
}
[Flags]
internal enum SetFlags
{