Наследование: EditorWindow
Пример #1
0
 private static void DrawLabelOutsideRect(Rect position, string label, ColorPicker.LabelLocation labelLocation)
 {
   Matrix4x4 matrix = GUI.matrix;
   Rect position1 = new Rect(position.x, position.y - 18f, position.width, 16f);
   switch (labelLocation)
   {
     case ColorPicker.LabelLocation.Bottom:
       position1 = new Rect(position.x, position.yMax, position.width, 16f);
       break;
     case ColorPicker.LabelLocation.Left:
       GUIUtility.RotateAroundPivot(-90f, position.center);
       break;
     case ColorPicker.LabelLocation.Right:
       GUIUtility.RotateAroundPivot(90f, position.center);
       break;
   }
   EditorGUI.BeginDisabledGroup(true);
   GUI.Label(position1, label, ColorPicker.styles.label);
   EditorGUI.EndDisabledGroup();
   GUI.matrix = matrix;
 }
Пример #2
0
 private static Texture2D Update1DSlider(Texture2D tex, int xSize, float const1, float const2, ref float oldConst1, ref float oldConst2, int idx, bool hsvSpace, float scale, float exposureValue, bool forceUpdate, ColorPicker.TonemappingType tonemappingType)
 {
   if (!(bool) ((UnityEngine.Object) tex) || (double) const1 != (double) oldConst1 || ((double) const2 != (double) oldConst2 || forceUpdate))
   {
     if (!(bool) ((UnityEngine.Object) tex))
       tex = ColorPicker.MakeTexture(xSize, 2);
     Color[] colorArray = new Color[xSize * 2];
     Color topLeftColor = Color.black;
     Color rightGradient = Color.black;
     switch (idx)
     {
       case 0:
         topLeftColor = new Color(0.0f, const1, const2, 1f);
         rightGradient = new Color(1f, 0.0f, 0.0f, 0.0f);
         break;
       case 1:
         topLeftColor = new Color(const1, 0.0f, const2, 1f);
         rightGradient = new Color(0.0f, 1f, 0.0f, 0.0f);
         break;
       case 2:
         topLeftColor = new Color(const1, const2, 0.0f, 1f);
         rightGradient = new Color(0.0f, 0.0f, 1f, 0.0f);
         break;
       case 3:
         topLeftColor = new Color(0.0f, 0.0f, 0.0f, 1f);
         rightGradient = new Color(1f, 1f, 1f, 0.0f);
         break;
     }
     ColorPicker.FillArea(xSize, 2, colorArray, topLeftColor, rightGradient, new Color(0.0f, 0.0f, 0.0f, 0.0f));
     if (hsvSpace)
       ColorPicker.HSVToRGBArray(colorArray, scale);
     else
       ColorPicker.ScaleColors(colorArray, scale);
     ColorPicker.DoTonemapping(colorArray, exposureValue, tonemappingType);
     oldConst1 = const1;
     oldConst2 = const2;
     tex.SetPixels(colorArray);
     tex.Apply();
   }
   return tex;
 }
Пример #3
0
 private string GetZAxisLabel(ColorPicker.ColorBoxMode colorBoxMode)
 {
   return this.m_ColorBoxZAxisLabels[(int) colorBoxMode];
 }
Пример #4
0
 private static void DoTonemapping(Color[] colors, float exposureAdjustment, ColorPicker.TonemappingType tonemappingType)
 {
   if ((double) exposureAdjustment < 0.0)
     return;
   if (tonemappingType == ColorPicker.TonemappingType.Linear)
   {
     for (int index = 0; index < colors.Length; ++index)
       colors[index] = colors[index].RGBMultiplied(exposureAdjustment);
   }
   else
   {
     for (int index = 0; index < colors.Length; ++index)
       colors[index] = ColorPicker.DoTonemapping(colors[index], exposureAdjustment);
   }
 }
Пример #5
0
 public void OnDestroy()
 {
   Undo.CollapseUndoOperations(this.m_ModalUndoGroup);
   if ((bool) ((UnityEngine.Object) this.m_ColorSlider))
     UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_ColorSlider);
   if ((bool) ((UnityEngine.Object) this.m_ColorBox))
     UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_ColorBox);
   if ((bool) ((UnityEngine.Object) this.m_RTexture))
     UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_RTexture);
   if ((bool) ((UnityEngine.Object) this.m_GTexture))
     UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_GTexture);
   if ((bool) ((UnityEngine.Object) this.m_BTexture))
     UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_BTexture);
   if ((bool) ((UnityEngine.Object) this.m_HueTexture))
     UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_HueTexture);
   if ((bool) ((UnityEngine.Object) this.m_SatTexture))
     UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_SatTexture);
   if ((bool) ((UnityEngine.Object) this.m_ValTexture))
     UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_ValTexture);
   if ((bool) ((UnityEngine.Object) this.m_AlphaTexture))
     UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_AlphaTexture);
   ColorPicker.s_SharedColorPicker = (ColorPicker) null;
   if (this.m_IsOSColorPicker)
     OSColorPicker.Close();
   EditorApplication.update -= new EditorApplication.CallbackFunction(this.PollOSColorPicker);
   if (this.m_ColorLibraryEditorState != null)
     this.m_ColorLibraryEditorState.TransferEditorPrefsState(false);
   if (this.m_ColorLibraryEditor != null)
     this.m_ColorLibraryEditor.UnloadUsedLibraries();
   if (this.m_ColorBoxMode != ColorPicker.ColorBoxMode.EyeDropper)
     return;
   EditorPrefs.SetInt("CPColorMode", (int) this.m_OldColorBoxMode);
 }
Пример #6
0
 public void OnDestroy()
 {
     Undo.CollapseUndoOperations(this.m_ModalUndoGroup);
     if (this.m_ColorSlider != null)
     {
         UnityEngine.Object.DestroyImmediate(this.m_ColorSlider);
     }
     if (this.m_ColorBox != null)
     {
         UnityEngine.Object.DestroyImmediate(this.m_ColorBox);
     }
     if (this.m_RTexture != null)
     {
         UnityEngine.Object.DestroyImmediate(this.m_RTexture);
     }
     if (this.m_GTexture != null)
     {
         UnityEngine.Object.DestroyImmediate(this.m_GTexture);
     }
     if (this.m_BTexture != null)
     {
         UnityEngine.Object.DestroyImmediate(this.m_BTexture);
     }
     if (this.m_HueTexture != null)
     {
         UnityEngine.Object.DestroyImmediate(this.m_HueTexture);
     }
     if (this.m_SatTexture != null)
     {
         UnityEngine.Object.DestroyImmediate(this.m_SatTexture);
     }
     if (this.m_ValTexture != null)
     {
         UnityEngine.Object.DestroyImmediate(this.m_ValTexture);
     }
     if (this.m_AlphaTexture != null)
     {
         UnityEngine.Object.DestroyImmediate(this.m_AlphaTexture);
     }
     s_SharedColorPicker = null;
     if (this.m_IsOSColorPicker)
     {
         OSColorPicker.Close();
     }
     EditorApplication.update = (EditorApplication.CallbackFunction) Delegate.Remove(EditorApplication.update, new EditorApplication.CallbackFunction(this.PollOSColorPicker));
     if (this.m_ColorLibraryEditorState != null)
     {
         this.m_ColorLibraryEditorState.TransferEditorPrefsState(false);
     }
     if (this.m_ColorLibraryEditor != null)
     {
         this.m_ColorLibraryEditor.UnloadUsedLibraries();
     }
 }
Пример #7
0
 private void OnEnable()
 {
     picker = target as ColorPicker;
 }
Пример #8
0
        private void ShowSwatchArray(Rect position, List <Swatch> swatches, bool isAlpha)
        {
            bool      flag2;
            int       controlID      = GUIUtility.GetControlID(0x26e20929, FocusType.Passive);
            Event     current        = Event.current;
            float     time           = this.GetTime((Event.current.mousePosition.x - position.x) / position.width);
            Vector2   point          = new Vector3(position.x + (time * position.width), Event.current.mousePosition.y);
            EventType typeForControl = current.GetTypeForControl(controlID);

            switch (typeForControl)
            {
            case EventType.MouseDown:
            {
                Rect rect = position;
                rect.xMin -= 10f;
                rect.xMax += 10f;
                if (rect.Contains(current.mousePosition))
                {
                    GUIUtility.hotControl = controlID;
                    current.Use();
                    if ((!swatches.Contains(this.m_SelectedSwatch) || this.m_SelectedSwatch.m_IsAlpha) || !this.CalcSwatchRect(position, this.m_SelectedSwatch).Contains(current.mousePosition))
                    {
                        flag2 = false;
                        foreach (Swatch swatch2 in swatches)
                        {
                            if (this.CalcSwatchRect(position, swatch2).Contains(point))
                            {
                                flag2 = true;
                                this.m_SelectedSwatch = swatch2;
                                break;
                            }
                        }
                        break;
                    }
                    if (current.clickCount == 2)
                    {
                        GUIUtility.keyboardControl = controlID;
                        ColorPicker.Show(GUIView.current, this.m_SelectedSwatch.m_Value, false, false, null);
                        GUIUtility.ExitGUI();
                    }
                }
                return;
            }

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    if (!swatches.Contains(this.m_SelectedSwatch))
                    {
                        this.m_SelectedSwatch = null;
                    }
                    this.RemoveDuplicateOverlappingSwatches();
                }
                return;

            case EventType.MouseDrag:
                if ((GUIUtility.hotControl == controlID) && (this.m_SelectedSwatch != null))
                {
                    current.Use();
                    if (((current.mousePosition.y + 5f) >= position.y) && ((current.mousePosition.y - 5f) <= position.yMax))
                    {
                        if (!swatches.Contains(this.m_SelectedSwatch))
                        {
                            swatches.Add(this.m_SelectedSwatch);
                        }
                        goto Label_03B1;
                    }
                    if (swatches.Count <= 1)
                    {
                        goto Label_03B1;
                    }
                    swatches.Remove(this.m_SelectedSwatch);
                    this.AssignBack();
                }
                return;

            case EventType.KeyDown:
                if (current.keyCode == KeyCode.Delete)
                {
                    if (this.m_SelectedSwatch != null)
                    {
                        List <Swatch> rGBSwatches;
                        if (!this.m_SelectedSwatch.m_IsAlpha)
                        {
                            rGBSwatches = this.m_RGBSwatches;
                        }
                        else
                        {
                            rGBSwatches = this.m_AlphaSwatches;
                        }
                        if (rGBSwatches.Count > 1)
                        {
                            rGBSwatches.Remove(this.m_SelectedSwatch);
                            this.AssignBack();
                            HandleUtility.Repaint();
                        }
                    }
                    current.Use();
                }
                return;

            case EventType.Repaint:
            {
                bool flag = false;
                foreach (Swatch swatch in swatches)
                {
                    if (this.m_SelectedSwatch == swatch)
                    {
                        flag = true;
                    }
                    else
                    {
                        this.DrawSwatch(position, swatch, !isAlpha);
                    }
                }
                if (flag && (this.m_SelectedSwatch != null))
                {
                    this.DrawSwatch(position, this.m_SelectedSwatch, !isAlpha);
                }
                return;
            }

            default:
                switch (typeForControl)
                {
                case EventType.ValidateCommand:
                    if (current.commandName == "Delete")
                    {
                        Event.current.Use();
                    }
                    return;

                case EventType.ExecuteCommand:
                    if (current.commandName == "ColorPickerChanged")
                    {
                        GUI.changed = true;
                        this.m_SelectedSwatch.m_Value = ColorPicker.color;
                        this.AssignBack();
                        HandleUtility.Repaint();
                    }
                    else if ((current.commandName == "Delete") && (swatches.Count > 1))
                    {
                        swatches.Remove(this.m_SelectedSwatch);
                        this.AssignBack();
                        HandleUtility.Repaint();
                    }
                    return;

                default:
                    return;
                }
                break;
            }
            if (!flag2)
            {
                if (swatches.Count < 8)
                {
                    Color color = this.m_Gradient.Evaluate(time);
                    if (isAlpha)
                    {
                        color = new Color(color.a, color.a, color.a, 1f);
                    }
                    else
                    {
                        color.a = 1f;
                    }
                    this.m_SelectedSwatch = new Swatch(time, color, isAlpha);
                    swatches.Add(this.m_SelectedSwatch);
                    this.AssignBack();
                }
                else
                {
                    Debug.LogWarning(string.Concat(new object[] { "Max ", 8, " color keys and ", 8, " alpha keys are allowed in a gradient." }));
                }
            }
            return;

Label_03B1:
            this.m_SelectedSwatch.m_Time = time;
            this.AssignBack();
        }
Пример #9
0
        private void ShowSwatchArray(Rect position, List <GradientEditor.Swatch> swatches, bool isAlpha)
        {
            int       controlID      = GUIUtility.GetControlID(652347689, FocusType.Passive);
            Event     current        = Event.current;
            float     time           = this.GetTime((Event.current.mousePosition.x - position.x) / position.width);
            Vector2   point          = new Vector3(position.x + time * position.width, Event.current.mousePosition.y);
            EventType typeForControl = current.GetTypeForControl(controlID);

            switch (typeForControl)
            {
            case EventType.MouseDown:
            {
                Rect rect = position;
                rect.xMin -= 10f;
                rect.xMax += 10f;
                if (rect.Contains(current.mousePosition))
                {
                    GUIUtility.hotControl = controlID;
                    current.Use();
                    if (swatches.Contains(this.m_SelectedSwatch) && !this.m_SelectedSwatch.m_IsAlpha && this.CalcSwatchRect(position, this.m_SelectedSwatch).Contains(current.mousePosition))
                    {
                        if (current.clickCount == 2)
                        {
                            GUIUtility.keyboardControl = controlID;
                            ColorPicker.Show(GUIView.current, this.m_SelectedSwatch.m_Value, false, this.m_HDR);
                            GUIUtility.ExitGUI();
                        }
                    }
                    else
                    {
                        bool flag = false;
                        foreach (GradientEditor.Swatch current2 in swatches)
                        {
                            if (this.CalcSwatchRect(position, current2).Contains(point))
                            {
                                flag = true;
                                this.m_SelectedSwatch = current2;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            if (swatches.Count < 8)
                            {
                                Color value = this.m_Gradient.Evaluate(time);
                                if (isAlpha)
                                {
                                    value = new Color(value.a, value.a, value.a, 1f);
                                }
                                else
                                {
                                    value.a = 1f;
                                }
                                this.m_SelectedSwatch = new GradientEditor.Swatch(time, value, isAlpha);
                                swatches.Add(this.m_SelectedSwatch);
                                this.AssignBack();
                            }
                            else
                            {
                                Debug.LogWarning(string.Concat(new object[]
                                    {
                                        "Max ",
                                        8,
                                        " color keys and ",
                                        8,
                                        " alpha keys are allowed in a gradient."
                                    }));
                            }
                        }
                    }
                }
                return;
            }

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    if (!swatches.Contains(this.m_SelectedSwatch))
                    {
                        this.m_SelectedSwatch = null;
                    }
                    this.RemoveDuplicateOverlappingSwatches();
                }
                return;

            case EventType.MouseMove:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
IL_9C:
                if (typeForControl == EventType.ValidateCommand)
                {
                    if (current.commandName == "Delete")
                    {
                        Event.current.Use();
                    }
                    return;
                }
                if (typeForControl != EventType.ExecuteCommand)
                {
                    return;
                }
                if (current.commandName == "ColorPickerChanged")
                {
                    GUI.changed = true;
                    this.m_SelectedSwatch.m_Value = ColorPicker.color;
                    this.AssignBack();
                    HandleUtility.Repaint();
                }
                else if (current.commandName == "Delete")
                {
                    if (swatches.Count > 1)
                    {
                        swatches.Remove(this.m_SelectedSwatch);
                        this.AssignBack();
                        HandleUtility.Repaint();
                    }
                }
                return;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID && this.m_SelectedSwatch != null)
                {
                    current.Use();
                    if (current.mousePosition.y + 5f < position.y || current.mousePosition.y - 5f > position.yMax)
                    {
                        if (swatches.Count > 1)
                        {
                            swatches.Remove(this.m_SelectedSwatch);
                            this.AssignBack();
                            return;
                        }
                    }
                    else if (!swatches.Contains(this.m_SelectedSwatch))
                    {
                        swatches.Add(this.m_SelectedSwatch);
                    }
                    this.m_SelectedSwatch.m_Time = time;
                    this.AssignBack();
                }
                return;

            case EventType.KeyDown:
                if (current.keyCode == KeyCode.Delete)
                {
                    if (this.m_SelectedSwatch != null)
                    {
                        List <GradientEditor.Swatch> list;
                        if (this.m_SelectedSwatch.m_IsAlpha)
                        {
                            list = this.m_AlphaSwatches;
                        }
                        else
                        {
                            list = this.m_RGBSwatches;
                        }
                        if (list.Count > 1)
                        {
                            list.Remove(this.m_SelectedSwatch);
                            this.AssignBack();
                            HandleUtility.Repaint();
                        }
                    }
                    current.Use();
                }
                return;

            case EventType.Repaint:
            {
                bool flag2 = false;
                foreach (GradientEditor.Swatch current3 in swatches)
                {
                    if (this.m_SelectedSwatch == current3)
                    {
                        flag2 = true;
                    }
                    else
                    {
                        this.DrawSwatch(position, current3, !isAlpha);
                    }
                }
                if (flag2 && this.m_SelectedSwatch != null)
                {
                    this.DrawSwatch(position, this.m_SelectedSwatch, !isAlpha);
                }
                return;
            }
            }
            goto IL_9C;
        }
Пример #10
0
 private void OnEditButtonClicked(string libraryPath)
 {
     ColorPicker.Show(GUIView.current, Color.white);
     ColorPicker.instance.currentPresetLibrary = libraryPath;
 }
Пример #11
0
        private void ShowSwatchArray(Rect position, List <GradientEditor.Swatch> swatches, bool isAlpha)
        {
            int       controlId      = GUIUtility.GetControlID(652347689, FocusType.Passive);
            Event     current1       = Event.current;
            float     time           = this.GetTime((Event.current.mousePosition.x - position.x) / position.width);
            Vector2   point          = (Vector2) new Vector3(position.x + time * position.width, Event.current.mousePosition.y);
            EventType typeForControl = current1.GetTypeForControl(controlId);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                Rect rect = position;
                rect.xMin -= 10f;
                rect.xMax += 10f;
                if (!rect.Contains(current1.mousePosition))
                {
                    break;
                }
                GUIUtility.hotControl = controlId;
                current1.Use();
                if (swatches.Contains(this.m_SelectedSwatch) && !this.m_SelectedSwatch.m_IsAlpha && this.CalcSwatchRect(position, this.m_SelectedSwatch).Contains(current1.mousePosition))
                {
                    if (current1.clickCount != 2)
                    {
                        break;
                    }
                    GUIUtility.keyboardControl = controlId;
                    ColorPicker.Show(GUIView.current, this.m_SelectedSwatch.m_Value, false, false, (ColorPickerHDRConfig)null);
                    GUIUtility.ExitGUI();
                    break;
                }
                bool flag1 = false;
                using (List <GradientEditor.Swatch> .Enumerator enumerator = swatches.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        GradientEditor.Swatch current2 = enumerator.Current;
                        if (this.CalcSwatchRect(position, current2).Contains(point))
                        {
                            flag1 = true;
                            this.m_SelectedSwatch = current2;
                            break;
                        }
                    }
                }
                if (flag1)
                {
                    break;
                }
                if (swatches.Count < 8)
                {
                    Color color = this.m_Gradient.Evaluate(time);
                    if (isAlpha)
                    {
                        color = new Color(color.a, color.a, color.a, 1f);
                    }
                    else
                    {
                        color.a = 1f;
                    }
                    this.m_SelectedSwatch = new GradientEditor.Swatch(time, color, isAlpha);
                    swatches.Add(this.m_SelectedSwatch);
                    this.AssignBack();
                    break;
                }
                Debug.LogWarning((object)("Max " + (object)8 + " color keys and " + (object)8 + " alpha keys are allowed in a gradient."));
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl != controlId)
                {
                    break;
                }
                GUIUtility.hotControl = 0;
                current1.Use();
                if (!swatches.Contains(this.m_SelectedSwatch))
                {
                    this.m_SelectedSwatch = (GradientEditor.Swatch)null;
                }
                this.RemoveDuplicateOverlappingSwatches();
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl != controlId || this.m_SelectedSwatch == null)
                {
                    break;
                }
                current1.Use();
                if ((double)current1.mousePosition.y + 5.0 < (double)position.y || (double)current1.mousePosition.y - 5.0 > (double)position.yMax)
                {
                    if (swatches.Count > 1)
                    {
                        swatches.Remove(this.m_SelectedSwatch);
                        this.AssignBack();
                        break;
                    }
                }
                else if (!swatches.Contains(this.m_SelectedSwatch))
                {
                    swatches.Add(this.m_SelectedSwatch);
                }
                this.m_SelectedSwatch.m_Time = time;
                this.AssignBack();
                break;

            case EventType.KeyDown:
                if (current1.keyCode != KeyCode.Delete)
                {
                    break;
                }
                if (this.m_SelectedSwatch != null)
                {
                    List <GradientEditor.Swatch> swatchList = !this.m_SelectedSwatch.m_IsAlpha ? this.m_RGBSwatches : this.m_AlphaSwatches;
                    if (swatchList.Count > 1)
                    {
                        swatchList.Remove(this.m_SelectedSwatch);
                        this.AssignBack();
                        HandleUtility.Repaint();
                    }
                }
                current1.Use();
                break;

            case EventType.Repaint:
                bool flag2 = false;
                using (List <GradientEditor.Swatch> .Enumerator enumerator = swatches.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        GradientEditor.Swatch current2 = enumerator.Current;
                        if (this.m_SelectedSwatch == current2)
                        {
                            flag2 = true;
                        }
                        else
                        {
                            this.DrawSwatch(position, current2, !isAlpha);
                        }
                    }
                }
                if (!flag2 || this.m_SelectedSwatch == null)
                {
                    break;
                }
                this.DrawSwatch(position, this.m_SelectedSwatch, !isAlpha);
                break;

            default:
                if (typeForControl != EventType.ValidateCommand)
                {
                    if (typeForControl != EventType.ExecuteCommand)
                    {
                        break;
                    }
                    if (current1.commandName == "ColorPickerChanged")
                    {
                        GUI.changed = true;
                        this.m_SelectedSwatch.m_Value = ColorPicker.color;
                        this.AssignBack();
                        HandleUtility.Repaint();
                        break;
                    }
                    if (!(current1.commandName == "Delete") || swatches.Count <= 1)
                    {
                        break;
                    }
                    swatches.Remove(this.m_SelectedSwatch);
                    this.AssignBack();
                    HandleUtility.Repaint();
                    break;
                }
                if (!(current1.commandName == "Delete"))
                {
                    break;
                }
                Event.current.Use();
                break;
            }
        }
        void ShowSwatchArray(Rect position, List <Swatch> swatches, bool isAlpha)
        {
            int   id  = GUIUtility.GetControlID(652347689, FocusType.Passive);
            Event evt = Event.current;

            float   mouseSwatchTime        = GetTime((Event.current.mousePosition.x - position.x) / position.width);
            Vector2 fixedStepMousePosition = new Vector3(position.x + mouseSwatchTime * position.width, Event.current.mousePosition.y);

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Repaint:
            {
                bool hasSelection = false;
                foreach (Swatch s in swatches)
                {
                    if (m_SelectedSwatch == s)
                    {
                        hasSelection = true;
                        continue;
                    }
                    DrawSwatch(position, s, !isAlpha);
                }
                // selected swatch drawn last
                if (hasSelection && m_SelectedSwatch != null)
                {
                    DrawSwatch(position, m_SelectedSwatch, !isAlpha);
                }
                break;
            }

            case EventType.MouseDown:
            {
                Rect clickRect = position;

                // Swatches have some thickness thus we enlarge the clickable area
                clickRect.xMin -= 10;
                clickRect.xMax += 10;
                if (clickRect.Contains(evt.mousePosition))
                {
                    GUIUtility.hotControl = id;
                    evt.Use();

                    // Make sure selected is topmost for the click
                    if (swatches.Contains(m_SelectedSwatch) && !m_SelectedSwatch.m_IsAlpha && CalcSwatchRect(position, m_SelectedSwatch).Contains(evt.mousePosition))
                    {
                        if (evt.clickCount == 2)
                        {
                            GUIUtility.keyboardControl = id;
                            ColorPicker.Show(GUIView.current, m_SelectedSwatch.m_Value, false, m_HDR);
                            GUIUtility.ExitGUI();
                        }
                        break;
                    }

                    bool found = false;
                    foreach (Swatch s in swatches)
                    {
                        if (CalcSwatchRect(position, s).Contains(fixedStepMousePosition))
                        {
                            found            = true;
                            m_SelectedSwatch = s;
                            break;
                        }
                    }

                    if (!found)
                    {
                        if (swatches.Count < k_MaxNumKeys)
                        {
                            Color currentColor = m_Gradient.Evaluate(mouseSwatchTime);
                            if (isAlpha)
                            {
                                currentColor = new Color(currentColor.a, currentColor.a, currentColor.a, 1f);
                            }
                            else
                            {
                                currentColor.a = 1f;
                            }
                            m_SelectedSwatch = new Swatch(mouseSwatchTime, currentColor, isAlpha);
                            swatches.Add(m_SelectedSwatch);
                            AssignBack();
                        }
                        else
                        {
                            Debug.LogWarning("Max " + k_MaxNumKeys + " color keys and " + k_MaxNumKeys + " alpha keys are allowed in a gradient.");
                        }
                    }
                }
                break;
            }

            case EventType.MouseDrag:

                if (GUIUtility.hotControl == id && m_SelectedSwatch != null)
                {
                    evt.Use();

                    // If user drags swatch outside in vertical direction, we'll remove the swatch
                    if ((evt.mousePosition.y + 5 < position.y || evt.mousePosition.y - 5 > position.yMax))
                    {
                        if (swatches.Count > 1)
                        {
                            swatches.Remove(m_SelectedSwatch);
                            AssignBack();
                            break;
                        }
                    }
                    else if (!swatches.Contains(m_SelectedSwatch))
                    {
                        swatches.Add(m_SelectedSwatch);
                    }

                    m_SelectedSwatch.m_Time = mouseSwatchTime;
                    AssignBack();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();

                    // If the dragged swatch is NOT in the timeline, it means it was dragged outside.
                    // We just forget about it and let GC get it later.
                    if (!swatches.Contains(m_SelectedSwatch))
                    {
                        m_SelectedSwatch = null;
                    }

                    // Remove duplicate keys on mouse up so that we do not kill any keys during the drag
                    RemoveDuplicateOverlappingSwatches();
                }
                break;

            case EventType.KeyDown:
                if (evt.keyCode == KeyCode.Delete)
                {
                    if (m_SelectedSwatch != null)
                    {
                        List <Swatch> listToDeleteFrom;
                        if (m_SelectedSwatch.m_IsAlpha)
                        {
                            listToDeleteFrom = m_AlphaSwatches;
                        }
                        else
                        {
                            listToDeleteFrom = m_RGBSwatches;
                        }

                        if (listToDeleteFrom.Count > 1)
                        {
                            listToDeleteFrom.Remove(m_SelectedSwatch);
                            AssignBack();
                            HandleUtility.Repaint();
                        }
                    }
                    evt.Use();
                }
                break;

            case EventType.ValidateCommand:
                if (evt.commandName == EventCommandNames.Delete)
                {
                    Event.current.Use();
                }
                break;

            case EventType.ExecuteCommand:
                if (evt.commandName == EventCommandNames.ColorPickerChanged)
                {
                    GUI.changed = true;
                    m_SelectedSwatch.m_Value = ColorPicker.color;
                    AssignBack();
                    HandleUtility.Repaint();
                }
                else if (evt.commandName == EventCommandNames.Delete)
                {
                    if (swatches.Count > 1)
                    {
                        swatches.Remove(m_SelectedSwatch);
                        AssignBack();
                        HandleUtility.Repaint();
                    }
                }
                break;
            }
        }