/// <summary> /// Triggered when the user selects a new mode for the color box, changing the gamut of colors displayed in the box. /// </summary> void OnColorBoxModeChanged() { int maxModes = Enum.GetNames(colorBoxMode.GetType()).Length; colorBoxMode = (ColorBoxMode)(((int)colorBoxMode + 1) % maxModes); guiColorBoxBtn.SetContent(colorBoxMode.ToString()); Update2DSliderTextures(); Update2DSliderValues(); }
/// <summary> /// Updates the texture displayed on the color box. /// </summary> /// <param name="mode">Mode determining the color gamut shown in the color box.</param> /// <param name="value">Value of the third component (normally retrieved from the separate side slider).</param> public void UpdateTexture(ColorBoxMode mode, float value) { Color[] colors = new Color[width * height]; switch (mode) { case ColorBoxMode.BG_R: FillArea(width, height, colors, new Color(value, 0, 0, 1), new Color(0, 0, 1, 0), new Color(0, 1, 0, 0)); break; case ColorBoxMode.BR_G: FillArea(width, height, colors, new Color(0, value, 0, 1), new Color(0, 0, 1, 0), new Color(1, 0, 0, 0)); break; case ColorBoxMode.RG_B: FillArea(width, height, colors, new Color(0, 0, value, 1), new Color(1, 0, 0, 0), new Color(0, 1, 0, 0)); break; case ColorBoxMode.SV_H: FillArea(width, height, colors, new Color(value, 0, 0, 1), new Color(0, 1, 0, 0), new Color(0, 0, 1, 0)); for (int i = 0; i < colors.Length; i++) { colors[i] = Color.HSV2RGB(colors[i]); } break; case ColorBoxMode.HV_S: FillArea(width, height, colors, new Color(0, value, 0, 1), new Color(1, 0, 0, 0), new Color(0, 0, 1, 0)); for (int i = 0; i < colors.Length; i++) { colors[i] = Color.HSV2RGB(colors[i]); } break; case ColorBoxMode.HS_V: FillArea(width, height, colors, new Color(0, 0, value, 1), new Color(1, 0, 0, 0), new Color(0, 1, 0, 0)); for (int i = 0; i < colors.Length; i++) { colors[i] = Color.HSV2RGB(colors[i]); } break; } texture.SetPixels(colors); guiTexture.SetTexture(spriteTexture); }
/// <summary> /// Updates the texture displayed on the color box. /// </summary> /// <param name="mode">Mode determining the color gamut shown in the color box.</param> /// <param name="value">Value of the third component (normally retrieved from the separate side slider).</param> public void UpdateTexture(ColorBoxMode mode, float value) { Color[] colors = new Color[width * height]; switch (mode) { case ColorBoxMode.BG_R: FillArea(width, height, colors, new Color(value, 0, 0, 1), new Color(0, 0, 1, 0), new Color(0, 1, 0, 0)); break; case ColorBoxMode.BR_G: FillArea(width, height, colors, new Color(0, value, 0, 1), new Color(0, 0, 1, 0), new Color(1, 0, 0, 0)); break; case ColorBoxMode.RG_B: FillArea(width, height, colors, new Color(0, 0, value, 1), new Color(1, 0, 0, 0), new Color(0, 1, 0, 0)); break; case ColorBoxMode.SV_H: FillArea(width, height, colors, new Color(value, 0, 0, 1), new Color(0, 1, 0, 0), new Color(0, 0, 1, 0)); for (int i = 0; i < colors.Length; i++) colors[i] = Color.HSV2RGB(colors[i]); break; case ColorBoxMode.HV_S: FillArea(width, height, colors, new Color(0, value, 0, 1), new Color(1, 0, 0, 0), new Color(0, 0, 1, 0)); for (int i = 0; i < colors.Length; i++) colors[i] = Color.HSV2RGB(colors[i]); break; case ColorBoxMode.HS_V: FillArea(width, height, colors, new Color(0, 0, value, 1), new Color(1, 0, 0, 0), new Color(0, 1, 0, 0)); for (int i = 0; i < colors.Length; i++) colors[i] = Color.HSV2RGB(colors[i]); break; } texture.SetPixels(colors); guiTexture.SetTexture(spriteTexture); }
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) { int num2; if (<>f__switch$map15 == null) { Dictionary<string, int> dictionary = new Dictionary<string, int>(3); dictionary.Add("EyeDropperUpdate", 0); dictionary.Add("EyeDropperClicked", 1); dictionary.Add("EyeDropperCancelled", 2); <>f__switch$map15 = dictionary; } if (<>f__switch$map15.TryGetValue(commandName, out num2)) { switch (num2) { case 0: base.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: base.Repaint(); this.m_ColorBoxMode = this.m_OldColorBoxMode; break; } } } } Rect rect = EditorGUILayout.BeginVertical(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 ((rect.height > 0f) && (Event.current.type == EventType.Repaint)) { this.SetHeight(rect.height); } if (Event.current.type != EventType.KeyDown) { goto Label_0321; } KeyCode keyCode = Event.current.keyCode; if (keyCode == KeyCode.Return) { goto Label_0316; } if (keyCode != KeyCode.Escape) { if (keyCode == KeyCode.KeypadEnter) { goto Label_0316; } } else { Undo.RevertAllDownToGroup(this.m_ModalUndoGroup); this.m_Color = this.m_OriginalColor; this.SendEvent(false); base.Close(); GUIUtility.ExitGUI(); } goto Label_0321; Label_0316: base.Close(); Label_0321: if (((Event.current.type == EventType.MouseDown) && (Event.current.button != 1)) || (Event.current.type == EventType.ContextClick)) { GUIUtility.keyboardControl = 0; base.Repaint(); } }
private void OnEnable() { this.m_HDRValues.m_ExposureAdjustment = EditorPrefs.GetFloat("CPickerExposure", 1f); this.m_UseTonemappingPreview = EditorPrefs.GetInt("CPTonePreview", 0) != 0; this.m_SliderMode = (SliderMode) EditorPrefs.GetInt("CPSliderMode", 0); this.m_ColorBoxMode = (ColorBoxMode) EditorPrefs.GetInt("CPColorMode", 0); this.m_ShowPresets = EditorPrefs.GetInt("CPPresetsShow", 1) != 0; }
private string GetZAxisLabel(ColorBoxMode colorBoxMode) { return this.m_ColorBoxZAxisLabels[(int) colorBoxMode]; }
private void DoColorSwatchAndEyedropper() { GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(40f), GUILayout.ExpandWidth(false) }; if (GUILayout.Button(styles.eyeDropper, GUIStyle.none, options)) { EyeDropper.Start(base.m_Parent); this.m_ColorBoxMode = 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; } GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.ExpandWidth(true) }; Rect position = GUILayoutUtility.GetRect(20f, 20f, 20f, 20f, styles.colorPickerBox, optionArray2); EditorGUIUtility.DrawColorSwatch(position, color, this.m_ShowAlpha, this.m_HDR); if (Event.current.type == EventType.Repaint) { styles.pickerBox.Draw(position, GUIContent.none, false, false, false, false); } GUILayout.EndHorizontal(); }
private void DoColorSpaceGUI() { GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.FlexibleSpace(); GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandWidth(false) }; if (GUILayout.Button(styles.colorCycle, GUIStyle.none, options)) { this.m_OldColorBoxMode = this.m_ColorBoxMode = (this.m_ColorBoxMode + 1) % ColorBoxMode.EyeDropper; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Space(20f); GUILayout.BeginVertical(new GUILayoutOption[0]); GUILayout.Space(7f); bool changed = GUI.changed; GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.ExpandHeight(false) }; GUILayout.BeginHorizontal(optionArray2); GUILayoutOption[] optionArray3 = new GUILayoutOption[] { GUILayout.MinWidth(64f), GUILayout.MinHeight(64f), GUILayout.MaxWidth(256f), GUILayout.MaxHeight(256f) }; Rect boxPos = GUILayoutUtility.GetAspectRect(1f, styles.pickerBox, optionArray3); EditorGUILayout.Space(); Rect sliderPos = GUILayoutUtility.GetRect(8f, 32f, 64f, 128f, styles.pickerBox); sliderPos.height = boxPos.height; GUILayout.EndHorizontal(); GUI.changed = false; switch (this.m_ColorBoxMode) { case ColorBoxMode.SV_H: this.Slider3D(boxPos, sliderPos, ref this.m_S, ref this.m_V, ref this.m_H, styles.pickerBox, styles.thumb2D, styles.thumbVert); if (GUI.changed) { this.HSVToRGB(); } break; case ColorBoxMode.HV_S: this.Slider3D(boxPos, sliderPos, ref this.m_H, ref this.m_V, ref this.m_S, styles.pickerBox, styles.thumb2D, styles.thumbVert); if (GUI.changed) { this.HSVToRGB(); } break; case ColorBoxMode.HS_V: this.Slider3D(boxPos, sliderPos, ref this.m_H, ref this.m_S, ref this.m_V, styles.pickerBox, styles.thumb2D, styles.thumbVert); if (GUI.changed) { this.HSVToRGB(); } break; case ColorBoxMode.BG_R: this.Slider3D(boxPos, sliderPos, ref this.m_B, ref this.m_G, ref this.m_R, styles.pickerBox, styles.thumb2D, styles.thumbVert); if (GUI.changed) { this.RGBToHSV(); } break; case ColorBoxMode.BR_G: this.Slider3D(boxPos, sliderPos, ref this.m_B, ref this.m_R, ref this.m_G, styles.pickerBox, styles.thumb2D, styles.thumbVert); if (GUI.changed) { this.RGBToHSV(); } break; case ColorBoxMode.RG_B: this.Slider3D(boxPos, sliderPos, ref this.m_R, ref this.m_G, ref this.m_B, styles.pickerBox, styles.thumb2D, styles.thumbVert); if (GUI.changed) { this.RGBToHSV(); } break; case ColorBoxMode.EyeDropper: EyeDropper.DrawPreview(Rect.MinMaxRect(boxPos.x, boxPos.y, sliderPos.xMax, boxPos.yMax)); break; } GUI.changed |= changed; GUILayout.Space(5f); GUILayout.EndVertical(); GUILayout.Space(20f); GUILayout.EndHorizontal(); }