Ejemplo n.º 1
0
 private void SetMouseHoverCore(Fragment fragment)
 {
     fragment.IsMouseHover = true;
     fragment.MouseEnter();
     MouseHoverFragments.Add(fragment);
 }
Ejemplo n.º 2
0
 public int Compare(Fragment fragment, Fragment _) => fragment.Bounds.Y < Offset ? -1 : 1;
Ejemplo n.º 3
0
        public virtual void MouseChanged(MouseState mouse)
        {
            if (Items.Count == 0)
            {
                return;
            }

            var pos = mouse.Position;

            int spatialBlockIndex = Math.Min(SpatialIndex.Count - 1, (int)(pos.Y / SpatialBlockHeight));
            int firstFragment = 0, lastFragment = Items.Count - 1;

            if (spatialBlockIndex >= 0)
            {
                lastFragment = SpatialIndex[spatialBlockIndex];
                if (spatialBlockIndex > 0)
                {
                    firstFragment = SpatialIndex[spatialBlockIndex - 1];
                }
            }

            var selectionLayer = Owner.SelectionLayer;
            var oldSelection   = new { selectionLayer.SelectionStart, selectionLayer.SelectionEnd };

            bool     selected = false;
            Fragment hitFragment = null, firstLineHit = null, lastLineHit = null;

            for (int i = firstFragment; i <= lastFragment; i++)
            {
                var fragment = Items[i];
                if (fragment.Contains(pos))
                {
                    hitFragment = fragment;

                    if (mouse.IsOverView)
                    {
                        TrySetMouseHover(fragment);
                    }
                    if (mouse.IsSelecting)
                    {
                        selected = selectionLayer.TrySetSelection(fragment);
                    }

                    break;
                }
                else if (lastLineHit == null)
                {
                    var bounds = fragment.Bounds;
                    if (pos.Y >= bounds.Top && pos.Y <= bounds.Bottom)
                    {
                        if (firstLineHit == null)
                        {
                            firstLineHit = fragment;
                        }
                        lastLineHit = fragment;
                    }
                }
            }

            if (mouse.IsSelecting && !selected)
            {
                if (hitFragment != null) // mouse is inside of some fragment
                {
                    // find nearest selectable fragment
                    selectionLayer.SetNearestSelection(hitFragment, pos);
                }
                else
                {
                    if (firstLineHit == null)
                    {
                        firstLineHit = Items.FirstOrDefault();
                        lastLineHit  = Items.LastOrDefault();
                    }

                    if (firstLineHit != null) // mouse is outside of any fragment
                    {
                        // find first or last selectable fragment
                        var firstBounds = firstLineHit.Bounds;
                        var lastBounds  = lastLineHit.Bounds;
                        if (pos.Y < firstBounds.Top || (pos.X < firstBounds.Left && pos.Y >= firstBounds.Top && pos.Y <= firstBounds.Bottom))
                        {
                            selectionLayer.SetNearestSelection(firstLineHit, pos);
                        }
                        else if (pos.Y > lastBounds.Bottom || (pos.X > lastBounds.Right && pos.Y >= lastBounds.Top && pos.Y <= lastBounds.Bottom))
                        {
                            selectionLayer.SetNearestSelection(lastLineHit, pos);
                        }
                    }
                }
            }

            LeaveUnhoveredFragments(mouse);

            if (mouse.IsSelecting && !oldSelection.Equals(new { selectionLayer.SelectionStart, selectionLayer.SelectionEnd }))
            {
                Owner.InvalidateArrange();
            }
        }