Example #1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Event guiEvent = Event.current;

        EditorGUI.BeginProperty(position, label, property);
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        CustomGradient gradient = GetDataObject(property) as CustomGradient;

        if (gradient == null)
        {
            return;
        }
        Rect textureRect = new Rect(position.x, position.y, position.width, position.height);

        if (guiEvent.type == EventType.Repaint)
        {
            GUIStyle gradientStyle = new GUIStyle();
            gradientStyle.normal.background = gradient.GetTexture((int)position.width);
            GUI.Label(textureRect, GUIContent.none, gradientStyle);
        }
        else
        {
            if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0)
            {
                if (textureRect.Contains(guiEvent.mousePosition))
                {
                    GradientEditor window = EditorWindow.GetWindow <GradientEditor>();
                    window.SetGradient(gradient);
                }
            }
        }

        EditorGUI.EndProperty();
    }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Event guiEvent = Event.current;

        CustomGradient gradient = (CustomGradient)fieldInfo.GetValue(property.serializedObject.targetObject);

        float labelWidth  = GUI.skin.label.CalcSize(label).x + 5;
        Rect  textureRect = new Rect(position.x + labelWidth, position.y, position.width - labelWidth, position.height);

        if (guiEvent.type == EventType.Repaint)
        {
            GUI.Label(position, label);
            GUIStyle gradientStyle = new GUIStyle();
            gradientStyle.normal.background = gradient.GetTexture((int)position.width);
            GUI.Label(textureRect, GUIContent.none, gradientStyle);
        }
        else
        {
            // Check if gradient is clicked
            if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0)
            {
                if (textureRect.Contains(guiEvent.mousePosition))
                {
                    // Open editor window
                    GradientEditor window = EditorWindow.GetWindow <GradientEditor>();
                    window.SetGradient(gradient);
                }
            }
        }
    }
    void DrawGradientVariable(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        //Draw the label of the variable and set the position
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        //Set the box position
        Rect boxRect = new Rect(position.x, position.y, position.width, 16);

        //Draw a Box behind the Gradient
        GUI.Box(boxRect, "");

        //Set the gradient position
        Rect gradientRect = new Rect(boxRect.position.x + 1, boxRect.position.y + 1, boxRect.width - 2, boxRect.height - 2);

        //Draw gradient texture with a workaround method
        PropertyDrawerMethods.DrawTexture(gradientRect, previewTexture);

        //Set the Color of the Editor GUI to transparent
        GUI.color = Color.clear;

        //Draw the button of the Gradient Editor
        if (GUI.Button(gradientRect, ""))
        {
            GradientEditor.Init(instance);
        }

        //Revert the Color of the Editor GUI
        GUI.color = Color.white;

        EditorGUI.EndProperty();
    }
Example #4
0
        public override void DoRepaint()
        {
            Texture2D     backgroundTexture = GradientEditor.GetBackgroundTexture();
            IStylePainter stylePainter      = base.elementPanel.stylePainter;
            TextureStylePainterParameters defaultTextureParameters = stylePainter.GetDefaultTextureParameters(this);

            defaultTextureParameters.texture = backgroundTexture;
            stylePainter.DrawTexture(defaultTextureParameters);
            base.DoRepaint();
        }
        public override void DoRepaint()
        {
            //Start by drawing the checkerboard background for alpha gradients.
            Texture2D backgroundTexture = GradientEditor.GetBackgroundTexture();
            var       painter           = elementPanel.stylePainter;
            var       painterParams     = painter.GetDefaultTextureParameters(this);

            painterParams.texture = backgroundTexture;
            painter.DrawTexture(painterParams);

            base.DoRepaint();
        }
Example #6
0
    /*
     * public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
     * {
     *  //return base.GetPropertyHeight(property, label);
     *  return customHeightInPixels;
     * }
     */

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //base.OnGUI(position, property, label);

        Event          guiEvent = Event.current;
        CustomGradient gradient = (CustomGradient)fieldInfo.GetValue(property.serializedObject.targetObject);

        Rect labelRect = new Rect(position);

        labelRect.width = EditorGUIUtility.labelWidth;

        Rect textureRect = new Rect(position);

        textureRect.width -= EditorGUIUtility.labelWidth;
        textureRect.x     += EditorGUIUtility.labelWidth;

        if (guiEvent.type == EventType.Repaint)
        {
            GUI.DrawTexture(textureRect, gradient.GetTexture((int)position.width));
            GUI.Label(position, label.text);

            // Workaround for background glitches (when moving cursor)
            // Doesn't appear to happen on 2019.3.0a4
#if !UNITY_2019_3_OR_NEWER
            GUIStyle gradientStyle = new GUIStyle();
            gradientStyle.normal.background = gradient.GetTexture((int)position.width);
            GUI.Label(textureRect, GUIContent.none, gradientStyle);
#endif
        }
        else
        {
            if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0)
            {
                if (textureRect.Contains(guiEvent.mousePosition))
                {
                    GradientEditor window = EditorWindow.GetWindow <GradientEditor>();
                    window.SetGradient(gradient);
                }
            }
        }
    }
Example #7
0
        private void ShowGradientEditor()
        {
            using (var ge = new GradientEditor())
              {
            string gradientPath = Path.Combine(CommonUtil.GetApplicationDataPath(), "Gradients");
            // get all unique gradients
            var gradients = new List<Gradient>();
            // from default route line settings
            foreach (RouteLineSettings rls in SessionSettings.CreateDefaultRouteLineSettingsCollection().Values)
            {
              if (!gradients.Contains(rls.ColorRange.Gradient)) gradients.Add(rls.ColorRange.Gradient);
            }
            // from gradients in this document
            foreach (RouteLineSettings rls in canvas.CurrentSession.Settings.RouteLineSettingsCollection.Values)
            {
              if (!gradients.Contains(rls.ColorRange.Gradient)) gradients.Add(rls.ColorRange.Gradient);
            }
            // from gradients saved on disk
            foreach (Gradient g in Util.GetGradientsInFolder(gradientPath))
            {
              if (!gradients.Contains(g)) gradients.Add(g);
            }

            ge.Gradients = gradients;

            ge.CurrentGradient = colorRangeIntervalSlider.SliderControl.ColorRange.Gradient;

            if (ge.ShowDialog() == DialogResult.OK)
            {
              foreach (string fileName in Directory.GetFiles(gradientPath))
              {
            File.Delete(fileName);
              }
              Util.SaveGradientsToFolder(ge.Gradients, gradientPath);
              if (ge.CurrentGradient != null)
              {
            BeginWork();
            canvas.CurrentSession.Settings.RouteLineSettingsCollection[SelectedColorCodingAttribute].ColorRange.Gradient
              = ge.CurrentGradient;
            canvas.CurrentSession.Settings.RouteLineSettingsCollection[SelectedColorCodingAttribute].MonochromeColor =
              ge.CurrentGradient.GetColor(1);
            UpdateUI();
            canvas.DrawMap(Canvas.MapDrawingFlags.Markers | Canvas.MapDrawingFlags.Route);
            CreateLapHistogram();
            DrawLapHistogram();
            CreateLineGraph();
            DrawLineGraph();
            EndWork();
              }
            }
              }
        }
    public static void Init(KR.Graphics.Gradient gradient)
    {
        GradientEditor instance = GetWindow <GradientEditor>();

        instance.Setup(gradient);
    }
Example #9
0
 //public void setColorStop(int order, ColorStop s) {
 public void setColorStop(int order, GradientEditor.GradientStop s)
 {
     map.Add(order, s);
 }