Example #1
0
        /// <summary>
        /// Returns a value, which determines that the image edge is visible.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="imageEdge">The image edge.</param>
        /// <returns>
        /// <b>true</b> - if image edge is visible.
        /// <b>false</b> - if image edge is not visible.
        /// </returns>
        private bool GetIsImageEdgeVisible(VintasoftImage image, Vintasoft.Imaging.AnchorType imageEdge)
        {
            // get image viewer state for the image
            Vintasoft.Imaging.UI.ImageViewerState focusedImageViewerState = ImageViewer.GetViewerState(image);

            // get the visible image rectangle in image viewer
            RectangleF imageVisibleRect;

            if (ImageViewer.IsMultipageDisplayMode)
            {
                imageVisibleRect = ImageViewer.ClientRectangle;
            }
            else
            {
                imageVisibleRect = focusedImageViewerState.ImageVisibleRect;
            }

            // get the image rectangle in image viewer
            RectangleF imageRect;

            if (ImageViewer.IsMultipageDisplayMode)
            {
                imageRect = focusedImageViewerState.ImageBoundingBox;
            }
            else
            {
                imageRect = new RectangleF(0, 0, ImageViewer.Image.Width, ImageViewer.Image.Height);
            }
            if (imageRect == RectangleF.Empty)
            {
                return(false);
            }

            // get the image "anchor" line
            RectangleF imageLine = RectangleF.Empty;

            if (imageEdge == Vintasoft.Imaging.AnchorType.Bottom)
            {
                // get bottom line of image
                imageLine = new RectangleF(imageRect.X, imageRect.Y + imageRect.Height - 1, imageRect.Width, 1);
            }
            else if (imageEdge == Vintasoft.Imaging.AnchorType.Top)
            {
                // get top line of image
                imageLine = new RectangleF(imageRect.X, imageRect.Y, imageRect.Width, 1);
            }
            else if (imageEdge == Vintasoft.Imaging.AnchorType.Left)
            {
                // get left line of image
                imageLine = new RectangleF(0, 0, 1, ImageViewer.Image.Height);
            }
            else if (imageEdge == Vintasoft.Imaging.AnchorType.Right)
            {
                // get right line of image
                imageLine = new RectangleF(ImageViewer.Image.Width - 1, 0, 1, ImageViewer.Image.Height);
            }

            // return a value that indicates whether the visible rectangle intersects with image line
            return(imageVisibleRect.IntersectsWith(imageLine));
        }
Example #2
0
        /// <summary>
        /// Inverts the specified anchor.
        /// </summary>
        /// <param name="anchor">The anchor.</param>
        /// <returns>
        /// The inverted value.
        /// </returns>
        private Vintasoft.Imaging.AnchorType Invert(Vintasoft.Imaging.AnchorType anchor)
        {
            switch (anchor)
            {
            case Vintasoft.Imaging.AnchorType.Top:
                return(Vintasoft.Imaging.AnchorType.Bottom);

            case Vintasoft.Imaging.AnchorType.Bottom:
                return(Vintasoft.Imaging.AnchorType.Top);

            case Vintasoft.Imaging.AnchorType.Left:
                return(Vintasoft.Imaging.AnchorType.Right);

            case Vintasoft.Imaging.AnchorType.Right:
                return(Vintasoft.Imaging.AnchorType.Left);

            default:
                throw new NotImplementedException();
            }
        }
Example #3
0
        /// <summary>
        /// Scrolls the image viewer.
        /// </summary>
        /// <param name="scrollStepSize">A scroll step size in pixels.</param>
        private void Scroll(int scrollStepSize)
        {
            VintasoftImage image = ImageViewer.Image;

            if (image == null)
            {
                return;
            }

            // determine the scroll direction
            bool scrollForward = true;

            _scrollAction = ScrollAction.MoveToNextPage;
            Vintasoft.Imaging.AnchorType imageEdge = Vintasoft.Imaging.AnchorType.Bottom;

            // if scroll step size is negative
            if (scrollStepSize < 0)
            {
                // change the scroll direction
                scrollForward = false;
                _scrollAction = ScrollAction.MoveToPreviousPage;
                imageEdge     = Invert(imageEdge);
            }

            // get new scroll step size according to the focused image resolution
            float newScrollStepSize = scrollStepSize * (float)image.Resolution.Vertical / 96.0f;

            // if edge (top/bottom) of focused image is visible
            if (GetIsImageEdgeVisible(image, imageEdge))
            {
                // if focused image is first image in image viewer
                // and viewer must be scrolled backward
                if (ImageViewer.FocusedIndex == 0 && !scrollForward)
                {
                    return;
                }

                // if focused image is last in image viewer
                // and viewer must be scrolled forward
                if (ImageViewer.FocusedIndex >= ImageViewer.Images.Count - 1 && scrollForward)
                {
                    return;
                }

                _isPageChanging = true;

                int newFocusedIndex = ImageViewer.FocusedIndex;
                if (scrollForward)
                {
                    newFocusedIndex++;
                }
                else
                {
                    newFocusedIndex--;
                }

                // if image viewer is in multipage mode
                if (ImageViewer.IsMultipageDisplayMode)
                {
                    // change focused image
                    ChangeFocusedImage(newFocusedIndex);

                    _isPageChanging = false;
                }
                // if image viewer is in single page mode
                else
                {
                    ImageViewer.ImageLoading += new EventHandler <ImageLoadingEventArgs>(ImageViewer_ImageLoading);
                    // save information about previous focused image
                    _previouslyFocusedImageAutoScrollPositionX = ImageViewer.ViewerState.AutoScrollPosition.X;
                    _previouslyFocusedImageWidth = ImageViewer.Image.Width;
                    // change focused index
                    ChangeFocusedImage(newFocusedIndex);
                }
            }

            // get the center point of previous focused image
            PointF previousFocusedImageCenterPoint = GetCenterPoint(ImageViewer.Image);

            // get the scroll point of new focused image
            PointF newFocusedImageScrollPoint;

            switch (ImageViewer.ImageRotationAngle)
            {
            case 90:
                newFocusedImageScrollPoint = new PointF(
                    previousFocusedImageCenterPoint.X + newScrollStepSize,
                    previousFocusedImageCenterPoint.Y);
                break;

            case 180:
                newFocusedImageScrollPoint = new PointF(
                    previousFocusedImageCenterPoint.X,
                    previousFocusedImageCenterPoint.Y - newScrollStepSize);
                break;

            case 270:
                newFocusedImageScrollPoint = new PointF(
                    previousFocusedImageCenterPoint.X - newScrollStepSize,
                    previousFocusedImageCenterPoint.Y);
                break;

            default:
                newFocusedImageScrollPoint = new PointF(
                    previousFocusedImageCenterPoint.X,
                    previousFocusedImageCenterPoint.Y + newScrollStepSize);
                break;
            }

            // scroll to the scroll point on new focused image
            ImageViewer.ScrollToPoint(newFocusedImageScrollPoint,
                                      Vintasoft.Imaging.AnchorType.Bottom |
                                      Vintasoft.Imaging.AnchorType.Left |
                                      Vintasoft.Imaging.AnchorType.Right |
                                      Vintasoft.Imaging.AnchorType.Top);

            _scrollAction = ScrollAction.None;
            SetFocusToVisibleImage();
        }