/// <summary> /// Overrides the default behavior when the control template is applied. /// </summary> protected override void OnApplyTemplate() { base.OnApplyTemplate(); transformRoot = GetTemplateChild( TransformRootName ) as Grid; contentPresenter = GetTemplateChild( PresenterName ) as ContentPresenter; renderTransform = new MatrixTransform(); if ( transformRoot != null ) transformRoot.RenderTransform = renderTransform; ApplyLayoutTransform(); }
private void SourceChanged(ImageSource image) { var transform = new MatrixTransform { Matrix = new Matrix(1d, 0d, 0d, -1d, 0d, 1d) }; transform.Freeze(); Fill = new ImageBrush { ImageSource = image, RelativeTransform = transform }; }
private void ArrangePopup() { if (((this._popup != null) && (this._popupRoot != null)) && this._popup.IsOpen) { System.Windows.Interop.Content content = Application.Current.Host.Content; double actualWidth = content.ActualWidth; double actualHeight = content.ActualHeight; double num3 = this._popupRoot.ActualWidth; double num4 = this._popupRoot.ActualHeight; if (((actualHeight != 0.0) && (actualWidth != 0.0)) && ((num3 != 0.0) && (num4 != 0.0))) { GeneralTransform transform = null; try { transform = this._popupRoot.TransformToVisual(null); } catch { //Don't need to do nothing. } if (transform != null) { Point point = new Point(0.0, 0.0); Point point2 = new Point(1.0, 0.0); Point point3 = new Point(0.0, 1.0); Point point4 = transform.Transform(point); Point point5 = transform.Transform(point2); Point point6 = transform.Transform(point3); double x = point4.X; double y = point4.Y; double num7 = base.ActualHeight; double num8 = base.ActualWidth; this._popup.HorizontalOffset = 0.0; this._popup.VerticalOffset = 0.0; this._canvasPopupOutside.Width = actualWidth; this._canvasPopupOutside.Height = actualHeight; Matrix identity = Matrix.Identity; identity.M11 = point5.X - point4.X; identity.M12 = point5.Y - point4.Y; identity.M21 = point6.X - point4.X; identity.M22 = point6.Y - point4.Y; identity.OffsetX -= point4.X; identity.OffsetY -= point4.Y; MatrixTransform transform2 = new MatrixTransform(); transform2.Matrix = identity; this._canvasPopupOutside.RenderTransform = transform2; this._popupRoot.MinWidth = num8; this._popupRoot.MaxWidth = actualWidth; this._popupRoot.MinHeight = num7; this._popupRoot.MaxHeight = actualHeight; this._popupRoot.HorizontalAlignment = HorizontalAlignment.Left; this._popupRoot.VerticalAlignment = VerticalAlignment.Top; try { transform = this.TransformToVisual(null); } catch { //Don't need to do nothing. } point4 = transform.Transform(point); if ((this._popupRoot.ActualWidth - base.ActualWidth) <= point4.X) { Canvas.SetLeft(this._popupRoot, -(this._popupRoot.ActualWidth - this.ActualWidth)); } else { Canvas.SetLeft(this._popupRoot, 0); } if (this._popupRoot.ActualHeight <= (actualHeight - point4.Y - base.ActualHeight)) { Canvas.SetTop(this._popupRoot, base.ActualHeight); } else { Canvas.SetTop(this._popupRoot, -this._popupRoot.ActualHeight); } bool isTop = false; bool isLeft = false; double popY = Canvas.GetTop(this._popupRoot); double popX = Canvas.GetLeft(this._popupRoot); if (popY < 0) { isTop = true; } if (popX < 0) { isLeft = true; } if (isTop && isLeft) { _popContent.Margin = new Thickness(0, 1, 0, 0); VisualStateManager.GoToState(this, "PopTopLeftState", false); } else if (!isTop && isLeft) { _popContent.Margin = new Thickness(0, -1, 0, 0); VisualStateManager.GoToState(this, "PopBottomLeftState", false); } else if (!isTop && !isLeft) { _popContent.Margin = new Thickness(0, -1, 0, 0); VisualStateManager.GoToState(this, "PopBottomRightState", false); } else if (isTop && !isLeft) { _popContent.Margin = new Thickness(0, 1, 0, 0); VisualStateManager.GoToState(this, "PopTopRightState", false); } } } } }
internal static void FixCoordinatesGreaterThanInt32MaxValue(double minX, double minY, double maxX, double maxY, ref Transform actualTransform, ref double int32FactorX, ref double int32FactorY) { const Int32 maxValue = Int32.MaxValue; //--------------------------- // Check the X axis: //--------------------------- if (Math.Abs(minX) > maxValue || Math.Abs(maxX) > maxValue) { // Take the biggest number and caculate a factor so that it stays withing the range of Int32: double max = Math.Max(Math.Abs(minX), Math.Abs(maxX)); int32FactorX = (maxValue / max) * 0.99; // Note: we multiply by 0.99 for a conservative margin, to make sure that the final points are not equal to maxValue. double invertedInt32FactorX = 1 / int32FactorX; Matrix scaleTransformMatrix = new Matrix(invertedInt32FactorX, 0, 0, 1, 0, 0); if (actualTransform != null) { if (actualTransform is MatrixTransform) { actualTransform = new MatrixTransform() { Matrix = Matrix.Multiply(scaleTransformMatrix, ((MatrixTransform)actualTransform).Matrix) }; } else { throw new NotSupportedException("The size of the shape exceeds Int32. This is currently supported only if the Transform is null or a MatrixTransform."); } } else { actualTransform = new MatrixTransform() { Matrix = scaleTransformMatrix }; } } //--------------------------- // Check the Y axis: //--------------------------- if (Math.Abs(minY) > maxValue || Math.Abs(maxY) > maxValue) { // Take the biggest number and caculate a factor so that it stays withing the range of Int32: double max = Math.Max(Math.Abs(minY), Math.Abs(maxY)); int32FactorY = (maxValue / max) * 0.99; // Note: we multiply by 0.99 for a conservative margin, to make sure that the final points are not equal to maxValue. double invertedInt32FactorY = 1 / int32FactorY; Matrix scaleTransformMatrix = new Matrix(1, 0, 0, invertedInt32FactorY, 0, 0); if (actualTransform != null) { if (actualTransform is MatrixTransform) { actualTransform = new MatrixTransform() { Matrix = Matrix.Multiply(scaleTransformMatrix, ((MatrixTransform)actualTransform).Matrix) }; } else { throw new NotSupportedException("The size of the shape exceeds Int32. This is currently supported only if the Transform is null or a MatrixTransform."); } } else { actualTransform = new MatrixTransform() { Matrix = scaleTransformMatrix }; } } }
private void RenderTheme(DrawingContext dc) { Size size = RenderSize; bool horizontal = Orientation == Orientation.Horizontal; bool isClickable = IsClickable && IsEnabled; bool isHovered = isClickable && IsHovered; bool isPressed = isClickable && IsPressed; ListSortDirection?sortDirection = SortDirection; bool isSorted = sortDirection != null; bool isSelected = IsSelected; EnsureCache((int)RoyaleFreezables.NumFreezables); if (horizontal) { // When horizontal, rotate the rendering by -90 degrees Matrix m1 = new Matrix(); m1.RotateAt(-90.0, 0.0, 0.0); Matrix m2 = new Matrix(); m2.Translate(0.0, size.Height); MatrixTransform horizontalRotate = new MatrixTransform(m1 * m2); horizontalRotate.Freeze(); dc.PushTransform(horizontalRotate); double temp = size.Width; size.Width = size.Height; size.Height = temp; } // Draw the background RoyaleFreezables backgroundType = isPressed ? RoyaleFreezables.PressedBackground : isHovered ? RoyaleFreezables.HoveredBackground : RoyaleFreezables.NormalBackground; LinearGradientBrush background = (LinearGradientBrush)GetCachedFreezable((int)backgroundType); if (background == null) { background = new LinearGradientBrush(); background.StartPoint = new Point(); background.EndPoint = new Point(0.0, 1.0); if (isPressed) { background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xB9, 0xB9, 0xC8), 0.0)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEC, 0xEC, 0xF3), 0.1)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEC, 0xEC, 0xF3), 1.0)); } else if (isHovered || isSelected) { background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFE, 0xFE, 0xFE), 0.0)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFE, 0xFE, 0xFE), 0.85)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBD, 0xBE, 0xCE), 1.0)); } else { background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF9, 0xFA, 0xFD), 0.0)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF9, 0xFA, 0xFD), 0.85)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBD, 0xBE, 0xCE), 1.0)); } background.Freeze(); CacheFreezable(background, (int)backgroundType); } dc.DrawRectangle(background, null, new Rect(0.0, 0.0, size.Width, size.Height)); if (isHovered && !isPressed && (size.Width >= 6.0) && (size.Height >= 4.0)) { // When hovered, there is a colored tab at the bottom TranslateTransform positionTransform = new TranslateTransform(0.0, size.Height - 3.0); positionTransform.Freeze(); dc.PushTransform(positionTransform); PathGeometry tabGeometry = new PathGeometry(); PathFigure tabFigure = new PathFigure(); tabFigure.StartPoint = new Point(0.5, 0.5); LineSegment line = new LineSegment(new Point(size.Width - 0.5, 0.5), true); line.Freeze(); tabFigure.Segments.Add(line); ArcSegment arc = new ArcSegment(new Point(size.Width - 2.5, 2.5), new Size(2.0, 2.0), 90.0, false, SweepDirection.Clockwise, true); arc.Freeze(); tabFigure.Segments.Add(arc); line = new LineSegment(new Point(2.5, 2.5), true); line.Freeze(); tabFigure.Segments.Add(line); arc = new ArcSegment(new Point(0.5, 0.5), new Size(2.0, 2.0), 90.0, false, SweepDirection.Clockwise, true); arc.Freeze(); tabFigure.Segments.Add(arc); tabFigure.IsClosed = true; tabFigure.Freeze(); tabGeometry.Figures.Add(tabFigure); tabGeometry.Freeze(); Pen tabStroke = (Pen)GetCachedFreezable((int)RoyaleFreezables.TabStroke); if (tabStroke == null) { SolidColorBrush tabStrokeBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xF8, 0xA9, 0x00)); tabStrokeBrush.Freeze(); tabStroke = new Pen(tabStrokeBrush, 1.0); tabStroke.Freeze(); CacheFreezable(tabStroke, (int)RoyaleFreezables.TabStroke); } LinearGradientBrush tabFill = (LinearGradientBrush)GetCachedFreezable((int)RoyaleFreezables.TabFill); if (tabFill == null) { tabFill = new LinearGradientBrush(); tabFill.StartPoint = new Point(); tabFill.EndPoint = new Point(1.0, 0.0); tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFC, 0xE0, 0xA6), 0.0)); tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF6, 0xC4, 0x56), 0.1)); tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF6, 0xC4, 0x56), 0.9)); tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xDF, 0x97, 0x00), 1.0)); tabFill.Freeze(); CacheFreezable(tabFill, (int)RoyaleFreezables.TabFill); } dc.DrawGeometry(tabFill, tabStroke, tabGeometry); dc.Pop(); // Translate Transform } if (isPressed && (size.Width >= 2.0) && (size.Height >= 2.0)) { // When pressed, there is a border on the left and bottom SolidColorBrush border = (SolidColorBrush)GetCachedFreezable((int)RoyaleFreezables.PressedBorder); if (border == null) { border = new SolidColorBrush(Color.FromArgb(0xFF, 0x80, 0x80, 0x99)); border.Freeze(); CacheFreezable(border, (int)RoyaleFreezables.PressedBorder); } dc.DrawRectangle(border, null, new Rect(0.0, 0.0, 1.0, size.Height)); dc.DrawRectangle(border, null, new Rect(0.0, Max0(size.Height - 1.0), size.Width, 1.0)); } if (!isPressed && !isHovered && (size.Width >= 4.0)) { if (SeparatorVisibility == Visibility.Visible) { Brush sideBrush; if (SeparatorBrush != null) { sideBrush = SeparatorBrush; } else { // When not pressed or hovered, draw the resize gripper LinearGradientBrush gripper = (LinearGradientBrush)GetCachedFreezable((int)(horizontal ? RoyaleFreezables.HorizontalGripper : RoyaleFreezables.VerticalGripper)); if (gripper == null) { gripper = new LinearGradientBrush(); gripper.StartPoint = new Point(); gripper.EndPoint = new Point(1.0, 0.0); Color highlight = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF); Color shadow = Color.FromArgb(0xFF, 0xC7, 0xC5, 0xB2); if (horizontal) { gripper.GradientStops.Add(new GradientStop(highlight, 0.0)); gripper.GradientStops.Add(new GradientStop(highlight, 0.25)); gripper.GradientStops.Add(new GradientStop(shadow, 0.75)); gripper.GradientStops.Add(new GradientStop(shadow, 1.0)); } else { gripper.GradientStops.Add(new GradientStop(shadow, 0.0)); gripper.GradientStops.Add(new GradientStop(shadow, 0.25)); gripper.GradientStops.Add(new GradientStop(highlight, 0.75)); gripper.GradientStops.Add(new GradientStop(highlight, 1.0)); } gripper.Freeze(); CacheFreezable(gripper, (int)(horizontal ? RoyaleFreezables.HorizontalGripper : RoyaleFreezables.VerticalGripper)); } sideBrush = gripper; } dc.DrawRectangle(sideBrush, null, new Rect(horizontal ? 0.0 : Max0(size.Width - 2.0), 4.0, 2.0, Max0(size.Height - 8.0))); } } if (isSorted && (size.Width > 14.0) && (size.Height > 10.0)) { // When sorted, draw an arrow on the right TranslateTransform positionTransform = new TranslateTransform(size.Width - 15.0, (size.Height - 5.0) * 0.5); positionTransform.Freeze(); dc.PushTransform(positionTransform); bool ascending = (sortDirection == ListSortDirection.Ascending); PathGeometry arrowGeometry = (PathGeometry)GetCachedFreezable(ascending ? (int)RoyaleFreezables.ArrowUpGeometry : (int)RoyaleFreezables.ArrowDownGeometry); if (arrowGeometry == null) { arrowGeometry = new PathGeometry(); PathFigure arrowFigure = new PathFigure(); if (ascending) { arrowFigure.StartPoint = new Point(0.0, 5.0); LineSegment line = new LineSegment(new Point(5.0, 0.0), false); line.Freeze(); arrowFigure.Segments.Add(line); line = new LineSegment(new Point(10.0, 5.0), false); line.Freeze(); arrowFigure.Segments.Add(line); } else { arrowFigure.StartPoint = new Point(0.0, 0.0); LineSegment line = new LineSegment(new Point(10.0, 0.0), false); line.Freeze(); arrowFigure.Segments.Add(line); line = new LineSegment(new Point(5.0, 5.0), false); line.Freeze(); arrowFigure.Segments.Add(line); } arrowFigure.IsClosed = true; arrowFigure.Freeze(); arrowGeometry.Figures.Add(arrowFigure); arrowGeometry.Freeze(); CacheFreezable(arrowGeometry, ascending ? (int)RoyaleFreezables.ArrowUpGeometry : (int)RoyaleFreezables.ArrowDownGeometry); } SolidColorBrush arrowFill = (SolidColorBrush)GetCachedFreezable((int)RoyaleFreezables.ArrowFill); if (arrowFill == null) { arrowFill = new SolidColorBrush(Color.FromArgb(0xFF, 0xAC, 0xA8, 0x99)); arrowFill.Freeze(); CacheFreezable(arrowFill, (int)RoyaleFreezables.ArrowFill); } dc.DrawGeometry(arrowFill, null, arrowGeometry); dc.Pop(); // Position Transform } if (horizontal) { dc.Pop(); // Horizontal Rotate } }
/// <summary> /// Walks the Transform(Group) and returns the corresponding Matrix. /// </summary> /// <param name="transform">Transform(Group) to walk.</param> /// <returns>Computed Matrix.</returns> private static Matrix GetTransformMatrix(Transform transform) { if (null == transform) { return(Matrix.Identity); } // WPF equivalent of this entire method: // return transform.Value; // Process the TransformGroup var transformGroup = transform as TransformGroup; if (null != transformGroup) { Matrix groupMatrix = Matrix.Identity; foreach (Transform child in transformGroup.Children) { groupMatrix = MatrixMultiply(groupMatrix, GetTransformMatrix(child)); } return(groupMatrix); } // Process the RotateTransform var rotateTransform = transform as RotateTransform; if (null != rotateTransform) { double angle = rotateTransform.Angle; double angleRadians = (2 * Math.PI * angle) / 360; double sine = Math.Sin(angleRadians); double cosine = Math.Cos(angleRadians); return(new Matrix(cosine, sine, -sine, cosine, 0, 0)); } // Process the ScaleTransform var scaleTransform = transform as ScaleTransform; if (null != scaleTransform) { double scaleX = scaleTransform.ScaleX; double scaleY = scaleTransform.ScaleY; return(new Matrix(scaleX, 0, 0, scaleY, 0, 0)); } // Process the SkewTransform var skewTransform = transform as SkewTransform; if (null != skewTransform) { double angleX = skewTransform.AngleX; double angleY = skewTransform.AngleY; double angleXRadians = (2 * Math.PI * angleX) / 360; double angleYRadians = (2 * Math.PI * angleY) / 360; return(new Matrix(1, angleYRadians, angleXRadians, 1, 0, 0)); } // Process the MatrixTransform MatrixTransform matrixTransform = transform as MatrixTransform; return(matrixTransform?.Matrix ?? Matrix.Identity); // TranslateTransform has no effect in LayoutTransform // Fall back to no-op transformation }
private void ArrangePopup() { if (((this._popup != null) && (this._popupRoot != null)) && this._popup.IsOpen) { System.Windows.Interop.Content content = Application.Current.Host.Content; double actualWidth = content.ActualWidth; double actualHeight = content.ActualHeight; double num3 = this._popupRoot.ActualWidth; double num4 = this._popupRoot.ActualHeight; if (((actualHeight != 0.0) && (actualWidth != 0.0)) && ((num3 != 0.0) && (num4 != 0.0))) { GeneralTransform transform = null; try { transform = this._popupRoot.TransformToVisual(null); } catch { //Don't need to do nothing. } if (transform != null) { Point point = new Point(0.0, 0.0); Point point2 = new Point(1.0, 0.0); Point point3 = new Point(0.0, 1.0); Point point4 = transform.Transform(point); Point point5 = transform.Transform(point2); Point point6 = transform.Transform(point3); double x = point4.X; double y = point4.Y; double num7 = base.ActualHeight; double num8 = base.ActualWidth; num3 = Math.Min(num3, actualWidth); num4 = Math.Min(num4, actualHeight); num3 = Math.Max(num8, num3); double num10 = x; if (actualWidth <= (num10 + num3)) { num10 = actualWidth - num3; num10 = Math.Max(0.0, num10); } double num11 = y + num7; if (actualHeight <= (num11 + num4)) { num11 = y - num4; if (num11 < 0.0) { if (y < ((actualHeight - num7) / 2.0)) { num11 = y + num7; } else { num11 = y - num4; } } } this._popup.HorizontalOffset = 0.0; this._popup.VerticalOffset = 0.0; this._canvasPopupOutside.Width = actualWidth; this._canvasPopupOutside.Height = actualHeight; Matrix identity = Matrix.Identity; identity.M11 = point5.X - point4.X; identity.M12 = point5.Y - point4.Y; identity.M21 = point6.X - point4.X; identity.M22 = point6.Y - point4.Y; identity.OffsetX -= point4.X; identity.OffsetY -= point4.Y; MatrixTransform transform2 = new MatrixTransform(); transform2.Matrix = identity; this._canvasPopupOutside.RenderTransform = transform2; this._popupRoot.MinWidth = num8; this._popupRoot.MaxWidth = actualWidth; this._popupRoot.MinHeight = num7; this._popupRoot.MaxHeight = actualHeight; this._popupRoot.HorizontalAlignment = HorizontalAlignment.Left; this._popupRoot.VerticalAlignment = VerticalAlignment.Top; Canvas.SetLeft(this._popupRoot, num10 - x); Canvas.SetTop(this._popupRoot, num11 - y); } } } }
/// <summary> /// Renders a bitmap using any affine transformation and transparency into this bitmap /// Unlike Silverlight's Render() method, this one uses 2-3 times less memory, and is the same or better quality /// The algorithm is simple dx/dy (bresenham-like) step by step painting, optimized with fixed point and fast bilinear filtering /// It's used in Fantasia Painter for drawing stickers and 3D objects on screen /// </summary> /// <param name="bmp">Destination bitmap.</param> /// <param name="source">The source WriteableBitmap.</param> /// <param name="shouldClear">If true, the the destination bitmap will be set to all clear (0) before rendering.</param> /// <param name="opacity">opacity of the source bitmap to render, between 0 and 1 inclusive</param> /// <param name="transform">Transformation to apply</param> public static void BlitRender(this WriteableBitmap bmp, WriteableBitmap source, bool shouldClear = true, float opacity = 1f, GeneralTransform transform = null) { const int PRECISION_SHIFT = 10; const int PRECISION_VALUE = (1 << PRECISION_SHIFT); const int PRECISION_MASK = PRECISION_VALUE - 1; using (BitmapContext destContext = bmp.GetBitmapContext()) { if (transform == null) transform = new MatrixTransform(); var destPixels = destContext.Pixels; int destWidth = destContext.Width; int destHeight = destContext.Height; var inverse = transform.Inverse; if(shouldClear) destContext.Clear(); using (BitmapContext sourceContext = source.GetBitmapContext()) { var sourcePixels = sourceContext.Pixels; int sourceWidth = sourceContext.Width; int sourceHeight = sourceContext.Height; Rect sourceRect = new Rect(0, 0, sourceWidth, sourceHeight); Rect destRect = new Rect(0, 0, destWidth, destHeight); Rect bounds = transform.TransformBounds(sourceRect); bounds.Intersect(destRect); int startX = (int)bounds.Left; int startY = (int)bounds.Top; int endX = (int)bounds.Right; int endY = (int)bounds.Bottom; #if NETFX_CORE Point zeroZero = inverse.TransformPoint(new Point(startX, startY)); Point oneZero = inverse.TransformPoint(new Point(startX + 1, startY)); Point zeroOne = inverse.TransformPoint(new Point(startX, startY + 1)); #else Point zeroZero = inverse.Transform(new Point(startX, startY)); Point oneZero = inverse.Transform(new Point(startX + 1, startY)); Point zeroOne = inverse.Transform(new Point(startX, startY + 1)); #endif float sourceXf = ((float)zeroZero.X); float sourceYf = ((float)zeroZero.Y); int dxDx = (int)((((float)oneZero.X) - sourceXf) * PRECISION_VALUE); // for 1 unit in X coord, how much does X change in source texture? int dxDy = (int)((((float)oneZero.Y) - sourceYf) * PRECISION_VALUE); // for 1 unit in X coord, how much does Y change in source texture? int dyDx = (int)((((float)zeroOne.X) - sourceXf) * PRECISION_VALUE); // for 1 unit in Y coord, how much does X change in source texture? int dyDy = (int)((((float)zeroOne.Y) - sourceYf) * PRECISION_VALUE); // for 1 unit in Y coord, how much does Y change in source texture? int sourceX = (int)(((float)zeroZero.X) * PRECISION_VALUE); int sourceY = (int)(((float)zeroZero.Y) * PRECISION_VALUE); int sourceWidthFixed = sourceWidth << PRECISION_SHIFT; int sourceHeightFixed = sourceHeight << PRECISION_SHIFT; int opacityInt = (int)(opacity * 255); int index = 0; for (int destY = startY; destY < endY; destY++) { index = destY * destWidth + startX; int savedSourceX = sourceX; int savedSourceY = sourceY; for (int destX = startX; destX < endX; destX++) { if ((sourceX >= 0) && (sourceX < sourceWidthFixed) && (sourceY >= 0) && (sourceY < sourceHeightFixed)) { // bilinear filtering int xFloor = sourceX >> PRECISION_SHIFT; int yFloor = sourceY >> PRECISION_SHIFT; if (xFloor < 0) xFloor = 0; if (yFloor < 0) yFloor = 0; int xCeil = xFloor + 1; int yCeil = yFloor + 1; if (xCeil >= sourceWidth) { xFloor = sourceWidth - 1; xCeil = 0; } else { xCeil = 1; } if (yCeil >= sourceHeight) { yFloor = sourceHeight - 1; yCeil = 0; } else { yCeil = sourceWidth; } int i1 = yFloor * sourceWidth + xFloor; int p1 = sourcePixels[i1]; int p2 = sourcePixels[i1 + xCeil]; int p3 = sourcePixels[i1 + yCeil]; int p4 = sourcePixels[i1 + yCeil + xCeil]; int xFrac = sourceX & PRECISION_MASK; int yFrac = sourceY & PRECISION_MASK; // alpha byte a1 = (byte)(p1 >> 24); byte a2 = (byte)(p2 >> 24); byte a3 = (byte)(p3 >> 24); byte a4 = (byte)(p4 >> 24); int comp1, comp2; byte a; if ((a1 == a2) && (a1 == a3) && (a1 == a4)) { if (a1 == 0) { destPixels[index] = 0; sourceX += dxDx; sourceY += dxDy; index++; continue; } a = a1; } else { comp1 = a1 + ((xFrac * (a2 - a1)) >> PRECISION_SHIFT); comp2 = a3 + ((xFrac * (a4 - a3)) >> PRECISION_SHIFT); a = (byte)(comp1 + ((yFrac * (comp2 - comp1)) >> PRECISION_SHIFT)); } // red comp1 = ((byte)(p1 >> 16)) + ((xFrac * (((byte)(p2 >> 16)) - ((byte)(p1 >> 16)))) >> PRECISION_SHIFT); comp2 = ((byte)(p3 >> 16)) + ((xFrac * (((byte)(p4 >> 16)) - ((byte)(p3 >> 16)))) >> PRECISION_SHIFT); byte r = (byte)(comp1 + ((yFrac * (comp2 - comp1)) >> PRECISION_SHIFT)); // green comp1 = ((byte)(p1 >> 8)) + ((xFrac * (((byte)(p2 >> 8)) - ((byte)(p1 >> 8)))) >> PRECISION_SHIFT); comp2 = ((byte)(p3 >> 8)) + ((xFrac * (((byte)(p4 >> 8)) - ((byte)(p3 >> 8)))) >> PRECISION_SHIFT); byte g = (byte)(comp1 + ((yFrac * (comp2 - comp1)) >> PRECISION_SHIFT)); // blue comp1 = ((byte)p1) + ((xFrac * (((byte)p2) - ((byte)p1))) >> PRECISION_SHIFT); comp2 = ((byte)p3) + ((xFrac * (((byte)p4) - ((byte)p3))) >> PRECISION_SHIFT); byte b = (byte)(comp1 + ((yFrac * (comp2 - comp1)) >> PRECISION_SHIFT)); // save updated pixel if (opacityInt != 255) { a = (byte)((a * opacityInt) >> 8); r = (byte)((r * opacityInt) >> 8); g = (byte)((g * opacityInt) >> 8); b = (byte)((b * opacityInt) >> 8); } destPixels[index] = (a << 24) | (r << 16) | (g << 8) | b; } sourceX += dxDx; sourceY += dxDy; index++; } sourceX = savedSourceX + dyDx; sourceY = savedSourceY + dyDy; } } } }
private void RenderTheme(DrawingContext dc) { Size size = RenderSize; bool horizontal = Orientation == Orientation.Horizontal; bool isClickable = IsClickable && IsEnabled; bool isHovered = isClickable && IsHovered; bool isPressed = isClickable && IsPressed; ListSortDirection?sortDirection = SortDirection; bool isSorted = sortDirection != null; bool isSelected = IsSelected; bool hasBevel = (!isHovered && !isPressed && !isSorted && !isSelected); EnsureCache((int)AeroFreezables.NumFreezables); if (horizontal) { // When horizontal, rotate the rendering by -90 degrees Matrix m1 = new Matrix(); m1.RotateAt(-90.0, 0.0, 0.0); Matrix m2 = new Matrix(); m2.Translate(0.0, size.Height); MatrixTransform horizontalRotate = new MatrixTransform(m1 * m2); horizontalRotate.Freeze(); dc.PushTransform(horizontalRotate); double temp = size.Width; size.Width = size.Height; size.Height = temp; } if (hasBevel) { // This is a highlight that can be drawn by just filling the background with the color. // It will be seen through the gab between the border and the background. LinearGradientBrush bevel = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.NormalBevel); if (bevel == null) { bevel = new LinearGradientBrush(); bevel.StartPoint = new Point(); bevel.EndPoint = new Point(0.0, 1.0); bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.0)); bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.4)); bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFC, 0xFC, 0xFD), 0.4)); bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFB, 0xFC, 0xFC), 1.0)); bevel.Freeze(); CacheFreezable(bevel, (int)AeroFreezables.NormalBevel); } dc.DrawRectangle(bevel, null, new Rect(0.0, 0.0, size.Width, size.Height)); } // Fill the background AeroFreezables backgroundType = AeroFreezables.NormalBackground; if (isPressed) { backgroundType = AeroFreezables.PressedBackground; } else if (isHovered) { backgroundType = AeroFreezables.HoveredBackground; } else if (isSorted || isSelected) { backgroundType = AeroFreezables.SortedBackground; } LinearGradientBrush background = (LinearGradientBrush)GetCachedFreezable((int)backgroundType); if (background == null) { background = new LinearGradientBrush(); background.StartPoint = new Point(); background.EndPoint = new Point(0.0, 1.0); switch (backgroundType) { case AeroFreezables.NormalBackground: background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.0)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF7, 0xF8, 0xFA), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF1, 0xF2, 0xF4), 1.0)); break; case AeroFreezables.PressedBackground: background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBC, 0xE4, 0xF9), 0.0)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBC, 0xE4, 0xF9), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x8D, 0xD6, 0xF7), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x8A, 0xD1, 0xF5), 1.0)); break; case AeroFreezables.HoveredBackground: background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE3, 0xF7, 0xFF), 0.0)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE3, 0xF7, 0xFF), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBD, 0xED, 0xFF), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xB7, 0xE7, 0xFB), 1.0)); break; case AeroFreezables.SortedBackground: background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF9, 0xFC), 0.0)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF9, 0xFC), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE1, 0xF1, 0xF9), 0.4)); background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xD8, 0xEC, 0xF6), 1.0)); break; } background.Freeze(); CacheFreezable(background, (int)backgroundType); } dc.DrawRectangle(background, null, new Rect(0.0, 0.0, size.Width, size.Height)); if (size.Width >= 2.0) { // Draw the borders on the sides AeroFreezables sideType = AeroFreezables.NormalSides; if (isPressed) { sideType = AeroFreezables.PressedSides; } else if (isHovered) { sideType = AeroFreezables.HoveredSides; } else if (isSorted || isSelected) { sideType = AeroFreezables.SortedSides; } if (SeparatorVisibility == Visibility.Visible) { Brush sideBrush; if (SeparatorBrush != null) { sideBrush = SeparatorBrush; } else { sideBrush = (Brush)GetCachedFreezable((int)sideType); if (sideBrush == null) { LinearGradientBrush lgBrush = null; if (sideType != AeroFreezables.SortedSides) { lgBrush = new LinearGradientBrush(); lgBrush.StartPoint = new Point(); lgBrush.EndPoint = new Point(0.0, 1.0); sideBrush = lgBrush; } switch (sideType) { case AeroFreezables.NormalSides: lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF2, 0xF2), 0.0)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEF, 0xEF, 0xEF), 0.4)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE7, 0xE8, 0xEA), 0.4)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xDE, 0xDF, 0xE1), 1.0)); break; case AeroFreezables.PressedSides: lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x7A, 0x9E, 0xB1), 0.0)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x7A, 0x9E, 0xB1), 0.4)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x50, 0x91, 0xAF), 0.4)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x4D, 0x8D, 0xAD), 1.0)); break; case AeroFreezables.HoveredSides: lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x88, 0xCB, 0xEB), 0.0)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x88, 0xCB, 0xEB), 0.4)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x69, 0xBB, 0xE3), 0.4)); lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x69, 0xBB, 0xE3), 1.0)); break; case AeroFreezables.SortedSides: sideBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x96, 0xD9, 0xF9)); break; } sideBrush.Freeze(); CacheFreezable(sideBrush, (int)sideType); } } dc.DrawRectangle(sideBrush, null, new Rect(0.0, 0.0, 1.0, Max0(size.Height - 0.95))); dc.DrawRectangle(sideBrush, null, new Rect(size.Width - 1.0, 0.0, 1.0, Max0(size.Height - 0.95))); } } if (isPressed && (size.Width >= 4.0) && (size.Height >= 4.0)) { // When pressed, there are added borders on the left and top LinearGradientBrush topBrush = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.PressedTop); if (topBrush == null) { topBrush = new LinearGradientBrush(); topBrush.StartPoint = new Point(); topBrush.EndPoint = new Point(0.0, 1.0); topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x86, 0xA3, 0xB2), 0.0)); topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x86, 0xA3, 0xB2), 0.1)); topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xAA, 0xCE, 0xE1), 0.9)); topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xAA, 0xCE, 0xE1), 1.0)); topBrush.Freeze(); CacheFreezable(topBrush, (int)AeroFreezables.PressedTop); } dc.DrawRectangle(topBrush, null, new Rect(0.0, 0.0, size.Width, 2.0)); LinearGradientBrush pressedBevel = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.PressedBevel); if (pressedBevel == null) { pressedBevel = new LinearGradientBrush(); pressedBevel.StartPoint = new Point(); pressedBevel.EndPoint = new Point(0.0, 1.0); pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xA2, 0xCB, 0xE0), 0.0)); pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xA2, 0xCB, 0xE0), 0.4)); pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x72, 0xBC, 0xDF), 0.4)); pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x6E, 0xB8, 0xDC), 1.0)); pressedBevel.Freeze(); CacheFreezable(pressedBevel, (int)AeroFreezables.PressedBevel); } dc.DrawRectangle(pressedBevel, null, new Rect(1.0, 0.0, 1.0, size.Height - 0.95)); dc.DrawRectangle(pressedBevel, null, new Rect(size.Width - 2.0, 0.0, 1.0, size.Height - 0.95)); } if (size.Height >= 2.0) { // Draw the bottom border AeroFreezables bottomType = AeroFreezables.NormalBottom; if (isPressed) { bottomType = AeroFreezables.PressedOrHoveredBottom; } else if (isHovered) { bottomType = AeroFreezables.PressedOrHoveredBottom; } else if (isSorted || isSelected) { bottomType = AeroFreezables.SortedBottom; } SolidColorBrush bottomBrush = (SolidColorBrush)GetCachedFreezable((int)bottomType); if (bottomBrush == null) { switch (bottomType) { case AeroFreezables.NormalBottom: bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xD5, 0xD5, 0xD5)); break; case AeroFreezables.PressedOrHoveredBottom: bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x93, 0xC9, 0xE3)); break; case AeroFreezables.SortedBottom: bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x96, 0xD9, 0xF9)); break; } bottomBrush.Freeze(); CacheFreezable(bottomBrush, (int)bottomType); } dc.DrawRectangle(bottomBrush, null, new Rect(0.0, size.Height - 1.0, size.Width, 1.0)); } if (isSorted && (size.Width > 14.0) && (size.Height > 10.0)) { // Draw the sort arrow TranslateTransform positionTransform = new TranslateTransform((size.Width - 8.0) * 0.5, 1.0); positionTransform.Freeze(); dc.PushTransform(positionTransform); bool ascending = (sortDirection == ListSortDirection.Ascending); PathGeometry arrowGeometry = (PathGeometry)GetCachedFreezable(ascending ? (int)AeroFreezables.ArrowUpGeometry : (int)AeroFreezables.ArrowDownGeometry); if (arrowGeometry == null) { arrowGeometry = new PathGeometry(); PathFigure arrowFigure = new PathFigure(); if (ascending) { arrowFigure.StartPoint = new Point(0.0, 4.0); LineSegment line = new LineSegment(new Point(4.0, 0.0), false); line.Freeze(); arrowFigure.Segments.Add(line); line = new LineSegment(new Point(8.0, 4.0), false); line.Freeze(); arrowFigure.Segments.Add(line); } else { arrowFigure.StartPoint = new Point(0.0, 0.0); LineSegment line = new LineSegment(new Point(8.0, 0.0), false); line.Freeze(); arrowFigure.Segments.Add(line); line = new LineSegment(new Point(4.0, 4.0), false); line.Freeze(); arrowFigure.Segments.Add(line); } arrowFigure.IsClosed = true; arrowFigure.Freeze(); arrowGeometry.Figures.Add(arrowFigure); arrowGeometry.Freeze(); CacheFreezable(arrowGeometry, ascending ? (int)AeroFreezables.ArrowUpGeometry : (int)AeroFreezables.ArrowDownGeometry); } // Draw two arrows, one inset in the other. This is to achieve a double gradient over both the border and the fill. LinearGradientBrush arrowBorder = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.ArrowBorder); if (arrowBorder == null) { arrowBorder = new LinearGradientBrush(); arrowBorder.StartPoint = new Point(); arrowBorder.EndPoint = new Point(1.0, 1.0); arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x3C, 0x5E, 0x72), 0.0)); arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x3C, 0x5E, 0x72), 0.1)); arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xC3, 0xE4, 0xF5), 1.0)); arrowBorder.Freeze(); CacheFreezable(arrowBorder, (int)AeroFreezables.ArrowBorder); } dc.DrawGeometry(arrowBorder, null, arrowGeometry); LinearGradientBrush arrowFill = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.ArrowFill); if (arrowFill == null) { arrowFill = new LinearGradientBrush(); arrowFill.StartPoint = new Point(); arrowFill.EndPoint = new Point(1.0, 1.0); arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x61, 0x96, 0xB6), 0.0)); arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x61, 0x96, 0xB6), 0.1)); arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xCA, 0xE6, 0xF5), 1.0)); arrowFill.Freeze(); CacheFreezable(arrowFill, (int)AeroFreezables.ArrowFill); } // Inset the fill arrow inside the border arrow ScaleTransform arrowScale = (ScaleTransform)GetCachedFreezable((int)AeroFreezables.ArrowFillScale); if (arrowScale == null) { arrowScale = new ScaleTransform(0.75, 0.75, 3.5, 4.0); arrowScale.Freeze(); CacheFreezable(arrowScale, (int)AeroFreezables.ArrowFillScale); } dc.PushTransform(arrowScale); dc.DrawGeometry(arrowFill, null, arrowGeometry); dc.Pop(); // Scale Transform dc.Pop(); // Position Transform } if (horizontal) { dc.Pop(); // Horizontal Rotate } }
internal static Transform CloneTransform(Transform transform) { ScaleTransform scaleTransform = null; RotateTransform rotateTransform = null; SkewTransform skewTransform = null; TranslateTransform translateTransform = null; MatrixTransform matrixTransform = null; TransformGroup transformGroup = null; if (transform == null) { return(null); } transform.GetType(); if ((scaleTransform = (transform as ScaleTransform)) != null) { ScaleTransform scaleTransform2 = new ScaleTransform(); scaleTransform2.CenterX = scaleTransform.CenterX; scaleTransform2.CenterY = scaleTransform.CenterY; scaleTransform2.ScaleX = scaleTransform.ScaleX; scaleTransform2.ScaleY = scaleTransform.ScaleY; return(scaleTransform2); } if ((rotateTransform = (transform as RotateTransform)) != null) { RotateTransform rotateTransform2 = new RotateTransform(); rotateTransform2.Angle = rotateTransform.Angle; rotateTransform2.CenterX = rotateTransform.CenterX; rotateTransform2.CenterY = rotateTransform.CenterY; return(rotateTransform2); } if ((skewTransform = (transform as SkewTransform)) != null) { SkewTransform skewTransform2 = new SkewTransform(); skewTransform2.AngleX = skewTransform.AngleX; skewTransform2.AngleY = skewTransform.AngleY; skewTransform2.CenterX = skewTransform.CenterX; skewTransform2.CenterY = skewTransform.CenterY; return(skewTransform2); } if ((translateTransform = (transform as TranslateTransform)) != null) { TranslateTransform translateTransform2 = new TranslateTransform(); translateTransform2.X = translateTransform.X; translateTransform2.Y = translateTransform.Y; return(translateTransform2); } if ((matrixTransform = (transform as MatrixTransform)) != null) { MatrixTransform matrixTransform2 = new MatrixTransform(); matrixTransform2.Matrix = matrixTransform.Matrix; return(matrixTransform2); } if ((transformGroup = (transform as TransformGroup)) != null) { TransformGroup transformGroup2 = new TransformGroup(); { foreach (Transform child in transformGroup.Children) { transformGroup2.Children.Add(CloneTransform(child)); } return(transformGroup2); } } return(null); }
private Brush GetLinearGradientBrush(SvgLinearGradientElement res, Transform viewBoxTransform = null) { double x1 = res.X1.AnimVal.Value; double x2 = res.X2.AnimVal.Value; double y1 = res.Y1.AnimVal.Value; double y2 = res.Y2.AnimVal.Value; GradientStopCollection gradientStops = GetGradientStops(res.Stops); if (gradientStops == null || gradientStops.Count == 0) { return(null); } LinearGradientBrush brush = new LinearGradientBrush(gradientStops, new Point(x1, y1), new Point(x2, y2)); SvgSpreadMethod spreadMethod = SvgSpreadMethod.Pad; if (res.SpreadMethod != null) { spreadMethod = (SvgSpreadMethod)res.SpreadMethod.AnimVal; if (spreadMethod != SvgSpreadMethod.None) { brush.SpreadMethod = WpfConvert.ToSpreadMethod(spreadMethod); } } SvgUnitType mappingMode = SvgUnitType.ObjectBoundingBox; if (res.GradientUnits != null) { mappingMode = (SvgUnitType)res.GradientUnits.AnimVal; if (mappingMode == SvgUnitType.ObjectBoundingBox) { brush.MappingMode = BrushMappingMode.RelativeToBoundingBox; } else if (mappingMode == SvgUnitType.UserSpaceOnUse) { brush.MappingMode = BrushMappingMode.Absolute; _isUserSpace = true; //if (viewBoxTransform == null || viewBoxTransform.Value.IsIdentity) //{ // if (!elementBounds.IsEmpty) // { // viewBoxTransform = FitToViewbox(new SvgRect(x1, y1, // Math.Abs(x2 - x1), Math.Abs(y2 - y1)), elementBounds); // } //} } } string colorInterpolation = res.GetPropertyValue("color-interpolation"); if (!string.IsNullOrWhiteSpace(colorInterpolation)) { if (colorInterpolation == "linearRGB") { brush.ColorInterpolationMode = ColorInterpolationMode.ScRgbLinearInterpolation; } else { brush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; } } MatrixTransform transform = GetTransformMatrix(res); if (transform != null && !transform.Matrix.IsIdentity) { if (viewBoxTransform != null && !viewBoxTransform.Value.IsIdentity) { TransformGroup group = new TransformGroup(); group.Children.Add(viewBoxTransform); group.Children.Add(transform); brush.Transform = group; } else { brush.Transform = transform; //brush.StartPoint = new Point(0, 0.5); //brush.EndPoint = new Point(1, 0.5); } //brush.StartPoint = new Point(0, 0); //brush.EndPoint = new Point(1, 1); } else { float fLeft = (float)res.X1.AnimVal.Value; float fRight = (float)res.X2.AnimVal.Value; float fTop = (float)res.Y1.AnimVal.Value; float fBottom = (float)res.Y2.AnimVal.Value; if (mappingMode == SvgUnitType.ObjectBoundingBox) { if (!fTop.Equals(fBottom) && !fLeft.Equals(fRight)) { var drawingBrush = new DrawingBrush(); drawingBrush.Stretch = Stretch.Fill; drawingBrush.Viewbox = new Rect(0, 0, 1, 1); var DrawingRect = new GeometryDrawing(brush, null, new RectangleGeometry(new Rect(0, 0, 1, 1))); drawingBrush.Drawing = DrawingRect; return(drawingBrush); } } if (fTop.Equals(fBottom)) { //mode = LinearGradientMode.Horizontal; //brush.StartPoint = new Point(0, 0.5); //brush.EndPoint = new Point(1, 0.5); } else { if (fLeft.Equals(fRight)) { //mode = LinearGradientMode.Vertical; //brush.StartPoint = new Point(0.5, 0); //brush.EndPoint = new Point(0.5, 1); } else { if (fLeft < fRight) { if (viewBoxTransform != null && !viewBoxTransform.Value.IsIdentity) { //TransformGroup group = new TransformGroup(); //group.Children.Add(viewBoxTransform); //group.Children.Add(new RotateTransform(45, 0.5, 0.5)); //brush.Transform = group; brush.Transform = viewBoxTransform; } //else //{ // brush.RelativeTransform = new RotateTransform(45, 0.5, 0.5); //} //mode = LinearGradientMode.ForwardDiagonal; //brush.EndPoint = new Point(x1, y1 + 1); //brush.StartPoint = new Point(0, 0); //brush.EndPoint = new Point(1, 1); } else { //mode = LinearGradientMode.BackwardDiagonal; if (viewBoxTransform != null && !viewBoxTransform.Value.IsIdentity) { //TransformGroup group = new TransformGroup(); //group.Children.Add(viewBoxTransform); //group.Children.Add(new RotateTransform(-45, 0.5, 0.5)); //brush.Transform = group; brush.Transform = viewBoxTransform; } //else //{ // brush.RelativeTransform = new RotateTransform(-45, 0.5, 0.5); //} //brush.StartPoint = new Point(0, 0); //brush.EndPoint = new Point(1, 1); } } } } return(brush); }
internal override WpfBrush RealizeWpfBrush() { //if (dirty) //{ // if (brush == null) // brush = new SolidBrush(color.ToGdiColor()); // else // { // brush.Color = color.ToGdiColor(); // } // dirty = false; //} System.Windows.Media.LinearGradientBrush brush; if (_useRect) { #if !SILVERLIGHT brush = new System.Windows.Media.LinearGradientBrush(_color1.ToWpfColor(), _color2.ToWpfColor(), new SysPoint(0, 0), new SysPoint(1, 1));// rect.TopLeft, this.rect.BottomRight); //brush = new System.Drawing.Drawing2D.LinearGradientBrush(rect.ToRectangleF(), // color1.ToGdiColor(), color2.ToGdiColor(), (LinearGradientMode)linearGradientMode); #else GradientStop gs1 = new GradientStop(); gs1.Color = _color1.ToWpfColor(); gs1.Offset = 0; GradientStop gs2 = new GradientStop(); gs2.Color = _color2.ToWpfColor(); gs2.Offset = 1; GradientStopCollection gsc = new GradientStopCollection(); gsc.Add(gs1); gsc.Add(gs2); brush = new LinearGradientBrush(gsc, 0); brush.StartPoint = new Point(0, 0); brush.EndPoint = new Point(1, 1); #endif } else { #if !SILVERLIGHT brush = new System.Windows.Media.LinearGradientBrush(_color1.ToWpfColor(), _color2.ToWpfColor(), _point1, _point2); //brush = new System.Drawing.Drawing2D.LinearGradientBrush( // point1.ToPointF(), point2.ToPointF(), // color1.ToGdiColor(), color2.ToGdiColor()); #else GradientStop gs1 = new GradientStop(); gs1.Color = _color1.ToWpfColor(); gs1.Offset = 0; GradientStop gs2 = new GradientStop(); gs2.Color = _color2.ToWpfColor(); gs2.Offset = 1; GradientStopCollection gsc = new GradientStopCollection(); gsc.Add(gs1); gsc.Add(gs2); brush = new LinearGradientBrush(gsc, 0); brush.StartPoint = _point1; brush.EndPoint = _point2; #endif } if (!_matrix.IsIdentity) { #if !SILVERLIGHT brush.Transform = new MatrixTransform(_matrix.ToWpfMatrix()); #else MatrixTransform transform = new MatrixTransform(); transform.Matrix = _matrix.ToWpfMatrix(); brush.Transform = transform; #endif } return(brush); }
public static void AddPointToStoryboard(Grid runPoint, Ellipse toEll, Storyboard sb, PathGeometry particle, double l, Point startPoint, Point endPoint, double pointTime) { //double pointTime = l / m_Speed;//点运动所需的时间 double particleTime = pointTime / 2;//轨迹呈现所需时间(跑的比点快两倍) #region 运动的点 TransformGroup tfg = new TransformGroup(); MatrixTransform mtf = new MatrixTransform(); tfg.Children.Add(mtf); TranslateTransform ttf = new TranslateTransform(-runPoint.Width / 2, -runPoint.Height / 2);//纠正最上角沿path运动到中心沿path运动 tfg.Children.Add(ttf); runPoint.RenderTransform = tfg; MatrixAnimationUsingPath maup = new MatrixAnimationUsingPath { PathGeometry = particle.GetFlattenedPathGeometry(), Duration = new Duration(TimeSpan.FromSeconds(pointTime)), RepeatBehavior = RepeatBehavior.Forever, AutoReverse = false, IsOffsetCumulative = false, DoesRotateWithTangent = true }; Storyboard.SetTarget(maup, runPoint); Storyboard.SetTargetProperty(maup, new PropertyPath("(Grid.RenderTransform).Children[0].(MatrixTransform.Matrix)")); sb.Children.Add(maup); #endregion #region 达到城市的圆 //轨迹到达圆时 圆呈现 var ellda = Animation1(particleTime); Storyboard.SetTarget(ellda, toEll); Storyboard.SetTargetProperty(ellda, new PropertyPath(Ellipse.OpacityProperty)); sb.Children.Add(ellda); //圆呈放射状 RadialGradientBrush rgBrush = new RadialGradientBrush(); GradientStop gStop0 = new GradientStop(Color.FromArgb(255, 0, 0, 0), 0); //此为控制点 color的a值设为0 off值走0-1 透明部分向外放射 初始设为255是为了初始化效果 开始不呈放射状 等跑动的点运动到城市的圆后 color的a值才设为0开始呈现放射动画 GradientStop gStopT = new GradientStop(Color.FromArgb(255, 0, 0, 0), 0); GradientStop gStop1 = new GradientStop(Color.FromArgb(255, 0, 0, 0), 1); rgBrush.GradientStops.Add(gStop0); rgBrush.GradientStops.Add(gStopT); rgBrush.GradientStops.Add(gStop1); toEll.OpacityMask = rgBrush; //跑动的点达到城市的圆时 控制点由不透明变为透明 color的a值设为0 动画时间为0 var ca = ColorAnimation(pointTime); Storyboard.SetTarget(ca, toEll); Storyboard.SetTargetProperty(ca, new PropertyPath("(Ellipse.OpacityMask).(GradientBrush.GradientStops)[1].(GradientStop.Color)")); sb.Children.Add(ca); var eda = Animation2(particleTime); Storyboard.SetTarget(eda, toEll); Storyboard.SetTargetProperty(eda, new PropertyPath("(Ellipse.OpacityMask).(GradientBrush.GradientStops)[1].(GradientStop.Offset)")); sb.Children.Add(eda); #endregion }
/// <summary> /// Parses a ResourceDictionary element. /// </summary> void ParseResourceDictionary(ResourceDictionary dict) { //Debug.Assert(this.reader.Name == "ResourceDictionary"); Debug.Assert(this.reader.Name.Contains("Resource")); try { bool isEmptyElement = this.reader.IsEmptyElement; //ResourceDictionary dict = new ResourceDictionary(); while (MoveToNextAttribute()) { switch (this.reader.Name) { case "Source": dict.Source = this.reader.Value; break; default: UnexpectedAttribute(this.reader.Name); break; } } if (!isEmptyElement) { MoveToNextElement(); while (this.reader.IsStartElement()) { switch (this.reader.Name) { case "ImageBrush": ImageBrush ibrush = ParseImageBrush(); dict.elements[ibrush.Key] = ibrush; ibrush.Parent = dict; break; case "LinearGradientBrush": LinearGradientBrush lbrush = ParseLinearGradientBrush(); dict.elements[lbrush.Key] = lbrush; lbrush.Parent = dict; break; case "RadialGradientBrush": RadialGradientBrush rbrush = ParseRadialGradientBrush(); dict.elements[rbrush.Key] = rbrush; rbrush.Parent = dict; break; case "VisualBrush": VisualBrush vbrush = ParseVisualBrush(); dict.elements[vbrush.Key] = vbrush; vbrush.Parent = dict; break; case "SolidColorBrush": VisualBrush sbrush = ParseVisualBrush(); dict.elements[sbrush.Key] = sbrush; sbrush.Parent = dict; break; case "MatrixTransform": MatrixTransform transform = ParseMatrixTransform(); dict.elements[transform.Key] = transform; transform.Parent = dict; break; case "PathGeometry": PathGeometry geo = ParsePathGeometry(); dict.elements[geo.Key] = geo; geo.Parent = dict; break; case "Path": Path path = ParsePath(); dict.elements[path.Key] = path; path.Parent = dict; break; case "Glyphs": Glyphs glyphs = ParseGlyphs(); dict.elements[glyphs.Key] = glyphs; glyphs.Parent = dict; break; case "Canvas": Canvas canvas = ParseCanvas(); dict.elements[canvas.Key] = canvas; canvas.Parent = dict; break; default: Debugger.Break(); break; } } } MoveToNextElement(); //return dict; } finally { } }
private Brush GetLinearGradientBrush(SvgLinearGradientElement res, Transform viewBoxTransform = null) { GradientStopCollection gradientStops = GetGradientStops(res.Stops); if (gradientStops == null || gradientStops.Count == 0) { return(null); } double x1 = res.X1.AnimVal.Value; double x2 = res.X2.AnimVal.Value; double y1 = res.Y1.AnimVal.Value; double y2 = res.Y2.AnimVal.Value; LinearGradientBrush brush = new LinearGradientBrush(gradientStops, new Point(x1, y1), new Point(x2, y2)); SvgSpreadMethod spreadMethod = SvgSpreadMethod.Pad; if (res.SpreadMethod != null) { spreadMethod = (SvgSpreadMethod)res.SpreadMethod.AnimVal; if (spreadMethod != SvgSpreadMethod.None) { brush.SpreadMethod = WpfConvert.ToSpreadMethod(spreadMethod); } } SvgUnitType mappingMode = SvgUnitType.ObjectBoundingBox; if (res.GradientUnits != null) { mappingMode = (SvgUnitType)res.GradientUnits.AnimVal; if (mappingMode == SvgUnitType.ObjectBoundingBox) { brush.MappingMode = BrushMappingMode.RelativeToBoundingBox; } else if (mappingMode == SvgUnitType.UserSpaceOnUse) { brush.MappingMode = BrushMappingMode.Absolute; _isUserSpace = true; } } string colorInterpolation = res.GetPropertyValue("color-interpolation"); if (!string.IsNullOrWhiteSpace(colorInterpolation)) { if (string.Equals(colorInterpolation, "linearRGB", StringComparison.OrdinalIgnoreCase)) { brush.ColorInterpolationMode = ColorInterpolationMode.ScRgbLinearInterpolation; } else { brush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; } } MatrixTransform transform = GetTransformMatrix(res); if (transform != null && !transform.Matrix.IsIdentity) { if (viewBoxTransform != null && !viewBoxTransform.Value.IsIdentity) { TransformGroup group = new TransformGroup(); group.Children.Add(viewBoxTransform); group.Children.Add(transform); brush.Transform = group; } else { brush.Transform = transform; } } else { float fLeft = (float)res.X1.AnimVal.Value; float fRight = (float)res.X2.AnimVal.Value; float fTop = (float)res.Y1.AnimVal.Value; float fBottom = (float)res.Y2.AnimVal.Value; if (mappingMode == SvgUnitType.ObjectBoundingBox) { if (!fTop.Equals(fBottom) && !fLeft.Equals(fRight)) { var drawingBrush = new DrawingBrush(); drawingBrush.Stretch = Stretch.Fill; drawingBrush.Viewbox = new Rect(0, 0, 1, 1); var DrawingRect = new GeometryDrawing(brush, null, new RectangleGeometry(new Rect(0, 0, 1, 1))); drawingBrush.Drawing = DrawingRect; return(drawingBrush); } } if (fTop.Equals(fBottom)) { } else { if (fLeft.Equals(fRight)) { } else { if (fLeft < fRight) { if (viewBoxTransform != null && !viewBoxTransform.Value.IsIdentity) { brush.Transform = viewBoxTransform; } } else { if (viewBoxTransform != null && !viewBoxTransform.Value.IsIdentity) { brush.Transform = viewBoxTransform; } } } } } return(brush); }
/// <summary> /// Returns a render transform of the specified type from the element, creating it if necessary /// </summary> /// <typeparam name="TRequestedTransform">The type of transform (Rotate, Translate, etc)</typeparam> /// <param name="element">The element to check</param> /// <param name="mode">The mode to use for creating transforms, if not found</param> /// <returns>The specified transform, or null if not found and not created</returns> public static TRequestedTransform GetTransform <TRequestedTransform>(this UIElement element, TransformCreationMode mode) where TRequestedTransform : Transform, new() { Transform originalTransform = element.RenderTransform; TRequestedTransform requestedTransform = null; MatrixTransform matrixTransform = null; TransformGroup transformGroup = null; // Current transform is null -- create if necessary and return if (originalTransform == null) { if ((mode & TransformCreationMode.Create) == TransformCreationMode.Create) { requestedTransform = new TRequestedTransform(); element.RenderTransform = requestedTransform; return(requestedTransform); } return(null); } // Transform is exactly what we want -- return it requestedTransform = originalTransform as TRequestedTransform; if (requestedTransform != null) { return(requestedTransform); } // The existing transform is matrix transform - overwrite if necessary and return matrixTransform = originalTransform as MatrixTransform; if (matrixTransform != null) { if (matrixTransform.Matrix.IsIdentity && (mode & TransformCreationMode.Create) == TransformCreationMode.Create && (mode & TransformCreationMode.IgnoreIdentityMatrix) == TransformCreationMode.IgnoreIdentityMatrix) { requestedTransform = new TRequestedTransform(); element.RenderTransform = requestedTransform; return(requestedTransform); } return(null); } // Transform is actually a group -- check for the requested type transformGroup = originalTransform as TransformGroup; if (transformGroup != null) { foreach (Transform child in transformGroup.Children) { // Child is the right type -- return it if (child is TRequestedTransform) { return(child as TRequestedTransform); } } // Right type was not found, but we are OK to add it if ((mode & TransformCreationMode.AddToGroup) == TransformCreationMode.AddToGroup) { requestedTransform = new TRequestedTransform(); transformGroup.Children.Add(requestedTransform); return(requestedTransform); } return(null); } // Current ransform is not a group and is not what we want; // create a new group containing the existing transform and the new one if ((mode & TransformCreationMode.CombineIntoGroup) == TransformCreationMode.CombineIntoGroup) { transformGroup = new TransformGroup(); transformGroup.Children.Add(originalTransform); transformGroup.Children.Add(requestedTransform); element.RenderTransform = transformGroup; return(requestedTransform); } Debug.Assert(false, "Shouldn't get here"); return(null); }
void dragElement_Moved() { if (mIsDrag) { if (mContainer != null && mDragObject != null) { //IDragElement dragElement = mDragObject as IDragElement; //FrameworkElement frameworkElement = mDragObject as FrameworkElement; //if (dragElement != null && frameworkElement != null) //{ // Point point = Mouse.GetPosition(mContainer); // MatrixTransform mt = frameworkElement.RenderTransform as MatrixTransform; // if (mt != null) // { // Matrix mx = mt.Matrix; // mx.OffsetX += point.X - mOriPosition.X; // mx.OffsetY += point.Y - mOriPosition.Y; // frameworkElement.RenderTransform = new MatrixTransform { Matrix = mx }; // mOriPosition = point; // } //} FrameworkElement dragElement = mDragObject as FrameworkElement; FrameworkElement container = mContainer as FrameworkElement; if (dragElement != null && container != null) { Point point1 = Mouse.GetPosition(container); Point point2 = Mouse.GetPosition(dragElement); double width1 = container.ActualWidth; double width2 = dragElement.ActualWidth; double height1 = container.ActualHeight; double height2 = dragElement.ActualHeight; double offsetX = 0.0; double offsetY = 0.0; if (point1.X < point2.X || point1.X - point2.X + width2 > width1) { offsetX = 0.0; } else { offsetX = point1.X - mOrgPoint.X; } if (point1.Y < point2.Y || point1.Y - point2.Y + height2 > height1) { offsetY = 0.0; } else { offsetY = point1.Y - mOrgPoint.Y; } MatrixTransform mt = dragElement.RenderTransform as MatrixTransform; if (mt != null) { Matrix mx = mt.Matrix; mx.OffsetX += offsetX; mx.OffsetY += offsetY; dragElement.RenderTransform = new MatrixTransform { Matrix = mx }; mOrgPoint = point1; } } } } }
internal override WpfBrush RealizeWpfBrush() { //if (dirty) //{ // if (brush == null) // brush = new SolidBrush(color.ToGdiColor()); // else // { // brush.Color = color.ToGdiColor(); // } // dirty = false; //} System.Windows.Media.LinearGradientBrush brush; if (_useRect) { #if !SILVERLIGHT brush = new System.Windows.Media.LinearGradientBrush(_color1.ToWpfColor(), _color2.ToWpfColor(), new SysPoint(0, 0), new SysPoint(1, 1));// rect.TopLeft, this.rect.BottomRight); //brush = new System.Drawing.Drawing2D.LinearGradientBrush(rect.ToRectangleF(), // color1.ToGdiColor(), color2.ToGdiColor(), (LinearGradientMode)linearGradientMode); #else GradientStop gs1 = new GradientStop(); gs1.Color = _color1.ToWpfColor(); gs1.Offset = 0; GradientStop gs2 = new GradientStop(); gs2.Color = _color2.ToWpfColor(); gs2.Offset = 1; GradientStopCollection gsc = new GradientStopCollection(); gsc.Add(gs1); gsc.Add(gs2); brush = new LinearGradientBrush(gsc, 0); brush.StartPoint = new Point(0, 0); brush.EndPoint = new Point(1, 1); #endif } else { #if !SILVERLIGHT brush = new System.Windows.Media.LinearGradientBrush(_color1.ToWpfColor(), _color2.ToWpfColor(), _point1, _point2); //brush = new System.Drawing.Drawing2D.LinearGradientBrush( // point1.ToPointF(), point2.ToPointF(), // color1.ToGdiColor(), color2.ToGdiColor()); #else GradientStop gs1 = new GradientStop(); gs1.Color = _color1.ToWpfColor(); gs1.Offset = 0; GradientStop gs2 = new GradientStop(); gs2.Color = _color2.ToWpfColor(); gs2.Offset = 1; GradientStopCollection gsc = new GradientStopCollection(); gsc.Add(gs1); gsc.Add(gs2); brush = new LinearGradientBrush(gsc, 0); brush.StartPoint = _point1; brush.EndPoint = _point2; #endif } if (!_matrix.IsIdentity) { #if !SILVERLIGHT brush.Transform = new MatrixTransform(_matrix.ToWpfMatrix()); #else MatrixTransform transform = new MatrixTransform(); transform.Matrix = _matrix.ToWpfMatrix(); brush.Transform = transform; #endif } return brush; }
/// <summary> /// Constructor. Initializes class fields. /// </summary> public AdornerCursorCoordinateDrawer(UIElement adornedElement, MatrixTransform shapeTransform) : base(adornedElement) { elementTransform = shapeTransform; IsHitTestVisible = false; }
private void SetPopUpPosition() { if (((this._calendar != null) && (Application.Current != null)) && ((Application.Current.Host != null) && (Application.Current.Host.Content != null))) { double actualHeight = Application.Current.Host.Content.ActualHeight; double actualWidth = Application.Current.Host.Content.ActualWidth; #if !SILVERLIGHT4 if (Application.Current.IsRunningOutOfBrowser) { Window window = Window.GetWindow(this); if ((window != null) && (window != Application.Current.MainWindow) && window.Content != null) { actualHeight = window.Content.ActualHeight; actualWidth = window.Content.ActualWidth; } } #endif double num3 = this._calendar.ActualHeight; double num4 = base.ActualHeight; if (this._root != null) { GeneralTransform transform = this._root.TransformToVisual(null); if (transform != null) { Point point = new Point(0.0, 0.0); Point point2 = new Point(1.0, 0.0); Point point3 = new Point(0.0, 1.0); Point point4 = transform.Transform(point); Point point5 = transform.Transform(point2); Point point6 = transform.Transform(point3); double x = point4.X; double y = point4.Y; double num7 = x; double num8 = y + num4; if (actualHeight < (num8 + num3)) { num8 = y - num3; } this._popup.HorizontalOffset = 0.0; this._popup.VerticalOffset = 0.0; this._outsidePopupCanvas.Width = actualWidth; this._outsidePopupCanvas.Height = actualHeight; this._calendar.HorizontalAlignment = HorizontalAlignment.Left; this._calendar.VerticalAlignment = VerticalAlignment.Top; Canvas.SetLeft(this._calendar, num7 - x); Canvas.SetTop(this._calendar, num8 - y); Matrix identity = Matrix.Identity; identity.M11 = point5.X - point4.X; identity.M12 = point5.Y - point4.Y; identity.M21 = point6.X - point4.X; identity.M22 = point6.Y - point4.Y; identity.OffsetX = point4.X; identity.OffsetY = point4.Y; MatrixTransform transform2 = new MatrixTransform(); InvertMatrix(ref identity); transform2.Matrix = identity; this._outsidePopupCanvas.RenderTransform = transform2; } } } }
protected override void OnDragDelta(object sender, DragDeltaEventArgs e) { double deltaVertical = 0, deltaHorizontal = 0; Point dragDelta = new Point(e.HorizontalChange, e.VerticalChange); dragDelta = GridManager.AdjustPointToGrid(dragDelta); Matrix m = ((Transform)this.TransformToVisual(_controlledItem)).Value; m.OffsetX = 0; m.OffsetY = 0; System.Windows.Media.Transform t = new MatrixTransform(m); dragDelta = t.Transform(dragDelta); Rect r = new Rect(Canvas.GetLeft(_controlledItem), Canvas.GetTop(_controlledItem), _controlledItem.Width, _controlledItem.Height); //r = GridManager.AdjustRectToGrid(r); switch (base.VerticalAlignment) { case System.Windows.VerticalAlignment.Bottom: deltaVertical = Math.Min(-dragDelta.Y, _controlledItem.ActualHeight - Height); r.Height -= deltaVertical; break; case System.Windows.VerticalAlignment.Top: deltaVertical = Math.Min(dragDelta.Y, _controlledItem.ActualHeight - Height); Point p = _controlledItem.RenderTransform.Transform(new Point(0, deltaVertical)); r.Y += p.Y; r.X += p.X; r.Height -= deltaVertical; break; default: break; } switch (base.HorizontalAlignment) { case System.Windows.HorizontalAlignment.Left: deltaHorizontal = Math.Min(dragDelta.X, _controlledItem.ActualWidth - Width); Point p = _controlledItem.RenderTransform.Transform(new Point(deltaHorizontal, 0)); r.Y += p.Y; r.X += p.X; r.Width -= deltaHorizontal; break; case System.Windows.HorizontalAlignment.Right: deltaHorizontal = Math.Min(-dragDelta.X, _controlledItem.ActualWidth - Width); r.Width -= deltaHorizontal; break; default: break; } Point sizeDelta = new Point(deltaHorizontal, deltaVertical); Point sizeDeltaTrans = _controlledItem.RenderTransform.Transform(sizeDelta); Vector v = sizeDelta - sizeDeltaTrans; r.X = r.X + v.X * _controlledItem.RenderTransformOrigin.X; r.Y = r.Y + v.Y * _controlledItem.RenderTransformOrigin.Y; EditorHelper.SetDependencyProperty(_controlledItem, Canvas.LeftProperty, r.X); EditorHelper.SetDependencyProperty(_controlledItem, Canvas.TopProperty, r.Y); EditorHelper.SetDependencyProperty(_controlledItem, FrameworkElement.WidthProperty, r.Width); EditorHelper.SetDependencyProperty(_controlledItem, FrameworkElement.HeightProperty, r.Height); }
private void UpdateUILayout() { CommonLabelsCanvas.Placement = placement; AdditionalLabelsCanvas.Placement = placement; //LayoutRoot.Background = new SolidColorBrush(Colors.Yellow); //CommonLabelsCanvas.Background = new SolidColorBrush(Color.FromArgb(200,255,200,200)); //AdditionalLabelsCanvas.Background = new SolidColorBrush(Color.FromArgb(200, 255, 100, 100)); LayoutRoot.ColumnDefinitions.Clear(); //TODO Do we need to clear/add children? LayoutRoot.RowDefinitions.Clear(); LayoutRoot.Children.Clear(); LayoutRoot.Margin = new Thickness(0.0); if (placement == AxisPlacement.Bottom || placement == AxisPlacement.Top) { LayoutRoot.RowDefinitions.Add(new RowDefinition()); LayoutRoot.RowDefinitions.Add(new RowDefinition()); LayoutRoot.RowDefinitions.Add(new RowDefinition()); } else { LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition()); LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition()); LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition()); } switch (placement) { case AxisPlacement.Bottom: Grid.SetRow(TicksPath, 0); Grid.SetRow(CommonLabelsCanvas, 1); Grid.SetRow(AdditionalLabelsCanvas, 2); break; case AxisPlacement.Top: Grid.SetRow(TicksPath, 2); //TODO matrixTranform TickPath Grid.SetRow(CommonLabelsCanvas, 1); Grid.SetRow(AdditionalLabelsCanvas, 0); break; case AxisPlacement.Left: MatrixTransform reflection = new MatrixTransform(); reflection.Matrix = new Matrix(-1, 0, 0, 1, 0, 0); TicksPath.RenderTransformOrigin = new Point(0.5, 0.5); TicksPath.RenderTransform = reflection; Grid.SetColumn(TicksPath, 2); Grid.SetColumn(CommonLabelsCanvas, 1); Grid.SetColumn(AdditionalLabelsCanvas, 0); TicksPath.Margin = new Thickness(0, 0, 0, 0); CommonLabelsCanvas.Margin = new Thickness(1, 0, 1, 0); AdditionalLabelsCanvas.Margin = new Thickness(1, 0, 1, 0); break; case AxisPlacement.Right: Grid.SetColumn(TicksPath, 0); Grid.SetColumn(CommonLabelsCanvas, 1); Grid.SetColumn(AdditionalLabelsCanvas, 2); CommonLabelsCanvas.Margin = new Thickness(1, 0, 0, 0); break; } LayoutRoot.Children.Add(TicksPath); LayoutRoot.Children.Add(CommonLabelsCanvas); LayoutRoot.Children.Add(AdditionalLabelsCanvas); partsLoaded = true; }
internal static extern void cgGLSetStateMatrixParameter(IntPtr param, MatrixType matrix, MatrixTransform transform);
/// <summary> /// Content arrangement. /// </summary> /// <param name="finalSize">The final size that element should use to arrange itself and its children.</param> protected override sealed Size ArrangeOverride(Size finalSize) { Transform pageTransform; ScaleTransform pageScaleTransform; Visual pageVisual; Size pageSize, pageZoom; CheckDisposed(); if (_pageVisualClone == null) { if (_pageHost == null) { _pageHost = new DocumentPageHost(); this.AddVisualChild(_pageHost); } Invariant.Assert(_pageHost != null); pageVisual = (_documentPage == null) ? null : _documentPage.Visual; if (pageVisual == null) { // Remove existing visiual children. _pageHost.PageVisual = null; // Reset offset and transform on the page host before Arrange _pageHost.CachedOffset = new Point(); _pageHost.RenderTransform = null; // Size for the page host needs to be set to finalSize _pageHost.Arrange(new Rect(_pageHost.CachedOffset, finalSize)); } else { // Add visual representing the page contents. For performance reasons // first check if it is already insered there. if (_pageHost.PageVisual != pageVisual) { // There might be a case where a visual associated with a page was // inserted to a visual tree before. It got removed later, but GC did not // destroy its parent yet. To workaround this case always check for the parent // of page visual and disconnect it, when necessary. DocumentPageHost.DisconnectPageVisual(pageVisual); _pageHost.PageVisual = pageVisual; } // Compute transform to be applied to the page visual. First take into account // mirroring transform, if necessary. Apply also scaling transform. pageSize = _documentPage.Size; pageTransform = Transform.Identity; // DocumentPage.Visual is always LeftToRight, so if the current // FlowDirection is RightToLeft, need to unmirror the child visual. if (FlowDirection == FlowDirection.RightToLeft) { pageTransform = new MatrixTransform(-1.0, 0.0, 0.0, 1.0, pageSize.Width, 0.0); } // Apply zooming if (!DoubleUtil.IsOne(_pageZoom)) { pageScaleTransform = new ScaleTransform(_pageZoom, _pageZoom); if (pageTransform == Transform.Identity) { pageTransform = pageScaleTransform; } else { pageTransform = new MatrixTransform(pageTransform.Value * pageScaleTransform.Value); } pageSize = new Size(pageSize.Width * _pageZoom, pageSize.Height * _pageZoom); } // Apply stretch properties pageZoom = Viewbox.ComputeScaleFactor(finalSize, pageSize, this.Stretch, this.StretchDirection); if (!DoubleUtil.IsOne(pageZoom.Width) || !DoubleUtil.IsOne(pageZoom.Height)) { pageScaleTransform = new ScaleTransform(pageZoom.Width, pageZoom.Height); if (pageTransform == Transform.Identity) { pageTransform = pageScaleTransform; } else { pageTransform = new MatrixTransform(pageTransform.Value * pageScaleTransform.Value); } pageSize = new Size(pageSize.Width * pageZoom.Width, pageSize.Height * pageZoom.Height); } // Set offset and transform on the page host before Arrange _pageHost.CachedOffset = new Point((finalSize.Width - pageSize.Width) / 2, (finalSize.Height - pageSize.Height) / 2); _pageHost.RenderTransform = pageTransform; // Arrange pagehost to original size of the page. _pageHost.Arrange(new Rect(_pageHost.CachedOffset, _documentPage.Size)); } // Fire sync notification if new page was connected. if (_newPageConnected) { OnPageConnected(); } // Transform for the page has been changed, need to notify TextView about the changes. OnTransformChangedAsync(); } else { if (_pageHost.PageVisual != _pageVisualClone) { // Remove existing visiual children. _pageHost.PageVisual = _pageVisualClone; // Size for the page host needs to be set to finalSize // Use previous offset and transform _pageHost.Arrange(new Rect(_pageHost.CachedOffset, finalSize)); } } return(base.ArrangeOverride(finalSize)); }
public TileLayer(ITileImageLoader tileImageLoader) { Initialize(); RenderTransform = new MatrixTransform(); TileImageLoader = tileImageLoader; Tiles = new List<Tile>(); TileZoomLevel = -1; updateTimer = new DispatcherTimer { Interval = UpdateInterval }; updateTimer.Tick += (s, e) => UpdateTileRect(); }
/// <summary> /// Does a recursive deep copy of the specified transform. /// </summary> /// <param name="transform">The transform to clone.</param> /// <returns>A deep copy of the specified transform, or null if the specified transform is null.</returns> /// <exception cref="System.ArgumentException">Thrown if the type of the Transform is not recognized.</exception> internal static Transform CloneTransform(Transform transform) { ScaleTransform scaleTransform = null; RotateTransform rotateTransform = null; SkewTransform skewTransform = null; TranslateTransform translateTransform = null; MatrixTransform matrixTransform = null; TransformGroup transformGroup = null; if (transform == null) { return(null); } Type transformType = transform.GetType(); if ((scaleTransform = transform as ScaleTransform) != null) { return(new ScaleTransform() { CenterX = scaleTransform.CenterX, CenterY = scaleTransform.CenterY, ScaleX = scaleTransform.ScaleX, ScaleY = scaleTransform.ScaleY, }); } else if ((rotateTransform = transform as RotateTransform) != null) { return(new RotateTransform() { Angle = rotateTransform.Angle, CenterX = rotateTransform.CenterX, CenterY = rotateTransform.CenterY, }); } else if ((skewTransform = transform as SkewTransform) != null) { return(new SkewTransform() { AngleX = skewTransform.AngleX, AngleY = skewTransform.AngleY, CenterX = skewTransform.CenterX, CenterY = skewTransform.CenterY, }); } else if ((translateTransform = transform as TranslateTransform) != null) { return(new TranslateTransform() { X = translateTransform.X, Y = translateTransform.Y, }); } else if ((matrixTransform = transform as MatrixTransform) != null) { return(new MatrixTransform() { Matrix = matrixTransform.Matrix, }); } else if ((transformGroup = transform as TransformGroup) != null) { TransformGroup group = new TransformGroup(); foreach (Transform childTransform in transformGroup.Children) { group.Children.Add(CloneTransform(childTransform)); } return(group); } Debug.Assert(false, "Unexpected Transform type encountered"); return(null); }
private RadialGradientBrush GetRadialGradientBrush(Rect elementBounds, SvgRadialGradientElement res) { double centerX = res.Cx.AnimVal.Value; double centerY = res.Cy.AnimVal.Value; double focusX = res.Fx.AnimVal.Value; double focusY = res.Fy.AnimVal.Value; double radius = res.R.AnimVal.Value; GradientStopCollection gradientStops = GetGradientStops(res.Stops); RadialGradientBrush brush = new RadialGradientBrush(gradientStops); brush.RadiusX = radius; brush.RadiusY = radius; brush.Center = new Point(centerX, centerY); brush.GradientOrigin = new Point(focusX, focusY); if (res.SpreadMethod != null) { SvgSpreadMethod spreadMethod = (SvgSpreadMethod)res.SpreadMethod.AnimVal; if (spreadMethod != SvgSpreadMethod.None) { brush.SpreadMethod = WpfConvert.ToSpreadMethod(spreadMethod); } } if (res.GradientUnits != null) { SvgUnitType mappingMode = (SvgUnitType)res.GradientUnits.AnimVal; if (mappingMode == SvgUnitType.ObjectBoundingBox) { brush.MappingMode = BrushMappingMode.RelativeToBoundingBox; } else if (mappingMode == SvgUnitType.UserSpaceOnUse) { brush.MappingMode = BrushMappingMode.Absolute; } } MatrixTransform transform = GetTransformMatrix(res); if (transform != null && !transform.Matrix.IsIdentity) { brush.Transform = transform; } else { } string colorInterpolation = res.GetPropertyValue("color-interpolation"); if (!String.IsNullOrEmpty(colorInterpolation)) { if (colorInterpolation == "linearRGB") { brush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; } else { brush.ColorInterpolationMode = ColorInterpolationMode.ScRgbLinearInterpolation; } } return(brush); }
public MatrixAnimationUsingPathDoesRotateWithTangentExample() { this.Margin = new Thickness(20); // Create a NameScope for the page so that // we can use Storyboards. NameScope.SetNameScope(this, new NameScope()); // Create a button. Button aButton = new Button(); aButton.MinWidth = 100; aButton.Content = "A Button"; // Create a MatrixTransform. This transform // will be used to move the button. MatrixTransform buttonMatrixTransform = new MatrixTransform(); aButton.RenderTransform = buttonMatrixTransform; // Register the transform's name with the page // so that it can be targeted by a Storyboard. this.RegisterName("ButtonMatrixTransform", buttonMatrixTransform); // Create a Canvas to contain the button // and add it to the page. // Although this example uses a Canvas, // any type of panel will work. Canvas mainPanel = new Canvas(); mainPanel.Width = 400; mainPanel.Height = 400; mainPanel.Children.Add(aButton); this.Content = mainPanel; // Create the animation path. PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); pFigure.StartPoint = new Point(10, 100); PolyBezierSegment pBezierSegment = new PolyBezierSegment(); pBezierSegment.Points.Add(new Point(35, 0)); pBezierSegment.Points.Add(new Point(135, 0)); pBezierSegment.Points.Add(new Point(160, 100)); pBezierSegment.Points.Add(new Point(180, 190)); pBezierSegment.Points.Add(new Point(285, 200)); pBezierSegment.Points.Add(new Point(310, 100)); pFigure.Segments.Add(pBezierSegment); animationPath.Figures.Add(pFigure); // Freeze the PathGeometry for performance benefits. animationPath.Freeze(); // Create a MatrixAnimationUsingPath to move the // button along the path by animating // its MatrixTransform. MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); matrixAnimation.PathGeometry = animationPath; matrixAnimation.Duration = TimeSpan.FromSeconds(5); matrixAnimation.RepeatBehavior = RepeatBehavior.Forever; // Set the animation's DoesRotateWithTangent property // to true so that rotates the rectangle in addition // to moving it. matrixAnimation.DoesRotateWithTangent = true; // Set the animation to target the Matrix property // of the MatrixTransform named "ButtonMatrixTransform". Storyboard.SetTargetName(matrixAnimation, "ButtonMatrixTransform"); Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty)); // Create a Storyboard to contain and apply the animation. Storyboard pathAnimationStoryboard = new Storyboard(); pathAnimationStoryboard.Children.Add(matrixAnimation); // Start the storyboard when the button is loaded. aButton.Loaded += delegate(object sender, RoutedEventArgs e) { // Start the storyboard. pathAnimationStoryboard.Begin(this); }; }
private LinearGradientBrush GetLinearGradientBrush(Rect elementBounds, SvgLinearGradientElement res) { double x1 = res.X1.AnimVal.Value; double x2 = res.X2.AnimVal.Value; double y1 = res.Y1.AnimVal.Value; double y2 = res.Y2.AnimVal.Value; GradientStopCollection gradientStops = GetGradientStops(res.Stops); //LinearGradientBrush brush = new LinearGradientBrush(gradientStops); LinearGradientBrush brush = new LinearGradientBrush(gradientStops, new Point(x1, y1), new Point(x2, y2)); SvgSpreadMethod spreadMethod = SvgSpreadMethod.Pad; if (res.SpreadMethod != null) { spreadMethod = (SvgSpreadMethod)res.SpreadMethod.AnimVal; if (spreadMethod != SvgSpreadMethod.None) { brush.SpreadMethod = WpfConvert.ToSpreadMethod(spreadMethod); } } Transform viewBoxTransform = null; SvgUnitType mappingMode = SvgUnitType.ObjectBoundingBox; if (res.GradientUnits != null) { mappingMode = (SvgUnitType)res.GradientUnits.AnimVal; if (mappingMode == SvgUnitType.ObjectBoundingBox) { brush.MappingMode = BrushMappingMode.RelativeToBoundingBox; } else if (mappingMode == SvgUnitType.UserSpaceOnUse) { brush.MappingMode = BrushMappingMode.Absolute; viewBoxTransform = FitToViewbox(new SvgRect(x1, y1, Math.Abs(x2 - x1), Math.Abs(y2 - y1)), elementBounds); } } MatrixTransform transform = GetTransformMatrix(res); if (transform != null && !transform.Matrix.IsIdentity) { if (viewBoxTransform != null) { TransformGroup group = new TransformGroup(); group.Children.Add(viewBoxTransform); group.Children.Add(transform); brush.Transform = group; } else { brush.Transform = transform; //brush.StartPoint = new Point(0, 0.5); //brush.EndPoint = new Point(1, 0.5); } //brush.StartPoint = new Point(0, 0); //brush.EndPoint = new Point(1, 1); } else { float fLeft = (float)res.X1.AnimVal.Value; float fRight = (float)res.X2.AnimVal.Value; float fTop = (float)res.Y1.AnimVal.Value; float fBottom = (float)res.Y2.AnimVal.Value; if (fTop == fBottom) { //mode = LinearGradientMode.Horizontal; //brush.StartPoint = new Point(0, 0.5); //brush.EndPoint = new Point(1, 0.5); } else { if (fLeft == fRight) { //var mode = LinearGradientMode.Vertical; //brush.StartPoint = new Point(0.5, 0); // brush.EndPoint = new Point(0.5, 1); } else { if (fLeft < fRight) { if (viewBoxTransform != null) { TransformGroup group = new TransformGroup(); group.Children.Add(viewBoxTransform); group.Children.Add(new RotateTransform(45, 0.5, 0.5)); brush.Transform = group; } else { //brush.RelativeTransform = new RotateTransform(45, 0.5, 0.5); } //mode = LinearGradientMode.ForwardDiagonal; //brush.EndPoint = new Point(x1, y1 + 1); //brush.StartPoint = new Point(0, 0); //brush.EndPoint = new Point(1, 1); } else { //mode = LinearGradientMode.BackwardDiagonal; if (viewBoxTransform != null) { TransformGroup group = new TransformGroup(); group.Children.Add(viewBoxTransform); group.Children.Add(new RotateTransform(-45, 0.5, 0.5)); brush.Transform = group; } else { brush.RelativeTransform = new RotateTransform(-45, 0.5, 0.5); } //brush.StartPoint = new Point(0, 0); //brush.EndPoint = new Point(1, 1); } } } } string colorInterpolation = res.GetPropertyValue("color-interpolation"); if (!String.IsNullOrEmpty(colorInterpolation)) { if (colorInterpolation == "linearRGB") { brush.ColorInterpolationMode = ColorInterpolationMode.ScRgbLinearInterpolation; } else { brush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; } } return(brush); }
private void _drawPerspectiveAreas(int mod, int rem) { bool animate = (this.AnimationDuration > 0); double xOffset = XOffsetPerspective, yOffset = YOffsetPerspective; double marginLeft = MarginLeft, marginTop = MarginTop; double marginRight = MarginRight, marginBottom = MarginBottom; double gridWidth = (ChartCanvas.Width - marginLeft - marginRight - xOffset); double gridHeight = (ChartCanvas.Height - marginTop - marginBottom - yOffset); LookAndFeel lf = CurrentLookAndFeel; string pathXAML = lf.GetAreaPathXAML(); Path pathElem; List <UIElement> dataElems = null; MatrixTransform defaultTransform = null; if (animate) { dataElems = DataElements; } bool isStacked = (Type == ChartType.AREA_STACKED); ChartModel model = Model; string [] groupLabels = model.GroupLabels; int groupCount = groupLabels.Length; string [] seriesLabels = model.SeriesLabels; int seriesCount = seriesLabels.Length; Color [] seriesColors = model.SeriesColors; double[,] yValues = model.YValues; double minValue = model.MinYValue, maxValue = model.MaxYValue; int yValueCount = yValues.GetUpperBound(0) + 1; double barWidth = (gridWidth / (Math.Max(yValueCount, groupCount))), stackBase; double barHeight; double gridBottom = gridHeight + marginTop + yOffset, dx, dy; double[] cumYs = isStacked? new double[yValueCount] : null; if (isStacked) { cumYs = new double[yValueCount]; for (int j = 0; j < yValueCount; ++j) { cumYs[j] = double.NaN; } } string gradientXAML = lf.GetElementGradientXAML(); for (int i = 0; i < seriesCount; ++i) { // for combo charts we draw a bar every once in a mod. if ((mod > 1) && (i % mod) != rem) { continue; } dx = marginLeft + barWidth / 2.0; // If we use non zero min and it is a stacked graph, we need to remove the min for only // the first series. stackBase = (i == 0?minValue:0); StringBuilder sb = new StringBuilder(); for (int j = 0; j < yValueCount; ++j) { barHeight = gridHeight * (yValues[j, i] - stackBase) / (maxValue - minValue); if (isStacked) { if (double.IsNaN(cumYs[j])) { cumYs[j] = gridBottom; } dy = (cumYs[j] -= barHeight); } else { dy = gridBottom - barHeight; } if (j == yValueCount - 1) { break; } sb.Append("M").Append(dx).Append(",").Append(dy); sb.Append(" l").Append(xOffset).Append(",").Append(-yOffset); if (i == 0 || !isStacked) { sb.Append(" L").Append(dx + xOffset).Append(",").Append(gridHeight + marginTop); } else { sb.Append(" v").Append(barHeight); } sb.Append(" l").Append(-xOffset).Append(",").Append(yOffset); sb.Append(" z"); sb.Append("M").Append(dx).Append(",").Append(dy); sb.Append(" l").Append(xOffset).Append(",").Append(-yOffset); double nextdy, nextdx = dx + barWidth; if (isStacked) { if (double.IsNaN(cumYs[j + 1])) { cumYs[j + 1] = gridBottom; } nextdy = (cumYs[j + 1] - gridHeight * (yValues[j + 1, i] - stackBase) / (maxValue - minValue)); } else { nextdy = gridBottom - gridHeight * (yValues[j + 1, i] - minValue) / (maxValue - minValue); } sb.Append(" L").Append(nextdx + xOffset).Append(",").Append(nextdy - yOffset); sb.Append(" l").Append(-xOffset).Append(",").Append(yOffset); sb.Append(" L").Append(dx).Append(",").Append(dy); sb.Append(" M").Append(nextdx).Append(",").Append(nextdy); sb.Append(" l").Append(xOffset).Append(",").Append(-yOffset); if (i == 0 || !isStacked) { sb.Append(" L").Append(nextdx + xOffset).Append(",").Append(gridHeight + marginTop); } else { sb.Append(" L").Append(nextdx + xOffset).Append(",").Append(cumYs[j + 1] - yOffset); } sb.Append(" l").Append(-xOffset).Append(",").Append(yOffset); sb.Append(" L").Append(nextdx).Append(",").Append(nextdy); sb.Append(" M").Append(dx).Append(",").Append(dy); sb.Append(" L").Append(nextdx).Append(",").Append(nextdy); if (i == 0 || !isStacked) { sb.Append(" L").Append(nextdx).Append(",").Append(gridBottom); sb.Append(" L").Append(dx).Append(",").Append(gridBottom); } else { sb.Append(" L").Append(nextdx).Append(",").Append(cumYs[j + 1]); sb.Append(" L").Append(dx).Append(",").Append( cumYs[j] + gridHeight * (yValues[j, i] - stackBase) / (maxValue - minValue)); } sb.Append(" L").Append(dx).Append(",").Append(dy); dx += barWidth; } pathElem = CreatePathFromXAMLAndData(pathXAML, sb); SetExpandosOnElement(pathElem, -1, i, new Point()); if (DisplayToolTip) { pathElem.MouseMove += new MouseEventHandler(ShowToolTip); pathElem.MouseLeave += new MouseEventHandler(HideToolTip); } pathElem.MouseLeftButtonUp += new MouseButtonEventHandler(ChartDataClicked); if (gradientXAML != null) { SetGradientOnElement(pathElem, gradientXAML, seriesColors[i], 0x7F); } else { SetFillOnElement(pathElem, seriesColors[i]); } pathElem.SetValue(Path.StrokeProperty, new SolidColorBrush(seriesColors[i])); (pathElem.Data as PathGeometry).FillRule = FillRule.Nonzero; if (animate) { dataElems.Add(pathElem); defaultTransform = new MatrixTransform(); Matrix m = new Matrix(); m.M11 = 0.0; defaultTransform.Matrix = m; pathElem.SetValue(UIElement.RenderTransformProperty, defaultTransform); } ChartCanvas.Children.Add(pathElem); } }
internal Combiner GetImageCombiner(IImageParams destImageParams, ColorManagement colorManagement, float scale, IEnumerable <IDisposable> deps, ScaleAlpha alpha) { if (!Configuration.FileCache.FileExists(SourceFileId)) { return(null); } var imageStream = Configuration.FileCache.GetReadStream(SourceFileId, true); ((IList)deps).Add(imageStream); var reader = ImageReader.Create(imageStream); ((IList)deps).Add(reader); IImageParams firstElement; var psdReader = reader as PsdReader; if (psdReader != null) { firstElement = psdReader.MergedImageFrame; } else { firstElement = reader; } var pipeline = new Pipeline((PipelineElement)firstElement); var dpi = destImageParams.DpiX * scale; var imageRect = GetImageRectangle(dpi); if (firstElement.Width != imageRect.Width || firstElement.Height != imageRect.Height) { pipeline.Add(new Resize(imageRect.Width, imageRect.Height, _resizeInterpolationMode)); } if (alpha != null) { pipeline.Add(alpha); } // Convert color of image var colorConverter = ColorManagement.GetColorConverter(colorManagement, firstElement, destImageParams); if (colorConverter != null) { pipeline.Add(colorConverter); } if (!Angle.Equals(0)) { // Don't rotate bitmap without alpha channel. if (!firstElement.PixelFormat.HasAlpha) { // Add alpha channel if scaleAlpha or color conversion does not add it if (alpha == null && (colorConverter == null || !colorConverter.DestinationPixelFormat.HasAlpha)) { pipeline.Add(new SetAlpha(1)); } } var rotate = new MatrixTransform { Matrix = Matrix.CreateRotate((float)Angle), InterpolationMode = InterpolationMode.High, BackgroundColor = ColorManagement.GetTransparentColor(destImageParams.PixelFormat) }; pipeline.Add(rotate); } var imageLocation = GetDrawingRectangle(dpi).Bounds.Location; var imageCombiner = new Combiner(CombineMode.AlphaOverlay, pipeline, true) { X = (int)imageLocation.X, Y = (int)imageLocation.Y }; return(imageCombiner); }
public void Invalidate() { if (!Node.IsVisible) { foreach (var fe in FrameworkElements) { fe.Visibility = Visibility.Hidden; } return; } if (BoundaryCurveIsDirty) { BoundaryPath.Data = CreatePathFromNodeBoundary(); BoundaryCurveIsDirty = false; } if (LgNodeInfo != null) { double scale = 1; // LgNodeInfo != null && LgNodeInfo.Kind == LgNodeInfoKind.Satellite // ? LgNodeInfo.Scale // : 1; var planeTransform = PlaneTransformation.ScaleAroundCenterTransformation(scale, node.BoundingBox.Center); var transform = new MatrixTransform(planeTransform[0, 0], planeTransform[0, 1], planeTransform[1, 0], planeTransform[1, 1], planeTransform[0, 2], planeTransform[1, 2]); BoundaryPath.RenderTransform = transform; if (FrameworkElementOfNodeForLabel != null) { Common.PositionFrameworkElement(FrameworkElementOfNodeForLabel, node.GeometryNode.Center, scale); } } else { Common.PositionFrameworkElement(FrameworkElementOfNodeForLabel, Node.BoundingBox.Center, 1); } SetFillAndStroke(); if (subgraph == null) { return; } PositionTopMarginBorder((Cluster)subgraph.GeometryNode); double collapseBorderSize = GetCollapseBorderSymbolSize(); var collapseButtonCenter = GetCollapseButtonCenter(collapseBorderSize); Common.PositionFrameworkElement(collapseButtonBorder, collapseButtonCenter, 1); double w = collapseBorderSize * 0.4; collapseSymbolPath.Data = CreateCollapseSymbolPath(collapseButtonCenter + new Point(0, -w / 2), w); collapseSymbolPath.RenderTransform = ((Cluster)subgraph.GeometryNode).IsCollapsed ? new RotateTransform(180, collapseButtonCenter.X, collapseButtonCenter.Y) : null; topMarginRect.Visibility = collapseSymbolPath.Visibility = collapseButtonBorder.Visibility = Visibility.Visible; }
public void ArrangePopup(Popup ElementPopup, Canvas ElementPopupChildCanvas, Canvas ElementOutsidePopup, FrameworkElement ElementPopupChild, ContentControl LeaderPopupContent, StackPanel ElementPopupChildMaxRangeStackPanel, Control AssociatedControl, ExpandDirection ExpandDirection, bool EnforceMinWidth = true, bool isNestedPopup = true ) { if (ElementPopup != null && AssociatedControl != null) { bool isRTL = (AssociatedControl.FlowDirection == FlowDirection.RightToLeft); System.Windows.Interop.Content content = System.Windows.Application.Current.Host.Content; double applicationWidth = content.ActualWidth; double applicationHeight = content.ActualHeight; double popupWidth = ElementPopupChild.ActualWidth; double popupHeight = ElementPopupChild.ActualHeight; if ((applicationHeight != 0.0) && (applicationWidth != 0.0)) { GeneralTransform transform = AssociatedControl.TransformToVisual(null); if (isRTL && transform is MatrixTransform) { var mt = (MatrixTransform)transform; transform = new MatrixTransform { Matrix = new Matrix { M11 = mt.Matrix.M11, M12 = mt.Matrix.M12, M21 = mt.Matrix.M21, M22 = mt.Matrix.M22, OffsetX = mt.Matrix.OffsetX - AssociatedControl.ActualWidth, OffsetY = mt.Matrix.OffsetY, } }; } if (transform != null) { Point topLeftTransPoint = new Point(0.0, 0.0); Point topRightTransPoint = new Point(1.0, 0.0); Point bottomLeftTransPoint = new Point(0.0, 1.0); Point topLeftPosition = transform.Transform(topLeftTransPoint); Point topRightPosition = transform.Transform(topRightTransPoint); Point bottomLeftPosition = transform.Transform(bottomLeftTransPoint); double xDropDown = topLeftPosition.X; double yDropDown = topLeftPosition.Y; double widthRatio = Math.Abs((double)(topRightPosition.X - topLeftPosition.X)); double heightRatio = Math.Abs((double)(bottomLeftPosition.Y - topLeftPosition.Y)); double heightDropDown = AssociatedControl.ActualHeight * heightRatio; double widthDropDown = AssociatedControl.ActualWidth * widthRatio; double yBottomDropDown = yDropDown + heightDropDown; if ((heightDropDown != 0.0) && (widthDropDown != 0.0)) { popupWidth *= widthRatio; popupHeight *= heightRatio; double maxDropDownHeight = double.PositiveInfinity; if (ExpandDirection == ExpandDirection.BottomLeft) { if (double.IsInfinity(maxDropDownHeight) || double.IsNaN(maxDropDownHeight)) { maxDropDownHeight = ((applicationHeight - heightDropDown) * 3.0) / 5.0; } bool flag = true; if (applicationHeight < (yBottomDropDown + popupHeight)) { flag = false; yBottomDropDown = yDropDown - popupHeight; if (yBottomDropDown < 0.0) { if (yDropDown < ((applicationHeight - heightDropDown) / 2.0)) { flag = true; yBottomDropDown = yDropDown + heightDropDown; } else { flag = false; yBottomDropDown = yDropDown - popupHeight; } } } if (popupHeight != 0.0) { if (flag) { maxDropDownHeight = Math.Min(applicationHeight - yBottomDropDown, maxDropDownHeight); } else { maxDropDownHeight = Math.Min(yDropDown, maxDropDownHeight); } } } else { if (double.IsInfinity(maxDropDownHeight) || double.IsNaN(maxDropDownHeight)) { maxDropDownHeight = applicationHeight - 2 * RIGHT_CENTER_TOP_BOTTOM_MARGIN; } } popupWidth = Math.Min(popupWidth, applicationWidth); popupHeight = Math.Min(popupHeight, maxDropDownHeight); popupWidth = Math.Max(widthDropDown, popupWidth); double applicationRemainWidth = 0.0; double leaderWidth = GetFrameworkElementWidth(LeaderPopupContent); if (double.IsNaN(leaderWidth) || double.IsInfinity(leaderWidth)) { leaderWidth = 0; } if (AssociatedControl.FlowDirection == FlowDirection.LeftToRight) { if (applicationWidth < (xDropDown + popupWidth)) { applicationRemainWidth = applicationWidth - (popupWidth + xDropDown); } } else if (0.0 > (xDropDown - popupWidth)) { applicationRemainWidth = xDropDown - popupWidth; } ElementPopup.HorizontalOffset = 0.0; ElementPopup.VerticalOffset = 0.0; Matrix identity = Matrix.Identity; identity.OffsetX -= topLeftPosition.X / widthRatio; identity.OffsetY -= topLeftPosition.Y / heightRatio; MatrixTransform transform2 = new MatrixTransform(); transform2.Matrix = identity; if (ElementOutsidePopup != null) { ElementOutsidePopup.Width = applicationWidth / widthRatio; ElementOutsidePopup.Height = applicationHeight / heightRatio; ElementOutsidePopup.RenderTransform = transform2; } double minWidthDropDown = 0.0; if (EnforceMinWidth) { minWidthDropDown = widthDropDown / widthRatio; ElementPopupChild.MinWidth = minWidthDropDown; } double maxPopupWidth = double.PositiveInfinity; bool reversePopupExpandDirection = false; if (ExpandDirection == ExpandDirection.BottomLeft) { maxPopupWidth = applicationWidth / widthRatio; } else { maxPopupWidth = applicationWidth - (xDropDown + widthDropDown) - leaderWidth; maxPopupWidth = maxPopupWidth / widthRatio; if (maxPopupWidth < popupWidth) { double tempMaxPopupWidth; //try show on the other side tempMaxPopupWidth = xDropDown - leaderWidth; if (tempMaxPopupWidth >= 0 && tempMaxPopupWidth > maxPopupWidth) { maxPopupWidth = tempMaxPopupWidth; reversePopupExpandDirection = true; } } } ElementPopupChild.MaxWidth = Math.Max(minWidthDropDown, maxPopupWidth); ElementPopupChild.MinHeight = heightDropDown / heightRatio; ElementPopupChild.MaxHeight = Math.Max((double)0.0, (double)(maxDropDownHeight / heightRatio)); ElementPopupChild.HorizontalAlignment = HorizontalAlignment.Left; ElementPopupChild.VerticalAlignment = VerticalAlignment.Top; ElementPopupChild.FlowDirection = AssociatedControl.FlowDirection; if (ElementPopupChildMaxRangeStackPanel != null) //if horizontal central alignment, then simply reuse the maxrange canvas and align within { double top = isNestedPopup ? (heightDropDown - popupHeight) / 2 : Math.Max(0.0, yDropDown + (heightDropDown - popupHeight) / 2); double overflow = Math.Abs(Math.Min(applicationHeight - (yDropDown + (yBottomDropDown - yDropDown) / 2 + popupHeight / 2 + RIGHT_CENTER_TOP_BOTTOM_MARGIN), 0.0)); if (overflow > 0) { top -= overflow; //move up if overflowing underneath } top = Math.Max(top, -yDropDown + RIGHT_CENTER_TOP_BOTTOM_MARGIN); //did our best to calculate top, so set to top or application level x=0 Canvas.SetTop(ElementPopupChildMaxRangeStackPanel, top); ElementPopupChildMaxRangeStackPanel.Width = maxPopupWidth; ElementPopupChildMaxRangeStackPanel.Height = popupHeight; if (isRTL && isNestedPopup) { reversePopupExpandDirection = !reversePopupExpandDirection; } if (reversePopupExpandDirection) { Canvas.SetLeft(ElementPopupChildMaxRangeStackPanel, isNestedPopup ? -xDropDown : 0); } else { Canvas.SetLeft(ElementPopupChildMaxRangeStackPanel, (isNestedPopup ? 0: xDropDown) + AssociatedControl.ActualWidth + leaderWidth); } if (reversePopupExpandDirection) { ElementPopupChild.HorizontalAlignment = HorizontalAlignment.Right; } SetupLeader(LeaderPopupContent, ElementPopupChildMaxRangeStackPanel, reversePopupExpandDirection, xDropDown, yDropDown, heightDropDown, ExpandDirection, AssociatedControl, isNestedPopup); } else { SetPopupTop(ElementPopupChild, yBottomDropDown, heightRatio, yDropDown, popupHeight, applicationHeight, ExpandDirection); SetPopupLeft(ElementPopupChild, applicationRemainWidth, widthRatio, popupWidth, maxPopupWidth, reversePopupExpandDirection, ExpandDirection, AssociatedControl, xDropDown); SetupLeader(LeaderPopupContent, ElementPopupChild, reversePopupExpandDirection, xDropDown, yDropDown, heightDropDown, ExpandDirection, AssociatedControl, isNestedPopup); } } } } } }
internal bool ApplyScale(ChartScaleInfo info) { if (info == null) { return(false); } double actualHeight = this.ActualHeight - 1; double actualWidth = this.ActualWidth; bool changed = false; this.minX = info.minX; this.maxX = info.maxX; this.minY = info.minY; this.maxY = info.maxY; double yRange = maxY - minY; if (yRange == 0) { yRange = 1; } double newyScale = actualHeight / yRange; if (newyScale == 0) { newyScale = 1; } if (newyScale != yScale) { yScale = newyScale; changed = true; } // overrides for automatic X-Scaling. if (fixedMaximumX.HasValue) { this.maxX = fixedMaximumX.Value; } if (fixedMinimumX.HasValue) { this.minX = fixedMinimumX.Value; } double newxScale = LiveScrollingXScale; if (!LiveScrolling) { double xRange = maxX - minX; if (xRange == 0) { xRange = 1; } newxScale = actualWidth / xRange; if (newxScale == 0) { newxScale = 1; } } if (newxScale != xScale) { xScale = newxScale; changed = true; } if (changed || scaleTransform == null) { Matrix m = new Matrix(); m.Scale(xScale, yScale); m.OffsetX = -minX * xScale; m.OffsetY = -minY * yScale; scaleTransform = new MatrixTransform(m); this.dirty = true; } return(changed); }
private void ManipulationDeltaHandler(object sender, System.Windows.Input.ManipulationDeltaEventArgs e) { var sourceElement = e.Source as FrameworkElement; if (sourceElement != null) { // e.DeltaManipulation has the changes // Scale is a delta multiplier; 1.0 is last size, (so 1.1 == scale 10%, 0.8 = shrink 20%) // Rotate = Rotation, in degrees // Pan = Translation, == Translate offset, in Device Independent Pixels var deltaManipulation = e.DeltaManipulation; var matrixTransform = sourceElement.RenderTransform as MatrixTransform; if (matrixTransform == null) { matrixTransform = new MatrixTransform(); sourceElement.RenderTransform = matrixTransform; } var matrix = matrixTransform.Matrix; if (_previousMatrix == null) { _previousMatrix = matrix; } // Center the translation around the user's fingers Point center = ((FrameworkElement)e.ManipulationContainer) .TranslatePoint(e.ManipulationOrigin, sourceElement); // transform it to take into account transforms from previous manipulations center = matrix.Transform(center); // Perform a scaling (zoom) tranformation if ((deltaManipulation.Scale.X < 1 && matrix.Determinant >= this.MinimumScale) || (deltaManipulation.Scale.X > 1 && matrix.Determinant <= this.MaximumScale)) { matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, center.X, center.Y); } // Prevent scaling below the minimum scale amount. if (matrix.Determinant < this.MinimumScale) { return; } // Rotation if (this.AllowRotate) { matrix.RotateAt(e.DeltaManipulation.Rotation, center.X, center.Y); } // Limit the X/Y translation extent to prevent the element from 'jumping' when using slow touchscreens, or many touch points. double translationThreshold = 100.0; // Perform a translation (pan) tranformation if ((deltaManipulation.Translation.X < translationThreshold && deltaManipulation.Translation.X > -translationThreshold) && (deltaManipulation.Translation.Y < translationThreshold && deltaManipulation.Translation.Y > -translationThreshold)) { matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); } // Perform the render transform on the element. sourceElement.RenderTransform = new MatrixTransform(matrix); e.Handled = true; } }
internal void ResetZoom() { zoomTransform = new MatrixTransform(); InvalidateArrange(); }
public TileContainer() { RenderTransform = new MatrixTransform(); updateTimer = new DispatcherTimer { Interval = UpdateInterval }; updateTimer.Tick += UpdateTiles; }