diff --git a/module/Base/Color3.cpp b/module/Base/Color3.cpp index 48a0f5f4..d4d1a7ec 100644 --- a/module/Base/Color3.cpp +++ b/module/Base/Color3.cpp @@ -22,6 +22,7 @@ const Color3 Color3::MAX = Color3(std::numeric_limits< Color3::Value >::max()); // ------------------------------------------------------------------------------------------------ SQChar Color3::Delim = ','; +bool Color3::UpperCaseHex = false; // ------------------------------------------------------------------------------------------------ Color3::Color3() noexcept @@ -637,7 +638,7 @@ LightObj Color3::ToHex() const { SQChar buff[16]; // 7 should be enough // Attempt to perform the format in the local buffer - if (std::snprintf(buff, 16, "%02x%02x%02x", r, g, b) <= 0) + if (std::snprintf(buff, 16, UpperCaseHex ? "%02X%02X%02X" : "%02x%02x%02x", r, g, b) <= 0) { STHROWF("Format failed (somehow)"); } @@ -650,7 +651,7 @@ LightObj Color3::ToHex4() const { SQChar buff[16]; // 9 should be enough // Attempt to perform the format in the local buffer - if (std::snprintf(buff, 16, "%02x%02x%02x%02x", r, g, b, 0) <= 0) + if (std::snprintf(buff, 16, UpperCaseHex ? "%02X%02X%02X%02X" : "%02x%02x%02x%02x", r, g, b, 0) <= 0) { STHROWF("Format failed (somehow)"); } @@ -722,6 +723,22 @@ const Color3 & Color3::GetEx(SQChar delim, StackStrF & str) return col; } +/* ------------------------------------------------------------------------------------------------ + * Retrieve the hex case preference of the Color3 type. +*/ +static bool SqGetColor3UpperCaseHex() +{ + return Color3::UpperCaseHex; +} + +/* ------------------------------------------------------------------------------------------------ + * Modify the hex case preference of the Color3 type. +*/ +static void SqSetColor3UpperCaseHex(bool t) +{ + Color3::UpperCaseHex = t; +} + // ================================================================================================ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-parameter" @@ -780,6 +797,8 @@ void Register_Color3(HSQUIRRELVM vm) // Static Functions .StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Color3 >) .StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Color3 >) + .StaticFunc(_SC("GetUpperCaseHex"), &SqGetColor3UpperCaseHex) + .StaticFunc(_SC("SetUpperCaseHex"), &SqSetColor3UpperCaseHex) .StaticFmtFunc(_SC("FromStr"), &Color3::Get) .StaticFmtFunc(_SC("FromStrEx"), &Color3::GetEx) // Operator Exposure diff --git a/module/Base/Color3.hpp b/module/Base/Color3.hpp index 900fda22..31a8689e 100644 --- a/module/Base/Color3.hpp +++ b/module/Base/Color3.hpp @@ -28,6 +28,11 @@ struct Color3 */ static SQChar Delim; + /* -------------------------------------------------------------------------------------------- + * Whenever converting colors to hex, useupper case characters. + */ + static bool UpperCaseHex; + /* -------------------------------------------------------------------------------------------- * The red, green and blue components of this type. */ diff --git a/module/Base/Color4.cpp b/module/Base/Color4.cpp index 2defb4de..0cd37255 100644 --- a/module/Base/Color4.cpp +++ b/module/Base/Color4.cpp @@ -22,6 +22,7 @@ const Color4 Color4::MAX = Color4(std::numeric_limits< Color4::Value >::max()); // ------------------------------------------------------------------------------------------------ SQChar Color4::Delim = ','; +bool Color4::UpperCaseHex = false; // ------------------------------------------------------------------------------------------------ Color4::Color4() noexcept @@ -672,7 +673,7 @@ LightObj Color4::ToHex() const { SQChar buff[16]; // 9 should be enough // Attempt to perform the format in the local buffer - if (std::snprintf(buff, 16, "%02x%02x%02x%02x", r, g, b, a) <= 0) + if (std::snprintf(buff, 16, UpperCaseHex ? "%02X%02X%02X%02X" : "%02x%02x%02x%02x", r, g, b, a) <= 0) { STHROWF("Format failed (somehow)"); } @@ -685,7 +686,7 @@ LightObj Color4::ToHex3() const { SQChar buff[16]; // 7 should be enough // Attempt to perform the format in the local buffer - if (std::snprintf(buff, 16, "%02x%02x%02x", r, g, b) <= 0) + if (std::snprintf(buff, 16, UpperCaseHex ? "%02X%02X%02X" : "%02x%02x%02x", r, g, b) <= 0) { STHROWF("Format failed (somehow)"); } @@ -759,6 +760,22 @@ const Color4 & Color4::GetEx(SQChar delim, StackStrF & str) return col; } +/* ------------------------------------------------------------------------------------------------ + * Retrieve the hex case preference of the Color4 type. +*/ +static bool SqGetColor4UpperCaseHex() +{ + return Color4::UpperCaseHex; +} + +/* ------------------------------------------------------------------------------------------------ + * Modify the hex case preference of the Color4 type. +*/ +static void SqSetColor4UpperCaseHex(bool t) +{ + Color4::UpperCaseHex = t; +} + // ================================================================================================ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-parameter" @@ -819,6 +836,8 @@ void Register_Color4(HSQUIRRELVM vm) // Static Functions .StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Color4 >) .StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Color4 >) + .StaticFunc(_SC("GetUpperCaseHex"), &SqGetColor4UpperCaseHex) + .StaticFunc(_SC("SetUpperCaseHex"), &SqSetColor4UpperCaseHex) .StaticFmtFunc(_SC("FromStr"), &Color4::Get) .StaticFmtFunc(_SC("FromStrEx"), &Color4::GetEx) // Operator Exposure diff --git a/module/Base/Color4.hpp b/module/Base/Color4.hpp index 671331ef..a1aec89f 100644 --- a/module/Base/Color4.hpp +++ b/module/Base/Color4.hpp @@ -28,6 +28,11 @@ struct Color4 */ static SQChar Delim; + /* -------------------------------------------------------------------------------------------- + * Whenever converting colors to hex, useupper case characters. + */ + static bool UpperCaseHex; + /* -------------------------------------------------------------------------------------------- * The red, green and blue components of this type. */