예제 #1
0
        public static BaseShape TryToHover(IToolContext context, SelectionMode mode, SelectionTargets targets, Point2 target, double radius)
        {
            var shapePoint =
                mode.HasFlag(SelectionMode.Point) &&
                targets.HasFlag(SelectionTargets.Shapes) ?
                context.HitTest?.TryToGetPoint(context.CurrentContainer.Shapes, target, radius, null) : null;

            var shape =
                mode.HasFlag(SelectionMode.Shape) &&
                targets.HasFlag(SelectionTargets.Shapes) ?
                context.HitTest?.TryToGetShape(context.CurrentContainer.Shapes, target, radius) : null;

            var guidePoint =
                mode.HasFlag(SelectionMode.Point) &&
                targets.HasFlag(SelectionTargets.Guides) ?
                context.HitTest?.TryToGetPoint(context.CurrentContainer.Guides, target, radius, null) : null;

            var guide =
                mode.HasFlag(SelectionMode.Shape) &&
                targets.HasFlag(SelectionTargets.Guides) ?
                context.HitTest?.TryToGetShape(context.CurrentContainer.Guides, target, radius) : null;

            if (shapePoint != null || shape != null || guide != null)
            {
                if (shapePoint != null)
                {
                    Log.Info($"Hover Shape Point: {shapePoint.GetType()}");
                    return(shapePoint);
                }
                else if (shape != null)
                {
                    Log.Info($"Hover Shape: {shape.GetType()}");
                    return(shape);
                }
                else if (guidePoint != null)
                {
                    Log.Info($"Hover Guide Point: {guidePoint.GetType()}");
                    return(guidePoint);
                }
                else if (guide != null)
                {
                    Log.Info($"Hover Guide: {guide.GetType()}");
                    return(guide);
                }
            }

            Log.Info("No Hover");
            return(null);
        }
예제 #2
0
        private void SetSelection(object[] items, LiteRow[] rows, LiteColumn[] columns, UIElement[] cells)
        {
            if (_configuringSelection)
            {
                return;
            }
            _configuringSelection = true;

            items   = items ?? new object[0];
            rows    = rows ?? new LiteRow[0];
            columns = columns ?? new LiteColumn[0];
            cells   = cells ?? new UIElement[0];

            cells = cells
                    .Concat(rows.SelectMany(r => r.Cells))
                    .Concat(columns.SelectMany(c => c.Cells))
                    .Concat(_rows.Where(r => items.Contains(r.Item)).SelectMany(r => r.Cells))
                    .Distinct()
                    .ToArray();
            rows = rows
                   .Concat(cells.Select(LiteRow.GetRow))
                   .Distinct()
                   .ToArray();
            columns = columns
                      .Concat(cells.Select(LiteColumn.GetColumn))
                      .Distinct()
                      .ToArray();

            var selection = new List <DependencyObject>();

            if (SelectionMode.HasFlag(DataGridLiteSelectionMode.SingleCell))
            {
                selection.AddRange(cells.Take(1));
            }
            if (SelectionMode.HasFlag(DataGridLiteSelectionMode.MultiCell))
            {
                selection.AddRange(cells);
            }
            if (SelectionMode.HasFlag(DataGridLiteSelectionMode.SingleRow))
            {
                selection.AddRange(rows.Take(1));
            }
            if (SelectionMode.HasFlag(DataGridLiteSelectionMode.MultiRow))
            {
                selection.AddRange(rows);
            }
            if (SelectionMode.HasFlag(DataGridLiteSelectionMode.SingleColumn))
            {
                selection.AddRange(columns.Take(1));
            }
            if (SelectionMode.HasFlag(DataGridLiteSelectionMode.MultiColumn))
            {
                selection.AddRange(columns);
            }
            selection = selection.Distinct().ToList();

            // Sync all selection types
            SelectedCells   = selection.OfType <UIElement>().Where(s => cells.Contains(s)).ToArray();
            SelectedRows    = selection.OfType <LiteRow>().ToArray();
            SelectedColumns = selection.OfType <LiteColumn>().ToArray();
            SelectedItems   = selection.OfType <LiteRow>()
                              .Concat(SelectedCells.Select(LiteRow.GetRow))
                              .Select(r => r.Item)
                              .ToArray();
            SelectedItem = SelectedItems.FirstOrDefault();

            var selected = selection.Concat(SelectedItems.OfType <DependencyObject>()).ToList();

            selected.ForEach(i => SetIsSelected(i, true));

            var deselected = Items.OfType <DependencyObject>()
                             .Concat(_cells)
                             .Concat(_rows)
                             .Concat(_columns)
                             .Where(i => !selected.Contains(i))
                             .ToList();

            deselected.ForEach(i => SetIsSelected(i, false));

            _configuringSelection = false;
        }
예제 #3
0
        public static bool TryToSelect(IToolContext context, SelectionMode mode, SelectionTargets targets, Modifier selectionModifier, Point2 point, double radius, Modifier modifier)
        {
            var shapePoint =
                mode.HasFlag(SelectionMode.Point) &&
                targets.HasFlag(SelectionTargets.Shapes) ?
                context.HitTest?.TryToGetPoint(context.CurrentContainer.Shapes, point, radius, null) : null;

            var shape =
                mode.HasFlag(SelectionMode.Shape) &&
                targets.HasFlag(SelectionTargets.Shapes) ?
                context.HitTest?.TryToGetShape(context.CurrentContainer.Shapes, point, radius) : null;

            var guidePoint =
                mode.HasFlag(SelectionMode.Point) &&
                targets.HasFlag(SelectionTargets.Guides) ?
                context.HitTest?.TryToGetPoint(context.CurrentContainer.Guides, point, radius, null) : null;

            var guide =
                mode.HasFlag(SelectionMode.Shape) &&
                targets.HasFlag(SelectionTargets.Guides) ?
                context.HitTest?.TryToGetShape(context.CurrentContainer.Guides, point, radius) : null;

            if (shapePoint != null || shape != null || guidePoint != null || guide != null)
            {
                bool haveNewSelection =
                    (shapePoint != null && !context.Renderer.SelectedShapes.Contains(shapePoint)) ||
                    (shape != null && !context.Renderer.SelectedShapes.Contains(shape)) ||
                    (guidePoint != null && !context.Renderer.SelectedShapes.Contains(guidePoint)) ||
                    (guide != null && !context.Renderer.SelectedShapes.Contains(guide));

                if (context.Renderer.SelectedShapes.Count >= 1 &&
                    !haveNewSelection &&
                    !modifier.HasFlag(selectionModifier))
                {
                    return(true);
                }
                else
                {
                    if (shapePoint != null)
                    {
                        if (modifier.HasFlag(selectionModifier))
                        {
                            if (context.Renderer.SelectedShapes.Contains(shapePoint))
                            {
                                Log.Info($"Deselected Shape Point: {shapePoint.GetType()}");
                                shapePoint.Deselect(context.Renderer);
                            }
                            else
                            {
                                Log.Info($"Selected Shape Point: {shapePoint.GetType()}");
                                shapePoint.Select(context.Renderer);
                            }
                            return(context.Renderer.SelectedShapes.Count > 0);
                        }
                        else
                        {
                            context.Renderer.SelectedShapes.Clear();
                            Log.Info($"Selected Shape Point: {shapePoint.GetType()}");
                            shapePoint.Select(context.Renderer);
                            return(true);
                        }
                    }
                    else if (shape != null)
                    {
                        if (modifier.HasFlag(selectionModifier))
                        {
                            if (context.Renderer.SelectedShapes.Contains(shape))
                            {
                                Log.Info($"Deselected Shape: {shape.GetType()}");
                                shape.Deselect(context.Renderer);
                            }
                            else
                            {
                                Log.Info($"Selected Shape: {shape.GetType()}");
                                shape.Select(context.Renderer);
                            }
                            return(context.Renderer.SelectedShapes.Count > 0);
                        }
                        else
                        {
                            context.Renderer.SelectedShapes.Clear();
                            Log.Info($"Selected Shape: {shape.GetType()}");
                            shape.Select(context.Renderer);
                            return(true);
                        }
                    }
                    else if (guidePoint != null)
                    {
                        if (modifier.HasFlag(selectionModifier))
                        {
                            if (context.Renderer.SelectedShapes.Contains(guidePoint))
                            {
                                Log.Info($"Deselected Guide Point: {guidePoint.GetType()}");
                                guidePoint.Deselect(context.Renderer);
                            }
                            else
                            {
                                Log.Info($"Selected Guide Point: {guidePoint.GetType()}");
                                guidePoint.Select(context.Renderer);
                            }
                            return(context.Renderer.SelectedShapes.Count > 0);
                        }
                        else
                        {
                            context.Renderer.SelectedShapes.Clear();
                            Log.Info($"Selected Guide Point: {guidePoint.GetType()}");
                            guidePoint.Select(context.Renderer);
                            return(true);
                        }
                    }
                    else if (guide != null)
                    {
                        if (modifier.HasFlag(selectionModifier))
                        {
                            if (context.Renderer.SelectedShapes.Contains(guide))
                            {
                                Log.Info($"Deselected Guide: {guide.GetType()}");
                                guide.Deselect(context.Renderer);
                            }
                            else
                            {
                                Log.Info($"Selected Guide: {guide.GetType()}");
                                guide.Select(context.Renderer);
                            }
                            return(context.Renderer.SelectedShapes.Count > 0);
                        }
                        else
                        {
                            context.Renderer.SelectedShapes.Clear();
                            Log.Info($"Selected Guide: {guide.GetType()}");
                            guide.Select(context.Renderer);
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
예제 #4
0
        public static bool TryToSelect(IToolContext context, SelectionMode mode, SelectionTargets targets, Modifier selectionModifier, Rect2 rect, double radius, Modifier modifier)
        {
            var shapes =
                mode.HasFlag(SelectionMode.Shape) &&
                targets.HasFlag(SelectionTargets.Shapes) ?
                context.HitTest?.TryToGetShapes(context.CurrentContainer.Shapes, rect, radius) : null;

            var guides =
                mode.HasFlag(SelectionMode.Shape) &&
                targets.HasFlag(SelectionTargets.Guides) ?
                context.HitTest?.TryToGetShapes(context.CurrentContainer.Guides, rect, radius) : null;

            if (shapes != null || guides != null)
            {
                if (shapes != null)
                {
                    if (modifier.HasFlag(selectionModifier))
                    {
                        foreach (var shape in shapes)
                        {
                            if (context.Renderer.SelectedShapes.Contains(shape))
                            {
                                Log.Info($"Deselected Shape: {shape.GetType()}");
                                shape.Deselect(context.Renderer);
                            }
                            else
                            {
                                Log.Info($"Selected Shape: {shape.GetType()}");
                                shape.Select(context.Renderer);
                            }
                        }
                        return(context.Renderer.SelectedShapes.Count > 0);
                    }
                    else
                    {
                        Log.Info($"Selected Shapes: {shapes?.Count ?? 0}");
                        context.Renderer.SelectedShapes.Clear();
                        foreach (var shape in shapes)
                        {
                            shape.Select(context.Renderer);
                        }
                        return(true);
                    }
                }
                else if (guides != null)
                {
                    if (modifier.HasFlag(selectionModifier))
                    {
                        foreach (var guide in guides)
                        {
                            if (context.Renderer.SelectedShapes.Contains(guide))
                            {
                                Log.Info($"Deselected Guide: {guide.GetType()}");
                                guide.Deselect(context.Renderer);
                            }
                            else
                            {
                                Log.Info($"Selected Guide: {guide.GetType()}");
                                guide.Select(context.Renderer);
                            }
                        }
                        return(context.Renderer.SelectedShapes.Count > 0);
                    }
                    else
                    {
                        Log.Info($"Selected Guides: {guides?.Count ?? 0}");
                        context.Renderer.SelectedShapes.Clear();
                        foreach (var guide in guides)
                        {
                            guide.Select(context.Renderer);
                        }
                        return(true);
                    }
                }
            }

            return(false);
        }