mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Adjust the Color3 and COlor4 type functions to use the new method of receiving formatted strings.
This commit is contained in:
parent
3ede9645e3
commit
3e35f7c916
@ -59,13 +59,6 @@ Color3 & Color3::operator = (Value s)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Color3 & Color3::operator = (CSStr name)
|
||||
{
|
||||
SetColor3(GetColor(name));
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Color3 & Color3::operator = (const Color4 & c)
|
||||
{
|
||||
@ -537,13 +530,13 @@ void Color3::SetColor4Ex(Value nr, Value ng, Value nb, Value /*na*/)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Color3::SetStr(CSStr str, SQChar delim)
|
||||
void Color3::SetStr(SQChar delim, const StackStrF & values)
|
||||
{
|
||||
SetColor3(Color3::Get(str, delim));
|
||||
SetColor3(Color3::GetEx(delim, values));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Color3::SetName(CSStr name)
|
||||
void Color3::SetName(const StackStrF & name)
|
||||
{
|
||||
SetColor3(GetColor(name));
|
||||
}
|
||||
@ -639,13 +632,13 @@ void Color3::Inverse()
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color3 & Color3::Get(CSStr str)
|
||||
const Color3 & Color3::Get(const StackStrF & str)
|
||||
{
|
||||
return Color3::Get(str, Color3::Delim);
|
||||
return Color3::GetEx(Color3::Delim, str);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color3 & Color3::Get(CSStr str, SQChar delim)
|
||||
const Color3 & Color3::GetEx(SQChar delim, const StackStrF & str)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %u , %u , %u ");
|
||||
@ -656,7 +649,7 @@ const Color3 & Color3::Get(CSStr str, SQChar delim)
|
||||
// Clear previous values, if any
|
||||
col.Clear();
|
||||
// Is the specified string empty?
|
||||
if (!str || *str == '\0')
|
||||
if (str.mLen <= 0)
|
||||
{
|
||||
return col; // Return the value as is!
|
||||
}
|
||||
@ -666,7 +659,7 @@ const Color3 & Color3::Get(CSStr str, SQChar delim)
|
||||
// The sscanf function requires at least 32 bit integers
|
||||
Uint32 r = 0, g = 0, b = 0;
|
||||
// Attempt to extract the component values from the specified string
|
||||
std::sscanf(str, fs, &r, &g, &b);
|
||||
std::sscanf(str.mPtr, fs, &r, &g, &b);
|
||||
// Cast the extracted integers to the value used by the Color3 type
|
||||
col.r = static_cast< Color3::Value >(Clamp(r, min, max));
|
||||
col.g = static_cast< Color3::Value >(Clamp(g, min, max));
|
||||
@ -747,8 +740,8 @@ void Register_Color3(HSQUIRRELVM vm)
|
||||
.Func(_SC("SetColor3Ex"), &Color3::SetColor3Ex)
|
||||
.Func(_SC("SetColor4"), &Color3::SetColor4)
|
||||
.Func(_SC("SetColor4Ex"), &Color3::SetColor4Ex)
|
||||
.Func(_SC("SetStr"), &Color3::SetStr)
|
||||
.Func(_SC("SetName"), &Color3::SetName)
|
||||
.FmtFunc(_SC("SetStr"), &Color3::SetStr)
|
||||
.FmtFunc(_SC("SetName"), &Color3::SetName)
|
||||
.Func(_SC("Clear"), &Color3::Clear)
|
||||
.Func(_SC("Random"), &Color3::Random)
|
||||
.Func(_SC("Inverse"), &Color3::Inverse)
|
||||
@ -756,12 +749,11 @@ void Register_Color3(HSQUIRRELVM vm)
|
||||
.Overload< void (Color3::*)(void) >(_SC("Generate"), &Color3::Generate)
|
||||
.Overload< void (Color3::*)(Val, Val) >(_SC("Generate"), &Color3::Generate)
|
||||
.Overload< void (Color3::*)(Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Color3::Generate)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Color3 & (*)(CSStr) >(_SC("FromStr"), &Color3::Get)
|
||||
.StaticOverload< const Color3 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Color3::Get)
|
||||
// Static Functions
|
||||
.StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Color3 >)
|
||||
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Color3 >)
|
||||
.StaticFmtFunc(_SC("FromStr"), &Color3::Get)
|
||||
.StaticFmtFunc(_SC("FromStrEx"), &Color3::GetEx)
|
||||
// Operator Exposure
|
||||
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opAddAssign"), &Color3::operator +=)
|
||||
.Func< Color3 & (Color3::*)(const Color3 &) >(_SC("opSubAssign"), &Color3::operator -=)
|
||||
|
@ -84,11 +84,6 @@ struct Color3
|
||||
*/
|
||||
Color3 & operator = (Value s);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Named color assignment operator.
|
||||
*/
|
||||
Color3 & operator = (CSStr name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Transparent color assignment operator.
|
||||
*/
|
||||
@ -434,12 +429,12 @@ struct Color3
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the values extracted from the specified string using the specified delimiter.
|
||||
*/
|
||||
void SetStr(CSStr str, SQChar delim);
|
||||
void SetStr(SQChar delim, const StackStrF & str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the values from the identified color.
|
||||
*/
|
||||
void SetName(CSStr name);
|
||||
void SetName(const StackStrF & name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Get the component values packed inside an integer value.
|
||||
@ -507,13 +502,12 @@ struct Color3
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Color3 type from a string.
|
||||
*/
|
||||
static const Color3 & Get(CSStr str);
|
||||
static const Color3 & Get(const StackStrF & str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Color3 type from a string.
|
||||
*/
|
||||
static const Color3 & Get(CSStr str, SQChar delim);
|
||||
|
||||
static const Color3 & GetEx( SQChar delim, const StackStrF & str);
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -60,13 +60,6 @@ Color4 & Color4::operator = (Value s)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Color4 & Color4::operator = (CSStr name)
|
||||
{
|
||||
SetColor3(GetColor(name));
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Color4 & Color4::operator = (const Color3 & c)
|
||||
{
|
||||
@ -566,13 +559,13 @@ void Color4::SetColor4Ex(Value nr, Value ng, Value nb, Value na)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Color4::SetStr(CSStr str, SQChar delim)
|
||||
void Color4::SetStr(SQChar delim, const StackStrF & values)
|
||||
{
|
||||
SetColor4(Color4::Get(str, delim));
|
||||
SetColor4(Color4::GetEx(delim, values));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Color4::SetName(CSStr name)
|
||||
void Color4::SetName(const StackStrF & name)
|
||||
{
|
||||
SetColor3(GetColor(name));
|
||||
}
|
||||
@ -674,13 +667,13 @@ void Color4::Inverse()
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color4 & Color4::Get(CSStr str)
|
||||
const Color4 & Color4::Get(const StackStrF & str)
|
||||
{
|
||||
return Color4::Get(str, Color4::Delim);
|
||||
return Color4::GetEx(Color4::Delim, str);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Color4 & Color4::Get(CSStr str, SQChar delim)
|
||||
const Color4 & Color4::GetEx(SQChar delim, const StackStrF & str)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %u , %u , %u , %u ");
|
||||
@ -691,7 +684,7 @@ const Color4 & Color4::Get(CSStr str, SQChar delim)
|
||||
// Clear previous values, if any
|
||||
col.Clear();
|
||||
// Is the specified string empty?
|
||||
if (!str || *str == '\0')
|
||||
if (str.mLen <= 0)
|
||||
{
|
||||
return col; // Return the value as is!
|
||||
}
|
||||
@ -702,7 +695,7 @@ const Color4 & Color4::Get(CSStr str, SQChar delim)
|
||||
// The sscanf function requires at least 32 bit integers
|
||||
Uint32 r = 0, g = 0, b = 0, a = 0;
|
||||
// Attempt to extract the component values from the specified string
|
||||
std::sscanf(str, fs, &r, &g, &b, &a);
|
||||
std::sscanf(str.mPtr, fs, &r, &g, &b, &a);
|
||||
// Cast the extracted integers to the value used by the Color4 type
|
||||
col.r = static_cast< Color4::Value >(Clamp(r, min, max));
|
||||
col.g = static_cast< Color4::Value >(Clamp(g, min, max));
|
||||
@ -794,8 +787,8 @@ void Register_Color4(HSQUIRRELVM vm)
|
||||
.Func(_SC("SetColor3Ex"), &Color4::SetColor3Ex)
|
||||
.Func(_SC("SetColor4"), &Color4::SetColor4)
|
||||
.Func(_SC("SetColor4Ex"), &Color4::SetColor4Ex)
|
||||
.Func(_SC("SetStr"), &Color4::SetStr)
|
||||
.Func(_SC("SetName"), &Color4::SetName)
|
||||
.FmtFunc(_SC("SetStr"), &Color4::SetStr)
|
||||
.FmtFunc(_SC("SetName"), &Color4::SetName)
|
||||
.Func(_SC("Clear"), &Color4::Clear)
|
||||
.Func(_SC("Random"), &Color4::Random)
|
||||
.Func(_SC("Inverse"), &Color4::Inverse)
|
||||
@ -803,12 +796,11 @@ void Register_Color4(HSQUIRRELVM vm)
|
||||
.Overload< void (Color4::*)(void) >(_SC("Generate"), &Color4::Generate)
|
||||
.Overload< void (Color4::*)(Val, Val) >(_SC("Generate"), &Color4::Generate)
|
||||
.Overload< void (Color4::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Color4::Generate)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Color4 & (*)(CSStr) >(_SC("FromStr"), &Color4::Get)
|
||||
.StaticOverload< const Color4 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Color4::Get)
|
||||
// Static Functions
|
||||
.StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Color4 >)
|
||||
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Color4 >)
|
||||
.StaticFmtFunc(_SC("FromStr"), &Color4::Get)
|
||||
.StaticFmtFunc(_SC("FromStrEx"), &Color4::GetEx)
|
||||
// Operator Exposure
|
||||
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opAddAssign"), &Color4::operator +=)
|
||||
.Func< Color4 & (Color4::*)(const Color4 &) >(_SC("opSubAssign"), &Color4::operator -=)
|
||||
|
@ -84,11 +84,6 @@ struct Color4
|
||||
*/
|
||||
Color4 & operator = (Value s);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Named color assignment operator.
|
||||
*/
|
||||
Color4 & operator = (CSStr name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Opaque color assignment operator.
|
||||
*/
|
||||
@ -434,12 +429,12 @@ struct Color4
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the values extracted from the specified string using the specified delimiter.
|
||||
*/
|
||||
void SetStr(CSStr name, SQChar delim);
|
||||
void SetStr(SQChar delim, const StackStrF & name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the values from the identified color.
|
||||
*/
|
||||
void SetName(CSStr name);
|
||||
void SetName(const StackStrF & name);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Get the component values packed inside an integer value.
|
||||
@ -507,13 +502,12 @@ struct Color4
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Color4 type from a string.
|
||||
*/
|
||||
static const Color4 & Get(CSStr str);
|
||||
static const Color4 & Get(const StackStrF & str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Color4 type from a string.
|
||||
*/
|
||||
static const Color4 & Get(CSStr str, SQChar delim);
|
||||
|
||||
static const Color4 & GetEx(SQChar delim, const StackStrF & str);
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -212,7 +212,7 @@ SQRESULT SqGrabPlayerMessageColor(HSQUIRRELVM vm, Int32 idx, Uint32 & color, Int
|
||||
// Attempt to treat the value as a color name
|
||||
try
|
||||
{
|
||||
color = (::SqMod::GetColor(str).GetRGBA() | 0xFF);
|
||||
color = (::SqMod::GetColorStr(str).GetRGBA() | 0xFF);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user