KSP-Conformal-Decals/Source/ConformalDecals/Text/DecalTextStyle.cs

102 lines
3.1 KiB
C#
Raw Normal View History

2020-07-24 21:39:35 +00:00
using System;
using TMPro;
using UnityEngine;
// ReSharper disable NonReadonlyMemberInGetHashCode
2020-07-24 21:39:35 +00:00
namespace ConformalDecals.Text {
2020-07-27 02:30:19 +00:00
public struct DecalTextStyle : IEquatable<DecalTextStyle> {
2020-07-26 06:49:47 +00:00
private FontStyles _fontStyle;
2020-07-27 02:30:19 +00:00
private bool _vertical;
private float _lineSpacing;
private float _characterSpacing;
2020-07-26 06:49:47 +00:00
public FontStyles FontStyle {
get => _fontStyle;
set => _fontStyle = value;
}
2020-07-24 21:39:35 +00:00
public bool Bold {
get => (FontStyle & FontStyles.Bold) != 0;
set {
if (value) FontStyle |= FontStyles.Bold;
else FontStyle &= ~FontStyles.Bold;
}
}
public bool Italic {
get => (FontStyle & FontStyles.Italic) != 0;
set {
if (value) FontStyle |= FontStyles.Italic;
else FontStyle &= ~FontStyles.Italic;
}
}
public bool Underline {
get => (FontStyle & FontStyles.Underline) != 0;
set {
if (value) FontStyle |= FontStyles.Underline;
else FontStyle &= ~FontStyles.Underline;
}
}
public bool SmallCaps {
get => (FontStyle & FontStyles.SmallCaps) != 0;
set {
if (value) FontStyle |= FontStyles.SmallCaps;
else FontStyle &= ~FontStyles.SmallCaps;
}
}
2020-07-26 06:49:47 +00:00
public bool Vertical {
get => _vertical;
set => _vertical = value;
}
public float LineSpacing {
get => _lineSpacing;
set => _lineSpacing = value;
}
2020-07-24 21:39:35 +00:00
2020-07-26 06:49:47 +00:00
public float CharacterSpacing {
get => _characterSpacing;
set => _characterSpacing = value;
}
2020-07-27 02:30:19 +00:00
public DecalTextStyle(FontStyles fontStyle, bool vertical, float lineSpacing, float characterSpacing) {
_fontStyle = fontStyle;
_vertical = vertical;
_lineSpacing = lineSpacing;
_characterSpacing = characterSpacing;
2020-07-26 06:49:47 +00:00
}
2020-07-27 02:30:19 +00:00
2020-07-24 21:39:35 +00:00
public bool Equals(DecalTextStyle other) {
2020-07-27 02:30:19 +00:00
return FontStyle == other.FontStyle && Vertical == other.Vertical &&
Mathf.Approximately(LineSpacing, other.LineSpacing) &&
Mathf.Approximately(CharacterSpacing, other.CharacterSpacing);
2020-07-24 21:39:35 +00:00
}
public override bool Equals(object obj) {
2020-07-27 02:30:19 +00:00
return obj is DecalTextStyle other && Equals(other);
2020-07-24 21:39:35 +00:00
}
public override int GetHashCode() {
unchecked {
2020-07-27 02:30:19 +00:00
var hashCode = (int) FontStyle;
hashCode = (hashCode * 397) ^ Vertical.GetHashCode();
hashCode = (hashCode * 397) ^ LineSpacing.GetHashCode();
hashCode = (hashCode * 397) ^ CharacterSpacing.GetHashCode();
2020-07-24 21:39:35 +00:00
return hashCode;
}
}
public static bool operator ==(DecalTextStyle left, DecalTextStyle right) {
2020-07-27 02:30:19 +00:00
return left.Equals(right);
2020-07-24 21:39:35 +00:00
}
public static bool operator !=(DecalTextStyle left, DecalTextStyle right) {
2020-07-27 02:30:19 +00:00
return !left.Equals(right);
2020-07-24 21:39:35 +00:00
}
}
}