public void Init(Gradient gradient, int numSteps)
 {
     this.m_Gradient = gradient;
     this.m_NumSteps = numSteps;
     this.BuildArrays();
     if (this.m_RGBSwatches.Count > 0)
     {
         this.m_SelectedSwatch = this.m_RGBSwatches[0];
     }
 }
 public void Init(Gradient gradient, int numSteps)
 {
   this.m_Gradient = gradient;
   this.m_TextureDirty = true;
   this.m_NumSteps = numSteps;
   this.BuildArrays();
   if (this.m_RGBSwatches.Count <= 0)
     return;
   this.m_SelectedSwatch = this.m_RGBSwatches[0];
 }
Exemple #3
0
 private int SwatchSort(GradientEditor.Swatch lhs, GradientEditor.Swatch rhs)
 {
     if (lhs.m_Time == rhs.m_Time && lhs == this.m_SelectedSwatch)
     {
         return(-1);
     }
     if (lhs.m_Time == rhs.m_Time && rhs == this.m_SelectedSwatch)
     {
         return(1);
     }
     return(lhs.m_Time.CompareTo(rhs.m_Time));
 }
 public void Init(Gradient gradient, int numSteps)
 {
     this.m_Gradient     = gradient;
     this.m_TextureDirty = true;
     this.m_NumSteps     = numSteps;
     this.BuildArrays();
     if (this.m_RGBSwatches.Count <= 0)
     {
         return;
     }
     this.m_SelectedSwatch = this.m_RGBSwatches[0];
 }
Exemple #5
0
        private void DrawSwatch(Rect totalPos, GradientEditor.Swatch s, bool upwards)
        {
            Color backgroundColor = GUI.backgroundColor;
            Rect  position        = this.CalcSwatchRect(totalPos, s);

            GUI.backgroundColor = s.m_Value;
            GUIStyle gUIStyle  = (!upwards) ? GradientEditor.s_Styles.downSwatch : GradientEditor.s_Styles.upSwatch;
            GUIStyle gUIStyle2 = (!upwards) ? GradientEditor.s_Styles.downSwatchOverlay : GradientEditor.s_Styles.upSwatchOverlay;

            gUIStyle.Draw(position, false, false, this.m_SelectedSwatch == s, false);
            GUI.backgroundColor = backgroundColor;
            gUIStyle2.Draw(position, false, false, this.m_SelectedSwatch == s, false);
        }
Exemple #6
0
        private int SwatchSort(GradientEditor.Swatch lhs, GradientEditor.Swatch rhs)
        {
            int result;

            if (lhs.m_Time == rhs.m_Time && lhs == this.m_SelectedSwatch)
            {
                result = -1;
            }
            else if (lhs.m_Time == rhs.m_Time && rhs == this.m_SelectedSwatch)
            {
                result = 1;
            }
            else
            {
                result = lhs.m_Time.CompareTo(rhs.m_Time);
            }
            return(result);
        }
 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;
   }
 }
Exemple #8
0
        private Rect CalcSwatchRect(Rect totalRect, GradientEditor.Swatch s)
        {
            float time = s.m_Time;

            return(new Rect(totalRect.x + Mathf.Round(totalRect.width * time) - 5f, totalRect.y, 10f, totalRect.height));
        }
Exemple #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, ColorPicker.defaultHDRConfig);
                            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;
        }
		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);
							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_9B:
				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" && 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_9B;
		}
        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;
            }
        }