private void OnEditButtonClicked(string libraryPath) { ColorPicker.Show(GUIView.current, Color.white, true, false); ColorPicker.instance.currentPresetLibrary = libraryPath; }
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) { //Storing the double click state to open the color picker on Mouse up event so that the user has completed his interaction with swatch movement/drag. m_DoubleClickDetected = true; } break; } bool found = false; foreach (Swatch s in swatches) { if (CalcSwatchRect(position, s).Contains(fixedStepMousePosition)) { found = true; m_SelectedSwatch = s; EditorGUI.EndEditingActiveTextField(); 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(); } else if (m_DoubleClickDetected) { m_DoubleClickDetected = false; GUIUtility.keyboardControl = id; ColorPicker.Show(GUIView.current, m_SelectedSwatch.m_Value, false, m_HDR); GUIUtility.ExitGUI(); } 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; } }
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(); }
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; }
public static void Show(GUIView viewToUpdate, Color col) { ColorPicker.Show(viewToUpdate, col, true); }
private void OnEditButtonClicked(string libraryPath) { ColorPicker.Show(GUIView.current, Color.white); ColorPicker.get.currentPresetLibrary = libraryPath; }
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; } }