/// <summary> /// Construct a TransformedBitmap with the given newTransform /// </summary> /// <param name="source">BitmapSource to apply to the newTransform to</param> /// <param name="newTransform">Transform to apply to the bitmap</param> public TransformedBitmap(BitmapSource source, Transform newTransform) : base(true) // Use base class virtuals { if (source == null) { throw new ArgumentNullException("source"); } if (newTransform == null) { throw new InvalidOperationException(SR.Get(SRID.Image_NoArgument, "Transform")); } if (!CheckTransform(newTransform)) { throw new InvalidOperationException(SR.Get(SRID.Image_OnlyOrthogonal)); } _bitmapInit.BeginInit(); Source = source; Transform = newTransform; _bitmapInit.EndInit(); FinalizeCreation(); }
public ImageSource ToImageSource(FrameworkElement obj) { // Save current canvas transform System.Windows.Media.Transform transform = obj.LayoutTransform; // fix margin offset as well Thickness margin = obj.Margin; obj.Margin = new Thickness(0, 0, margin.Right - margin.Left, margin.Bottom - margin.Top); // Get the size of canvas Size size = new Size(obj.ActualWidth, obj.ActualHeight); // force control to Update obj.Measure(size); obj.Arrange(new Rect(size)); RenderTargetBitmap bmp = new RenderTargetBitmap( (int)obj.ActualWidth, (int)obj.ActualHeight, 96, 96, PixelFormats.Pbgra32); bmp.Render(obj); // return values as they were before obj.LayoutTransform = transform; obj.Margin = margin; return(bmp); }
protected override void OnMouseMove(MouseEventArgs e) { Window wnd = Window.GetWindow(this); Point currentLocation = e.MouseDevice.GetPosition(wnd); var move = new TranslateTransform( currentLocation.X - _previousLocation.X, currentLocation.Y - _previousLocation.Y); if (e.LeftButton == MouseButtonState.Pressed) { var group = new TransformGroup(); if (_previousTransform != null) { group.Children.Add(_previousTransform); } group.Children.Add(move); RenderTransform = group; } else { Cursor = Cursors.Hand; } _previousLocation = currentLocation; _previousTransform = RenderTransform; MainWindow.Instance.CalculatePositions(); base.OnMouseMove(e); }
internal override PathFigureCollection GetTransformedFigureCollection(Transform transform) { // Combine the transform argument with the internal transform Transform combined = new MatrixTransform(GetCombinedMatrix(transform)); PathFigureCollection result = new PathFigureCollection(); GeometryCollection children = Children; if (children != null) { for (int i = 0; i < children.Count; i++) { PathFigureCollection pathFigures = children.Internal_GetItem(i).GetTransformedFigureCollection(combined); if (pathFigures != null) { int count = pathFigures.Count; for (int j = 0; j < count; ++j) { result.Add(pathFigures[j]); } } } } return result; }
/// <summary> /// /// </summary> public LineGeometry( Point startPoint, Point endPoint, Transform transform) : this(startPoint, endPoint) { Transform = transform; }
public RectangleGeometry (Rect rect, double radiusX, double radiusY, Transform transform) { Transform = transform; Rect = rect; RadiusX = radiusX; RadiusY = radiusY; }
/// <summary> /// Gets the rectangle that bounds the specified element, relative /// to the client area of the window the element is in. /// </summary> /// <param name='element'>Element to get rectangle for.</param> /// <returns>The System.Windows.Rect that bounds the element.</returns> public static Rect GetClientRelativeRect(UIElement element) { if (element == null) { throw new ArgumentNullException("element"); } Visual parent = GetTopMostVisual(element); LHPoint[] points = GetRenderSizeBoxPoints(element); Matrix m; System.Windows.Media.GeneralTransform gt = element.TransformToAncestor(parent); System.Windows.Media.Transform t = gt as System.Windows.Media.Transform; if (t == null) { throw new System.ApplicationException("//TODO: Handle GeneralTransform Case - introduced by Transforms Breaking Change"); } m = t.Value; m.Transform(points); // Calculate the regular Rectangle that encloses all the points. LHPoint topLeft, bottomRight; CalculateBoundingPoints(points, out topLeft, out bottomRight); return(new Rect( topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y)); }
public EllipseGeometry (Point center, double radiusX, double radiusY, Transform transform) { Transform = transform; Center = center; RadiusX = radiusX; RadiusY = radiusY; }
public AdornerChartMarkers(UIElement adornedElement, Transform shapeTransform, IList<ChartMarkerSet> markerSets, XYLineChart parentChart) : base(adornedElement) { _adornedElement = adornedElement; _parentChart = parentChart; _markerSets = markerSets; _transform = shapeTransform; }
/// <summary> /// Gets the rectangle that bounds the specified element, relative /// to the client area of the window the element is in. /// </summary> /// <param name='element'>Element to get rectangle for.</param> /// <returns>The System.Windows.Rect that bounds the element.</returns> public static Rect GetClientRelativeRect(UIElement element) { Visual parent; // Topmost parent of element. Matrix m; // Matrix to transform corodinates. Point[] points; // Points around element. if (element == null) { throw new ArgumentNullException("element"); } parent = GetTopMostVisual(element); points = GetRenderSizeBoxPoints(element); System.Windows.Media.GeneralTransform gt = element.TransformToAncestor(parent); System.Windows.Media.Transform t = gt as System.Windows.Media.Transform; if (t == null) { throw new System.ApplicationException("//TODO: Handle GeneralTransform Case - introduced by Transforms Breaking Change"); } m = t.Value; m.Transform(points); // Assume there is no rotation. return(new Rect(points[0], points[3])); }
/// <summary> /// /// </summary> /// <param name="rect"></param> /// <param name="radiusX"></param> /// <param name="radiusY"></param> /// <param name="transform"></param> public RectangleGeometry( Rect rect, double radiusX, double radiusY, Transform transform) : this(rect, radiusX, radiusY) { Transform = transform; }
/// <summary> /// Constructor - sets the ellipse to the parameters /// </summary> public EllipseGeometry( Point center, double radiusX, double radiusY, Transform transform) : this(center, radiusX, radiusY) { Transform = transform; }
// ------------------------------------------------------------------ // Dump content of the specified DocumentPage. // // writer - stream to be used for dump // element - element to be dumped // parent - parent element // ------------------------------------------------------------------ internal static void DumpDocumentPage(XmlNode writer, DocumentPage page, Visual parent) { if (writer == null) { throw new ArgumentNullException("writer"); } if (page == null) { throw new ArgumentNullException("page"); } if (parent == null) { throw new ArgumentNullException("parent"); } XmlNode node = PropertyDumpCore.xmldoc.CreateElement("DocumentPage"); writer.AppendChild(node); AppendAttribute(node, "Type", page.GetType().FullName); if (page == DocumentPage.Missing) { AppendAttribute(node, "Missing", "True"); } else { DumpSize(writer, "Size", page.Size); // Dump transform relative to its parent Matrix m; System.Windows.Media.GeneralTransform gt = page.Visual.TransformToAncestor(parent); System.Windows.Media.Transform t = (System.Windows.Media.Transform)gt; if (t == null) { throw new System.ApplicationException("//TODO: Handle GeneralTransform Case - introduced by Transforms Breaking Change"); } m = t.Value; Point point = new Point(0, 0) * m; if (point.X != 0 || point.Y != 0) { DumpPoint(writer, "Position", point); } //check for registered handler for this document page DumpCustomDocumentPage dumpDocumentPage = _documentPageToDumpHandler[page.GetType()] as DumpCustomDocumentPage; //Hack: need to itentify if test code should be using the Debug Class //Debug.Assert(dumpDocumentPage == null, String.Format("Unknown documentpage of type {0}", page.GetType())); if (dumpDocumentPage != null) { dumpDocumentPage(node, page); } } }
public static void WriteTransform(BinaryWriter w, System.Windows.Media.Transform t) { w.Write(t.Value.M11); w.Write(t.Value.M12); w.Write(t.Value.M21); w.Write(t.Value.M22); w.Write(t.Value.OffsetX); w.Write(t.Value.OffsetY); }
public static IEnumerable<Geometry> GetTransformedGeometries(IEnumerable<SqlGeometry> collection, Transform transform) { foreach (var item in collection) { Geometry wpf = item.ToWpfGeometry(); wpf.Transform = transform; yield return wpf; } }
public static IEnumerable<Geometry> GetTransformedGeometries(Connection connection, string query, Transform transform) { var collection = connection.Select<Geom>(query); foreach (var item in collection) { Geometry wpf = item.Geometry.ToWpfGeometry(); wpf.Transform = transform; yield return wpf; } }
/// <summary> /// Initializes a new instance of the LayoutTransformerScenario class. /// </summary> /// <param name="preferredWidth">Preferred width of the test control.</param> /// <param name="preferredHeight">Preferred height of the test control.</param> /// <param name="measureAtPreferredSize">Whether the child control should force its preferred size during Measure.</param> /// <param name="arrangeAtPreferredSize">Whether the child control should force its preferred size during Arrange.</param> /// <param name="measureWidth">Width to pass to Measure.</param> /// <param name="measureHeight">Height to pass to Measure.</param> /// <param name="desiredWidth">Expected DesiredSize.Width.</param> /// <param name="desiredHeight">Expected DesiredSize.Height.</param> /// <param name="arrangeWidth">Width to pass to Arrange.</param> /// <param name="arrangeHeight">Height to pass to Arrange.</param> /// <param name="renderWidth">Expected RenderSize.Width.</param> /// <param name="renderHeight">Expected RenderSize.Height.</param> /// <param name="transform">Transform to use.</param> public LayoutTransformerScenario(double preferredWidth, double preferredHeight, bool measureAtPreferredSize, bool arrangeAtPreferredSize, double measureWidth, double measureHeight, double desiredWidth, double desiredHeight, double arrangeWidth, double arrangeHeight, double renderWidth, double renderHeight, Transform transform) { PreferredSize = new Size(preferredWidth, preferredHeight); _measureAtPreferredSize = measureAtPreferredSize; _arrangeAtPreferredSize = arrangeAtPreferredSize; MeasureSize = new Size(measureWidth, measureHeight); DesiredSize = new Size(desiredWidth, desiredHeight); ArrangeSize = new Size(arrangeWidth, arrangeHeight); RenderSize = new Size(renderWidth, renderHeight); Transform = transform; }
public void RenderUnfilledElements(DrawingContext ctx, Rect chartArea, Transform transform) { CalculateGeometry(chartArea); if(LineColor != Colors.Transparent && LineThickness > 0) { Pen pen = new Pen(new SolidColorBrush(LineColor), LineThickness); pen.LineJoin = PenLineJoin.Bevel; if(IsDashed) { pen.DashStyle = new DashStyle(new double[] { 2, 2 }, 0); } _unfilledGeometry.Transform = transform; ctx.DrawGeometry(null, pen, _unfilledGeometry); } }
public static void StartAnimation (Transform animatableElement, DependencyProperty dependencyProperty, double toValue, double durationMilliseconds, double accelerationRatio, double decelerationRatio) { DoubleAnimation animation = new DoubleAnimation(); animation.To = toValue; animation.AccelerationRatio = accelerationRatio; animation.DecelerationRatio = decelerationRatio; animation.FillBehavior = FillBehavior.HoldEnd; animation.Duration = TimeSpan.FromMilliseconds(durationMilliseconds); animation.Freeze(); animatableElement.BeginAnimation(dependencyProperty, animation, HandoffBehavior.Compose); }
public void RenderUnfilledElements(DrawingContext ctx, Rect chartArea, Transform transform) { for(int segmentIndex = 0; segmentIndex < _lineColors.Count; ++segmentIndex) { SolidColorBrush brush = new SolidColorBrush(_lineColors[segmentIndex]); Pen pen = new Pen(brush, LineThickness); pen.LineJoin = PenLineJoin.Bevel; if(IsDashed) { pen.DashStyle = new DashStyle(new double[] { 2, 2 }, 0); } ctx.DrawLine(pen, transform.Transform(Points[segmentIndex*2]), transform.Transform(Points[segmentIndex*2+1])); } }
/// <summary> /// Initializes a new instance of the <see cref="DoubleAnimator"/> class. /// </summary> /// <param name="translateTransform">The translate transform.</param> /// <param name="property">The property.</param> public DoubleAnimator(Transform transform, string property) { this.transform = transform; this.storyboard.Completed += this.OnCompleted; this.storyboard.Children.Add(this.animation); Storyboard.SetTarget(this.animation, this.transform); #if WINDOWS_PHONE Storyboard.SetTargetProperty(this.animation, new PropertyPath(property)); #else Storyboard.SetTargetProperty(this.animation, property); #endif }
public override void Setup(VisualBrush prevBrush, VisualBrush nextBrush) { //store the visual that will be moved to view, so that if any changes are done to it we can rollback to the original state elementToMoveToView = (FrameworkElement)nextBrush.Visual; elementToMoveToViewTransform = elementToMoveToView.RenderTransform; elementToMovePoint = elementToMoveToView.RenderTransformOrigin; Owner.AddTransitionElement(_viewport); RegisterNameScope(); AdjustViewport(Owner, prevBrush, nextBrush); }
/// <summary> /// Gets the UIElement that can be added to the plot /// </summary> /// <returns></returns> public void RenderFilledElements(DrawingContext ctx, Rect chartArea, Transform transform) { CalculateGeometry(); int colorIndex = 0; foreach(var childGeometry in _filledGeometry.Children) { Color fillColor = _colors[colorIndex].Item2; if(fillColor != Colors.Transparent) { Brush brush = IsDashed ? (Brush)(ChartUtilities.CreateHatch50(fillColor, new Size(2, 2))) : (Brush)(new SolidColorBrush(fillColor)); childGeometry.Transform = transform; ctx.DrawGeometry(brush, null, childGeometry); } ++colorIndex; } }
public RelativeLocationBinding(FrameworkElement item, IObservable<Transform> transforms, IObservable<Point?> locations = null) { if (item == null) throw new ArgumentNullException("item"); if (transforms == null) throw new ArgumentNullException("transforms"); this.item = item; item.Visibility = Visibility.Collapsed; subscription.Add(transforms.Subscribe(t => Transform = t)); if (locations != null) this.subscription.Add(locations.Subscribe(loc => RelativeLocation = loc)); }
internal PathStreamGeometryContext(FillRule fillRule, Transform transform) { _pathGeometry = new PathGeometry(); if (fillRule != s_defaultFillRule) { _pathGeometry.FillRule = fillRule; } if ((transform != null) && !transform.IsIdentity) { _pathGeometry.Transform = transform.Clone(); } }
partial static void ScaleRect(ref Rect rect, ref Transform transform) { // Scales the RectangleGeometry to compensate inaccurate hit testing in WPF. // See http://stackoverflow.com/a/19335624/1136211 rect.Scale(1e6, 1e6); var scaleTransform = new ScaleTransform(1e-6, 1e-6); // reverts rect scaling scaleTransform.Freeze(); var transformGroup = new TransformGroup(); transformGroup.Children.Add(scaleTransform); transformGroup.Children.Add(transform); transform = transformGroup; }
public static System.Drawing.Rectangle GetScreenBoundingRectangle(UIElement target) { PresentationSource source = PresentationSource.FromVisual(target); if (source == null) { throw new InvalidOperationException("The specified UiElement is not connected to a rendering Visual Tree."); } Matrix transform; try { System.Windows.Media.GeneralTransform gt = target.TransformToAncestor(source.RootVisual); System.Windows.Media.Transform t = gt as System.Windows.Media.Transform; if (t != null) { transform = t.Value; } else { throw new System.ApplicationException("//TODO: Handle GeneralTransform Case - introduced by Transforms Breaking Change"); } } catch (InvalidOperationException) { throw new InvalidOperationException("The specified UiElement is not connected to a rendering Visual Tree."); } Rect targetRect = new Rect(new Point(), target.RenderSize); targetRect.Transform(transform); Point rootOffset = targetRect.TopLeft; System.Windows.Media.CompositionTarget vm = source.CompositionTarget; rootOffset = vm.TransformToDevice.Transform(rootOffset);//vm.DeviceUnitsFromMeasureUnits(rootOffset); System.Drawing.Point topLeft = new System.Drawing.Point((int)rootOffset.X, (int)rootOffset.Y); User32.ClientToScreen(((System.Windows.Interop.HwndSource)source).Handle, ref topLeft); System.Drawing.Rectangle rect = new System.Drawing.Rectangle(topLeft, new System.Drawing.Size(Convert.ToInt32(Monitor.ConvertLogicalToScreen(Dimension.Width, target.RenderSize.Width)), Convert.ToInt32(Monitor.ConvertLogicalToScreen(Dimension.Height, target.RenderSize.Height)))); return(rect); }
// ------------------------------------------------------------------ // Dump paragraph offset. // ------------------------------------------------------------------ private static Visual DumpParagraphOffset(XmlNode writer, ParagraphResultW paragraph, Visual visualParent) { if (writer == null) { throw new ArgumentNullException("writer"); } if (paragraph == null) { throw new ArgumentNullException("paragraph"); } if (visualParent == null) { throw new ArgumentNullException("visualParent"); } object paraClient = paragraph.GetField("_paraClient"); Type paraClientType = paraClient.GetType(); //PropertyInfoSW prop = TypeSW.Wrap(paraClientType).GetProperty("Visual", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); PropertyInfo prop = paraClientType.GetProperty("Visual", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); Visual visual = (Visual)prop.GetValue(paraClient, null); // Dump transform relative to its parent Matrix m; System.Windows.Media.GeneralTransform gt = visual.TransformToAncestor(visualParent); System.Windows.Media.Transform t = gt as System.Windows.Media.Transform; if (t == null) { //throw new System.ApplicationException("// GlobalLog.LogEvidence(new System.ApplicationException("//TODO: Handle GeneralTransform Case - introduced by Transforms Breaking Change")); } m = t.Value; Point point = new Point(0.0f, 0.0f) * m; if (point.X != 0 || point.Y != 0) { DumpPoint(writer, "Origin", point); } return(visual); }
/// <summary> /// This returns the position of the element. /// </summary> /// <param element="element"> element as a UIElement </param> /// <param ancestor="ancestor"> ancestor as a UIElement </param> /// <returns> Point of position X and Y of element </returns> public static System.Windows.Point GetElementPosition(UIElement element, UIElement ancestor) { System.Windows.Point position = new System.Windows.Point(); Matrix pt; System.Windows.Media.GeneralTransform gt = element.TransformToAncestor(ancestor); System.Windows.Media.Transform t = gt as System.Windows.Media.Transform; if (t == null) { //throw new System.ApplicationException("// GlobalLog.LogEvidence(new System.ApplicationException("//TODO: Handle GeneralTransform Case - introduced by Transforms Breaking Change")); } pt = t.Value; position.X = pt.OffsetX; position.Y = pt.OffsetY; return(position); }
//---------------------------------------- // constructor //---------------------------------------- /// <summary> /// Constructor to TextEffect /// </summary> /// <param name="transform">transform of the text effect</param> /// <param name="foreground">foreground of the text effect</param> /// <param name="clip">clip of the text effect</param> /// <param name="positionStart">starting character index of the text effect</param> /// <param name="positionCount">number of code points</param> public TextEffect( Transform transform, Brush foreground, Geometry clip, int positionStart, int positionCount ) { if (positionCount < 0) { throw new ArgumentOutOfRangeException("positionCount", SR.Get(SRID.ParameterCannotBeNegative)); } Transform = transform; Foreground = foreground; Clip = clip; PositionStart = positionStart; PositionCount = positionCount; }
/// <summary> /// Führt die Animation für beide Contents aus /// </summary> private void _BeginAnimateContentReplacement() { OldContentTransform = new TranslateTransform(); NewContentTransform = new TranslateTransform(); _paintArea.Visibility = Visibility.Visible; _paintArea.RenderTransform = OldContentTransform; _mainContent.RenderTransform = NewContentTransform; IEasingFunction ease = new BackEase { Amplitude = 0.5, EasingMode = EasingMode.EaseInOut }; NewContentTransform.BeginAnimation(TranslateTransform.XProperty, AnimateLib.CreateAnimation(this.ActualWidth, 0, 0, 1, ease)); OldContentTransform.BeginAnimation(TranslateTransform.XProperty, AnimateLib.CreateAnimation(0, -this.ActualWidth, 0, 1, ease, (s, e) => { _paintArea.Visibility = Visibility.Hidden; })); }
/// <summary> /// Export the currently displayed content to an xps (vector format) file. /// </summary> /// <param name="path">The .xps file to export to.</param> /// <remarks> /// Adapted from http://denisvuyka.wordpress.com/2007/12/03/wpf-diagramming-saving-you-canvas-to-image-xps-document-or-raw-xaml/. /// </remarks> public void ExportXPS(Uri path) { if (path == null) { return; } // Save current canvas transorm System.Windows.Media.Transform transform = this.LayoutTransform; Thickness oldMargin = this.Margin; // Temporarily reset the layout transform before saving this.LayoutTransform = null; this.Margin = new Thickness(0); // Get the size of canvas double w = this.Width.CompareTo(double.NaN) == 0 ? this.ActualWidth : this.Width; double h = this.Height.CompareTo(double.NaN) == 0 ? this.ActualHeight : this.Height; Size size = new Size(w, h); // Measure and arrange elements this.Measure(size); this.Arrange(new Rect(size)); // Open new package Package package = Package.Open(path.LocalPath, FileMode.Create); // Create new xps document based on the package opened XpsDocument doc = new XpsDocument(package); // Create an instance of XpsDocumentWriter for the document XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc); // Write the canvas (as Visual) to the document writer.Write(this); // Close document doc.Close(); // Close package package.Close(); // Restore previously saved layout this.Margin = oldMargin; this.LayoutTransform = transform; }
public ResourcesVisual(MapOctree snapshot, Func<MapOctree, double> getValue, Color color, Transform transform) { //const double STANDARDAREA = 1000000; const double STANDARDAREA = 750000; //TODO: Use this to get a normalization multiplier double totalArea = (snapshot.MaxRange.X - snapshot.MinRange.X) * (snapshot.MaxRange.Y - snapshot.MinRange.Y); double valueMult = totalArea / STANDARDAREA; _visual = new DrawingVisual(); using (DrawingContext dc = _visual.RenderOpen()) { foreach (MapOctree node in snapshot.Descendants(o => o.Children)) { if (node.Items == null) { continue; } // Get the color Brush brush = GetBrush(node, getValue, valueMult, color); if (brush == null) { continue; } // Define the rectangle Point min = transform.Transform(new Point(node.MinRange.X, -node.MinRange.Y)); // need to negate Y Point max = transform.Transform(new Point(node.MaxRange.X, -node.MaxRange.Y)); double x = min.X; double y = max.Y; // can't use min, because Y is backward double width = max.X - min.X; double height = Math.Abs(max.Y - min.Y); // Y is all flipped around // Fill the box dc.DrawRectangle(brush, null, new Rect(x, y, width, height)); } } }
public SvgDrawingCanvas() { _drawForInteractivity = true; _drawObjects = new List<Drawing>(); _linkObjects = new List<Drawing>(); _displayTransform = Transform.Identity; // Create a tooltip and set its position. _tooltip = new ToolTip(); _tooltip.Placement = PlacementMode.MousePoint; _tooltip.PlacementRectangle = new Rect(50, 0, 0, 0); _tooltip.HorizontalOffset = 20; _tooltip.VerticalOffset = 20; _tooltipText = new TextBlock(); _tooltipText.Text = String.Empty; _tooltipText.Margin = new Thickness(6, 0, 0, 0); //Create BulletDecorator and set it as the tooltip content. Ellipse bullet = new Ellipse(); bullet.Height = 10; bullet.Width = 10; bullet.Fill = Brushes.LightCyan; BulletDecorator decorator = new BulletDecorator(); decorator.Bullet = bullet; decorator.Margin = new Thickness(0, 0, 10, 0); decorator.Child = _tooltipText; _tooltip.Content = decorator; _tooltip.IsOpen = false; _tooltip.Visibility = Visibility.Hidden; //Finally, set tooltip on this canvas this.ToolTip = _tooltip; this.Background = Brushes.Transparent; _animationCanvas = new SvgAnimationLayer(this); }
// // Summary: // Gets the current transformation as a System.Windows.Media.Matrix object. // // Returns: // The current matrix transformation. public static Matrix GetTransformValue(Transform Transform) { Matrix m = Matrix.Identity; if (Transform is TransformGroup) { var transformGroup = Transform as TransformGroup; m = transformGroup.Value; } else if (Transform is RotateTransform) { var rotateTransform = Transform as RotateTransform; double angleRadians = rotateTransform.Angle*Math.PI/180; m.M11 = Math.Cos(angleRadians); m.M12 = Math.Sin(angleRadians); m.M21 = -m.M12; m.M22 = m.M11; } else if (Transform is TranslateTransform) { var translateTranform = Transform as TranslateTransform; m.OffsetX = translateTranform.X; m.OffsetY = translateTranform.Y; } else if (Transform is ScaleTransform) { var scaleTransform = Transform as ScaleTransform; m.M11 = scaleTransform.ScaleX; m.M12 = 0; m.M21 = 0; m.M22 = scaleTransform.ScaleY; } else if (Transform is SkewTransform) { throw new Exception("Sorry Skew not implemented"); } return m; }
public HtmlVisualRenderElement(object owner, IRenderQueue renderQueue, IHtmlValueConverter converter) : base(GetElementTagName(owner), GetElementId(owner), renderQueue) { this.converter = converter; this.children = new List<object>(); this.childrenActions = new List<Action>(); bounds = Rect.Zero; isVisible = true; opacity = 1; transform = Transform.Identity; Style.SetBackground(Background, converter); Style.SetBounds(Bounds, converter); Style.SetClipToBounds(ClipToBounds); Style.SetIsHitTestVisible(IsHitTestVisible && Background != null); Style.SetIsVisible(IsVisible); Style.SetOpacity(Opacity, converter); Style.SetTransform(Transform, converter); }
private TextBlock GetRenderedCueTextBlock(WebVTTCue cue, WebVTTAlignment alignment, Brush brush, TextPosition textPosition, Transform transform = null) { var content = cue.Content; var result = new TextBlock { TextWrapping = TextWrapping.Wrap, RenderTransform = transform, Foreground = brush }; switch (alignment) { case WebVTTAlignment.Middle: result.TextAlignment = TextAlignment.Center; break; case WebVTTAlignment.Left: result.TextAlignment = TextAlignment.Left; break; case WebVTTAlignment.Right: result.TextAlignment = TextAlignment.Right; break; case WebVTTAlignment.Start: result.TextAlignment = TextAlignment.Left; break; case WebVTTAlignment.End: result.TextAlignment = TextAlignment.Right; break; } CreateInlines(cue, content, result.Inlines, brush); // If a Text Rendering event handler has been added, call it. if (this.TextRendering != null) { this.TextRendering(this, new CaptionTextEventArgs(result, textPosition)); } return result; }
internal static Rect GetBoundingRectangle(UIElement element) { // get visual size (to get width and height) PresentationSource s = PresentationSource.FromVisual(element); Point size = s.CompositionTarget.TransformToDevice.Transform(new Point(element.RenderSize.Width, element.RenderSize.Height)); // get absolute position Matrix m; System.Windows.Media.GeneralTransform gt = element.TransformToAncestor(s.RootVisual); System.Windows.Media.Transform t = gt as System.Windows.Media.Transform; if (t == null) { throw new System.ApplicationException("//TODO: Handle GeneralTransform Case - introduced by Transforms Breaking Change"); } m = t.Value; Rect clientCoordinates = new Rect( m.OffsetX, m.OffsetY, m.OffsetX + size.X, m.OffsetY + size.Y); // get root hwnd HwndSource rootHwnd = (HwndSource)s; // get screen coordinates POINT topLeft = new POINT((int)m.OffsetX, (int)m.OffsetY); POINT screenTopLeft = new POINT(); ClientToScreen(rootHwnd.Handle, ref screenTopLeft); Rect screenCoordinates = new Rect( m.OffsetX + screenTopLeft.x, m.OffsetY + screenTopLeft.y, size.X, size.Y); return(screenCoordinates); }
private static Rectangle GetTopLevelClientRelativeRect( UIElement element) { // Get top-most visual. Visual parent = element; while (VisualTreeHelper.GetParent(parent) != null) { parent = (Visual)VisualTreeHelper.GetParent(parent); } // Get the points for the rectangle and transform them. double height = element.RenderSize.Height; double width = element.RenderSize.Width; LHPoint[] points = new LHPoint[4]; points[0] = new LHPoint(0, 0); points[1] = new LHPoint(width, 0); points[2] = new LHPoint(0, height); points[3] = new LHPoint(width, height); Matrix m; System.Windows.Media.GeneralTransform gt = element.TransformToAncestor(parent); System.Windows.Media.Transform t = gt as System.Windows.Media.Transform; if (t == null) { throw new System.ApplicationException("//TODO: Handle GeneralTransform Case - introduced by Transforms Breaking Change"); } m = t.Value; m.Transform(points); LHPoint topLeft, bottomRight; CalculateBoundingPoints(points, out topLeft, out bottomRight); return(new Rectangle( (int)topLeft.X, (int)topLeft.Y, (int)bottomRight.X - (int)topLeft.X, (int)bottomRight.Y - (int)topLeft.Y)); }
public void Execute(Canvas element) { _oldSettings = element.RenderTransform.Clone(); InitializeSettings(element); RotateTransform rotate = _currentSettings.Children[0] as RotateTransform; TranslateTransform translate = _currentSettings.Children[1] as TranslateTransform; SetRotateOfCanvas(element, rotate); if (!IsCanvasBeingFliped(rotate)) SetTranslateOfCanvas(element, translate); else { if (_degrees != 180) DontTranslate(translate); else TranslateFlippedVerticalCanvas(translate); } element.RenderTransform = _currentSettings; _canvasNode = element; }
internal override PathFigureCollection GetTransformedFigureCollection(Transform transform) { Point [] points = GetPointList(); // Get the combined transform argument with the internal transform Matrix matrix = GetCombinedMatrix(transform); if (!matrix.IsIdentity) { for (int i=0; i<points.Length; i++) { points[i] *= matrix; } } PathFigureCollection figureCollection = new PathFigureCollection(); figureCollection.Add( new PathFigure( points[0], new PathSegment[]{ new BezierSegment(points[1], points[2], points[3], true, true), new BezierSegment(points[4], points[5], points[6], true, true), new BezierSegment(points[7], points[8], points[9], true, true), new BezierSegment(points[10], points[11], points[12], true, true)}, true ) ); return figureCollection; }
public static IMatrix ToEtoMatrix(this swm.Transform transform) { return(new MatrixHandler(transform.Value)); }