Exemplo n.º 1
0
        public void MouseMove(Point position)
        {
            if (_workspace == null || _workspace.InputService == null)
            {
                return;
            }

            lastPointerPosition = position;
            var delta = lastPanPoint - position;

            if (panning)
            {
                var vp    = _workspace.ActiveViewPort;
                var scale = vp.ViewHeight / Height;
                var dx    = vp.BottomLeft.X + delta.X * scale;
                var dy    = vp.BottomLeft.Y - delta.Y * scale;
                _workspace.Update(activeViewPort: vp.Update(bottomLeft: new Point(dx, dy, vp.BottomLeft.Z)));
                lastPanPoint         = position;
                firstSelectionPoint -= delta;
            }

            if (selecting)
            {
                var left   = Math.Min(position.X, firstSelectionPoint.X);
                var top    = Math.Min(position.Y, firstSelectionPoint.Y);
                var width  = Math.Abs(position.X - firstSelectionPoint.X);
                var height = Math.Abs(position.Y - firstSelectionPoint.Y);
                var rect   = new Rect(left, top, width, height);
                var mode   = position.X < firstSelectionPoint.X
                    ? SelectionMode.PartialEntity
                    : SelectionMode.WholeEntity;
                currentSelectionPoint = position;
                UpdateSelectionRectangle(new SelectionState(rect, mode));
            }

            updateSnapPointsTask.ContinueWith(_ =>
            {
                var snapPoint = GetActiveModelPoint(position, updateSnapPointsCancellationTokenSource.Token);
                CursorWorldLocationUpdated?.Invoke(this, snapPoint.WorldPoint);
                CurrentSnapPointUpdated?.Invoke(this, snapPoint);
                UpdateRubberBandLines(snapPoint.WorldPoint);
                if ((_workspace.InputService.AllowedInputTypes & InputType.Point) == InputType.Point ||
                    selectingRectangle)
                {
                    DrawSnapPoint(snapPoint, GetNextDrawSnapPointId());
                }
            }, updateSnapPointsCancellationTokenSource.Token).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public void Zoom(ZoomDirection direction, Point zoomCenter)
        {
            // scale everything
            double scale = ZoomScale;

            switch (direction)
            {
            case ZoomDirection.In:
                scale = 1.0 / scale;
                break;

            case ZoomDirection.Out:
                break;
            }

            // center zoom operation on mouse
            lastPointerPosition = zoomCenter;
            var vp          = _workspace.ActiveViewPort;
            var oldHeight   = vp.ViewHeight;
            var oldWidth    = Width * oldHeight / Height;
            var newHeight   = oldHeight * scale;
            var newWidth    = oldWidth * scale;
            var heightDelta = newHeight - oldHeight;
            var widthDelta  = newWidth - oldWidth;

            var relHoriz     = zoomCenter.X / Width;
            var relVert      = (Height - zoomCenter.Y) / Height;
            var botLeftDelta = new Vector(relHoriz * widthDelta, relVert * heightDelta, 0.0);
            var newVp        = vp.Update(
                bottomLeft: (Point)(vp.BottomLeft - botLeftDelta),
                viewHeight: vp.ViewHeight * scale);

            _workspace.Update(activeViewPort: newVp);

            updateSnapPointsTask.ContinueWith(_ =>
            {
                var snapPoint = GetActiveModelPoint(zoomCenter, updateSnapPointsCancellationTokenSource.Token);
                CursorWorldLocationUpdated?.Invoke(this, snapPoint.WorldPoint);
                if ((_workspace.InputService.AllowedInputTypes & InputType.Point) == InputType.Point)
                {
                    DrawSnapPoint(snapPoint, GetNextDrawSnapPointId());
                }
            }).ConfigureAwait(false);
        }