Beispiel #1
0
        private void LButtonDown(Point pt)
        {
            offsetFromFigureLeftTopCorner = this.ToLogical(pt);

            oldCoordinates = offsetFromFigureLeftTopCorner;

            moving = new List <IMovable>();
            IEnumerable <IFigure> roots = null;

            IFigure found = Drawing.Figures.HitTest(offsetFromFigureLeftTopCorner);
            IEnumerable <IFigure> selection = null;

            if (found is SubPoint)
            {// can't move sub point 01-11-10 scott
                return;
            }
            // remove by scott 08-25-2009
            if (IsCtrlPressed())
            {
                if (found != null)
                {
                    found.Selected = !found.Selected;
                }
                selection = Drawing.GetSelectedFigures();
            }
            else
            {
                if (found == null || !found.Selected)
                {
                    Drawing.ClearSelectedFigures();
                    if (found != null)
                    {
                        found.Selected = true;
                        selection      = found.AsEnumerable();
                    }
                }
            }

            IEnumerable <IFigure> selectedFigures = Drawing.GetSelectedFigures();

            Drawing.RaiseSelectionChanged(new Drawing.SelectionChangedEventArgs(selectedFigures));

            IMovable oneMovable = found as IMovable;

            if (oneMovable != null /*&&!(oneMovable is Game.Zone)* 03-10-2011 Scott*/)
            {
                /*if (oneMovable is IPoint)
                 * {
                 *  // when we drag a point, we want it to snap to the cursor
                 *  // so that the point center is directly under the tip of the mouse
                 *  offsetFromFigureLeftTopCorner = new Point();
                 *  oldCoordinates = oneMovable.Coordinates;
                 * }
                 * else
                 * {*/
                // however when we drag other stuff (such as text labels)
                // we want the mouse to always touch the part of the draggable
                // where it first touched during MouseDown
                // we don't want the draggable to "snap" to the cursor like points do
                offsetFromFigureLeftTopCorner = offsetFromFigureLeftTopCorner.Minus(oneMovable.Coordinates);
                /*}*/
                moving.Add(oneMovable);
                roots = found.AsEnumerable();
            }
            else if (found != null)
            {
                if (!(found is Game.Zone) && !(found is LineBase))  // 11-18-2010 Scott
                {
                    roots = DependencyAlgorithms.FindRoots(f => f.Dependencies, found);
                    if (roots.All(root => root is IMovable))
                    {
                        moving.AddRange(roots.Cast <IMovable>());
                    }
                }
            }

            if (roots != null)
            {
                toRecalculate = DependencyAlgorithms.FindDescendants(f => f.Dependents, roots).Reverse();
            }
            else
            {
                toRecalculate = null;
            }

            //03-09-2010 Scott
            if (moving.Count > 0 && moving[0] is Game.PBBall && mode == 1)
            {
                Drawing.Figures.OfType <IMovable>().ForEach(f =>
                {
                    if (!(f is Game.PBBall) && !(f is SubPoint))
                    {
                        moving.Add(f);
                    }
                }
                                                            );
            }
            else if (found != null)
            {
                IEnumerable <IFigure> figuresSelected = Drawing.GetSelectedFigures();
                if (figuresSelected.All(f => f is Game.PBPlayer || f is LabelBase || f is FreePoint || f is PrePoint || f is PBLine)) // 11-12-2010 Scott add labelbase support
                {
                    moving.Clear();
                    IEnumerable <IFigure> fs = Drawing.GetSelectedFigures();
                    // 08-04-11 Scott
                    foreach (IFigure f in fs)
                    {
                        if (f is PBLine)
                        {
                            foreach (IFigure pf in (f as PBLine).Dependencies)
                            {
                                if (pf is IMovable && !moving.Contains(pf as IMovable))
                                {
                                    moving.Add(pf as IMovable);
                                }
                            }
                        }

                        if (f is IMovable)
                        {
                            moving.Add(f as IMovable);
                        }
                    }
                    // end
                }
            }

            if (moving.IsEmpty())
            {// coordinate system
             //Drawing.Canvas.Cursor = new Cursor(AppDomain.CurrentDomain.BaseDirectory + @"\Resource\CursorHand.cur");    //01-04-2010 scott

                //moving.Add(Drawing.CoordinateSystem);

                //var allFigures = Drawing.Figures.GetAllFiguresRecursive();    // remove by scott 06-24-2009
                //roots = DependencyAlgorithms.FindRoots(f => f.Dependencies, allFigures);
                //moving.AddRange(roots.OfType<IMovable>());
                //roots = null;
                toRecalculate = null; // Figures;
            }
        }
Beispiel #2
0
        protected override void MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            base.MouseLeftButtonDown(sender, e);

            if (e.Handled)
            {
                return;
            }

            offsetFromFigureLeftTopCorner = Coordinates(e);
            oldCoordinates = offsetFromFigureLeftTopCorner;

            moving = new List <IMovable>();
            IEnumerable <IFigure> roots = null;

            IFigure found = Drawing.Figures.HitTest(offsetFromFigureLeftTopCorner);
            IEnumerable <IFigure> selection = null;

            // 11-12-2010 Scott
            if (IsCtrlPressed())
            {
                if (found != null)
                {
                    found.Selected = !found.Selected;
                }
                selection = Drawing.GetSelectedFigures();
            }
            else
            {
                if (found == null || !found.Selected)
                {
                    Drawing.ClearSelectedFigures();
                    if (found != null && (found is Game.PBPlayer || found is LabelBase || found is LineBase))   // 11-19-2010 Scott
                    {
                        found.Selected = true;
                        selection      = found.AsEnumerable();
                    }
                }
            }

            Drawing.RaiseSelectionChanged(new Drawing.SelectionChangedEventArgs(Drawing.GetSelectedFigures()));

            IMovable oneMovable = found as IMovable;

            if (oneMovable != null)
            {
                offsetFromFigureLeftTopCorner = offsetFromFigureLeftTopCorner.Minus(oneMovable.Coordinates);
                moving.Add(oneMovable);
                roots = found.AsEnumerable();
            }
            else if (found != null)
            {
                if (!(found is Game.Zone) && !(found is LineBase))  // 11-19-2010 Scott
                {
                    roots = DependencyAlgorithms.FindRoots(f => f.Dependencies, found);
                    if (roots.All(root => root is IMovable))
                    {
                        moving.AddRange(roots.Cast <IMovable>());
                    }
                }
            }

            if (roots != null)
            {
                toRecalculate = DependencyAlgorithms.FindDescendants(f => f.Dependents, roots).Reverse();
            }
            else
            {
                toRecalculate = null;
            }

            if (moving.IsEmpty())
            {
                toRecalculate = null;
            }

            //if (found == null)
            //{
            //    if (!Drawing.Canvas.Children.Contains(SelectRect))
            //    {
            //        Drawing.Canvas.Children.Add(SelectRect);
            //    }
            //    System.Windows.Controls.Canvas.SetLeft(SelectRect, e.GetPosition(Drawing.Canvas).X);
            //    System.Windows.Controls.Canvas.SetTop(SelectRect, e.GetPosition(Drawing.Canvas).Y);
            //    SelectRect.Visibility = Visibility.Visible;
            //}
            Drawing.Figures.UpdateVisual();
        }
Beispiel #3
0
        /// <summary>
        /// Assumes coordinates are logical already
        /// </summary>
        /// <param name="coordinates">Logical coordinates of the click point</param>
        protected override void  MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (e.ClickCount > 1)
            {
                Drawing.SetDefaultBehavior();
                return;
            }

            IEnumerable <IFigure> selectedFigures = Drawing.GetSelectedFigures();
            PBPlayer player    = null;
            IFigure  endFigure = null;

            if (selectedFigures != null && selectedFigures.Count() > 0)
            {
                player = selectedFigures.ElementAt(0) as PBPlayer;
            }

            //Type expectedType = ExpectedDependency;
            System.Windows.Point coordinates = Coordinates(e);
            IFigure underMouse = null;

            underMouse = Drawing.Figures.HitTest(coordinates);
            if (underMouse is Game.PBPlayer)
            {
                if (underMouse == player)
                {
                    Drawing.SetDefaultBehavior();
                    return;
                }

                player = underMouse as Game.PBPlayer;

                Drawing.ClearSelectedFigures();
                player.Selected = true;
                Drawing.Figures.UpdateVisual();
                return;
            }
            else if (underMouse is IPoint && (underMouse as IPoint).Dependents.Count == 1)
            {
                Drawing.ClearSelectedFigures();
                underMouse.Selected = true;
                Drawing.Figures.UpdateVisual();
                return;
            }

            if (player == null)
            {
                if (selectedFigures != null && selectedFigures.Count() > 0)
                {
                    IFigure figure = selectedFigures.ElementAt(0);
                    if (figure is IPoint && (figure as IPoint).Dependents.Count == 1)
                    {
                        endFigure = figure;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {// 09-26-2011 Scott
                endFigure = null;
                //endFigure = player.GetEndFigure();
                //player.ChangeLineType(CapType.Arrow);

                //if (endFigure is Game.Zone)
                //{
                //    return;
                //}
            }

            FreePoint  pp = CreatePointAtCurrentPosition(coordinates, false);
            FigureList fl = new FigureList();

            if (endFigure != null)
            {
                if (endFigure is Game.PBPlayer)
                {
                    player.ClearEndPath();
                    endFigure = player.GetEndFigure();
                    if (endFigure != null)
                    {
                        fl.Add(endFigure);
                    }
                    else
                    {
                        fl.Add(player);
                    }
                }
                else
                {
                    fl.Add(endFigure);
                }
            }
            else
            {
                fl.Add(player);
            }
            fl.Add(pp);
            PBLine line = Factory.CreateArrowLine(Drawing, fl);

            if (!Drawing.DrawingMode)
            {
                line.StrokeColor = Webb.Playbook.Data.ColorSetting.Instance.RouteColor;
            }
            FigureList figureList = new FigureList();

            figureList.Add(line);
            figureList.Add(pp);

            Drawing.Add(figureList as IEnumerable <IFigure>);

            Drawing.ClearSelectedFigures();
            pp.Selected = true;

            Drawing.Figures.CheckConsistency();
            Drawing.Figures.UpdateVisual();
        }