diff --git a/Engine/source/console/consoleFunctions.cpp b/Engine/source/console/consoleFunctions.cpp index aeb98067d..a2555c99f 100644 --- a/Engine/source/console/consoleFunctions.cpp +++ b/Engine/source/console/consoleFunctions.cpp @@ -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), , diff --git a/Engine/source/console/consoleTypes.cpp b/Engine/source/console/consoleTypes.cpp index 283cd0351..fb9d2049b 100644 --- a/Engine/source/console/consoleTypes.cpp +++ b/Engine/source/console/consoleTypes.cpp @@ -409,6 +409,27 @@ ConsoleSetType( TypeS32Vector ) else Con::printf("Vector 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 diff --git a/Engine/source/console/consoleTypes.h b/Engine/source/console/consoleTypes.h index 646ffb450..8025071a3 100644 --- a/Engine/source/console/consoleTypes.h +++ b/Engine/source/console/consoleTypes.h @@ -66,6 +66,7 @@ DefineConsoleType( TypeBoolVector, Vector) DefineConsoleType( TypeS8, S8 ) DefineConsoleType( TypeS32, S32 ) DefineConsoleType( TypeS32Vector, Vector ) +DefineConsoleType( TypeF64, F64 ) DefineConsoleType( TypeF32, F32 ) DefineConsoleType( TypeF32Vector, Vector ) DefineUnmappedConsoleType( TypeString, const char * ) // plain UTF-8 strings are not supported in new interop diff --git a/Engine/source/core/color.h b/Engine/source/core/color.h index d4c3b3b65..2b6ade809 100644 --- a/Engine/source/core/color.h +++ b/Engine/source/core/color.h @@ -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(r * 255.0); - green = static_cast(g * 255.0); - blue = static_cast(b * 255.0); + red = static_cast(r * 255.0 + 0.5); + green = static_cast(g * 255.0 + 0.5); + blue = static_cast(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(H + 0.5); // Round to nearest integer - val.sat = static_cast(S * 100.0 + 0.5); // Convert to percentage - val.brightness = static_cast(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; } diff --git a/Engine/source/gui/controls/guiColorPicker.cpp b/Engine/source/gui/controls/guiColorPicker.cpp index ced6daba8..7ca985a20 100644 --- a/Engine/source/gui/controls/guiColorPicker.cpp +++ b/Engine/source/gui/controls/guiColorPicker.cpp @@ -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(relX * 100.0f)); - setSelectedBrightness(static_cast(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(relX * 360.0f)); + setSelectedHue(relX * 360.0); break; } case GuiColorPickerCtrl::sVertical: { F32 relY = F32(mousePoint.y) / F32(ext.y); - setSelectedHue(static_cast(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(relX * 255.0f)); + setSelectedAlpha(relX * 255.0); break; } case GuiColorPickerCtrl::sVertical: { F32 relY = F32(mousePoint.y) / F32(ext.y); - setSelectedAlpha(static_cast(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(relX * 100.0f)); - setSelectedBrightness(static_cast(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(relX * 360.0f)); + setSelectedHue(relX * 360.0); break; } case GuiColorPickerCtrl::sVertical: { F32 relY = F32(mousePoint.y) / F32(ext.y); - setSelectedHue(static_cast(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(relX * 255.0f)); + setSelectedAlpha(relX * 255.0); break; } case GuiColorPickerCtrl::sVertical: { F32 relY = F32(mousePoint.y) / F32(ext.y); - setSelectedAlpha(static_cast(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(); } diff --git a/Engine/source/gui/controls/guiColorPicker.h b/Engine/source/gui/controls/guiColorPicker.h index 0375c48ff..48639520a 100644 --- a/Engine/source/gui/controls/guiColorPicker.h +++ b/Engine/source/gui/controls/guiColorPicker.h @@ -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. /// /// Hue value, 0 - 360. - void setSelectedHue(const U32& hueValue); - U32 getSelectedHue() { return mSelectedHue; } + void setSelectedHue(const F64& hueValue); + F64 getSelectedHue() { return mSelectedHue; } /// /// Set the selected brightness. /// /// Brightness value, 0 - 100. - void setSelectedBrightness(const U32& brightValue); - U32 getSelectedBrightness() { return mSelectedBrightness; } + void setSelectedBrightness(const F64& brightValue); + F64 getSelectedBrightness() { return mSelectedBrightness; } /// /// Set the selected saturation. /// /// Saturation value, 0 - 100. - void setSelectedSaturation(const U32& satValue); - U32 getSelectedSaturation() { return mSelectedSaturation; } + void setSelectedSaturation(const F64& satValue); + F64 getSelectedSaturation() { return mSelectedSaturation; } /// /// Set the selected alpha. /// /// Alpha value, 0 - 255. - void setSelectedAlpha(const U32& alphaValue); - U32 getSelectedAlpha() { return mSelectedAlpha; } + void setSelectedAlpha(const F64& alphaValue); + F64 getSelectedAlpha() { return mSelectedAlpha; } }; typedef GuiColorPickerCtrl::PickMode GuiColorPickMode;