mirror of
https://github.com/ZuneDev/MicrosoftIris.git
synced 2026-07-27 13:13:29 -07:00
Make Color and TextStyle serializable
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user