Ejemplo n.º 1
0
 public void TestPicker_SV_H_Hue(float z, float hueDegrees)
 {
     Vector3 v = new Vector3(1, 1, z);
     Color rgb;
     bool ok = ColorPickerUtils.RawValueToColor(ColorPickerMode.SV_H_Rect, v, out rgb);
     Assert.IsTrue(ok, "{0}", v);
     AssertEqualPeriodic(hueDegrees, ((HSLColor)rgb).HueDegrees, 360, 1e-3f);
 }
Ejemplo n.º 2
0
 public void TestPicker_HL_S()
 {
     var mode = ColorPickerMode.HL_S_Polar;
     Vector3 raw = new Vector3(0.75f, 0.5f, 1);
     Color rgb;
     bool ok = ColorPickerUtils.RawValueToColor(mode, raw, out rgb);
     Assert.IsTrue(ok);
     AssertNearlyEqualRGB((Color)new HSLColor(0, 0, 0.5f, 1), rgb);
 }
Ejemplo n.º 3
0
 private void Single_ColorPickerRoundTripFromColor(ColorPickerMode mode, Color rgb)
 {
     Vector3 raw = ColorPickerUtils.ColorToRawValue(mode, rgb);
     Color rgb2;
     bool ok = ColorPickerUtils.RawValueToColor(mode, raw, out rgb2);
     Assert.IsTrue(ok, "Mode {0}: {1} -> {2} -> fail", mode, Repr(rgb), raw);
     // RawValueToColor should always return colors with a=1
     Assert.AreEqual(1, rgb2.a, "RawValueToColor alpha");
     rgb.a = 1; // Don't check incoming alpha
     AssertNearlyEqualRGB(rgb, rgb2);
 }
Ejemplo n.º 4
0
 public void TestPicker_HS_L_Hue(float angle, float hueDegrees)
 {
     float radius = .5f; // - 1e-5f;
     Vector3 v = new Vector3(
         .5f + radius * Mathf.Cos(angle * Mathf.Deg2Rad),
         .5f + radius * Mathf.Sin(angle * Mathf.Deg2Rad),
         0.5f);
     Color rgb;
     bool ok = ColorPickerUtils.RawValueToColor(ColorPickerMode.HS_L_Polar, v, out rgb);
     Assert.IsTrue(ok, "{0}", v);
     AssertEqualPeriodic(hueDegrees, ((HSLColor)rgb).HueDegrees, 360, 1e-3f);
 }
Ejemplo n.º 5
0
 private void Single_ColorPickerRoundTripFromRawValue(ColorPickerMode mode, Vector3 raw)
 {
     Color rgb;
     bool ok = ColorPickerUtils.RawValueToColor(mode, raw, out rgb);
     if (!ok) { return; }
     Vector3 raw2 = ColorPickerUtils.ColorToRawValue(mode, rgb);
     Vector3 diff = raw2 - raw;
     float EPSILON = 1e-4f;
     if (Mathf.Abs(diff.x) > EPSILON ||
         Mathf.Abs(diff.y) > EPSILON ||
         Mathf.Abs(diff.z) > EPSILON)
     {
         Assert.Fail("Mode {0} sent {1} -> {2}", mode, raw, raw2);
     }
 }
Ejemplo n.º 6
0
        void UpdateColorSelectorAndSlider(bool inputValid, Ray inputRay, Collider parentCollider)
        {
            // Reset our input object if we're not holding the trigger.
            if (!InputManager.m_Instance.GetCommand(InputManager.SketchCommands.Activate))
            {
                ResetActiveInputObject();
            }

            // Color limits if we're tied to the brush color.
            float luminanceMin  = 0.0f;
            float saturationMax = 1.0f;
            BrushColorController brushController = m_ColorController as BrushColorController;

            if (brushController != null)
            {
                luminanceMin  = brushController.BrushLuminanceMin;
                saturationMax = brushController.BrushSaturationMax;
            }

            // Cache mode cause we use it a bunch.
            ColorPickerMode mode = ColorPickerUtils.GetActiveMode(m_ColorController.IsHdr);

            // Check for collision against our color slider first.
            RaycastHit hitInfo;

            if (m_ActiveInputObject == null || m_ActiveInputObject == m_ColorPickerSlider.gameObject)
            {
                bool validCollision = BasePanel.DoesRayHitCollider(inputRay,
                                                                   m_ColorPickerSlider.GetCollider(), out hitInfo);

                // TODO : ColorPickerSlider should be a UIComponent that handles this stuff
                // on its own.
                // If we're not colliding with the slider, but we were before, get our collision with
                // our parent collider.
                if (!validCollision && m_ActiveInputObject == m_ColorPickerSlider.gameObject)
                {
                    validCollision = BasePanel.DoesRayHitCollider(inputRay, parentCollider, out hitInfo);
                }

                if (validCollision)
                {
                    // Over slider, check for mouse down.
                    if (InputManager.m_Instance.GetCommand(InputManager.SketchCommands.Activate))
                    {
                        float value = ColorPickerUtils.ApplySliderConstraint(mode,
                                                                             m_ColorPickerSlider.GetValueFromHit(hitInfo),
                                                                             luminanceMin, saturationMax);
                        UpdateSelectorSlider(value);
                        UpdateSliderPosition();
                        Color newColor;
                        if (ColorPickerUtils.RawValueToColor(mode,
                                                             m_ColorPickerSelector.RawValue, out newColor))
                        {
                            m_ColorController.SetCurrentColorSilently(newColor);
                            TriggerColorPicked(newColor);
                        }
                        else
                        {
                            // Indicates some logic fault: the user isn't modifying the color plane,
                            // so why is the color plane's value outside the valid range?
                            Debug.LogErrorFormat("Unexpected bad RawValue. mode:{0} val:{1}", mode,
                                                 m_ColorPickerSelector.RawValue);
                        }

                        SketchSurfacePanel.m_Instance.VerifyValidToolWithColorUpdate();
                        m_ActiveInputObject = m_ColorPickerSlider.gameObject;
                    }
                }
            }

            if (m_ActiveInputObject == null || m_ActiveInputObject == m_ColorPickerSelector.gameObject)
            {
                if (BasePanel.DoesRayHitCollider(inputRay, m_ColorPickerSelector.GetCollider(),
                                                 out hitInfo))
                {
                    // Over color picker, check for input.
                    if (InputManager.m_Instance.GetCommand(InputManager.SketchCommands.Activate))
                    {
                        Vector3 value = ColorPickerUtils.ApplyPlanarConstraint(
                            m_ColorPickerSelector.GetValueFromHit(hitInfo),
                            mode, luminanceMin, saturationMax);
                        Color color;
                        if (ColorPickerUtils.RawValueToColor(mode, value, out color))
                        {
                            m_ColorPickerSelector.RawValue = value;
                            m_ColorController.SetCurrentColorSilently(color);
                            TriggerColorPicked(color);
                            m_ColorPickerSlider.OnColorChanged(mode, value);

                            SketchSurfacePanel.m_Instance.VerifyValidToolWithColorUpdate();
                            m_ActiveInputObject = m_ColorPickerSelector.gameObject;
                        }
                    }
                }
            }
        }