mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
more fixes for hsb conversion and gui updated
This commit is contained in:
parent
29a9bd7917
commit
5ca1c37fe9
|
|
@ -1095,7 +1095,7 @@ DefineEngineFunction(ColorRGBToHEX, const char*, (ColorI color), ,
|
|||
return Con::getReturnBuffer(color.getHex());
|
||||
}
|
||||
|
||||
DefineEngineFunction(ColorRGBToHSB, const char*, (ColorI color), ,
|
||||
DefineEngineFunction(ColorRGBToHSB, Point3I, (ColorI color), ,
|
||||
"Convert from a integer RGB (red, green, blue) color to HSB (hue, saturation, brightness). HSB is also know as HSL or HSV as well, with the last letter standing for lightness or value.\n"
|
||||
"@param color Integer color value to be converted in the form \"R G B A\", where R is red, G is green, B is blue, and A is alpha. It excepts an alpha, but keep in mind this will not be converted.\n"
|
||||
"@return HSB color value, alpha isn't handled/converted so it is only the RGB value\n\n"
|
||||
|
|
@ -1105,8 +1105,8 @@ DefineEngineFunction(ColorRGBToHSB, const char*, (ColorI color), ,
|
|||
"@ingroup Strings")
|
||||
{
|
||||
ColorI::Hsb hsb(color.getHSB());
|
||||
String s(String::ToString(hsb.hue) + " " + String::ToString(hsb.sat) + " " + String::ToString(hsb.brightness));
|
||||
return Con::getReturnBuffer(s);
|
||||
Point3I hsbPoint(hsb.hue, hsb.sat, hsb.brightness);
|
||||
return hsbPoint;
|
||||
}
|
||||
|
||||
DefineEngineFunction(ColorHEXToRGB, ColorI, (const char* hex), ,
|
||||
|
|
|
|||
|
|
@ -725,9 +725,9 @@ inline ColorI::Hsb ColorI::getHSB() const
|
|||
F64 gPercent = (F64)green / 255.0;
|
||||
F64 bPercent = (F64)blue / 255.0;
|
||||
|
||||
// Find the min and max values among the normalized RGB values
|
||||
F64 maxColor = mMax( rPercent, mMax(gPercent, bPercent));
|
||||
F64 minColor = mMin( rPercent, mMin(gPercent, bPercent));
|
||||
// Find the max and min values among the normalized RGB values
|
||||
F64 maxColor = mMax(rPercent, mMax(gPercent, bPercent));
|
||||
F64 minColor = mMin(rPercent, mMin(gPercent, bPercent));
|
||||
|
||||
// Initialize H, S, B
|
||||
F64 H = 0.0, S = 0.0, B = maxColor;
|
||||
|
|
@ -739,29 +739,25 @@ inline ColorI::Hsb ColorI::getHSB() const
|
|||
S = delta / maxColor; // Saturation
|
||||
|
||||
// Compute hue
|
||||
if (maxColor == rPercent)
|
||||
if (fabs(maxColor - rPercent) < 1e-6)
|
||||
{
|
||||
H = 60.0 * mFmodD(((gPercent - bPercent) / delta), 6.0);
|
||||
H = 60.0 * ((gPercent - bPercent) / delta);
|
||||
}
|
||||
else if (maxColor == gPercent)
|
||||
else if (fabs(maxColor - gPercent) < 1e-6)
|
||||
{
|
||||
H = 60.0 * (((bPercent - rPercent) / delta) + 2.0);
|
||||
}
|
||||
else if (maxColor == bPercent)
|
||||
else if (fabs(maxColor - bPercent) < 1e-6)
|
||||
{
|
||||
H = 60.0 * (((rPercent - gPercent) / delta) + 4.0);
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize hue to [0, 360)
|
||||
if (H < 0.0)
|
||||
H += 360.0;
|
||||
|
||||
// Prepare the output HSB struct
|
||||
ColorI::Hsb val;
|
||||
val.hue = static_cast<U32>(H);
|
||||
val.sat = static_cast<U32>(S * 100.0); // Saturation as percentage
|
||||
val.brightness = static_cast<U32>(B * 100.0); // Brightness as percentage
|
||||
val.hue = static_cast<U32>(H + 0.5); // Round to nearest integer
|
||||
val.sat = static_cast<U32>(S * 100.0 + 0.5); // Convert to percentage
|
||||
val.brightness = static_cast<U32>(B * 100.0 + 0.5); // Convert to percentage
|
||||
|
||||
return val;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue