Exemplo n.º 1
0
 internal static Matrix CreateMatrix(GeneralTransform transform)
 {
     if (transform != null && !IsIdentity(transform))
     {
         Point offset = transform.Transform(new Point(0, 0));
         Point i = transform.Transform(new Point(1, 0)).Minus(offset);
         Point j = transform.Transform(new Point(0, 1)).Minus(offset);
         Matrix matrix = new Matrix(i.X, i.Y, j.X, j.Y, offset.X, offset.Y);
         return matrix;
     }
     else
     {
         return Matrix.Identity;
     }
 }
Exemplo n.º 2
0
		static Rect TransformRectByMiddlePoint(GeneralTransform transform, Rect r)
		{
			// we don't want to adjust the size of the control when moving it out of a scaled
			// container, we just want to move it correcly
			Point p = new Point(r.Left + r.Width / 2, r.Top + r.Height / 2);
			Vector movement = transform.Transform(p) - p;
			return new Rect(r.TopLeft + movement, r.Size);
		}
        /// <summary>
        /// Handles when the mouse moves
        /// </summary>
        /// <param name="mousePos"></param>
        /// <param name="screenToSceneTransform"></param>
        public void MouseMoved(Point mousePos, GeneralTransform screenToSceneTransform)
        {
            if (screenToSceneTransform == null)
                return;
            // Convert the mouse coordinates to scene coordinates
            mousePos = screenToSceneTransform.Transform(mousePos);

            bool newLocked = false;
            Point newPoint = mousePos;

            if (points.Count > 0)
            {
                // Transform the minimum distance ignoring the translation
                Rect minimumBounds = screenToSceneTransform.TransformBounds(minimumDistance);

                double nearestDistanceSquared;
                newPoint = GetEllipseScaledNearestPoint(points, mousePos, (Vector) (minimumBounds.Size),
                                                        out nearestDistanceSquared);
                newLocked = nearestDistanceSquared <= 1;
            }

            bool lockedChanged = newLocked != locked;
            bool pointChanged = newPoint != closestPoint;

            locked = newLocked;
            closestPoint = newPoint;

            if ((pointChanged && locked) || lockedChanged)
            {
                OnClosestPointChanged();
            }
        }
 /// <summary>
 /// Handles when the mouse moves
 /// </summary>
 /// <param name="mousePos"></param>
 /// <param name="screenToSceneTransform"></param>
 public Point MouseMoved(Point mousePos, GeneralTransform screenToSceneTransform) {
   if(screenToSceneTransform == null)
     return new Point(0, 0);
   // Convert the mouse coordinates to scene coordinates
   mousePos = screenToSceneTransform.Transform(mousePos);
   // Transform the minimum distance ignoring the translation
   Rect minimumBounds = screenToSceneTransform.TransformBounds(_minimumDistance);
   return MouseMoved(mousePos, minimumBounds);
 }
 public void QueueMouseMove(Point mousePos, GeneralTransform screenToSceneTransform) {
   mousePos = screenToSceneTransform.Transform(mousePos);
   Rect minimumBounds = screenToSceneTransform.TransformBounds(_minimumDistance);
   _mousePosQueue.Add(new PointAndBounds(mousePos, minimumBounds));
 }
 void ArrangeTicksAndMarkers(IEnumerable<DataAxisTick> ticksOrMarkers, GeneralTransform axisTransform, Size arrangeSize, double tickLength)
 {
     foreach (var tick in ticksOrMarkers)
     {
         Point tickLabelPosition;
         switch (AxisLocation)
         {
             case AxisLocation.Top:
             case AxisLocation.Bottom:
                 tick.Location = axisTransform.Transform(new Point(tick.Value, 0)).X;
                 if (tick.TextBlockBorder != null)
                 {
                     var yPos = tickLength;
                     if (AxisLocation == AxisLocation.Top) yPos += tick.TextBlockBorder.DesiredSize.Height;
                     tickLabelPosition = axisTransform.Transform(new Point(tick.Value, yPos));
                     tickLabelPosition.X -= tick.TextBlockBorder.DesiredSize.Width / 2;
                     tickLabelPosition.X = Math.Min(Math.Max(tickLabelPosition.X, 0), arrangeSize.Width - tick.TextBlockBorder.DesiredSize.Width);
                     tick.TextBlockBorder.Arrange(new Rect(tickLabelPosition, tick.TextBlockBorder.DesiredSize));
                 }
                 break;
             case AxisLocation.Left:
             case AxisLocation.Right:
                 tick.Location = axisTransform.Transform(new Point(tick.Value, 0)).Y;
                 if (tick.TextBlockBorder != null)
                 {
                     tickLabelPosition = axisTransform.Transform(new Point(tick.Value, tickLength + 2));
                     if (AxisLocation == AxisLocation.Left) tickLabelPosition.X -= tick.TextBlockBorder.DesiredSize.Width;
                     tickLabelPosition.Y -= tick.TextBlockBorder.DesiredSize.Height / 2;
                     tickLabelPosition.Y = Math.Min(Math.Max(tickLabelPosition.Y, 0), arrangeSize.Height - tick.TextBlockBorder.DesiredSize.Height);
                     tick.TextBlockBorder.Arrange(new Rect(tickLabelPosition, tick.TextBlockBorder.DesiredSize));
                 }
                 break;
             default:
                 throw new ApplicationException("DataAxis: Unknown AxisLocation value.");
         }
     }
 }
 /// <summary>
 /// Sets the coordinates on the cursor using the transform passed in
 /// </summary>
 /// <param name="mousePos"></param>
 /// <param name="uiElement"></param>
 /// <param name="transform"></param>
 public void SetCoordinatesOnCursor(Point mousePos, FrameworkElement uiElement, GeneralTransform transform)
 {
     if (transform != null && hasPermissionToRun)
     {
         try
         {
             cursorPosition = mousePos;
             lastCoordinate = transform.Transform(mousePos);
             SetStringFormat(transform);
             SetCoordinatesOnCursor(uiElement);
         }
         catch (Exception)
         {
             hasPermissionToRun = false;
         }
     }
 }