private bool EnableCreatePointRepaint(IGUIState guiState, GUIAction action)
 {
     return(guiState.nearestControl != m_PointControl.ID &&
            guiState.hotControl == 0 &&
            (guiState.nearestControl != m_LeftTangentControl.ID) &&
            (guiState.nearestControl != m_RightTangentControl.ID));
 }
Пример #2
0
    public static void endRotate()
    {
        int lastI = actionList.Count - 1;

        GUIAction action = actionList[lastI];

        action.undo();
        actionList.RemoveAt(lastI);
    }
Пример #3
0
        public RectSelector(GUISystem guiSystem)
        {
            m_GUISystem = guiSystem;

            m_RectSelectorControl = new GenericDefaultControl("RectSelector");

            var start   = Vector2.zero;
            var rectEnd = Vector2.zero;

            m_RectSelectAction = new SliderAction(m_RectSelectorControl)
            {
                enable        = (guiState, action) => !IsAltDown(guiState),
                enableRepaint = (guiState, action) =>
                {
                    var size = start - rectEnd;
                    return(size != Vector2.zero && guiState.hotControl == action.ID);
                },
                onSliderBegin = (guiState, control, position) =>
                {
                    start     = guiState.mousePosition;
                    rectEnd   = guiState.mousePosition;
                    m_GUIRect = FromToRect(start, rectEnd);

                    if (onSelectionBegin != null)
                    {
                        onSelectionBegin(this, guiState.isShiftDown);
                    }
                },
                onSliderChanged = (guiState, control, position) =>
                {
                    rectEnd   = guiState.mousePosition;
                    m_GUIRect = FromToRect(start, rectEnd);

                    if (onSelectionChanged != null)
                    {
                        onSelectionChanged(this);
                    }
                },
                onSliderEnd = (guiState, control, position) =>
                {
                    if (onSelectionEnd != null)
                    {
                        onSelectionEnd(this);
                    }
                },
                onRepaint = (guiState, action) =>
                {
                    Handles.BeginGUI();
                    styles.selectionRectStyle.Draw(m_GUIRect, GUIContent.none, false, false, false, false);
                    Handles.EndGUI();
                }
            };

            m_GUISystem.AddControl(m_RectSelectorControl);
            m_GUISystem.AddAction(m_RectSelectAction);
        }
Пример #4
0
 public PhTextEdit(float left, float top, float width, float height, string text, string caption, ValueType type, GUIAction onChange, GUIAction onExit)
     : base(left, top, width, height)
 {
     this.Text = text;
     this.Caption = caption;
     this.onChange = onChange;
     this.onExit = onExit;
     this.keyMap = new Konsoul.KeyMap();
     this.Type =type;
     cursor = text.Length;
 }
Пример #5
0
        public PhInputDialog(float left, float top, string title, string caption, string text, PhControl.GUIAction onInput)
            : base(left, top, 400, 120, title)
        {
            edit = new PhTextEdit(10, 60, 380, 20, text, caption, PhTextEdit.ValueType.String, null, null);
            edit.CaptionPosition = new Microsoft.Xna.Framework.Vector2(5, -30);

            this.onInput = onInput;

            AddComponent(edit);
            AddComponent(new PhButton(200, 90, 80, 24, "OK", Confirm));
            AddComponent(new PhButton(300, 90, 80, 24, "Cancel", Cancel));
        }
Пример #6
0
    public static void endClip()
    {
        int lastI = actionList.Count - 1;

        GUIAction action = actionList[lastI];

        action.undo();
        actionList.RemoveAt(lastI);

        if (clipStack.Count > 0)
        {
            clipStack.Pop();
            localClipStack.Pop();
        }
    }
Пример #7
0
        public RectSelector(GUISystem guiSystem)
        {
            m_GUISystem = guiSystem;

            m_RectSelectorControl = new GenericDefaultControl("RectSelector")
            {
                position = (guiState) =>
                {
                    return(GUIToWorld(guiState, guiState.mousePosition));
                },
                forward = (guiState) =>
                {
                    if (Camera.current)
                    {
                        return(Camera.current.transform.forward);
                    }

                    return(Vector3.forward);
                },
                right = (guiState) =>
                {
                    if (Camera.current)
                    {
                        return(Camera.current.transform.right);
                    }

                    return(Vector3.right);
                },
                up = (guiState) =>
                {
                    if (Camera.current)
                    {
                        return(Camera.current.transform.up);
                    }

                    return(Vector3.up);
                }
            };

            m_RectSelectAction = new SliderAction(m_RectSelectorControl)
            {
                enableRepaint = (guiState, action) =>
                {
                    var size = m_RectStart - m_RectEnd;
                    return(size != Vector3.zero && guiState.hotControl == action.ID);
                },
                onClick = (guiState, control) =>
                {
                    m_RectStart = GUIToWorld(guiState, guiState.mousePosition);
                    m_RectEnd   = m_RectStart;
                    m_GUIRect   = CalculateGUIRect();
                },
                onSliderBegin = (guiState, control, position) =>
                {
                    m_RectEnd = position;
                    m_GUIRect = CalculateGUIRect();

                    if (onSelectionBegin != null)
                    {
                        onSelectionBegin(this, guiState.isShiftDown);
                    }
                },
                onSliderChanged = (guiState, control, position) =>
                {
                    m_RectEnd = position;
                    m_GUIRect = CalculateGUIRect();

                    if (onSelectionChanged != null)
                    {
                        onSelectionChanged(this);
                    }
                },
                onSliderEnd = (guiState, control, position) =>
                {
                    if (onSelectionEnd != null)
                    {
                        onSelectionEnd(this);
                    }
                },
                onRepaint = (guiState, action) =>
                {
                    m_Drawer.DrawSelectionRect(m_GUIRect);
                }
            };

            m_GUISystem.AddControl(m_RectSelectorControl);
            m_GUISystem.AddAction(m_RectSelectAction);
        }
        public EditablePathView(IDrawer drawer)
        {
            m_Drawer = drawer;

            m_PointControl = new GenericControl("Point")
            {
                count    = GetPointCount,
                distance = (guiState, i) =>
                {
                    var position = GetPoint(i).position;
                    return(guiState.DistanceToCircle(position, guiState.GetHandleSize(position) * 10f));
                },
                position  = (i) => { return(GetPoint(i).position); },
                forward   = (i) => { return(GetForward()); },
                up        = (i) => { return(GetUp()); },
                right     = (i) => { return(GetRight()); },
                onRepaint = DrawPoint
            };

            m_EdgeControl = new GenericControl("Edge")
            {
                onEndLayout = (guiState) => { controller.AddClosestPath(m_EdgeControl.layoutData.distance); },
                count       = GetEdgeCount,
                distance    = DistanceToEdge,
                position    = (i) => { return(GetPoint(i).position); },
                forward     = (i) => { return(GetForward()); },
                up          = (i) => { return(GetUp()); },
                right       = (i) => { return(GetRight()); },
                onRepaint   = DrawEdge
            };

            m_LeftTangentControl = new GenericControl("LeftTangent")
            {
                count = () =>
                {
                    if (GetShapeType() != ShapeType.Spline)
                    {
                        return(0);
                    }

                    return(GetPointCount());
                },
                distance = (guiState, i) =>
                {
                    if (!IsSelected(i) || IsOpenEnded() && i == 0)
                    {
                        return(float.MaxValue);
                    }

                    var position = GetLeftTangent(i);
                    return(guiState.DistanceToCircle(position, guiState.GetHandleSize(position) * 10f));
                },
                position  = (i) => { return(GetLeftTangent(i)); },
                forward   = (i) => { return(GetForward()); },
                up        = (i) => { return(GetUp()); },
                right     = (i) => { return(GetRight()); },
                onRepaint = (guiState, control, i) =>
                {
                    if (!IsSelected(i) || IsOpenEnded() && i == 0)
                    {
                        return;
                    }

                    var position    = GetPoint(i).position;
                    var leftTangent = GetLeftTangent(i);

                    m_Drawer.DrawTangent(position, leftTangent);
                }
            };

            m_RightTangentControl = new GenericControl("RightTangent")
            {
                count = () =>
                {
                    if (GetShapeType() != ShapeType.Spline)
                    {
                        return(0);
                    }

                    return(GetPointCount());
                },
                distance = (guiState, i) =>
                {
                    if (!IsSelected(i) || IsOpenEnded() && i == GetPointCount() - 1)
                    {
                        return(float.MaxValue);
                    }

                    var position = GetRightTangent(i);
                    return(guiState.DistanceToCircle(position, guiState.GetHandleSize(position) * 10f));
                },
                position  = (i) => { return(GetRightTangent(i)); },
                forward   = (i) => { return(GetForward()); },
                up        = (i) => { return(GetUp()); },
                right     = (i) => { return(GetRight()); },
                onRepaint = (guiState, control, i) =>
                {
                    if (!IsSelected(i) || IsOpenEnded() && i == GetPointCount() - 1)
                    {
                        return;
                    }

                    var position     = GetPoint(i).position;
                    var rightTangent = GetRightTangent(i);

                    m_Drawer.DrawTangent(position, rightTangent);
                }
            };

            m_CreatePointAction = new CreatePointAction(m_PointControl, m_EdgeControl)
            {
                enable             = (guiState, action) => { return(!guiState.isShiftDown && controller.closestEditablePath == controller.editablePath); },
                enableRepaint      = EnableCreatePointRepaint,
                repaintOnMouseMove = (guiState, action) => { return(true); },
                guiToWorld         = GUIToWorld,
                onCreatePoint      = (index, position) =>
                {
                    controller.RegisterUndo("Create Point");
                    controller.CreatePoint(index, position);
                },
                onPreRepaint = (guiState, action) =>
                {
                    if (GetPointCount() > 0)
                    {
                        var position = ClosestPointInEdge(guiState, guiState.mousePosition, m_EdgeControl.layoutData.index);
                        m_Drawer.DrawCreatePointPreview(position);
                    }
                }
            };

            Action <IGUIState> removePoints = (guiState) =>
            {
                controller.RegisterUndo("Remove Point");
                controller.RemoveSelectedPoints();
                guiState.changed = true;
            };

            m_RemovePointAction1 = new CommandAction(kDeleteCommandName)
            {
                enable    = (guiState, action) => { return(GetSelectedPointCount() > 0); },
                onCommand = removePoints
            };

            m_RemovePointAction2 = new CommandAction(kSoftDeleteCommandName)
            {
                enable    = (guiState, action) => { return(GetSelectedPointCount() > 0); },
                onCommand = removePoints
            };

            m_MovePointAction = new SliderAction(m_PointControl)
            {
                onClick = (guiState, control) =>
                {
                    var index = control.layoutData.index;

                    if (!guiState.isActionKeyDown && !IsSelected(index))
                    {
                        controller.ClearSelection();
                    }

                    controller.SelectPoint(index, true);
                    guiState.changed = true;
                },
                onSliderBegin = (guiState, control, position) =>
                {
                    controller.RegisterUndo("Move Point");
                },
                onSliderChanged = (guiState, control, position) =>
                {
                    var index = control.hotLayoutData.index;
                    var delta = SnapIfNeeded(position) - GetPoint(index).position;

                    controller.MoveSelectedPoints(delta);
                }
            };

            m_MoveEdgeAction = new SliderAction(m_EdgeControl)
            {
                enable        = (guiState, action) => { return(guiState.isShiftDown); },
                onSliderBegin = (guiState, control, position) =>
                {
                    controller.RegisterUndo("Move Edge");
                },
                onSliderChanged = (guiState, control, position) =>
                {
                    var index = control.hotLayoutData.index;
                    var delta = position - GetPoint(index).position;

                    controller.MoveEdge(index, delta);
                }
            };

            var cachedRightTangent = Vector3.zero;
            var cachedLeftTangent  = Vector3.zero;

            m_MoveLeftTangentAction = new SliderAction(m_LeftTangentControl)
            {
                onSliderBegin = (guiState, control, position) =>
                {
                    controller.RegisterUndo("Move Tangent");
                    cachedRightTangent = GetPoint(control.hotLayoutData.index).rightTangent;
                },
                onSliderChanged = (guiState, control, position) =>
                {
                    var index       = control.hotLayoutData.index;
                    var setToLinear = guiState.nearestControl == m_PointControl.ID && m_PointControl.layoutData.index == index;

                    controller.SetLeftTangent(index, position, setToLinear, guiState.isShiftDown, cachedRightTangent);
                },
                onSliderEnd = (guiState, control, position) =>
                {
                    controller.editablePath.UpdateTangentMode(control.hotLayoutData.index);
                    guiState.changed = true;
                }
            };

            m_MoveRightTangentAction = new SliderAction(m_RightTangentControl)
            {
                onSliderBegin = (guiState, control, position) =>
                {
                    controller.RegisterUndo("Move Tangent");
                    cachedLeftTangent = GetPoint(control.hotLayoutData.index).leftTangent;
                },
                onSliderChanged = (guiState, control, position) =>
                {
                    var index       = control.hotLayoutData.index;
                    var setToLinear = guiState.nearestControl == m_PointControl.ID && m_PointControl.layoutData.index == index;

                    controller.SetRightTangent(index, position, setToLinear, guiState.isShiftDown, cachedLeftTangent);
                },
                onSliderEnd = (guiState, control, position) =>
                {
                    controller.editablePath.UpdateTangentMode(control.hotLayoutData.index);
                    guiState.changed = true;
                }
            };
        }
        private GUISystem CreateSystem(UnityObject target)
        {
            var guiSystem = new GUISystem(new GUIState());

            GUIAction removePointAction = null;

            var pointControl = new GenericControl("Point")
            {
                count = () =>
                {
                    return(GetPointCount(target));
                },
                distance = (guiState, i) =>
                {
                    var position = GetPointWorld(target, i);
                    return(ShapeEditorUtility.DistanceToCircle(position, ShapeEditorUtility.GetHandleSize(position) * 10f));
                },
                position = (i) =>
                {
                    return(GetPointWorld(target, i));
                },
                forward = (i) =>
                {
                    return(GetForward(target));
                },
                up = (i) =>
                {
                    return(GetUp(target));
                },
                right = (i) =>
                {
                    return(GetRight(target));
                },
                onRepaint = (IGUIState guiState, Control control, int index) =>
                {
                    var position = GetPointWorld(target, index);

                    if (guiState.hotControl == control.actionID && control.hotLayoutData.index == index)
                    {
                        m_Drawer.DrawPointSelected(position);
                    }
                    else if (guiState.hotControl == 0 && guiState.nearestControl == control.ID && control.layoutData.index == index)
                    {
                        if (removePointAction.IsEnabled(guiState))
                        {
                            m_Drawer.DrawRemovePointPreview(position);
                        }
                        else
                        {
                            m_Drawer.DrawPointHovered(position);
                        }
                    }
                    else
                    {
                        m_Drawer.DrawPoint(position);
                    }
                }
            };

            var edgeControl = new GenericControl("Edge")
            {
                count = () =>
                {
                    return(GetPointCount(target));
                },
                distance = (IGUIState guiState, int index) =>
                {
                    return(ShapeEditorUtility.DistanceToSegment(GetPointWorld(target, index), NextControlPoint(target, index)));
                },
                position = (i) =>
                {
                    return(GetPointWorld(target, i));
                },
                forward = (i) =>
                {
                    return(GetForward(target));
                },
                up = (i) =>
                {
                    return(GetUp(target));
                },
                right = (i) =>
                {
                    return(GetRight(target));
                },
                onRepaint = (IGUIState guiState, Control control, int index) =>
                {
                    var nextIndex = NextIndex(target, index);
                    var prevIndex = PrevIndex(target, index);

                    var isEndpointHovered =
                        guiState.hotControl == 0 &&
                        guiState.nearestControl == pointControl.ID &&
                        (index == pointControl.layoutData.index || nextIndex == pointControl.layoutData.index);

                    var isPointHovered =
                        guiState.hotControl == 0 &&
                        guiState.nearestControl == pointControl.ID &&
                        index == pointControl.layoutData.index;

                    var color = Color.white;

                    if (guiState.hotControl == 0 && guiState.nearestControl == control.ID && control.layoutData.index == index)
                    {
                        color = Color.yellow;
                    }
                    else if (removePointAction.IsEnabled(guiState) && isEndpointHovered)
                    {
                        if (isPointHovered)
                        {
                            m_Drawer.DrawDottedLine(GetPointWorld(target, prevIndex), GetPointWorld(target, nextIndex), 5f, color);
                        }

                        color = Color.red;
                    }

                    m_Drawer.DrawLine(GetPointWorld(target, index), GetPointWorld(target, nextIndex), 5f, color);
                }
            };

            var createPointAction = new CreatePointAction(pointControl, edgeControl)
            {
                enable = (guiState, action) =>
                {
                    return(guiState.isShiftDown);
                },
                enableRepaint = (IGUIState guiState, GUIAction action) =>
                {
                    return(guiState.nearestControl != pointControl.ID && guiState.hotControl == 0);
                },
                repaintOnMouseMove = (guiState, action) =>
                {
                    return(true);
                },
                guiToWorld = (mousePosition) =>
                {
                    return(GUIToWorld(target, mousePosition));
                },
                onCreatePoint = (int index, Vector3 position) =>
                {
                    InsertPointWorld(target, index + 1, position);
                },
                onPreRepaint = (guiState, action) =>
                {
                    var position = ClosestPointInEdge(target, guiState.mousePosition, edgeControl.layoutData.index);

                    m_Drawer.DrawCreatePointPreview(position);
                }
            };

            removePointAction = new ClickAction(pointControl, 0)
            {
                enable = (guiState, action) =>
                {
                    return(guiState.isActionKeyDown);
                },
                onClick = (GUIState, control) =>
                {
                    if (GetPointCount(target) > 3)
                    {
                        RemovePoint(target, control.layoutData.index);
                    }
                }
            };

            var movePointAction = new SliderAction(pointControl)
            {
                onSliderChanged = (guiState, control, position) =>
                {
                    var index         = control.hotLayoutData.index;
                    var pointPosition = GetPointWorld(target, index);
                    pointPosition = position;
                    SetPointWorld(target, index, pointPosition);
                }
            };

            var moveEdgeAction = new SliderAction(edgeControl)
            {
                onSliderChanged = (guiState, control, position) =>
                {
                    var index         = control.hotLayoutData.index;
                    var pointPosition = GetPointWorld(target, index);
                    var delta         = position - pointPosition;
                    pointPosition += delta;
                    SetPointWorld(target, index, pointPosition);
                    pointPosition  = NextControlPoint(target, index);
                    pointPosition += delta;
                    SetPointWorld(target, NextIndex(target, index), pointPosition);
                }
            };

            guiSystem.AddControl(edgeControl);
            guiSystem.AddControl(pointControl);
            guiSystem.AddAction(createPointAction);
            guiSystem.AddAction(removePointAction);
            guiSystem.AddAction(movePointAction);
            guiSystem.AddAction(moveEdgeAction);

            return(guiSystem);
        }
Пример #10
0
 public PhButton(float left, float top, float width, float height, string text, GUIAction onClick)
     : base(left, top, width, height)
 {
     this.Text = text;
     this.onClick = onClick;
 }