public static winFound.Rect Transform(this Matrix3x2 matrix, winFound.Rect rect) { winFound.Point point1 = matrix.Transform(new winFound.Point(rect.Left, rect.Top)); winFound.Point point2 = matrix.Transform(new winFound.Point(rect.Right, rect.Bottom)); return(new winFound.Rect(point1, point2)); }
/// <summary> /// Creates a transformed bounds <see cref="Rect"/> using a <see cref="Matrix3x2"/>. /// </summary> /// <param name="rect">The rectangle to transform</param> /// <param name="matrix">The matrix to use to transform the <paramref name="rect"/></param> /// <returns>A new rectangle</returns> public static Rect Transform(this Matrix3x2 matrix, Rect rect) { var leftTop = matrix.Transform(rect.Left, rect.Top); var leftBottom = matrix.Transform(rect.Left, rect.Bottom); var rightTop = matrix.Transform(rect.Right, rect.Top); var rightBottom = matrix.Transform(rect.Right, rect.Bottom); var point1 = Min(leftTop, leftBottom, rightTop, rightBottom); var point2 = Max(leftTop, leftBottom, rightTop, rightBottom); return(new Rect(point1, point2)); }
private static void AddPoint([CanBeNull] Matrix3x2?transform, Vector2 point, List <ContourVertex> vertices) { ContourVertex vertex; if (transform != null) { var pt = Matrix3x2.Transform(transform.Value, point); vertex = new ContourVertex { Position = new Vec3 { X = pt.X, Y = pt.Y, Z = StandardZ } }; } else { vertex = new ContourVertex { Position = new Vec3 { X = point.X, Y = point.Y, Z = StandardZ } }; } vertices.Add(vertex); }
protected override void RenderInternal(Triangle[] triangles, Effect effect, Matrix3x2?transform) { var brushEffect = (LinearGradientBrushEffect)effect; var graphicsDevice = DrawingContext.GraphicsDevice; var brushProps = BrushProperties; var props = Properties; var gsc = GradientStopCollection; var projection = DrawingContext.DefaultOrthographicProjection; var world = transform?.ToMatrix4x4() ?? BrushEffect.DefaultWorld; brushEffect.SetWorldViewProjection(world, BrushEffect.DefaultView, projection); brushEffect.Opacity = brushProps.Opacity; brushEffect.SetGradientStops(gsc.GradientStopsDirect); brushEffect.Gamma = gsc.Gamma; brushEffect.ExtendMode = gsc.ExtendMode; brushEffect.StartPoint = props.StartPoint; brushEffect.EndPoint = props.EndPoint; graphicsDevice.RasterizerState = DefaultBrushRasterizerState; graphicsDevice.DepthStencilState = DefaultBrushDepthStencilState; brushEffect.Apply(); var vertices = new Vector2[triangles.Length * 3]; var indices = new uint[triangles.Length * 3]; for (var i = 0; i < triangles.Length; ++i) { var s = i * 3; vertices[s] = Matrix3x2.Transform(brushProps.Transform, triangles[i].Point1); vertices[s + 1] = Matrix3x2.Transform(brushProps.Transform, triangles[i].Point2); vertices[s + 2] = Matrix3x2.Transform(brushProps.Transform, triangles[i].Point3); } for (var i = 0; i < indices.Length; ++i) { indices[i] = (uint)i; } using (var vertexBuffer = new VertexBuffer(graphicsDevice, new VertexDeclaration(VertexElements), vertices.Length, BufferUsage.WriteOnly)) { using (var indexBuffer = new IndexBuffer(graphicsDevice, IndexElementSize.ThirtyTwoBits, indices.Length, BufferUsage.WriteOnly)) { vertexBuffer.SetData(vertices); indexBuffer.SetData(indices); graphicsDevice.SetVertexBuffer(vertexBuffer); graphicsDevice.Indices = indexBuffer; graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, triangles.Length); graphicsDevice.SetVertexBuffer(null); graphicsDevice.Indices = null; } } }
private static void AddPoints([CanBeNull] Matrix3x2?transform, [NotNull] Vector2[] points, List <ContourVertex> vertices) { if (points.Length < 2) { return; } // Don't add the first point. var verts = new ContourVertex[points.Length - 1]; if (transform != null) { for (var i = 1; i < points.Length; ++i) { var pt = Matrix3x2.Transform(transform.Value, points[i]); verts[i - 1] = new ContourVertex { Position = new Vec3 { X = pt.X, Y = pt.Y, Z = StandardZ } }; } } else { for (var i = 1; i < points.Length; ++i) { var pt = points[i]; verts[i - 1] = new ContourVertex { Position = new Vec3 { X = pt.X, Y = pt.Y, Z = StandardZ } }; } } vertices.AddRange(verts); }
private bool PropagageEventRecursive(PointerEventArgs args, Point root, UIElement element, Matrix3x2 currentTransform, Action <UIElement> raiseEvent) { bool raised = false; var elementRect = element.LayoutSlotWithMarginsAndAlignments; elementRect.X += root.X; elementRect.Y += root.Y; var position = args.CurrentPoint.Position; var pointer = new Pointer(args.CurrentPoint.PointerId, PointerDeviceType.Mouse, false, isInRange: true); var pointerArgs = new PointerRoutedEventArgs(args, element); if (element.RenderTransform != null) { currentTransform *= element.RenderTransform.MatrixCore; elementRect = currentTransform.Transform(elementRect); } if (elementRect.Contains(position)) { foreach (var e in element.GetChildren().Reverse().ToArray()) { if (PropagageEventRecursive(args, elementRect.Location, e, currentTransform, raiseEvent)) { return(true); } } var isHitTestVisible = element.GetValue(HitTestVisibilityProperty) is HitTestVisibility hitTestVisibility && hitTestVisibility == HitTestVisibility.Visible; if (isHitTestVisible) { if (!element.IsOver(pointer)) { element.OnNativePointerEnter(pointerArgs); } raiseEvent(element); return(true); } } else { bool RecursePointerExited(UIElement e) { if (e.IsOver(pointer)) { foreach (var child in e.GetChildren().Reverse().ToArray()) { if (RecursePointerExited(child)) { return(true); } } e.OnNativePointerExited(pointerArgs); return(true); } return(false); } RecursePointerExited(element); } return(raised); }
/// <summary> /// Creates a transformed <see cref="Point"/> using a <see cref="Matrix3x2"/>. /// </summary> /// <param name="point">The point to transform</param> /// <param name="matrix">The matrix to use to transform the <paramref name="point"/></param> /// <returns>A new rectangle</returns> public static Point Transform(this Matrix3x2 matrix, Point point) => matrix.Transform(point.X, point.Y);