Example #1
0
        /* Gets how well an overlay at the given point will fit within the viewport. */
        public OverlayFit GetOverlayFit(Point point, ClientRect overlay, ClientRect viewport, ConnectedPosition position)
        {
            var x = point.X;
            var y = point.Y;

            var offsetX = GetOffset(position, "x");
            var offsetY = GetOffset(position, "y");

            // Account for the offsets since they could push the overlay out of the viewport.
            if (offsetX != null)
            {
                x += (double)offsetX;
            }

            if (offsetY != null)
            {
                y += (double)offsetY;
            }

            // How much the overlay would overflow at this position, on each side.
            var leftOverflow = 0 - x;

            var rightOverflow = (x + overlay.Width) - viewport.Width;

            var topOverflow = 0 - y;

            var bottomOverflow = (y + overlay.Height) - viewport.Height;

            // Visible parts of the element on each axis.
            var visibleWidth = this.SubtractOverflows(overlay.Width, new List <double> {
                leftOverflow, rightOverflow
            });

            var visibleHeight = this.SubtractOverflows(overlay.Height, new List <double> {
                topOverflow, bottomOverflow
            });

            var visibleArea = visibleWidth * visibleHeight;

            return(new OverlayFit()
            {
                VisibleArea = visibleArea,
                IsCompletelyWithinViewport = (overlay.Width * overlay.Height) == visibleArea,
                FitsInViewportVertically = visibleHeight == overlay.Height,
                FitsInViewportHorizontally = visibleWidth == overlay.Width,
            });
        }
Example #2
0
        /* Returns the ClientRect of the current origin. */
        public async Task <ClientRect> GetOriginRect(DnetOverlayInterop dnetOverlayInterop)
        {
            if (!string.IsNullOrEmpty(_originElementReference.Id))
            {
                _origin = await dnetOverlayInterop.GetBoundingClientRect(_originElementReference);
            }

            var originRect = new ClientRect
            {
                Top    = _origin.Top,
                Left   = _origin.Left,
                Right  = _origin.Left + _origin.Width,
                Bottom = _origin.Top + _origin.Height,
                Width  = _origin.Width,
                Height = _origin.Height
            };

            return(originRect);
        }