mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
change hsb to doubles internally
This commit is contained in:
parent
5ca1c37fe9
commit
029a495de1
|
|
@ -1095,7 +1095,7 @@ DefineEngineFunction(ColorRGBToHEX, const char*, (ColorI color), ,
|
|||
return Con::getReturnBuffer(color.getHex());
|
||||
}
|
||||
|
||||
DefineEngineFunction(ColorRGBToHSB, Point3I, (ColorI color), ,
|
||||
DefineEngineFunction(ColorRGBToHSB, const char*, (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"
|
||||
|
|
@ -1104,9 +1104,9 @@ DefineEngineFunction(ColorRGBToHSB, Point3I, (ColorI color), ,
|
|||
"@endtsexample\n"
|
||||
"@ingroup Strings")
|
||||
{
|
||||
ColorI::Hsb hsb(color.getHSB());
|
||||
Point3I hsbPoint(hsb.hue, hsb.sat, hsb.brightness);
|
||||
return hsbPoint;
|
||||
ColorI::Hsb hsb(color.getHSB());
|
||||
String s(String::ToString(hsb.hue) + " " + String::ToString(hsb.sat) + " " + String::ToString(hsb.brightness));
|
||||
return Con::getReturnBuffer(s);
|
||||
}
|
||||
|
||||
DefineEngineFunction(ColorHEXToRGB, ColorI, (const char* hex), ,
|
||||
|
|
|
|||
|
|
@ -409,6 +409,27 @@ ConsoleSetType( TypeS32Vector )
|
|||
else
|
||||
Con::printf("Vector<S32> must be set as { a, b, c, ... } or \"a b c ...\"");
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// TypeF64
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType(double, TypeF64, F64, "")
|
||||
ImplementConsoleTypeCasters(TypeF64, F64)
|
||||
|
||||
ConsoleGetType(TypeF64)
|
||||
{
|
||||
static const U32 bufSize = 256;
|
||||
char* returnBuffer = Con::getReturnBuffer(bufSize);
|
||||
dSprintf(returnBuffer, bufSize, "%Lg", *((F64*)dptr));
|
||||
return returnBuffer;
|
||||
}
|
||||
ConsoleSetType(TypeF64)
|
||||
{
|
||||
if (argc == 1)
|
||||
*((F64*)dptr) = dAtod(argv[0]);
|
||||
else
|
||||
Con::printf("(TypeF64) Cannot set multiple args to a single F64.");
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// TypeF32
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ DefineConsoleType( TypeBoolVector, Vector<bool>)
|
|||
DefineConsoleType( TypeS8, S8 )
|
||||
DefineConsoleType( TypeS32, S32 )
|
||||
DefineConsoleType( TypeS32Vector, Vector<S32> )
|
||||
DefineConsoleType( TypeF64, F64 )
|
||||
DefineConsoleType( TypeF32, F32 )
|
||||
DefineConsoleType( TypeF32Vector, Vector<F32> )
|
||||
DefineUnmappedConsoleType( TypeString, const char * ) // plain UTF-8 strings are not supported in new interop
|
||||
|
|
|
|||
|
|
@ -129,11 +129,11 @@ public:
|
|||
struct Hsb
|
||||
{
|
||||
Hsb() :hue(0), sat(0), brightness(0){};
|
||||
Hsb(U32 h, U32 s, U32 b) :hue(h), sat(s), brightness(b){};
|
||||
Hsb(F64 h, F64 s, F64 b) :hue(h), sat(s), brightness(b){};
|
||||
|
||||
U32 hue; ///Hue
|
||||
U32 sat; ///Saturation
|
||||
U32 brightness; //Brightness/Value/Lightness
|
||||
F64 hue; ///Hue
|
||||
F64 sat; ///Saturation
|
||||
F64 brightness; //Brightness/Value/Lightness
|
||||
};
|
||||
|
||||
public:
|
||||
|
|
@ -504,9 +504,9 @@ inline void ColorI::set(const Hsb& color)
|
|||
}
|
||||
|
||||
// Convert normalized [0.0, 1.0] RGB values to integer [0, 255]
|
||||
red = static_cast<U32>(r * 255.0);
|
||||
green = static_cast<U32>(g * 255.0);
|
||||
blue = static_cast<U32>(b * 255.0);
|
||||
red = static_cast<U32>(r * 255.0 + 0.5);
|
||||
green = static_cast<U32>(g * 255.0 + 0.5);
|
||||
blue = static_cast<U32>(b * 255.0 + 0.5);
|
||||
alpha = 255; // Set alpha to fully opaque
|
||||
}
|
||||
|
||||
|
|
@ -755,9 +755,9 @@ inline ColorI::Hsb ColorI::getHSB() const
|
|||
|
||||
// Prepare the output HSB struct
|
||||
ColorI::Hsb val;
|
||||
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
|
||||
val.hue = H; // Round to nearest integer
|
||||
val.sat = S * 100.0; // Convert to percentage
|
||||
val.brightness = B * 100.0; // Convert to percentage
|
||||
|
||||
return val;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ void GuiColorPickerCtrl::renderAlphaGradient(RectI& bounds)
|
|||
ColorI currentColor;
|
||||
currentColor.set(ColorI::Hsb(mSelectedHue, 100, 100));
|
||||
|
||||
ColorI alphaCol = currentColor;
|
||||
ColorI alphaCol = ColorI::BLACK;
|
||||
alphaCol.alpha = 0;
|
||||
|
||||
// Begin primitive building, 4 vertices per rectangle
|
||||
|
|
@ -448,8 +448,8 @@ void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event)
|
|||
{
|
||||
F32 relX = F32(mousePoint.x) / F32(ext.x);
|
||||
F32 relY = 1.0f - F32(mousePoint.y) / F32(ext.y);
|
||||
setSelectedSaturation(static_cast<U32>(relX * 100.0f));
|
||||
setSelectedBrightness(static_cast<U32>(relY * 100.0f));
|
||||
setSelectedSaturation(relX * 100.0);
|
||||
setSelectedBrightness(relY * 100.0);
|
||||
break;
|
||||
}
|
||||
case GuiColorPickerCtrl::pHueRange:
|
||||
|
|
@ -459,13 +459,13 @@ void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event)
|
|||
case GuiColorPickerCtrl::sHorizontal:
|
||||
{
|
||||
F32 relX = F32(mousePoint.x) / F32(ext.x);
|
||||
setSelectedHue(static_cast<U32>(relX * 360.0f));
|
||||
setSelectedHue(relX * 360.0);
|
||||
break;
|
||||
}
|
||||
case GuiColorPickerCtrl::sVertical:
|
||||
{
|
||||
F32 relY = F32(mousePoint.y) / F32(ext.y);
|
||||
setSelectedHue(static_cast<U32>(relY * 360.0f));
|
||||
setSelectedHue(relY * 360.0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -480,13 +480,13 @@ void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event)
|
|||
case GuiColorPickerCtrl::sHorizontal:
|
||||
{
|
||||
F32 relX = F32(mousePoint.x) / F32(ext.x);
|
||||
setSelectedAlpha(static_cast<U32>(relX * 255.0f));
|
||||
setSelectedAlpha(relX * 255.0);
|
||||
break;
|
||||
}
|
||||
case GuiColorPickerCtrl::sVertical:
|
||||
{
|
||||
F32 relY = F32(mousePoint.y) / F32(ext.y);
|
||||
setSelectedAlpha(static_cast<U32>(relY * 255.0f));
|
||||
setSelectedAlpha(relY * 255.0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -518,8 +518,8 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event)
|
|||
{
|
||||
F32 relX = F32(mousePoint.x) / F32(ext.x);
|
||||
F32 relY = 1.0f - F32(mousePoint.y) / F32(ext.y);
|
||||
setSelectedSaturation(static_cast<U32>(relX * 100.0f));
|
||||
setSelectedBrightness(static_cast<U32>(relY * 100.0f));
|
||||
setSelectedSaturation(relX * 100.0);
|
||||
setSelectedBrightness(relY * 100.0);
|
||||
break;
|
||||
}
|
||||
case GuiColorPickerCtrl::pHueRange:
|
||||
|
|
@ -529,13 +529,13 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event)
|
|||
case GuiColorPickerCtrl::sHorizontal:
|
||||
{
|
||||
F32 relX = F32(mousePoint.x) / F32(ext.x);
|
||||
setSelectedHue(static_cast<U32>(relX * 360.0f));
|
||||
setSelectedHue(relX * 360.0);
|
||||
break;
|
||||
}
|
||||
case GuiColorPickerCtrl::sVertical:
|
||||
{
|
||||
F32 relY = F32(mousePoint.y) / F32(ext.y);
|
||||
setSelectedHue(static_cast<U32>(relY * 360.0f));
|
||||
setSelectedHue(relY * 360.0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -550,13 +550,13 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event)
|
|||
case GuiColorPickerCtrl::sHorizontal:
|
||||
{
|
||||
F32 relX = F32(mousePoint.x) / F32(ext.x);
|
||||
setSelectedAlpha(static_cast<U32>(relX * 255.0f));
|
||||
setSelectedAlpha(relX * 255.0);
|
||||
break;
|
||||
}
|
||||
case GuiColorPickerCtrl::sVertical:
|
||||
{
|
||||
F32 relY = F32(mousePoint.y) / F32(ext.y);
|
||||
setSelectedAlpha(static_cast<U32>(relY * 255.0f));
|
||||
setSelectedAlpha(relY * 255.0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -587,7 +587,7 @@ void GuiColorPickerCtrl::onMouseLeave(const GuiEvent &)
|
|||
mMouseOver = false;
|
||||
}
|
||||
|
||||
void GuiColorPickerCtrl::setSelectedHue(const U32& hueValue)
|
||||
void GuiColorPickerCtrl::setSelectedHue(const F64& hueValue)
|
||||
{
|
||||
if (hueValue < 0)
|
||||
{
|
||||
|
|
@ -605,7 +605,7 @@ void GuiColorPickerCtrl::setSelectedHue(const U32& hueValue)
|
|||
|
||||
}
|
||||
|
||||
void GuiColorPickerCtrl::setSelectedBrightness(const U32& brightValue)
|
||||
void GuiColorPickerCtrl::setSelectedBrightness(const F64& brightValue)
|
||||
{
|
||||
if (brightValue < 0)
|
||||
{
|
||||
|
|
@ -622,7 +622,7 @@ void GuiColorPickerCtrl::setSelectedBrightness(const U32& brightValue)
|
|||
mSelectedBrightness = brightValue;
|
||||
}
|
||||
|
||||
void GuiColorPickerCtrl::setSelectedSaturation(const U32& satValue)
|
||||
void GuiColorPickerCtrl::setSelectedSaturation(const F64& satValue)
|
||||
{
|
||||
if (satValue < 0)
|
||||
{
|
||||
|
|
@ -639,7 +639,7 @@ void GuiColorPickerCtrl::setSelectedSaturation(const U32& satValue)
|
|||
mSelectedSaturation = satValue;
|
||||
}
|
||||
|
||||
void GuiColorPickerCtrl::setSelectedAlpha(const U32& alphaValue)
|
||||
void GuiColorPickerCtrl::setSelectedAlpha(const F64& alphaValue)
|
||||
{
|
||||
if (alphaValue < 0)
|
||||
{
|
||||
|
|
@ -673,42 +673,42 @@ DefineEngineMethod(GuiColorPickerCtrl, executeUpdate, void, (), , "Execute the o
|
|||
object->onAction();
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiColorPickerCtrl, setSelectedHue, void, (U32 hueValue), , "Sets the selected hue value should be 0-360.")
|
||||
DefineEngineMethod(GuiColorPickerCtrl, setSelectedHue, void, (F64 hueValue), , "Sets the selected hue value should be 0-360.")
|
||||
{
|
||||
object->setSelectedHue(hueValue);
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiColorPickerCtrl, getSelectedHue, S32, (), , "Gets the current selected hue value.")
|
||||
DefineEngineMethod(GuiColorPickerCtrl, getSelectedHue, F64, (), , "Gets the current selected hue value.")
|
||||
{
|
||||
return object->getSelectedHue();
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiColorPickerCtrl, setSelectedBrightness, void, (U32 brightness), , "Sets the selected brightness value should be 0-100.")
|
||||
DefineEngineMethod(GuiColorPickerCtrl, setSelectedBrightness, void, (F64 brightness), , "Sets the selected brightness value should be 0-100.")
|
||||
{
|
||||
object->setSelectedBrightness(brightness);
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiColorPickerCtrl, getSelectedBrightness, S32, (), , "Gets the current selected brightness.")
|
||||
DefineEngineMethod(GuiColorPickerCtrl, getSelectedBrightness, F64, (), , "Gets the current selected brightness.")
|
||||
{
|
||||
return object->getSelectedBrightness();
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiColorPickerCtrl, setSelectedSaturation, void, (U32 saturation), , "Sets the selected saturation value should be 0-100.")
|
||||
DefineEngineMethod(GuiColorPickerCtrl, setSelectedSaturation, void, (F64 saturation), , "Sets the selected saturation value should be 0-100.")
|
||||
{
|
||||
object->setSelectedSaturation(saturation);
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiColorPickerCtrl, getSelectedSaturation, S32, (), , "Gets the current selected saturation value.")
|
||||
DefineEngineMethod(GuiColorPickerCtrl, getSelectedSaturation, F64, (), , "Gets the current selected saturation value.")
|
||||
{
|
||||
return object->getSelectedSaturation();
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiColorPickerCtrl, setSelectedAlpha, void, (U32 alpha), , "Sets the selected alpha value should be 0-255.")
|
||||
DefineEngineMethod(GuiColorPickerCtrl, setSelectedAlpha, void, (F64 alpha), , "Sets the selected alpha value should be 0-255.")
|
||||
{
|
||||
object->setSelectedAlpha(alpha);
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiColorPickerCtrl, getSelectedAlpha, S32, (), , "Gets the current selected alpha value.")
|
||||
DefineEngineMethod(GuiColorPickerCtrl, getSelectedAlpha, F64, (), , "Gets the current selected alpha value.")
|
||||
{
|
||||
return object->getSelectedAlpha();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,10 +112,10 @@ class GuiColorPickerCtrl : public GuiControl
|
|||
/// @{
|
||||
PickMode mDisplayMode; ///< Current color display mode of the selector
|
||||
SelectorMode mSelectorMode; ///< Current color display mode of the selector
|
||||
U32 mSelectedHue;
|
||||
U32 mSelectedSaturation;
|
||||
U32 mSelectedBrightness;
|
||||
U32 mSelectedAlpha;
|
||||
F64 mSelectedHue;
|
||||
F64 mSelectedSaturation;
|
||||
F64 mSelectedBrightness;
|
||||
F64 mSelectedAlpha;
|
||||
|
||||
bool mMouseOver; ///< Mouse is over?
|
||||
bool mMouseDown; ///< Mouse button down?
|
||||
|
|
@ -158,29 +158,29 @@ class GuiColorPickerCtrl : public GuiControl
|
|||
/// Set the selected hue.
|
||||
/// </summary>
|
||||
/// <param name="hueValue">Hue value, 0 - 360.</param>
|
||||
void setSelectedHue(const U32& hueValue);
|
||||
U32 getSelectedHue() { return mSelectedHue; }
|
||||
void setSelectedHue(const F64& hueValue);
|
||||
F64 getSelectedHue() { return mSelectedHue; }
|
||||
|
||||
/// <summary>
|
||||
/// Set the selected brightness.
|
||||
/// </summary>
|
||||
/// <param name="brightValue">Brightness value, 0 - 100.</param>
|
||||
void setSelectedBrightness(const U32& brightValue);
|
||||
U32 getSelectedBrightness() { return mSelectedBrightness; }
|
||||
void setSelectedBrightness(const F64& brightValue);
|
||||
F64 getSelectedBrightness() { return mSelectedBrightness; }
|
||||
|
||||
/// <summary>
|
||||
/// Set the selected saturation.
|
||||
/// </summary>
|
||||
/// <param name="satValue">Saturation value, 0 - 100.</param>
|
||||
void setSelectedSaturation(const U32& satValue);
|
||||
U32 getSelectedSaturation() { return mSelectedSaturation; }
|
||||
void setSelectedSaturation(const F64& satValue);
|
||||
F64 getSelectedSaturation() { return mSelectedSaturation; }
|
||||
|
||||
/// <summary>
|
||||
/// Set the selected alpha.
|
||||
/// </summary>
|
||||
/// <param name="alphaValue">Alpha value, 0 - 255.</param>
|
||||
void setSelectedAlpha(const U32& alphaValue);
|
||||
U32 getSelectedAlpha() { return mSelectedAlpha; }
|
||||
void setSelectedAlpha(const F64& alphaValue);
|
||||
F64 getSelectedAlpha() { return mSelectedAlpha; }
|
||||
};
|
||||
|
||||
typedef GuiColorPickerCtrl::PickMode GuiColorPickMode;
|
||||
|
|
|
|||
Loading…
Reference in a new issue