private void DoColorSwatchAndEyedropper() { GUILayout.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button(ColorPicker.styles.eyeDropper, GUIStyle.none, new GUILayoutOption[] { GUILayout.Width(40f), GUILayout.ExpandWidth(false) })) { EyeDropper.Start(this.m_Parent); this.m_ColorBoxMode = ColorPicker.ColorBoxMode.EyeDropper; GUIUtility.ExitGUI(); } Color color = new Color(this.m_R, this.m_G, this.m_B, this.m_A); Rect rect = GUILayoutUtility.GetRect(20f, 20f, 20f, 20f, ColorPicker.styles.colorPickerBox, new GUILayoutOption[] { GUILayout.ExpandWidth(true) }); EditorGUIUtility.DrawColorSwatch(rect, color, this.m_ShowAlpha); if (Event.current.type == EventType.Repaint) { ColorPicker.styles.pickerBox.Draw(rect, GUIContent.none, false, false, false, false); } GUILayout.EndHorizontal(); }
public ColorPicker() { base.hideFlags = HideFlags.DontSave; this.m_ShowSliders = (EditorPrefs.GetInt("CPSliderShow", 1) != 0); this.m_SliderMode = (ColorPicker.SliderMode)EditorPrefs.GetInt("CPSliderMode", 0); this.m_ShowColors = (EditorPrefs.GetInt("CPColorShow", 1) != 0); this.m_ColorBoxMode = (ColorPicker.ColorBoxMode)EditorPrefs.GetInt("CPColorMode", 0); this.m_IsOSColorPicker = EditorPrefs.GetBool("UseOSColorPicker"); this.m_ShowPresets = (EditorPrefs.GetInt("CPPresetsShow", 1) != 0); EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(this.PollOSColorPicker)); EditorGUIUtility.editingTextField = true; }
private void OnGUI() { this.InitIfNeeded(); if (this.m_resetKeyboardControl) { GUIUtility.keyboardControl = 0; this.m_resetKeyboardControl = false; } if (Event.current.type == EventType.ExecuteCommand) { string commandName = Event.current.commandName; if (commandName != null) { // ISSUE: reference to a compiler-generated field if (ColorPicker.\u003C\u003Ef__switch\u0024map17 == null) { // ISSUE: reference to a compiler-generated field ColorPicker.\u003C\u003Ef__switch\u0024map17 = new Dictionary<string, int>(3) { { "EyeDropperUpdate", 0 }, { "EyeDropperClicked", 1 }, { "EyeDropperCancelled", 2 } }; } int num; // ISSUE: reference to a compiler-generated field if (ColorPicker.\u003C\u003Ef__switch\u0024map17.TryGetValue(commandName, out num)) { switch (num) { case 0: this.Repaint(); break; case 1: Color lastPickedColor = EyeDropper.GetLastPickedColor(); this.m_R = lastPickedColor.r; this.m_G = lastPickedColor.g; this.m_B = lastPickedColor.b; this.RGBToHSV(); this.m_ColorBoxMode = this.m_OldColorBoxMode; this.m_Color = new Color(this.m_R, this.m_G, this.m_B, this.m_A); this.SendEvent(true); break; case 2: this.Repaint(); this.m_ColorBoxMode = this.m_OldColorBoxMode; break; } } } } Rect rect = EditorGUILayout.BeginVertical(ColorPicker.styles.background, new GUILayoutOption[0]); float width = EditorGUILayout.GetControlRect(false, 1f, EditorStyles.numberField, new GUILayoutOption[0]).width; EditorGUIUtility.labelWidth = width - this.fieldWidth; EditorGUIUtility.fieldWidth = this.fieldWidth; EditorGUI.BeginChangeCheck(); GUILayout.Space(10f); this.DoColorSwatchAndEyedropper(); GUILayout.Space(10f); if (this.m_HDR) { this.TonemappingControls(); GUILayout.Space(10f); } this.DoColorSpaceGUI(); GUILayout.Space(10f); if (this.m_HDR) { GUILayout.Space(5f); this.BrightnessField(); GUILayout.Space(10f); } this.DoColorSliders(); GUILayout.Space(5f); this.DoHexField(width); GUILayout.Space(10f); if (EditorGUI.EndChangeCheck()) this.colorChanged = true; this.DoPresetsGUI(); this.HandleCopyPasteEvents(); if (this.colorChanged) { this.colorChanged = false; this.m_Color = new Color(this.m_R, this.m_G, this.m_B, this.m_A); this.SendEvent(true); } EditorGUILayout.EndVertical(); if ((double) rect.height > 0.0 && Event.current.type == EventType.Repaint) this.SetHeight(rect.height); if (Event.current.type == EventType.KeyDown) { switch (Event.current.keyCode) { case KeyCode.Return: case KeyCode.KeypadEnter: this.Close(); break; case KeyCode.Escape: Undo.RevertAllDownToGroup(this.m_ModalUndoGroup); this.m_Color = this.m_OriginalColor; this.SendEvent(false); this.Close(); GUIUtility.ExitGUI(); break; } } if ((Event.current.type != EventType.MouseDown || Event.current.button == 1) && Event.current.type != EventType.ContextClick) return; GUIUtility.keyboardControl = 0; this.Repaint(); }
private void DoColorSpaceGUI() { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(ColorPicker.styles.colorCycle, GUIStyle.none, new GUILayoutOption[1]{ GUILayout.ExpandWidth(false) })) this.m_OldColorBoxMode = this.m_ColorBoxMode = (ColorPicker.ColorBoxMode) ((int) (this.m_ColorBoxMode + 1) % 6); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(20f); GUILayout.BeginVertical(); GUILayout.Space(7f); bool changed = GUI.changed; GUILayout.BeginHorizontal(GUILayout.ExpandHeight(false)); Rect aspectRect = GUILayoutUtility.GetAspectRect(1f, ColorPicker.styles.pickerBox, GUILayout.MinWidth(64f), GUILayout.MinHeight(64f), GUILayout.MaxWidth(256f), GUILayout.MaxHeight(256f)); EditorGUILayout.Space(); Rect rect = GUILayoutUtility.GetRect(8f, 32f, 64f, 128f, ColorPicker.styles.pickerBox); rect.height = aspectRect.height; GUILayout.EndHorizontal(); GUI.changed = false; switch (this.m_ColorBoxMode) { case ColorPicker.ColorBoxMode.SV_H: this.Slider3D(aspectRect, rect, ref this.m_S, ref this.m_V, ref this.m_H, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert); if (GUI.changed) { this.HSVToRGB(); break; } break; case ColorPicker.ColorBoxMode.HV_S: this.Slider3D(aspectRect, rect, ref this.m_H, ref this.m_V, ref this.m_S, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert); if (GUI.changed) { this.HSVToRGB(); break; } break; case ColorPicker.ColorBoxMode.HS_V: this.Slider3D(aspectRect, rect, ref this.m_H, ref this.m_S, ref this.m_V, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert); if (GUI.changed) { this.HSVToRGB(); break; } break; case ColorPicker.ColorBoxMode.BG_R: this.Slider3D(aspectRect, rect, ref this.m_B, ref this.m_G, ref this.m_R, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert); if (GUI.changed) { this.RGBToHSV(); break; } break; case ColorPicker.ColorBoxMode.BR_G: this.Slider3D(aspectRect, rect, ref this.m_B, ref this.m_R, ref this.m_G, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert); if (GUI.changed) { this.RGBToHSV(); break; } break; case ColorPicker.ColorBoxMode.RG_B: this.Slider3D(aspectRect, rect, ref this.m_R, ref this.m_G, ref this.m_B, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert); if (GUI.changed) { this.RGBToHSV(); break; } break; case ColorPicker.ColorBoxMode.EyeDropper: EyeDropper.DrawPreview(Rect.MinMaxRect(aspectRect.x, aspectRect.y, rect.xMax, aspectRect.yMax)); break; } GUI.changed |= changed; GUILayout.Space(5f); GUILayout.EndVertical(); GUILayout.Space(20f); GUILayout.EndHorizontal(); }
private void DoColorSwatchAndEyedropper() { GUILayout.BeginHorizontal(); if (GUILayout.Button(ColorPicker.styles.eyeDropper, GUIStyle.none, GUILayout.Width(40f), GUILayout.ExpandWidth(false))) { EyeDropper.Start((GUIView) this.m_Parent); this.m_ColorBoxMode = ColorPicker.ColorBoxMode.EyeDropper; GUIUtility.ExitGUI(); } Color color = new Color(this.m_R, this.m_G, this.m_B, this.m_A); if (this.m_HDR) color = ColorPicker.color; Rect rect = GUILayoutUtility.GetRect(20f, 20f, 20f, 20f, ColorPicker.styles.colorPickerBox, GUILayout.ExpandWidth(true)); EditorGUIUtility.DrawColorSwatch(rect, color, this.m_ShowAlpha, this.m_HDR); if (Event.current.type == EventType.Repaint) ColorPicker.styles.pickerBox.Draw(rect, GUIContent.none, false, false, false, false); GUILayout.EndHorizontal(); }
private void OnEnable() { this.m_HDRValues.m_ExposureAdjustment = EditorPrefs.GetFloat("CPickerExposure", 1f); this.m_UseTonemappingPreview = EditorPrefs.GetInt("CPTonePreview", 0) != 0; this.m_SliderMode = (ColorPicker.SliderMode) EditorPrefs.GetInt("CPSliderMode", 0); this.m_ColorBoxMode = (ColorPicker.ColorBoxMode) EditorPrefs.GetInt("CPColorMode", 0); this.m_ShowPresets = EditorPrefs.GetInt("CPPresetsShow", 1) != 0; }
private void OnGUI() { this.InitIfNeeded(); if (this.m_resetKeyboardControl) { GUIUtility.keyboardControl = 0; this.m_resetKeyboardControl = false; } EventType type = Event.current.type; if (type == EventType.ExecuteCommand) { string commandName = Event.current.commandName; switch (commandName) { case "EyeDropperUpdate": base.Repaint(); break; case "EyeDropperClicked": { Color lastPickedColor = EyeDropper.GetLastPickedColor(); this.m_R = lastPickedColor.r; this.m_G = lastPickedColor.g; this.m_B = lastPickedColor.b; this.RGBToHSV(); this.m_ColorBoxMode = this.m_OldColorBoxMode; this.m_Color = new Color(this.m_R, this.m_G, this.m_B, this.m_A); this.SendEvent(true); break; } case "EyeDropperCancelled": base.Repaint(); this.m_ColorBoxMode = this.m_OldColorBoxMode; break; } } EditorGUIUtility.labelWidth = 15f; EditorGUIUtility.fieldWidth = 30f; Rect rect = EditorGUILayout.BeginVertical(ColorPicker.styles.background, new GUILayoutOption[0]); EditorGUI.BeginChangeCheck(); GUILayout.Space(10f); this.DoColorSwatchAndEyedropper(); GUILayout.Space(10f); this.DoColorSpaceGUI(); GUILayout.Space(10f); this.DoColorSliders(); GUILayout.Space(10f); if (EditorGUI.EndChangeCheck()) { this.colorChanged = true; } this.DoPresetsGUI(); if (this.colorChanged) { EditorPrefs.SetInt("CPSliderShow", (!this.m_ShowSliders) ? 0 : 1); EditorPrefs.SetInt("CPSliderMode", (int)this.m_SliderMode); EditorPrefs.SetInt("CPColorShow", (!this.m_ShowColors) ? 0 : 1); EditorPrefs.SetInt("CPColorMode", (int)this.m_ColorBoxMode); } if (this.colorChanged) { this.colorChanged = false; this.m_Color = new Color(this.m_R, this.m_G, this.m_B, this.m_A); this.SendEvent(true); } EditorGUILayout.EndVertical(); if (rect.height > 0f) { this.SetHeight(rect.height); } if (Event.current.type == EventType.KeyDown) { KeyCode keyCode = Event.current.keyCode; if (keyCode != KeyCode.Return) { if (keyCode == KeyCode.Escape) { Undo.RevertAllDownToGroup(this.m_ModalUndoGroup); this.m_Color = this.m_OriginalColor; this.SendEvent(false); base.Close(); GUIUtility.ExitGUI(); return; } if (keyCode != KeyCode.KeypadEnter) { return; } } base.Close(); } }
private void DoColorSpaceGUI() { GUILayout.BeginHorizontal(new GUILayoutOption[0]); this.m_ShowColors = GUILayout.Toggle(this.m_ShowColors, ColorPicker.styles.colorToggle, EditorStyles.foldout, new GUILayoutOption[0]); GUI.enabled = this.m_ShowColors; if (GUILayout.Button(ColorPicker.styles.colorCycle, GUIStyle.none, new GUILayoutOption[] { GUILayout.ExpandWidth(false) })) { this.m_OldColorBoxMode = (this.m_ColorBoxMode = (this.m_ColorBoxMode + 1) % ColorPicker.ColorBoxMode.EyeDropper); } GUI.enabled = true; GUILayout.EndHorizontal(); if (this.m_ShowColors) { bool changed = GUI.changed; GUILayout.BeginHorizontal(new GUILayoutOption[] { GUILayout.ExpandHeight(false) }); Rect aspectRect = GUILayoutUtility.GetAspectRect(1f, ColorPicker.styles.pickerBox, new GUILayoutOption[] { GUILayout.MinWidth(64f), GUILayout.MinHeight(64f), GUILayout.MaxWidth(256f), GUILayout.MaxHeight(256f) }); EditorGUILayout.Space(); Rect rect = GUILayoutUtility.GetRect(8f, 32f, 64f, 128f, ColorPicker.styles.pickerBox); rect.height = aspectRect.height; GUILayout.EndHorizontal(); GUI.changed = false; switch (this.m_ColorBoxMode) { case ColorPicker.ColorBoxMode.SV_H: this.Slider3D(aspectRect, rect, ref this.m_S, ref this.m_V, ref this.m_H, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert); if (GUI.changed) { this.HSVToRGB(); } break; case ColorPicker.ColorBoxMode.HV_S: this.Slider3D(aspectRect, rect, ref this.m_H, ref this.m_V, ref this.m_S, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert); if (GUI.changed) { this.HSVToRGB(); } break; case ColorPicker.ColorBoxMode.HS_V: this.Slider3D(aspectRect, rect, ref this.m_H, ref this.m_S, ref this.m_V, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert); if (GUI.changed) { this.HSVToRGB(); } break; case ColorPicker.ColorBoxMode.BG_R: this.Slider3D(aspectRect, rect, ref this.m_B, ref this.m_G, ref this.m_R, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert); if (GUI.changed) { this.RGBToHSV(); } break; case ColorPicker.ColorBoxMode.BR_G: this.Slider3D(aspectRect, rect, ref this.m_B, ref this.m_R, ref this.m_G, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert); if (GUI.changed) { this.RGBToHSV(); } break; case ColorPicker.ColorBoxMode.RG_B: this.Slider3D(aspectRect, rect, ref this.m_R, ref this.m_G, ref this.m_B, ColorPicker.styles.pickerBox, ColorPicker.styles.thumb2D, ColorPicker.styles.thumbVert); if (GUI.changed) { this.RGBToHSV(); } break; case ColorPicker.ColorBoxMode.EyeDropper: EyeDropper.DrawPreview(Rect.MinMaxRect(aspectRect.x, aspectRect.y, rect.xMax, aspectRect.yMax)); break; } GUI.changed |= changed; } }