예제 #1
0
        protected override void AddDependency(Point coordinates)
        {
            IFigure underMouse = null;

            if (GetExpectedDependencyType() != null)
            {
                underMouse = LookForExpectedDependencyUnderCursor(coordinates);
                if (underMouse != null && FoundDependencies.Contains(underMouse) && !CanReuseDependency)
                {
                    return;
                }
            }

            Drawing.RaiseConstructionStepStarted();

            if (GetExpectedDependencyType() != null)
            {
                AddFoundDependency(underMouse);
            }

            if (GetExpectedDependencyType() != null)
            {
                AdvertiseNextDependency();
            }
            else
            {
                AddFiguresAndRestart();
            }

            Drawing.Figures.CheckConsistency();
        }
        protected override void Click(Point coordinates)
        {
            var figure = Drawing.Figures.HitTest(coordinates);

            if (figure is IShapeWithInterior)
            {
                FoundDependencies.Clear();
                FoundDependencies.Add(figure);
                RemoveIntermediateFigureIfNecessary();
                RemoveTempPointIfNecessary();
                AddFiguresAndRestart();
                return;
            }

            //var point = Drawing.Figures.HitTest<IPoint>(coordinates);
            if (figure is PointBase && FoundDependencies.Count >= 4 // 4 including the TempPoint
                // (and 3 after TempPoint is removed)
                && FoundDependencies.Contains(figure))
            {
                RemoveIntermediateFigureIfNecessary();
                RemoveTempPointIfNecessary();
                AddFiguresAndRestart();
                return;
            }

            base.Click(coordinates);
        }
예제 #3
0
        protected int FoundDependenciesMinimum = 3; // Includes TempPoint
        protected override void Click(Point coordinates)
        {
            var point = Drawing.Figures.HitTest <IPoint>(coordinates);

            if (point != null &&
                FoundDependencies.Count >= FoundDependenciesMinimum + 1 && // Add 1 for TempPoint
                FoundDependencies.Contains(point))
            {
                RemoveIntermediateFigureIfNecessary();
                RemoveTempPointIfNecessary();
                AddFiguresAndRestart();
                return;
            }
            base.Click(coordinates);
        }
예제 #4
0
        /// <summary>
        /// Assumes coordinates are logical already
        /// </summary>
        /// <param name="coordinates">Logical coordinates of the click point</param>
        protected virtual void Click(System.Windows.Point coordinates)
        {
            IFigure underMouse   = null;
            Type    expectedType = ExpectedDependency;

            if (TempPoint != null)
            {
                underMouse = Drawing.Figures.HitTest(
                    coordinates,
                    typeof(IPoint));
            }
            else if (expectedType != null)
            {
                underMouse = Drawing.Figures.HitTest(coordinates, expectedType);
            }
            else
            {
                underMouse = Drawing.Figures.HitTest(coordinates);
            }

            if (underMouse != null &&
                underMouse != TempPoint &&
                ((FoundDependencies.Contains(underMouse) && !CanReuseDependency()) ||
                 underMouse == TempResult))
            {
                return;
            }

            if (ExpectingAPoint())
            {
                if (underMouse == null)
                {
                    underMouse = CreatePointAtCurrentPosition(coordinates, true);
                }
            }

            RemoveIntermediateFigureIfNecessary();

            if (TempPoint != null)
            {
                if (underMouse == TempPoint || underMouse == TempResult || underMouse == null)
                {
                    underMouse = CreatePointAtCurrentPosition(coordinates, true);
                }
                TempPoint.SubstituteWith(underMouse);
                FoundDependencies.Remove(TempPoint);
                Drawing.Figures.Remove(TempPoint);
                TempPoint = null;
            }

            if (ExpectedDependency != null)
            {
                AddFoundDependency(underMouse);
            }

            if (ExpectedDependency != null)
            {
                if (ExpectingAPoint())
                {
                    TempPoint = CreateTempPoint(coordinates);
                    AddFoundDependency(TempPoint);
                    if (ExpectedDependency == null)
                    {
                        CreateAndAddFigure();
                    }
                }
                AddIntermediateFigureIfNecessary();
                AdvertiseNextDependency();
            }
            else
            {
                Finish();
            }

            Drawing.Figures.CheckConsistency();
        }
예제 #5
0
        /// <summary>
        /// Assumes coordinates are logical already
        /// </summary>
        /// <param name="coordinates">Logical coordinates of the click point</param>
        protected virtual void Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            System.Windows.Point coordinates = Coordinates(e);

            IFigure underMouse   = null;
            Type    expectedType = ExpectedDependency;

            if (TempPoint != null)
            {
                underMouse = Drawing.Figures.HitTest(
                    coordinates,
                    typeof(IPoint));
            }
            else if (expectedType != null)
            {
                underMouse = Drawing.Figures.HitTest(coordinates, expectedType);
            }
            else
            {
                underMouse = Drawing.Figures.HitTest(coordinates);
            }

            if (underMouse != null &&
                underMouse != TempPoint &&
                ((FoundDependencies.Contains(underMouse) && !CanReuseDependency()) ||
                 underMouse == TempResult))
            {
                return;
            }

            if (ExpectingAPoint())
            {
                if (underMouse == null)
                {
                    //underMouse = CreatePointAtCurrentPosition(coordinates, true);
                    return;
                }
                else
                {
                    // one branch only
                    if (underMouse is Webb.Playbook.Geometry.Game.PBPlayer && underMouse.Dependents.Count > 0)
                    {
                        return;
                    }
                    // at most two branch
                    if (underMouse is IPoint && underMouse.Dependents.Count > 1)
                    {
                        return;
                    }
                }
            }

            RemoveIntermediateFigureIfNecessary();

            if (TempPoint != null)
            {
                //if (underMouse == TempPoint || underMouse == TempResult || underMouse == null)
                //{
                underMouse = CreatePointAtCurrentPosition(coordinates, true);
                //}
                TempPoint.SubstituteWith(underMouse);
                FoundDependencies.Remove(TempPoint);
                Drawing.Figures.Remove(TempPoint);
                TempPoint = null;
            }

            if (ExpectedDependency != null)
            {
                AddFoundDependency(underMouse);
            }

            if (ExpectedDependency != null)
            {
                if (ExpectingAPoint())
                {
                    TempPoint = CreateTempPoint(coordinates);
                    AddFoundDependency(TempPoint);
                    if (ExpectedDependency == null)
                    {
                        CreateAndAddFigure();
                    }
                }
                AddIntermediateFigureIfNecessary();
                AdvertiseNextDependency();
            }
            else
            {
                Finish();

                //07-22-2009 scott
                if (IsMouseButtonDown)
                {// click mode
                    IFigure endFigure = Drawing.Figures.HitTest(coordinates, typeof(Webb.Playbook.Geometry.Game.PBPlayer));
                    if (endFigure is Webb.Playbook.Geometry.Game.PBPlayer)
                    {
                        Drawing.ActionManager.Undo();
                    }
                    else
                    {
                        MouseLeftButtonDown(sender, e as System.Windows.Input.MouseButtonEventArgs);
                    }
                }
                else
                {// drag mode
                }
            }

            Drawing.Figures.CheckConsistency();
        }