Exemplo n.º 1
0
        protected virtual void OnSliceHovered()
        {
            if (Disposing || IsDisposed)
            {
                return;
            }

            var hoveredItem = GetRectangleUnderMouse();

            if (ShowToolTip)
            {
                if (hoveredItem == null)
                {
                    toolTip1.Hide(this);
                }
                else if (!toolTip1.Active || _currentHoveredRectangle != hoveredItem)
                {
                    toolTip1.Show(hoveredItem.Slice.ToElementNames(), this, new Point(0, Height + 2));
                }
            }

            if (_currentHoveredRectangle != hoveredItem && hoveredItem != null)
            {
                SliceHovered?.Invoke(this, new SliceEventArgs(hoveredItem));
            }

            _currentHoveredRectangle = hoveredItem;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculate area to be drawn for this rectangle.
        /// Make sure to leave a 1px border around the map and between other rectangles.
        /// </summary>
        private void CalculatePaintRect(SliceRectangle <object> r)
        {
            r.PaintRect = new Rectangle(r.X == 0 ? 1 : r.X, r.Y == 0 ? 1 : r.Y, r.Width - (r.X == 0 ? 2 : 1), r.Height - (r.Y == 0 ? 2 : 1));

            r.PaintRect.Offset(ClientRectangle.Location);

            // Avoid unnecessary drawing
            if (r.PaintRect.Height < 2 || r.PaintRect.Width < 2)
            {
                r.PaintRect = Rectangle.Empty;
            }
        }
Exemplo n.º 3
0
        public static IEnumerable <SliceRectangle <T> > GetRectangles <T>(SliceRectangle <T> sliceRectangle)
        {
            var isHorizontalSplit = sliceRectangle.Width >= sliceRectangle.Height;
            var currentPos        = 0;

            if (sliceRectangle.Slice?.SubSlices == null)
            {
                yield break;
            }

            foreach (var subSlice in sliceRectangle.Slice.SubSlices)
            {
                var subRect = new SliceRectangle <T> {
                    Slice = subSlice
                };
                int rectSize;

                if (isHorizontalSplit)
                {
                    rectSize       = (int)Math.Round(sliceRectangle.Width * subSlice.Size);
                    subRect.X      = sliceRectangle.X + currentPos;
                    subRect.Y      = sliceRectangle.Y;
                    subRect.Width  = rectSize;
                    subRect.Height = sliceRectangle.Height;
                }
                else
                {
                    rectSize       = (int)Math.Round(sliceRectangle.Height * subSlice.Size);
                    subRect.X      = sliceRectangle.X;
                    subRect.Y      = sliceRectangle.Y + currentPos;
                    subRect.Width  = sliceRectangle.Width;
                    subRect.Height = rectSize;
                }

                currentPos += rectSize;

                if (subSlice.Elements.Count > 1)
                {
                    foreach (var sr in GetRectangles(subRect))
                    {
                        yield return(sr);
                    }
                }
                else if (subSlice.Elements.Count == 1)
                {
                    yield return(subRect);
                }
            }
        }
Exemplo n.º 4
0
        public static IEnumerable <SliceRectangle <T> > GetRectangles <T>(Slice <T> slice, int width, int height)
        {
            if (slice == null)
            {
                yield break;
            }

            var area = new SliceRectangle <T>
            {
                Slice = slice, Width = width, Height = height
            };

            // Handle single-item lists
            if (slice.SubSlices == null && slice.Elements.Count == 1)
            {
                var sliceRectangle = new SliceRectangle <T>
                {
                    X      = 0,
                    Y      = 0,
                    Height = height,
                    Width  = width,
                    Slice  = slice
                };
                yield return(sliceRectangle);

                yield break;
            }

            foreach (var rect in GetRectangles(area))
            {
                // Make sure no rectangle go outside the original area
                if (rect.X + rect.Width > area.Width)
                {
                    rect.Width = area.Width - rect.X;
                }
                if (rect.Y + rect.Height > area.Height)
                {
                    rect.Height = area.Height - rect.Y;
                }

                yield return(rect);
            }
        }
Exemplo n.º 5
0
        public static IEnumerable <SliceRectangle <T> > GetRectangles <T>(Slice <T> slice, int width, int height)
        {
            var area = new SliceRectangle <T>
            {
                Slice = slice, Width = width, Height = height
            };

            foreach (var rect in GetRectangles(area))
            {
                // Make sure no rectangle go outside the original area
                if (rect.X + rect.Width > area.Width)
                {
                    rect.Width = area.Width - rect.X;
                }
                if (rect.Y + rect.Height > area.Height)
                {
                    rect.Height = area.Height - rect.Y;
                }

                yield return(rect);
            }
        }
Exemplo n.º 6
0
 public SliceClickedEventArgs(SliceRectangle <object> rectangle, ICollection <object> o, bool addToSelection)
     : base(rectangle, o)
 {
     AddToSelection = addToSelection;
 }
Exemplo n.º 7
0
 public SliceEventArgs(SliceRectangle <object> rectangle, ICollection <object> o)
 {
     Rectangle = rectangle;
     Objects   = o;
 }
Exemplo n.º 8
0
 public SliceEventArgs(SliceRectangle <object> rectangle)
     : this(rectangle, rectangle.Slice.Elements.Select(x => x.Object).ToList())
 {
 }