Beispiel #1
0
        private void ZoomControl_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            switch (ModifierMode)
            {
            case ZoomViewModifierMode.None:
                return;

            case ZoomViewModifierMode.Pan:
                var translate = _startTranslate + (e.GetPosition(this) - _mouseDownPos);
                TranslateX = translate.X;
                TranslateY = translate.Y;
                Mode       = ZoomControlModes.Custom;
                break;

            case ZoomViewModifierMode.ZoomIn:
                break;

            case ZoomViewModifierMode.ZoomOut:
                break;

            case ZoomViewModifierMode.ZoomBox:
                var pos   = e.GetPosition(this);
                var x     = Math.Min(_mouseDownPos.X, pos.X);
                var y     = Math.Min(_mouseDownPos.Y, pos.Y);
                var sizeX = Math.Abs(_mouseDownPos.X - pos.X);
                var sizeY = Math.Abs(_mouseDownPos.Y - pos.Y);
                ZoomBox = new Rect(x, y, sizeX, sizeY);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #2
0
        private void DoZoom(double deltaZoom, int mod, Point origoPosition, Point startHandlePosition, Point targetHandlePosition, bool setDelta = false)
        {
            var startZoom   = Zoom;
            var currentZoom = setDelta ? deltaZoom : (mod == -1 ? (startZoom / deltaZoom) : (startZoom * deltaZoom));

            currentZoom = Math.Max(MinZoom, Math.Min(MaxZoom, currentZoom));

            var startTranslate = new Point(TranslateX, TranslateY);

            var v       = startHandlePosition.Subtract(origoPosition);
            var vTarget = targetHandlePosition.Subtract(origoPosition);

            var targetPoint          = v.Subtract(startTranslate).Div(startZoom);
            var zoomedTargetPointPos = targetPoint.Mul(currentZoom).Sum(startTranslate);
            var endTranslate         = vTarget.Subtract(zoomedTargetPointPos);


            if (setDelta)
            {
                var transformX = GetCoercedTranslate(endTranslate.X);
                var transformY = GetCoercedTranslate(endTranslate.Y);
                DoZoomAnimation(currentZoom, transformX, transformY);
            }
            else
            {
                var transformX = GetCoercedTranslate(TranslateX + endTranslate.X);
                var transformY = GetCoercedTranslate(TranslateY + endTranslate.Y);
                DoZoomAnimation(currentZoom, transformX, transformY);
            }
            Mode = ZoomControlModes.Custom;
        }
Beispiel #3
0
 /// <summary>
 /// Zoom to fill screen area with the content
 /// </summary>
 public void ZoomToFill()
 {
     if (Mode == ZoomControlModes.Fill)
     {
         DoZoomToFill();
     }
     else
     {
         Mode = ZoomControlModes.Fill;
     }
 }
Beispiel #4
0
 /// <summary>
 /// Zoom to original size
 /// </summary>
 public void ZoomToOriginal()
 {
     if (Mode == ZoomControlModes.Original)
     {
         DoZoomToOriginal();
     }
     else
     {
         Mode = ZoomControlModes.Original;
     }
 }
Beispiel #5
0
        private static void Mode_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ZoomControl      zc   = (ZoomControl)d;
            ZoomControlModes mode = (ZoomControlModes)e.NewValue;

            if (mode == ZoomControlModes.Fill)
            {
                zc.TranslateX = 0;
                zc.TranslateY = 0;
                zc.Zoom       = 1;
            }
        }
Beispiel #6
0
        private void OnMouseDown(MouseButtonEventArgs e, bool isPreview)
        {
            if ((Keyboard.Modifiers & ModifierKeys.Control) > 0 && e.MiddleButton == MouseButtonState.Pressed)
            {
                Mode      = ZoomControlModes.Fill;
                e.Handled = true;
                return;
            }

            if (ModifierMode != ZoomViewModifierMode.None)
            {
                return;
            }

            switch (Keyboard.Modifiers)
            {
            case ModifierKeys.None:
                if (!isPreview)
                {
                    ModifierMode = ZoomViewModifierMode.Pan;
                }
                break;

            case ModifierKeys.Alt:
                ModifierMode = ZoomViewModifierMode.ZoomBox;
                break;

            case ModifierKeys.Control:
                break;

            case ModifierKeys.Shift:
                ModifierMode = ZoomViewModifierMode.Pan;
                break;

            case ModifierKeys.Windows:
                break;

            default:
                return;
            }

            if (ModifierMode == ZoomViewModifierMode.None)
            {
                return;
            }

            _mouseDownPos   = e.GetPosition(this);
            _startTranslate = new Vector(TranslateX, TranslateY);
            Mouse.Capture(this);
            PreviewMouseMove += ZoomControl_PreviewMouseMove;
        }
Beispiel #7
0
        private void DoZoom(double deltaZoom, Point origoPosition, Point startHandlePosition, Point targetHandlePosition)
        {
            var startZoom   = Zoom;
            var currentZoom = startZoom * deltaZoom;

            currentZoom = Math.Max(MinZoom, Math.Min(MaxZoom, currentZoom));

            var startTranslate = new Vector(TranslateX, TranslateY);

            var v       = startHandlePosition - origoPosition;
            var vTarget = targetHandlePosition - origoPosition;

            var targetPoint          = (v - startTranslate) / startZoom;
            var zoomedTargetPointPos = targetPoint * currentZoom + startTranslate;
            var endTranslate         = vTarget - zoomedTargetPointPos;

            var transformX = GetCoercedTranslateX(TranslateX + endTranslate.X, currentZoom);
            var transformY = GetCoercedTranslateY(TranslateY + endTranslate.Y, currentZoom);

            DoZoomAnimation(currentZoom, transformX, transformY);
            Mode = ZoomControlModes.Custom;
        }
Beispiel #8
0
        private void DoZoom(double deltaZoom, Point origoPosition, Point startHandlePosition, Point targetHandlePosition)
        {
            double startZoom   = Zoom;
            double currentZoom = startZoom * deltaZoom;

            currentZoom = Math.Max(MinZoom, Math.Min(MaxZoom, currentZoom));

            var startTranslate = new Vector(TranslateX, TranslateY);

            var v       = (startHandlePosition - origoPosition);
            var vTarget = (targetHandlePosition - origoPosition);

            var targetPoint          = (v - startTranslate) / startZoom;
            var zoomedTargetPointPos = targetPoint * currentZoom + startTranslate;
            var endTranslate         = vTarget - zoomedTargetPointPos;

            double transformX = _presenter == null ? 0.0 : TranslateX + endTranslate.X;
            double transformY = _presenter == null ? 0.0 : TranslateY + endTranslate.Y;

            DoZoomAnimation(currentZoom, transformX, transformY);
            Mode = ZoomControlModes.Custom;
        }
Beispiel #9
0
        private void DoZoom(double deltaZoom, Point origoPosition, Point startHandlePosition, Point targetHandlePosition)
        {
            double startZoom   = Zoom;
            double currentZoom = startZoom * deltaZoom;

            currentZoom = Math.Max(MinZoom, Math.Min(MaxZoom, currentZoom));

            Vector startTranslate = new Vector(TranslateX, TranslateY);

            Vector v       = (startHandlePosition - origoPosition);
            Vector vTarget = (targetHandlePosition - origoPosition);

            Vector targetPoint          = (v - startTranslate) / startZoom;
            Vector zoomedTargetPointPos = targetPoint * currentZoom + startTranslate;
            Vector endTranslate         = vTarget - zoomedTargetPointPos;

            double transformX = TranslateX + endTranslate.X;
            double transformY = TranslateY + endTranslate.Y;

            TranslateX = transformX;
            TranslateY = transformY;
            Zoom       = currentZoom;
            Mode       = ZoomControlModes.Custom;
        }
 public void ZoomToFill()
 {
     Mode = ZoomControlModes.Fill;
 }
 public void ZoomToOriginal()
 {
     Mode = ZoomControlModes.Original;
 }
        private void DoZoom(double deltaZoom, Point origoPosition, Point startHandlePosition, Point targetHandlePosition)
        {
            double startZoom = Zoom;
            double currentZoom = startZoom * deltaZoom;
            currentZoom = Math.Max(MinZoom, Math.Min(MaxZoom, currentZoom));

            var startTranslate = new Vector(TranslateX, TranslateY);

            var v = (startHandlePosition - origoPosition);
            var vTarget = (targetHandlePosition - origoPosition);

            var targetPoint = (v - startTranslate) / startZoom;
            var zoomedTargetPointPos = targetPoint * currentZoom + startTranslate;
            var endTranslate = vTarget - zoomedTargetPointPos;

            double transformX = GetCoercedTranslateX(TranslateX + endTranslate.X, currentZoom);
            double transformY = GetCoercedTranslateY(TranslateY + endTranslate.Y, currentZoom);

            DoZoomAnimation(currentZoom, transformX, transformY);
            Mode = ZoomControlModes.Custom;
        }
Beispiel #13
0
 public void ZoomToOriginal()
 {
     Mode = ZoomControlModes.Original;
 }
Beispiel #14
0
 /// <summary>
 /// Zoom to fill screen area with the content
 /// </summary>
 public void ZoomToFill()
 {
     if(Mode == ZoomControlModes.Fill)
         DoZoomToFill();
     else Mode = ZoomControlModes.Fill;
 }
Beispiel #15
0
        private void DoZoom(double deltaZoom, int mod, Point origoPosition, Point startHandlePosition, Point targetHandlePosition, bool setDelta = false)
        {
            var startZoom = Zoom;
            var currentZoom = setDelta ? deltaZoom : (mod == -1 ? (startZoom / deltaZoom) : (startZoom * deltaZoom));
            currentZoom = Math.Max(MinZoom, Math.Min(MaxZoom, currentZoom));

            var startTranslate = new Vector(TranslateX, TranslateY);

            var v = (startHandlePosition - origoPosition);
            var vTarget = (targetHandlePosition - origoPosition);

            var targetPoint = (v - startTranslate) / startZoom;
            var zoomedTargetPointPos = targetPoint * currentZoom + startTranslate;
            var endTranslate = vTarget - zoomedTargetPointPos;


            if (setDelta)
            {
                var transformX = GetCoercedTranslateX(endTranslate.X, currentZoom);
                var transformY = GetCoercedTranslateY(endTranslate.Y, currentZoom);
                DoZoomAnimation(currentZoom, transformX, transformY);
            }
            else
            {
                var transformX = GetCoercedTranslateX(TranslateX + endTranslate.X, currentZoom);
                var transformY = GetCoercedTranslateY(TranslateY + endTranslate.Y, currentZoom);
                DoZoomAnimation(currentZoom, transformX, transformY);
            }
            Mode = ZoomControlModes.Custom;
        }
Beispiel #16
0
 /// <summary>
 /// Zoom to original size
 /// </summary>
 public void ZoomToOriginal()
 {
     if (Mode == ZoomControlModes.Original)
         DoZoomToOriginal();
     else Mode = ZoomControlModes.Original;
 }
Beispiel #17
0
 private void ResetExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     Mode = ZoomControlModes.Fill;
 }
Beispiel #18
0
 public void ZoomToFill()
 {
     Mode = ZoomControlModes.Fill;
 }
Beispiel #19
0
        private void DoZoom(double deltaZoom, int mod, Point origoPosition, Point startHandlePosition, Point targetHandlePosition, bool setDelta = false)
        {
            var startZoom = Zoom;
            var currentZoom = setDelta ? deltaZoom : (mod == -1 ? (startZoom / deltaZoom) : (startZoom * deltaZoom));
            currentZoom = Math.Max(MinZoom, Math.Min(MaxZoom, currentZoom));

            var startTranslate = new Point(TranslateX, TranslateY);

            var v = startHandlePosition.Subtract(origoPosition);
            var vTarget = targetHandlePosition.Subtract(origoPosition);

            var targetPoint = v.Subtract(startTranslate).Div(startZoom);
            var zoomedTargetPointPos = targetPoint.Mul(currentZoom).Sum(startTranslate);
            var endTranslate = vTarget.Subtract(zoomedTargetPointPos);


            if (setDelta)
            {
                var transformX = GetCoercedTranslate(endTranslate.X);
                var transformY = GetCoercedTranslate(endTranslate.Y);
                DoZoomAnimation(currentZoom, transformX, transformY);
            }
            else
            {
                var transformX = GetCoercedTranslate(TranslateX + endTranslate.X);
                var transformY = GetCoercedTranslate(TranslateY + endTranslate.Y);
                DoZoomAnimation(currentZoom, transformX, transformY);
            }
            Mode = ZoomControlModes.Custom;
        }