コード例 #1
0
        private float HandleBorderScaleSlider(float x, float y, float width, float height, bool isHorizontal)
        {
            if (styles == null)
            {
                return(0f);
            }

            float   fixedWidth = styles.dragBorderdot.fixedWidth;
            Vector2 pos        = Handles.matrix.MultiplyPoint(new Vector2(x, y));

            EditorGUI.BeginChangeCheck();
            float result = 0f;

            if (isHorizontal)
            {
                Rect cursorRect = new Rect(pos.x - fixedWidth * 0.5f, pos.y, fixedWidth, height);
                result = SVGEditorHandles.ScaleSlider(pos, MouseCursor.ResizeHorizontal, cursorRect).x;
            }
            else
            {
                Rect cursorRect2 = new Rect(pos.x, pos.y - fixedWidth * 0.5f, width, fixedWidth);
                result = SVGEditorHandles.ScaleSlider(pos, MouseCursor.ResizeVertical, cursorRect2).y;
            }

            if (EditorGUI.EndChangeCheck())
            {
                return(result);
            }

            return((!isHorizontal) ? y : x);
        }
コード例 #2
0
        private void HandleBorderPointSlider(ref float x, ref float y, MouseCursor mouseCursor, bool isHidden, GUIStyle dragDot, GUIStyle dragDotActive, Color color)
        {
            Color color2 = GUI.color;

            GUI.color = color;

            Vector2 vector = SVGEditorHandles.PointSlider(new Vector2(x, y), mouseCursor, dragDot, dragDotActive);

            x         = vector.x;
            y         = vector.y;
            GUI.color = color2;
        }
コード例 #3
0
        protected void DoTextureGUIExtras()
        {
            HandleBorderCornerScalingHandles();
            HandleBorderSidePointScalingSliders();
            HandleBorderSideScalingHandles();
            HandlePivotHandle();

            if (Event.current.type == EventType.Repaint)
            {
                Vector4 border = svgAsset.border;

                Rect rect     = new Rect(-textureOrigRect.size.x * 0.5f, -textureOrigRect.size.y * 0.5f, textureOrigRect.size.x, textureOrigRect.size.y);
                Rect drawRect = new Rect(
                    rect.x + rect.size.x * border.x,
                    rect.y + rect.size.y * border.w,
                    rect.size.x * Mathf.Abs(border.z - (1f - border.x)),
                    rect.size.y * Mathf.Abs(border.y - (1f - border.w))
                    );

                SVGEditorHandles.BeginLines(Color.green * 1.5f);
                SVGEditorHandles.DrawLine(
                    new Vector2(-position.width, drawRect.min.y),
                    new Vector2(position.width, drawRect.min.y)
                    );

                SVGEditorHandles.DrawLine(
                    new Vector2(-position.width, drawRect.max.y),
                    new Vector2(position.width, drawRect.max.y)
                    );

                SVGEditorHandles.DrawLine(
                    new Vector2(drawRect.min.x, -position.height),
                    new Vector2(drawRect.min.x, position.height)
                    );

                SVGEditorHandles.DrawLine(
                    new Vector2(drawRect.max.x, -position.height),
                    new Vector2(drawRect.max.x, position.height)
                    );

                //SVGEditorHandles.DrawBox(drawRect);
                SVGEditorHandles.EndLines();
            }
        }
コード例 #4
0
    public static Vector2 PointSlider(Vector2 pos, UnityEditor.MouseCursor cursor, GUIStyle dragDot, GUIStyle dragDotActive)
    {
        int       controlID      = GUIUtility.GetControlID("Slider1D".GetHashCode(), FocusType.Keyboard);
        Vector2   vector         = Handles.matrix.MultiplyPoint(pos);
        Rect      rect           = new Rect(vector.x - dragDot.fixedWidth * 0.5f, vector.y - dragDot.fixedHeight * 0.5f, dragDot.fixedWidth, dragDot.fixedHeight);
        Event     current        = Event.current;
        EventType typeForControl = current.GetTypeForControl(controlID);

        if (typeForControl == EventType.Repaint)
        {
            if (GUIUtility.hotControl == controlID)
            {
                dragDotActive.Draw(rect, GUIContent.none, controlID);
            }
            else
            {
                dragDot.Draw(rect, GUIContent.none, controlID);
            }
        }
        return(SVGEditorHandles.ScaleSlider(pos, cursor, rect));
    }
コード例 #5
0
    public static Rect SliderRect(Rect pos)
    {
        int   controlID = GUIUtility.GetControlID("SliderRect".GetHashCode(), FocusType.Keyboard);
        Event current   = Event.current;

        if (SVGEditorHandles.s_OneClickDragStarted && current.type == EventType.Repaint)
        {
            SVGEditorHandles.HandleSliderRectMouseDown(controlID, current, pos);
            SVGEditorHandles.s_OneClickDragStarted = false;
        }
        switch (current.GetTypeForControl(controlID))
        {
        case EventType.MouseDown:
            if (current.button == 0 && pos.Contains(Handles.inverseMatrix.MultiplyPoint(Event.current.mousePosition)) && !current.alt)
            {
                SVGEditorHandles.HandleSliderRectMouseDown(controlID, current, pos);
                current.Use();
            }
            break;

        case EventType.MouseUp:
            if (GUIUtility.hotControl == controlID && (current.button == 0 || current.button == 2))
            {
                GUIUtility.hotControl = 0;
                current.Use();
                EditorGUIUtility.SetWantsMouseJumping(0);
            }
            break;

        case EventType.MouseDrag:
            if (GUIUtility.hotControl == controlID)
            {
                SVGEditorHandles.s_CurrentMousePosition += current.delta;
                Vector2 center = pos.center;
                pos.center = Handles.inverseMatrix.MultiplyPoint(SVGEditorHandles.s_CurrentMousePosition - SVGEditorHandles.s_DragScreenOffset);
                if (!Mathf.Approximately((center - pos.center).magnitude, 0f))
                {
                    GUI.changed = true;
                }
                current.Use();
            }
            break;

        case EventType.KeyDown:
            if (GUIUtility.hotControl == controlID && current.keyCode == KeyCode.Escape)
            {
                pos.center            = Handles.inverseMatrix.MultiplyPoint(SVGEditorHandles.s_DragStartScreenPosition - SVGEditorHandles.s_DragScreenOffset);
                GUIUtility.hotControl = 0;
                GUI.changed           = true;
                current.Use();
            }
            break;

        case EventType.Repaint:
        {
            Vector2 vector  = Handles.inverseMatrix.MultiplyPoint(new Vector2(pos.xMin, pos.yMin));
            Vector2 vector2 = Handles.inverseMatrix.MultiplyPoint(new Vector2(pos.xMax, pos.yMax));
            EditorGUIUtility.AddCursorRect(new Rect(vector.x, vector.y, vector2.x - vector.x, vector2.y - vector.y), UnityEditor.MouseCursor.Arrow, controlID);
            break;
        }
        }
        return(pos);
    }
コード例 #6
0
    public static Vector2 ScaleSlider(Vector2 pos, UnityEditor.MouseCursor cursor, Rect cursorRect)
    {
        int controlID = GUIUtility.GetControlID("Slider1D".GetHashCode(), FocusType.Keyboard);

        return(SVGEditorHandles.ScaleSlider(controlID, pos, cursor, cursorRect));
    }
コード例 #7
0
    public static Rect RectCreator(float textureWidth, float textureHeight, GUIStyle rectStyle)
    {
        Event   current       = Event.current;
        Vector2 mousePosition = current.mousePosition;
        int     num           = SVGEditorHandles.s_RectSelectionID;
        Rect    result        = default(Rect);

        switch (current.GetTypeForControl(num))
        {
        case EventType.MouseDown:
            if (current.button == 0)
            {
                GUIUtility.hotControl = num;
                Rect    rect = new Rect(0f, 0f, textureWidth, textureHeight);
                Vector2 v    = Handles.inverseMatrix.MultiplyPoint(mousePosition);
                v.x = Mathf.Min(Mathf.Max(v.x, rect.xMin), rect.xMax);
                v.y = Mathf.Min(Mathf.Max(v.y, rect.yMin), rect.yMax);
                SVGEditorHandles.s_DragStartScreenPosition = Handles.matrix.MultiplyPoint(v);
                SVGEditorHandles.s_CurrentMousePosition    = mousePosition;
                current.Use();
            }
            break;

        case EventType.MouseUp:
            if (GUIUtility.hotControl == num && current.button == 0)
            {
                if (SVGEditorHandles.ValidRect(SVGEditorHandles.s_DragStartScreenPosition, SVGEditorHandles.s_CurrentMousePosition))
                {
                    result      = SVGEditorHandles.GetCurrentRect(false, textureWidth, textureHeight, SVGEditorHandles.s_DragStartScreenPosition, SVGEditorHandles.s_CurrentMousePosition);
                    GUI.changed = true;
                    current.Use();
                }
                GUIUtility.hotControl = 0;
            }
            break;

        case EventType.MouseDrag:
            if (GUIUtility.hotControl == num)
            {
                SVGEditorHandles.s_CurrentMousePosition = new Vector2(mousePosition.x, mousePosition.y);
                current.Use();
            }
            break;

        case EventType.KeyDown:
            if (GUIUtility.hotControl == num && current.keyCode == KeyCode.Escape)
            {
                GUIUtility.hotControl = 0;
                GUI.changed           = true;
                current.Use();
            }
            break;

        case EventType.Repaint:
            if (GUIUtility.hotControl == num && SVGEditorHandles.ValidRect(SVGEditorHandles.s_DragStartScreenPosition, SVGEditorHandles.s_CurrentMousePosition))
            {
                BeginLines(Color.green * 1.5f);
                DrawBox(SVGEditorHandles.GetCurrentRect(false, textureWidth, textureHeight, SVGEditorHandles.s_DragStartScreenPosition, SVGEditorHandles.s_CurrentMousePosition));
                EndLines();
            }
            break;
        }
        return(result);
    }