Exemplo n.º 1
0
        public void UpdatePositions()
        {
            var displayStartPointX = X + StartPointX * Scale;
            var displayStartPointY = Y + StartPointY * Scale;

            var displayEndPointX = X + EndPointX * Scale;
            var displayEndPointY = Y + EndPointY * Scale;

            var centerX = (displayStartPointX + displayEndPointX) / 2;
            var centerY = (displayStartPointY + displayEndPointY) / 2;

            _line.X1 = displayStartPointX;
            _line.Y1 = displayStartPointY;

            _line.X2 = displayEndPointX;
            _line.Y2 = displayEndPointY;

//            var leftCornerX = displayStartPointX < displayEndPointX ? displayStartPointX : displayEndPointX;
//            var leftCornerY = displayStartPointY < displayEndPointY ? displayStartPointY : displayEndPointY;
            var displayRegionWidth = RegionWidth * Scale;

            var    startVector = new Vector(displayStartPointX, displayStartPointY);
            var    endVector   = new Vector(displayEndPointX, displayEndPointY);
            Vector linkVector  = (startVector - endVector);
            var    length      = linkVector.Length;

            var angle = Vector.AngleBetween(new Vector(0, 100), linkVector);

            RegionIndicatorMarker.SetValue(Canvas.LeftProperty, centerX);
            RegionIndicatorMarker.SetValue(Canvas.TopProperty, centerY);
            RegionIndicatorMarker.Width  = displayRegionWidth * 2;
            RegionIndicatorMarker.Height = length;


            var renderTransform = new TransformGroup();

//            renderTransform.Children.Add(new TranslateTransform(0 - (int)displayRegionWidth / 2, 0));
            renderTransform.Children.Add(new TranslateTransform(0 - (int)(displayRegionWidth), 0 - (int)(length / 2)));
            renderTransform.Children.Add(new RotateTransform(angle)
            {
                //                                                         CenterX = 0 - (int)displayRegionWidth / 2
            });
            RegionIndicatorMarker.RenderTransform = renderTransform;


            _line.Stroke          = Stroke ?? Brushes.Magenta;
            _line.StrokeThickness = StrokeThickness <= 0 ? 2 : StrokeThickness;
            _line.StrokeDashArray = StrokeDashArray;

            RegionIndicatorMarker.Stroke          = Stroke ?? Brushes.Magenta;
            RegionIndicatorMarker.StrokeThickness = StrokeThickness <= 0 ? 2 : StrokeThickness;
            RegionIndicatorMarker.StrokeDashArray = StrokeDashArray;
        }
        public void UpdatePositions()
        {
            var displayWidth  = RectWidth * Scale;
            var displayHeight = RectHeight * Scale;

            var topLeftX = X + RectCenterX * Scale - displayWidth / 2.0;
            var topLeftY = Y + RectCenterY * Scale - displayHeight / 2.0;

            RegionIndicatorMarker.SetValue(Canvas.LeftProperty, topLeftX);
            RegionIndicatorMarker.SetValue(Canvas.TopProperty, topLeftY);
            RegionIndicatorMarker.Width  = displayWidth;
            RegionIndicatorMarker.Height = displayHeight;

            RegionIndicatorMarker.Stroke          = Stroke ?? Brushes.Magenta;
            RegionIndicatorMarker.StrokeThickness = StrokeThickness <= 0 ? 2 : StrokeThickness;
            RegionIndicatorMarker.StrokeDashArray = StrokeDashArray;
        }