Ejemplo n.º 1
0
        public override InputReturns Undo(StateControls stateControls)
        {
            selections.Clear();
            stateControls.Reverse();

            return(true, this);
        }
Ejemplo n.º 2
0
        public override InputReturns KeyDown(StateControls stateControls)
        {
            bool toRefresh = ExecuteHotkey(stateControls.State, stateControls.PressedKeyLower, stateControls.Modifiers, stateControls.RegisterChange, out var circuitProperties);

            stateControls.CircuitPropertiesOutput = circuitProperties;
            return(toRefresh, this);
        }
Ejemplo n.º 3
0
        public override InputReturns Redo(StateControls stateControls)
        {
            selections.Clear();
            stateControls.Advance();

            return(true, this);
        }
Ejemplo n.º 4
0
        public override InputReturns MouseMove(StateControls stateControls)
        {
            mouseBox.Width  = stateControls.LocalMousePosition.X - mouseBox.X;
            mouseBox.Height = stateControls.LocalMousePosition.Y - mouseBox.Y;

            //Update selection box and load intersections into selections
            mouseBox.GetNormalized().GetIntersections(stateControls.State, (true, true, true), out _, out var newSelections);
            selections.Clear();
            selections.UnionWith(newSelections);
            selections.UnionWith(additiveSelections);
            stateControls.CircuitPropertiesOutput = GetUpdatedCircuitProperties(stateControls.RegisterChange);
            return(true, this);
        }
Ejemplo n.º 5
0
        public override InputReturns Copy(StateControls stateControls, HashSet <BoardObject> clipBoard)
        {
            //if no objects can be copied, return
            if (selections.Count == 0)
            {
                return(false, this);
            }

            clipBoard.Clear();
            clipBoard.UnionWith(selections);

            return(false, this);
        }
Ejemplo n.º 6
0
 public override InputReturns MouseRightDown(StateControls stateControls)
 {
     //true if you click a gate
     if (new BoxCollider(stateControls.LocalMousePosition.X, stateControls.LocalMousePosition.Y, 0, 0).GetIntersections(stateControls.State, (true, true, true), out _, out var boardObjects, false))
     {
         BoardObject clickedBoardObject = boardObjects.First();
         selections.Clear();
         selections.Add(clickedBoardObject);
         //Load [CircuitActions]
         var actions = CircuitAttributes.GetActions(clickedBoardObject, RefreshSelections, stateControls.RegisterChange);
         stateControls.CircuitActionsOutput = actions;
         return(true, this);
     }
     return(false, this);
 }
Ejemplo n.º 7
0
        public override InputReturns MouseLeftUp(StateControls stateControls)
        {
            primaryLine.InsertAndAttach(stateControls.State.Wires, stateControls.State.Connections);
            secondaryLine.InsertAndAttach(stateControls.State.Wires, stateControls.State.Connections);

            if (primaryLine.StartPoint != secondaryLine.EndPoint)
            {
                stateControls.RegisterChange($"Created wire from {primaryLine.StartPoint}-{secondaryLine.EndPoint}");
            }
            else
            {
                stateControls.State.Propogate();
            }
            return(true, new WireToolState());
        }
Ejemplo n.º 8
0
        public override InputReturns MouseLeftDown(StateControls stateControls)
        {
            RemoveBar();
            DeleteIfEmpty(stateControls);
            circuitLabel = default;

            //If mouse clicked a CircuitLabel
            if (new BoxCollider(stateControls.LocalMousePosition.X, stateControls.LocalMousePosition.Y, 0, 0).GetIntersections(stateControls.State, (false, false, true), out _, out var boardObjects, false))
            {
                var label = (CircuitLabel)boardObjects.Where((x) => x is CircuitLabel).FirstOrDefault();
                if (label != default)
                {
                    stateControls.State.Extras.Remove(label);
                    draggingLabel      = true;
                    circuitLabel       = label;
                    circuitLabel.Text += '|';
                }
            }
Ejemplo n.º 9
0
        public override InputReturns Cut(StateControls stateControls, HashSet <BoardObject> clipBoard)
        {
            //if no objects can be cut, return
            if (selections.Count == 0)
            {
                return(false, this);
            }

            clipBoard.Clear();
            foreach (var selection in selections)
            {
                selection.Delete(stateControls.State);
                clipBoard.Add((CircuitObject)selection.Copy());
            }
            selections.Clear();

            stateControls.RegisterChange("Cut selections");
            return(true, this);
        }
Ejemplo n.º 10
0
        public override InputReturns MouseMove(StateControls stateControls)
        {
            Vec2 gridPoint  = stateControls.LocalMousePosition + offset;
            Vec2 gridPointR = gridPoint.Round();

            bool delta  = gridPoint == selectedObject.StartPoint;          //ungridded position unchanged
            bool deltaR = gridPointR == selectedObject.StartPoint.Round(); //gridded position unchanged

            if (selectedObject.Gridded && deltaR || !selectedObject.Gridded && delta)
            {
                return(false, this);
            }

            Vec2 change  = gridPoint - selectedObject.StartPoint;
            Vec2 changeR = gridPointR - selectedObject.StartPoint.Round();

            if (!deltaR)
            {
                intersectedBoxes.Clear();
            }

            //Drag all objects to their new positions
            foreach (var selection in selections)
            {
                if (selectedObject.Gridded)
                {
                    selection.OffsetPosition(changeR);
                }
                else
                {
                    selection.OffsetPosition(selection.Gridded ? changeR : change);
                }
            }

            if (!deltaR)
            {
                CheckIntersections(stateControls.State);
            }

            return(true, this);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Helper function which makes StateControls
        /// </summary>
        public StateControls MakeControls(char?keyChar, Keys ModifierKeys)
        {
            var      mousePoint   = (Vec2)drawingPanel.PointToClient(Cursor.Position);
            Modifier modifierKeys = Modifier.None;

            if (ModifierKeys.HasFlag(Keys.Control))
            {
                modifierKeys |= Modifier.Control;
            }
            if (ModifierKeys.HasFlag(Keys.Shift))
            {
                modifierKeys |= Modifier.Shift;
            }
            if (ModifierKeys.HasFlag(Keys.Alt))
            {
                modifierKeys |= Modifier.Alt;
            }
            var stateControls = new StateControls(stateStack.CurrentState, mousePoint, stateManager.Zoom, keyChar, modifierKeys, stateStack.RegisterChange, stateStack.Reverse, stateStack.Advance);

            return(stateControls);
        }
Ejemplo n.º 12
0
        public override InputReturns MouseLeftDown(StateControls stateControls)
        {
            Vec2 localPoint = stateControls.LocalMousePosition;
            //if the shift key is held down, additive selection is activated. This will allow you to
            //edit the current set of selections (add/remove selections) without starting over.
            bool additiveSelection = stateControls.Modifiers.HasFlag(Modifier.Shift);

            //true if you click a gate
            if (new BoxCollider(localPoint.X, localPoint.Y, 0, 0).GetIntersections(stateControls.State, (true, true, true), out _, out var boardObjects, false))
            {
                BoardObject clickedBoardObject = boardObjects.First();
                //If you click something which is not already selected
                if (!selections.Contains(clickedBoardObject))
                {
                    if (!additiveSelection)
                    {
                        selections.Clear();
                    }
                    selections.Add(clickedBoardObject);
                }
                //If you click something which is already selected with additiveSelection enabled, remove it
                else if (additiveSelection)
                {
                    selections.Remove(clickedBoardObject);
                }

                //Load [CircuitProperties] for clicked object
                stateControls.CircuitPropertiesOutput = GetUpdatedCircuitProperties(stateControls.RegisterChange);

                return(true, new MovingSelectionState(stateControls.LocalMousePosition, selections, clickedBoardObject, stateControls.State, true));
            }
            //Begin dragging selection box
            //Clear selections if additiveSelection is not activated
            if (!additiveSelection)
            {
                selections.Clear();
                stateControls.CircuitPropertiesOutput = CircuitPropertyCollection.Empty;
            }
            return(true, new SelectingState(localPoint, selections));
        }
Ejemplo n.º 13
0
        public override InputReturns Paste(StateControls stateControls, HashSet <BoardObject> clipBoard)
        {
            selections.Clear();

            CircuitObject currentObject = null;
            //Average position of all added objects
            Vec2 averagePosition = Vec2.Zero;

            foreach (var obj in clipBoard)
            {
                var newObj = (CircuitObject)obj.Copy();
                selections.Add(newObj);

                if (currentObject == null)
                {
                    currentObject = newObj;
                }

                averagePosition += newObj.StartPoint;
            }

            averagePosition /= selections.Count;

            //Moves object so that they are centered around the mouse for ease of selection
            foreach (var obj in selections)
            {
                Vec2 offset = obj.StartPoint - averagePosition + stateControls.LocalMousePosition;
                obj.SetPosition(offset);
            }

            stateControls.CircuitPropertiesOutput = GetUpdatedCircuitProperties(stateControls.RegisterChange);
            //New objects pasted and are now being held
            if (selections.Count > 0)
            {
                return(true, new MovingSelectionState(stateControls.LocalMousePosition, selections, currentObject, stateControls.State, false));
            }

            return(false, this);
        }
Ejemplo n.º 14
0
        public override InputReturns MouseMove(StateControls stateControls)
        {
            Vec2 endPosition = stateControls.GriddedMousePosition;

            //If the target position has not changed return
            if (secondaryLine.EndPoint == endPosition)
            {
                return(false, this);
            }

            //The position where the primary and secondary wires split
            Vec2 branchPosition;

            if (isHorizontal)
            {
                branchPosition = new Vec2(endPosition.X, primaryLine.StartPoint.Y);
            }
            else
            {
                branchPosition = new Vec2(primaryLine.StartPoint.X, endPosition.Y);
            }

            primaryLine.EndPoint     = branchPosition;
            secondaryLine.StartPoint = branchPosition;
            secondaryLine.EndPoint   = endPosition;

            primaryLine.IsHorizontal   = isHorizontal;
            secondaryLine.IsHorizontal = !isHorizontal;

            //If the primary line has lost relevance, the assumed direction should be changed
            if (primaryLine.StartPoint == primaryLine.EndPoint)
            {
                isHorizontal = !isHorizontal;
            }

            return(true, this);
        }
Ejemplo n.º 15
0
        public override InputReturns MouseLeftUp(StateControls stateControls)
        {
            CheckIntersections(stateControls.State);
            if (intersectedBoxes.Count > 0)
            {
                //If the objects were just created and are placed in an invalid state, they have nowhere
                //to be reset to and thus should be destroyed
                if (!resettable)
                {
                    selections.Clear();
                    return(true, new SelectionToolState(selections));
                }

                Vec2 totalOffset  = startPosition - selectedObject.StartPoint;
                Vec2 totalOffsetR = startPosition.Round() - selectedObject.StartPoint.Round();
                foreach (var selection in selections)
                {
                    selection.OffsetPosition(selection.Gridded ? totalOffsetR : totalOffset);
                }
            }


            stateControls.State.AttachAll(selections);

            //If it has moved, register movement
            if (intersectedBoxes.Count == 0 && startPosition != selectedObject.StartPoint)
            {
                stateControls.RegisterChange(resettable ? "Moved selections" : "Placed selections");
            }
            else
            {
                stateControls.State.Propogate();
            }

            return(true, new SelectionToolState(selections));
        }
Ejemplo n.º 16
0
 public override InputReturns MouseLeftDown(StateControls stateControls) => (true, new DrawingWireState(stateControls.GriddedMousePosition));
Ejemplo n.º 17
0
 public override InputReturns MouseMove(StateControls stateControls)
 {
     return(removeWire(stateControls.State.Wires, stateControls.GriddedMousePosition, stateControls.State.Connections));
 }
Ejemplo n.º 18
0
 public virtual InputReturns MouseRightUp(StateControls stateControls) => (false, this);
Ejemplo n.º 19
0
 public override InputReturns MouseLeftDown(StateControls stateControls)
 {
     //No need to duplicate logic
     return(new TextToolState().MouseLeftDown(stateControls));
 }
Ejemplo n.º 20
0
 //Mouse Operations
 public virtual InputReturns MouseLeftDown(StateControls stateControls) => (false, this);
Ejemplo n.º 21
0
 //Special operations
 /// <summary>
 /// This function is called only if IsClean returned true, and the state manager wishes to change the current
 /// state. It is the only InputState with no return value.
 /// </summary>
 public virtual InputReturns CleanupState(StateControls stateControls) => (false, this);
Ejemplo n.º 22
0
 public virtual InputReturns Paste(StateControls stateControls, HashSet <BoardObject> clipBoard) => (false, this);
Ejemplo n.º 23
0
 public virtual InputReturns Redo(StateControls stateControls) => (false, this);
Ejemplo n.º 24
0
 //Keyboard Operations
 public virtual InputReturns KeyDown(StateControls stateControls) => (false, this);
Ejemplo n.º 25
0
 public override InputReturns MouseLeftUp(StateControls stateControls)
 {
     return(true, new SelectionToolState(selections));
 }
Ejemplo n.º 26
0
 public override InputReturns MouseRightUp(StateControls stateControls)
 {
     stateControls.RegisterChange("Deleted Wires");
     return(true, new WireToolState());
 }
Ejemplo n.º 27
0
 public override InputReturns KeyDown(StateControls stateControls)
 {
     circuitLabel.Text += stateControls.PressedKey;
     return(true, this);
 }
Ejemplo n.º 28
0
 public virtual InputReturns MouseMove(StateControls stateControls) => (false, this);