Przeglądaj źródła

more fixes for hsb conversion and gui updated

marauder2k7 7 miesięcy temu
rodzic
commit
5ca1c37fe9

+ 3 - 3
Engine/source/console/consoleFunctions.cpp

@@ -1095,7 +1095,7 @@ DefineEngineFunction(ColorRGBToHEX, const char*, (ColorI color), ,
    return Con::getReturnBuffer(color.getHex());
    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"
    "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"
    "@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"
    "@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")
    "@ingroup Strings")
 {
 {
    ColorI::Hsb hsb(color.getHSB());
    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), ,
 DefineEngineFunction(ColorHEXToRGB, ColorI, (const char* hex), ,

+ 10 - 14
Engine/source/core/color.h

@@ -725,9 +725,9 @@ inline ColorI::Hsb ColorI::getHSB() const
    F64 gPercent = (F64)green / 255.0;
    F64 gPercent = (F64)green / 255.0;
    F64 bPercent = (F64)blue / 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
    // Initialize H, S, B
    F64 H = 0.0, S = 0.0, B = maxColor;
    F64 H = 0.0, S = 0.0, B = maxColor;
@@ -739,29 +739,25 @@ inline ColorI::Hsb ColorI::getHSB() const
       S = delta / maxColor; // Saturation
       S = delta / maxColor; // Saturation
 
 
       // Compute hue
       // 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);
          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);
          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
    // Prepare the output HSB struct
    ColorI::Hsb val;
    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;
    return val;
 }
 }

Plik diff jest za duży
+ 267 - 708
Templates/BaseGame/game/tools/gui/colorPicker.ed.gui


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików