Merge remote-tracking branch 'origin/master' into 1.9
# Conflicts: # Flax.flaxproj
This commit is contained in:
@@ -18,7 +18,7 @@ namespace FlaxEditor.Content.Settings
|
||||
/// <summary>
|
||||
/// The layers names.
|
||||
/// </summary>
|
||||
[EditorOrder(10), EditorDisplay("Layers", EditorDisplayAttribute.InlineStyle), Collection(ReadOnly = true, Display = CollectionAttribute.DisplayType.Inline)]
|
||||
[EditorOrder(10), EditorDisplay("Layers", EditorDisplayAttribute.InlineStyle), Collection(CanResize = true, Display = CollectionAttribute.DisplayType.Inline)]
|
||||
public string[] Layers = new string[32];
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -32,41 +32,39 @@ Color::Color(const Color32& color)
|
||||
{
|
||||
}
|
||||
|
||||
Color Color::FromHex(const String& hexString, bool& isValid)
|
||||
Color Color::FromHex(const String& hex, bool& isValid)
|
||||
{
|
||||
int32 r, g, b, a = 255;
|
||||
isValid = true;
|
||||
|
||||
int32 startIndex = !hexString.IsEmpty() && hexString[0] == Char('#') ? 1 : 0;
|
||||
if (hexString.Length() == 3 + startIndex)
|
||||
int32 startIndex = !hex.IsEmpty() && hex[0] == Char('#') ? 1 : 0;
|
||||
if (hex.Length() == 3 + startIndex)
|
||||
{
|
||||
r = StringUtils::HexDigit(hexString[startIndex++]);
|
||||
g = StringUtils::HexDigit(hexString[startIndex++]);
|
||||
b = StringUtils::HexDigit(hexString[startIndex]);
|
||||
r = StringUtils::HexDigit(hex[startIndex++]);
|
||||
g = StringUtils::HexDigit(hex[startIndex++]);
|
||||
b = StringUtils::HexDigit(hex[startIndex]);
|
||||
|
||||
r = (r << 4) + r;
|
||||
g = (g << 4) + g;
|
||||
b = (b << 4) + b;
|
||||
}
|
||||
else if (hexString.Length() == 6 + startIndex)
|
||||
else if (hex.Length() == 6 + startIndex)
|
||||
{
|
||||
r = (StringUtils::HexDigit(hexString[startIndex + 0]) << 4) + StringUtils::HexDigit(hexString[startIndex + 1]);
|
||||
g = (StringUtils::HexDigit(hexString[startIndex + 2]) << 4) + StringUtils::HexDigit(hexString[startIndex + 3]);
|
||||
b = (StringUtils::HexDigit(hexString[startIndex + 4]) << 4) + StringUtils::HexDigit(hexString[startIndex + 5]);
|
||||
r = (StringUtils::HexDigit(hex[startIndex + 0]) << 4) + StringUtils::HexDigit(hex[startIndex + 1]);
|
||||
g = (StringUtils::HexDigit(hex[startIndex + 2]) << 4) + StringUtils::HexDigit(hex[startIndex + 3]);
|
||||
b = (StringUtils::HexDigit(hex[startIndex + 4]) << 4) + StringUtils::HexDigit(hex[startIndex + 5]);
|
||||
}
|
||||
else if (hexString.Length() == 8 + startIndex)
|
||||
else if (hex.Length() == 8 + startIndex)
|
||||
{
|
||||
r = (StringUtils::HexDigit(hexString[startIndex + 0]) << 4) + StringUtils::HexDigit(hexString[startIndex + 1]);
|
||||
g = (StringUtils::HexDigit(hexString[startIndex + 2]) << 4) + StringUtils::HexDigit(hexString[startIndex + 3]);
|
||||
b = (StringUtils::HexDigit(hexString[startIndex + 4]) << 4) + StringUtils::HexDigit(hexString[startIndex + 5]);
|
||||
a = (StringUtils::HexDigit(hexString[startIndex + 6]) << 4) + StringUtils::HexDigit(hexString[startIndex + 7]);
|
||||
r = (StringUtils::HexDigit(hex[startIndex + 0]) << 4) + StringUtils::HexDigit(hex[startIndex + 1]);
|
||||
g = (StringUtils::HexDigit(hex[startIndex + 2]) << 4) + StringUtils::HexDigit(hex[startIndex + 3]);
|
||||
b = (StringUtils::HexDigit(hex[startIndex + 4]) << 4) + StringUtils::HexDigit(hex[startIndex + 5]);
|
||||
a = (StringUtils::HexDigit(hex[startIndex + 6]) << 4) + StringUtils::HexDigit(hex[startIndex + 7]);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = g = b = 0;
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
return FromBytes(r, g, b, a);
|
||||
}
|
||||
|
||||
@@ -122,8 +120,9 @@ String Color::ToHexString() const
|
||||
const byte r = static_cast<byte>(R * MAX_uint8);
|
||||
const byte g = static_cast<byte>(G * MAX_uint8);
|
||||
const byte b = static_cast<byte>(B * MAX_uint8);
|
||||
const byte a = static_cast<byte>(A * MAX_uint8);
|
||||
|
||||
Char result[6];
|
||||
Char result[8];
|
||||
|
||||
result[0] = digits[r >> 4 & 0x0f];
|
||||
result[1] = digits[r & 0x0f];
|
||||
@@ -134,7 +133,10 @@ String Color::ToHexString() const
|
||||
result[4] = digits[b >> 4 & 0x0f];
|
||||
result[5] = digits[b & 0x0f];
|
||||
|
||||
return String(result, 6);
|
||||
result[6] = digits[a >> 4 & 0x0f];
|
||||
result[7] = digits[a & 0x0f];
|
||||
|
||||
return String(result, 8);
|
||||
}
|
||||
|
||||
bool Color::IsTransparent() const
|
||||
|
||||
@@ -230,36 +230,93 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates <see cref="Color"/> from the RGB value and separate alpha channel.
|
||||
/// Creates <see cref="Color"/> from the RGB value (bottom bits contain Blue) and separate alpha channel.
|
||||
/// </summary>
|
||||
/// <param name="rgb">The packed RGB value.</param>
|
||||
/// <param name="rgb">The packed RGB value (bottom bits contain Blue).</param>
|
||||
/// <param name="a">The alpha channel value.</param>
|
||||
/// <returns>The color.</returns>
|
||||
public static Color FromRGB(uint rgb, float a = 1.0f)
|
||||
{
|
||||
return new Color(
|
||||
((rgb >> 16) & 0xff) / 255.0f,
|
||||
((rgb >> 8) & 0xff) / 255.0f,
|
||||
(rgb & 0xff) / 255.0f,
|
||||
a);
|
||||
return new Color(((rgb >> 16) & 0xff) / 255.0f, ((rgb >> 8) & 0xff) / 255.0f, (rgb & 0xff) / 255.0f, a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates <see cref="Color"/> from the RGBA value.
|
||||
/// Creates <see cref="Color"/> from the ARGB value (bottom bits contain Blue).
|
||||
/// </summary>
|
||||
/// <param name="rgb">The packed RGBA value.</param>
|
||||
/// <param name="argb">The packed ARGB value (bottom bits contain Blue).</param>
|
||||
/// <returns>The color.</returns>
|
||||
public static Color FromRGBA(uint rgb)
|
||||
public static Color FromARGB(uint argb)
|
||||
{
|
||||
return new Color(
|
||||
((rgb >> 16) & 0xff) / 255.0f,
|
||||
((rgb >> 8) & 0xff) / 255.0f,
|
||||
(rgb & 0xff) / 255.0f,
|
||||
((rgb >> 24) & 0xff) / 255.0f);
|
||||
return new Color(((argb >> 16) & 0xff) / 255.0f, ((argb >> 8) & 0xff) / 255.0f, ((argb >> 0) & 0xff) / 255.0f, ((argb >> 24) & 0xff) / 255.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color value as the hexadecimal string.
|
||||
/// Creates <see cref="Color"/> from the RGBA value (bottom bits contain Alpha).
|
||||
/// </summary>
|
||||
/// <param name="rgba">The packed RGBA value (bottom bits Alpha Red).</param>
|
||||
/// <returns>The color.</returns>
|
||||
public static Color FromRGBA(uint rgba)
|
||||
{
|
||||
return new Color(((rgba >> 24) & 0xff) / 255.0f, ((rgba >> 16) & 0xff) / 255.0f, ((rgba >> 8) & 0xff) / 255.0f, ((rgba >> 0) & 0xff) / 255.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates <see cref="Color"/> from the Hex string.
|
||||
/// </summary>
|
||||
/// <param name="hex">The hexadecimal color string.</param>
|
||||
/// <returns>The output color value.</returns>
|
||||
public static Color FromHex(string hex)
|
||||
{
|
||||
FromHex(hex, out var color);
|
||||
return color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates <see cref="Color"/> from the Hex string.
|
||||
/// </summary>
|
||||
/// <param name="hex">The hexadecimal color string.</param>
|
||||
/// <param name="color">The output color value. Valid if method returns true.</param>
|
||||
/// <returns>True if method was able to convert color, otherwise false.</returns>
|
||||
public static bool FromHex(string hex, out Color color)
|
||||
{
|
||||
int r, g, b, a = 255;
|
||||
bool isValid = true;
|
||||
|
||||
int startIndex = hex.Length != 0 && hex[0] == '#' ? 1 : 0;
|
||||
if (hex.Length == 3 + startIndex)
|
||||
{
|
||||
r = StringUtils.HexDigit(hex[startIndex++]);
|
||||
g = StringUtils.HexDigit(hex[startIndex++]);
|
||||
b = StringUtils.HexDigit(hex[startIndex]);
|
||||
r = (r << 4) + r;
|
||||
g = (g << 4) + g;
|
||||
b = (b << 4) + b;
|
||||
}
|
||||
else if (hex.Length == 6 + startIndex)
|
||||
{
|
||||
r = (StringUtils.HexDigit(hex[startIndex + 0]) << 4) + StringUtils.HexDigit(hex[startIndex + 1]);
|
||||
g = (StringUtils.HexDigit(hex[startIndex + 2]) << 4) + StringUtils.HexDigit(hex[startIndex + 3]);
|
||||
b = (StringUtils.HexDigit(hex[startIndex + 4]) << 4) + StringUtils.HexDigit(hex[startIndex + 5]);
|
||||
}
|
||||
else if (hex.Length == 8 + startIndex)
|
||||
{
|
||||
r = (StringUtils.HexDigit(hex[startIndex + 0]) << 4) + StringUtils.HexDigit(hex[startIndex + 1]);
|
||||
g = (StringUtils.HexDigit(hex[startIndex + 2]) << 4) + StringUtils.HexDigit(hex[startIndex + 3]);
|
||||
b = (StringUtils.HexDigit(hex[startIndex + 4]) << 4) + StringUtils.HexDigit(hex[startIndex + 5]);
|
||||
a = (StringUtils.HexDigit(hex[startIndex + 6]) << 4) + StringUtils.HexDigit(hex[startIndex + 7]);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = g = b = 0;
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
color = new Color(r, g, b, a);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color value as the hexadecimal string (in RGBA order).
|
||||
/// </summary>
|
||||
/// <returns>Hex string.</returns>
|
||||
public string ToHexString()
|
||||
@@ -287,7 +344,7 @@ namespace FlaxEngine
|
||||
|
||||
return new string(result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates <see cref="Color"/> from the text string (hex or color name).
|
||||
/// </summary>
|
||||
|
||||
@@ -126,9 +126,9 @@ public:
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes from packed RGB value of the color and separate alpha channel value.
|
||||
/// Initializes from packed RGB value (bottom bits contain Blue) of the color and separate alpha channel value.
|
||||
/// </summary>
|
||||
/// <param name="rgb">The packed RGB value.</param>
|
||||
/// <param name="rgb">The packed RGB value (bottom bits contain Blue).</param>
|
||||
/// <param name="a">The alpha channel.</param>
|
||||
/// <returns>The color.</returns>
|
||||
static Color FromRGB(uint32 rgb, float a = 1.0f)
|
||||
@@ -137,22 +137,32 @@ public:
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes from packed RGBA value.
|
||||
/// Initializes from packed ARGB value (bottom bits contain Blue).
|
||||
/// </summary>
|
||||
/// <param name="rgba">The packed RGBA value.</param>
|
||||
/// <param name="argb">The packed ARGB value (bottom bits contain Blue).</param>
|
||||
/// <returns>The color.</returns>
|
||||
static Color FromARGB(uint32 argb)
|
||||
{
|
||||
return Color((float)((argb >> 16) & 0xff) / 255.0f,(float)((argb >> 8) & 0xff) / 255.0f, (float)((argb >> 0) & 0xff) / 255.0f, (float)((argb >> 24) & 0xff) / 255.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes from packed RGBA value (bottom bits contain Alpha).
|
||||
/// </summary>
|
||||
/// <param name="rgba">The packed RGBA value (bottom bits contain Alpha).</param>
|
||||
/// <returns>The color.</returns>
|
||||
static Color FromRGBA(uint32 rgba)
|
||||
{
|
||||
return Color(static_cast<float>(rgba >> 16 & 0xff) / 255.0f, static_cast<float>(rgba >> 8 & 0xff) / 255.0f, static_cast<float>(rgba & 0xff) / 255.0f, static_cast<float>(rgba >> 24 & 0xff) / 255.0f);
|
||||
return Color((float)((rgba >> 24) & 0xff) / 255.0f,(float)((rgba >> 16) & 0xff) / 255.0f, (float)((rgba >> 8) & 0xff) / 255.0f, (float)((rgba >> 0) & 0xff) / 255.0f);
|
||||
}
|
||||
|
||||
static Color FromHex(const String& hexString)
|
||||
static Color FromHex(const String& hex)
|
||||
{
|
||||
bool isValid;
|
||||
return FromHex(hexString, isValid);
|
||||
return FromHex(hex, isValid);
|
||||
}
|
||||
|
||||
static Color FromHex(const String& hexString, bool& isValid);
|
||||
static Color FromHex(const String& hex, bool& isValid);
|
||||
|
||||
/// <summary>
|
||||
/// Creates RGB color from Hue[0-360], Saturation[0-1] and Value[0-1].
|
||||
|
||||
Reference in New Issue
Block a user