示例#1
0
        private void OnGUI()
        {
            EventType type = Event.current.type;

            if (type != EventType.MouseMove)
            {
                if (type != EventType.MouseDown)
                {
                    if (type == EventType.KeyDown)
                    {
                        if (Event.current.keyCode == KeyCode.Escape)
                        {
                            base.window.Close();
                            this.SendEvent("EyeDropperCancelled", true);
                        }
                    }
                }
                else if (Event.current.button == 0)
                {
                    EyeDropper.s_PickCoordinates = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
                    base.window.Close();
                    EyeDropper.s_LastPickedColor = EyeDropper.GetPickedColor();
                    this.SendEvent("EyeDropperClicked", true);
                }
            }
            else
            {
                EyeDropper.s_PickCoordinates = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
                base.StealMouseCapture();
                this.SendEvent("EyeDropperUpdate", true);
            }
        }
示例#2
0
        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();
        }
示例#3
0
        private void OnGUI()
        {
            switch (Event.current.type)
            {
            case EventType.MouseDown:
                if (Event.current.button == 0)
                {
                    EyeDropper.s_PickCoordinates = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
                    base.window.Close();
                    EyeDropper.s_LastPickedColor = EyeDropper.GetPickedColor();
                    this.SendEvent("EyeDropperClicked");
                }
                break;

            case EventType.MouseMove:
                EyeDropper.s_PickCoordinates = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
                base.StealMouseCapture();
                this.SendEvent("EyeDropperUpdate");
                break;

            case EventType.KeyDown:
                if (Event.current.keyCode == KeyCode.Escape)
                {
                    base.window.Close();
                    this.SendEvent("EyeDropperCancelled");
                }
                break;
            }
        }
示例#4
0
 private EyeDropper()
 {
     EyeDropper.s_Instance = this;
 }
示例#5
0
 private EyeDropper()
 {
     s_Instance = this;
 }
示例#6
0
 public static void Start(Action <Color> colorPickedCallback, bool stealFocus = true)
 {
     EyeDropper.Start(null, colorPickedCallback, stealFocus);
 }
示例#7
0
 public static void Start(GUIView viewToUpdate, bool stealFocus = true)
 {
     EyeDropper.Start(viewToUpdate, null, stealFocus);
 }
示例#8
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();
            }
        }
示例#9
0
        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;
            }
        }