本文整理汇总了C#中System.Windows.Media.MatrixTransform.Freeze方法的典型用法代码示例。如果您正苦于以下问题:C# MatrixTransform.Freeze方法的具体用法?C# MatrixTransform.Freeze怎么用?C# MatrixTransform.Freeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.MatrixTransform
的用法示例。
在下文中一共展示了MatrixTransform.Freeze方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DpiHelper
static DpiHelper()
{
var dc = NativeMethods.NativeMethods.GetDC(IntPtr.Zero);
if (dc != IntPtr.Zero)
{
DeviceDpiX = NativeMethods.NativeMethods.GetDeviceCaps(dc, 88);
DeviceDpiY = NativeMethods.NativeMethods.GetDeviceCaps(dc, 90);
NativeMethods.NativeMethods.ReleaseDC(IntPtr.Zero, dc);
}
else
{
DeviceDpiX = 96.0;
DeviceDpiY = 96.0;
}
var identity1 = Matrix.Identity;
var identity2 = Matrix.Identity;
identity1.Scale(DeviceDpiX / 96.0, DeviceDpiY / 96.0);
identity2.Scale(96.0 / DeviceDpiX, 96.0 / DeviceDpiY);
transformFromDevice = new MatrixTransform(identity2);
transformFromDevice.Freeze();
transformToDevice = new MatrixTransform(identity1);
transformToDevice.Freeze();
}
示例2: InternalTransformToAncestor
/// <summary>
/// Returns the transform or the inverse transform between this visual and the specified ancestor.
/// If inverse is requested but does not exist (if the transform is not invertible), null is returned.
/// </summary>
/// <param name="ancestor">Ancestor visual.</param>
/// <param name="inverse">Returns inverse if this argument is true.</param>
private GeneralTransform InternalTransformToAncestor(Visual ancestor, bool inverse)
{
GeneralTransform generalTransform;
Matrix simpleTransform;
bool isSimple = TrySimpleTransformToAncestor(ancestor,
inverse,
out generalTransform,
out simpleTransform);
if (isSimple)
{
MatrixTransform matrixTransform = new MatrixTransform(simpleTransform);
matrixTransform.Freeze();
return matrixTransform;
}
else
{
return generalTransform;
}
}
示例3: TransformToVisual
/// <summary>
/// The returned matrix can be used to transform coordinates from this Visual to
/// the specified Visual.
/// Returns null if no such transform exists due to a non-invertible Transform.
/// </summary>
/// <exception cref="ArgumentNullException">If visual is null.</exception>
/// <exception cref="InvalidOperationException">If the Visuals are not connected.</exception>
public GeneralTransform TransformToVisual(Visual visual)
{
DependencyObject ancestor = FindCommonVisualAncestor(visual);
Visual ancestorAsVisual = ancestor as Visual;
if (ancestorAsVisual == null)
{
throw new System.InvalidOperationException(SR.Get(SRID.Visual_NoCommonAncestor));
}
GeneralTransform g0;
Matrix m0;
bool isSimple0 = this.TrySimpleTransformToAncestor(ancestorAsVisual,
false,
out g0,
out m0);
GeneralTransform g1;
Matrix m1;
bool isSimple1 = visual.TrySimpleTransformToAncestor(ancestorAsVisual,
true,
out g1,
out m1);
// combine the transforms
// if both transforms are simple Matrix transforms, just multiply them and
// return the result.
if (isSimple0 && isSimple1)
{
MatrixUtil.MultiplyMatrix(ref m0, ref m1);
MatrixTransform m = new MatrixTransform(m0);
m.Freeze();
return m;
}
// Handle the case where 0 is simple and 1 is complex.
if (isSimple0)
{
g0 = new MatrixTransform(m0);
g0.Freeze();
}
else if (isSimple1)
{
g1 = new MatrixTransform(m1);
g1.Freeze();
}
// If inverse was requested, TrySimpleTransformToAncestor can return null
// add the transform only if it is not null
if (g1 != null)
{
GeneralTransformGroup group = new GeneralTransformGroup();
group.Children.Add(g0);
group.Children.Add(g1);
group.Freeze();
return group;
}
return g0;
}
示例4: RenderTheme
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)
//.........这里部分代码省略.........
示例5: RenderAeroNormalColor
private void RenderAeroNormalColor(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));
//.........这里部分代码省略.........
示例6: UpdateVisualTransform
void UpdateVisualTransform() {
if (drawingVisual == null)
return;
var t = new MatrixTransform(1, 0, 0, lineTransform.VerticalScale, 0, TextTop);
t.Freeze();
drawingVisual.Transform = t;
}
示例7: OnRender
protected override void OnRender(DrawingContext dc)
{
// Draw background
dc.DrawRectangle(Brushes.White, null, new Rect(RenderSize));
Transform t = new MatrixTransform(TheModel.GetTikzToScreenTransform().ToWpfMatrix());
t.Freeze();
Pen pen = new Pen(Brushes.WhiteSmoke, 1);
pen.Freeze();
TheModel.DrawRaster(
(p1, p2) => dc.DrawLine(pen, t.Transform(p1), t.Transform(p2)),
(r1, r2) =>
{
EllipseGeometry eg = new EllipseGeometry(new Point(0, 0), r1, r2);
eg.Transform = t;
eg.Freeze();
dc.DrawGeometry(null, pen, eg);
});
}
示例8: MakeBrushFromVisual
private Brush MakeBrushFromVisual(Visual visual, Rect bounds)
{
Viewport3D viewport = visual as Viewport3D;
if (viewport == null)
{
Drawing drawing = VisualTreeHelper.GetDrawing(visual);
if (this.drawOutlines)
{
bounds.Inflate(VisualTree3DView.OutlinePen.Thickness / 2, VisualTree3DView.OutlinePen.Thickness / 2);
}
Matrix offsetMatrix = new Matrix(1, 0, 0, 1, -bounds.Left, -bounds.Top);
MatrixTransform offsetMatrixTransform = new MatrixTransform(offsetMatrix);
offsetMatrixTransform.Freeze();
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
drawingContext.PushTransform(offsetMatrixTransform);
if (this.drawOutlines)
{
drawingContext.DrawRectangle(null, VisualTree3DView.OutlinePen, bounds);
}
drawingContext.DrawDrawing(drawing);
drawingContext.Pop();
drawingContext.Close();
visual = drawingVisual;
}
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap((int)Math.Ceiling(bounds.Width), (int)Math.Ceiling(bounds.Height), 96, 96, PixelFormats.Default);
if (viewport != null)
{
typeof(RenderTargetBitmap).GetMethod("RenderForBitmapEffect", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(renderTargetBitmap,
new object[] { visual, Matrix.Identity, Rect.Empty });
}
else
{
renderTargetBitmap.Render(visual);
}
renderTargetBitmap.Freeze();
ImageBrush imageBrush = new ImageBrush(renderTargetBitmap);
imageBrush.Freeze();
return imageBrush;
}