public void RefreshOptions()
        {
            var           pickers = App.Instance.GetComponent <CustomColorPaletteStorage>();
            List <Option> options = new List <Option>();

            foreach (var modeAndInfo in pickers.ModeToPickerInfo)
            {
                if (ColorPickerUtils.ModeIsValid(modeAndInfo.mode))
                {
                    options.Add(new Option {
                        m_Description = modeAndInfo.mode.ToString(),
                        m_Texture     = modeAndInfo.info.icon
                    });
                }
            }

            m_Options = options.ToArray();
            if (m_Options.Length < 2)
            {
                gameObject.SetActive(false);
            }
            else
            {
                CreateOptionSides();
                ColorPickerMode initialMode = CustomColorPaletteStorage.m_Instance.Mode;
                if (ColorPickerUtils.ModeIsValid(initialMode))
                {
                    ForceSelectedOption((int)initialMode);
                }
                else
                {
                    ColorPickerUtils.GoToNextMode();
                }
            }
        }
示例#2
0
        override protected void OnButtonPressed()
        {
            if (m_Trash)
            {
                // If we're a trash button, clear our storage index and notify our lord.
                CustomColorPaletteStorage.m_Instance.ClearColor(m_StorageIndex);
            }
            else
            {
                if (m_CurrentState == State.Set)
                {
                    m_ColorController.CurrentColor = m_CustomColor;
                    m_Manager.GetComponent <CustomColorPalette>().TriggerColorPicked(m_CustomColor);
                }
                else if (m_CurrentState == State.ReadyForAdd)
                {
                    Color color = m_ColorController.IsHdr ?
                                  ColorPickerUtils.ClampColorIntensityToLdr(m_ColorController.CurrentColor) :
                                  m_ColorController.CurrentColor;
                    CustomColorPaletteStorage.m_Instance.SetColor(m_StorageIndex, color, true);
                }
            }

            CustomColorPalette palette = m_Manager.GetComponent <CustomColorPalette>();

            if (palette == null)
            {
                Debug.LogWarning("CustomColorButton needs a CustomColorPalette manager.");
            }
            palette.RefreshPaletteButtons();
        }
示例#3
0
 public void TestPicker_SL_H()
 {
     Color rgb = Color.green;
     float expected = ((HSLColor)rgb).Hue01;
     Vector3 raw = ColorPickerUtils.ColorToRawValue(ColorPickerMode.SL_H_Triangle, rgb);
     Assert.AreEqual(expected, raw.z, 1e-4f);
 }
示例#4
0
        void OnModeChanged()
        {
            ColorPickerMode mode = ColorPickerUtils.GetActiveMode(m_ColorController.IsHdr);
            ColorPickerInfo info = ColorPickerUtils.GetInfoForMode(mode);

            if (m_ColorPickerSelectorBorderCube != null && m_ColorPickerSelectorBorderCylinder != null)
            {
                m_ColorPickerSelectorBorderCube.enabled     = false;
                m_ColorPickerSelectorBorderCylinder.enabled = false;
                if (info.cylindrical)
                {
                    m_ColorPickerSelectorBorderCylinder.enabled = true;
                }
                else
                {
                    m_ColorPickerSelectorBorderCube.enabled = true;
                }
            }

            if (m_CircleBack != null)
            {
                m_CircleBack.SetActive(info.cylindrical);
            }

            m_ColorPickerSelector.SetLocalMode(mode);
            m_ColorPickerSlider.SetLocalMode(mode);

            m_ColorController.CurrentColor = m_ColorController.CurrentColor;
        }
示例#5
0
        override public void SetColor(Color rColor)
        {
            var color = Color.white;

            switch (m_ButtonType)
            {
            case LightMode.Ambient:
                color = RenderSettings.ambientLight;
                break;

            case LightMode.Shadow:
                color = App.Scene.GetLight((int)LightMode.Shadow).color;
                break;

            case LightMode.NoShadow:
                color = App.Scene.GetLight((int)LightMode.NoShadow).color;
                break;
            }

            Color mainColor = new Color(color.r * rColor.r, color.g * rColor.g,
                                        color.b * rColor.b, color.a * rColor.a);

            if (m_ButtonType == LightMode.Shadow || m_ButtonType == LightMode.NoShadow)
            {
                // If button is HDR, convert to LDR and set the LDR color as secondary color
                Color ldrColor       = ColorPickerUtils.ClampColorIntensityToLdr(color);
                Color secondaryColor = new Color(ldrColor.r * rColor.r, ldrColor.g * rColor.g,
                                                 ldrColor.b * rColor.b, ldrColor.a * rColor.a);
                SetHDRButtonColor(mainColor, secondaryColor);
            }
            else
            {
                base.SetColor(mainColor);
            }
        }
示例#6
0
        public void ButtonPressed(LightMode mode)
        {
            m_LightGizmo_Shadow.Visible   = false;
            m_LightGizmo_NoShadow.Visible = false;
            m_PreviewSphereParent.gameObject.SetActive(false);

            // Create the popup with callback.
            SketchControlsScript.GlobalCommands command =
                (mode == LightMode.Shadow || mode == LightMode.NoShadow) ?
                SketchControlsScript.GlobalCommands.LightingHdr :
                SketchControlsScript.GlobalCommands.LightingLdr;
            CreatePopUp(command, -1, -1, LightModeToString(mode), MakeOnPopUpClose(mode));

            // Init popup according to current light mode.
            var popup = (m_ActivePopUp as ColorPickerPopUpWindow);

            popup.transform.localPosition += new Vector3(0, m_ColorPickerPopUpHeightOffset, 0);
            ColorPickerUtils.SetLogVRangeForMode(mode);
            popup.ColorPicker.ColorPicked += OnColorPicked(mode);
            popup.ColorPicker.ColorPicked += delegate(Color c) {
                m_LightButtons[(int)mode + 1].SetDescriptionText(LightModeToString(mode),
                                                                 ColorTable.m_Instance.NearestColorTo(c));
                SetLightColor(mode, c);
            };

            // Init must be called after all popup.ColorPicked actions have been assigned.
            popup.ColorPicker.Controller.CurrentColor = GetLightColor(mode);
            popup.ColorPicker.ColorFinalized         += MakeLightColorFinalized(mode);
            popup.CustomColorPalette.ColorPicked     += MakeLightColorPickedAsFinal(mode);

            m_EatInput = true;
        }
示例#7
0
 public virtual void SetColor(Color color)
 {
     m_Light.color = color;
     m_ColorIndicator.material.SetColor("_ClampedColor",
                                        ColorPickerUtils.ClampColorIntensityToLdr(m_Light.color));
     m_ColorIndicator.material.SetColor("_TrueColor", color);
 }
示例#8
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);
 }
示例#9
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);
 }
示例#10
0
 private void ApplyColorAndBrushToObject(Color color, Guid brushGuid)
 {
     m_TargetStroke.m_Color = ColorPickerUtils.ClampLuminance(
         color, BrushCatalog.m_Instance.GetBrush(brushGuid).m_ColorLuminanceMin);
     m_TargetStroke.m_BrushGuid = brushGuid;
     m_TargetStroke.InvalidateCopy();
     m_TargetStroke.Uncreate();
     m_TargetStroke.Recreate();
 }
示例#11
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);
 }
示例#12
0
        void OnModeChanged()
        {
            ColorPickerInfo info =
                ColorPickerUtils.GetInfoForMode(CustomColorPaletteStorage.m_Instance.Mode);

            if (!m_AtlasTexture)
            {
                m_ButtonRenderer.material.mainTexture = info.icon;
            }
            SetSelectedOption((int)CustomColorPaletteStorage.m_Instance.Mode);
        }
示例#13
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);
 }
示例#14
0
 public Color GenerateJitteredColor(float colorLuminanceMin)
 {
     Color.RGBToHSV(m_lastChosenColor, out var h, out var s, out var v);
     return(ColorPickerUtils.ClampLuminance(
                Random.ColorHSV(
                    h - colorJitter.x, h + colorJitter.x,
                    s - colorJitter.y, s + colorJitter.y,
                    v - colorJitter.z, v + colorJitter.z
                    ),
                colorLuminanceMin
                ));
 }
示例#15
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);
     }
 }
        void OnModeChanged()
        {
            ColorPickerInfo info = ColorPickerUtils.GetInfoForMode(m_LocalMode);

            m_Renderer.material.shader = info.shader;

            if (m_LocalMode == ColorPickerMode.SL_H_Triangle)
            {
                GetComponent <MeshFilter>().sharedMesh = m_TriangleMesh;
            }
            else
            {
                GetComponent <MeshFilter>().sharedMesh = m_StandardMesh;
            }
            RawValue = RawValue; // force update of material param
        }
示例#17
0
        void RefreshLightButtons()
        {
            Color panelColor = GetGazeColor();

            m_LightButtons[0].SetColor(panelColor);
            m_LightButtons[1].SetColor(panelColor);
            m_LightButtons[2].SetColor(panelColor);

            for (int i = -1; i < (int)LightMode.NumLights; i++)
            {
                m_LightButtons[i + 1].SetDescriptionText(LightModeToString((LightMode)i),
                                                         ColorTable.m_Instance.NearestColorTo(GetLightColor((LightMode)i)));
            }

            m_LightButtonHDRMaterial.SetColor(
                "_ClampedColor", ColorPickerUtils.ClampColorIntensityToLdr(m_LightGizmo_Shadow.GetColor()));
        }
示例#18
0
        void OnModeChanged()
        {
            switch (m_LocalMode)
            {
            case ColorPickerMode.SL_H_Triangle:
            case ColorPickerMode.SV_H_Rect:
                ColorPickerUtils.MakeRamp(m_LocalMode, m_Width, m_Height, m_tempColors);
                m_sliderTex.SetPixels(m_tempColors);
                m_sliderTex.Apply();
                break;

            case ColorPickerMode.HL_S_Polar:
            case ColorPickerMode.HS_L_Polar:
            case ColorPickerMode.HS_LogV_Polar:
                // Texture updates when color updates
                break;

            default:
                Debug.Assert(false);
                break;
            }
        }
示例#19
0
        public void Refresh()
        {
            var shadowColor   = m_LightGizmo_Shadow.SetLight(0);
            var noShadowColor = m_LightGizmo_NoShadow.SetLight(1);

            m_ShadowLightColorIndicator.material.SetColor("_TrueColor", shadowColor);
            m_ShadowLightColorIndicator.material.SetColor("_ClampedColor",
                                                          ColorPickerUtils.ClampColorIntensityToLdr(shadowColor));
            m_NoShadowLightColorIndicator.material.SetColor("_TrueColor", noShadowColor);
            m_NoShadowLightColorIndicator.material.SetColor("_ClampedColor",
                                                            ColorPickerUtils.ClampColorIntensityToLdr(noShadowColor));

            // TODO : Patch this up.
            //if (m_PanelPopUpScript) {
            //  ColorPickerPopUpWindow picker = m_PanelPopUpScript as ColorPickerPopUpWindow;
            //  if (picker) {
            //    picker.RefreshCurrentColor();
            //  }
            //}

            RefreshLightButtons();
            OnPanelMoved();
        }
示例#20
0
 override protected void OnButtonPressed()
 {
     ColorPickerUtils.GoToNextMode();
 }
示例#21
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;
                        }
                    }
                }
            }
        }
示例#22
0
 // Notification from sibling objects in the color picker UI that
 // the color has changed.
 // TODO: make this a no-op when color changes on the slider's axis?
 // Caller is responsible for guaranteeing that "mode+raw" maps to a valid color.
 public void OnColorChanged(ColorPickerMode mode, Vector3 raw)
 {
     ColorPickerUtils.MakeRamp(mode, m_Width, m_Height, m_tempColors, raw);
     m_sliderTex.SetPixels(m_tempColors);
     m_sliderTex.Apply();
 }