本文整理汇总了C#中System.Windows.Media.GeometryDrawing.Freeze方法的典型用法代码示例。如果您正苦于以下问题:C# GeometryDrawing.Freeze方法的具体用法?C# GeometryDrawing.Freeze怎么用?C# GeometryDrawing.Freeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.GeometryDrawing
的用法示例。
在下文中一共展示了GeometryDrawing.Freeze方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateVisuals
/// <summary>
/// Within the given line add the scarlet box behind the a
/// </summary>
private void CreateVisuals(ITextViewLine line)
{
//grab a reference to the lines in the current TextView
IWpfTextViewLineCollection textViewLines = _view.TextViewLines;
int start = line.Start;
int end = line.End;
//Loop through each character, and place a box around any a
for (int i = start; (i < end); ++i)
{
if (_view.TextSnapshot[i] == 'a')
{
SnapshotSpan span = new SnapshotSpan(_view.TextSnapshot, Span.FromBounds(i, i + 1));
Geometry g = textViewLines.GetMarkerGeometry(span);
if (g != null)
{
GeometryDrawing drawing = new GeometryDrawing(_brush, _pen, g);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
Image image = new Image();
image.Source = drawingImage;
//Align the image with the top of the bounds of the text geometry
Canvas.SetLeft(image, g.Bounds.Left);
Canvas.SetTop(image, g.Bounds.Top);
_layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
}
}
}
}
示例2: TranslationAdornment
/// <summary>
/// Creates a square image and attaches an event handler to the layout changed event that
/// adds the the square in the upper right-hand corner of the TextView via the adornment layer
/// </summary>
/// <param name="view">The <see cref="IWpfTextView"/> upon which the adornment will be drawn</param>
public TranslationAdornment(IWpfTextView view)
{
_view = view;
Brush brush = new SolidColorBrush(Colors.BlueViolet);
brush.Freeze();
Brush penBrush = new SolidColorBrush(Colors.Red);
penBrush.Freeze();
Pen pen = new Pen(penBrush, 0.5);
pen.Freeze();
//draw a square with the created brush and pen
System.Windows.Rect r = new System.Windows.Rect(0, 0, 30, 30);
Geometry g = new RectangleGeometry(r);
GeometryDrawing drawing = new GeometryDrawing(brush, pen, g);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
_image = new Image();
_image.Source = drawingImage;
//Grab a reference to the adornment layer that this adornment should be added to
_adornmentLayer = view.GetAdornmentLayer("TranslationAdornment");
_view.ViewportHeightChanged += delegate { this.onSizeChange(); };
_view.ViewportWidthChanged += delegate { this.onSizeChange(); };
}
示例3: AddDecorationError
public void AddDecorationError(BasePropertyDeclarationSyntax _property, string textFull, string toolTipText, FixErrorCallback errorCallback)
{
var lineSpan = tree.GetLineSpan(_property.Span, usePreprocessorDirectives: false);
int lineNumber = lineSpan.StartLinePosition.Line;
var line = _textView.TextSnapshot.GetLineFromLineNumber(lineNumber);
var textViewLine = _textView.GetTextViewLineContainingBufferPosition(line.Start);
int startSpace = textFull.Length - textFull.TrimStart().Length;
int endSpace = textFull.Length - textFull.TrimEnd().Length;
SnapshotSpan span = new SnapshotSpan(_textView.TextSnapshot, Span.FromBounds(line.Start.Position + startSpace, line.End.Position - endSpace));
Geometry g = _textView.TextViewLines.GetMarkerGeometry(span);
if (g != null)
{
rects.Add(g.Bounds);
GeometryDrawing drawing = new GeometryDrawing(_brush, _pen, g);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
Image image = new Image();
image.Source = drawingImage;
//image.Visibility = Visibility.Hidden;
Canvas.SetLeft(image, g.Bounds.Left);
Canvas.SetTop(image, g.Bounds.Top);
_layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, (t, ui) =>
{
rects.Remove(g.Bounds);
});
DrawIcon(span, g.Bounds.Left - 30, g.Bounds.Top, toolTipText, errorCallback);
}
}
示例4: CreateAndAddAdornment
void CreateAndAddAdornment(ITextViewLine line, SnapshotSpan span, Brush brush, bool extendToRight)
{
var markerGeometry = _view.TextViewLines.GetMarkerGeometry(span);
double left = markerGeometry.Bounds.Left;
double width = extendToRight ? _view.ViewportWidth + _view.MaxTextRightCoordinate : markerGeometry.Bounds.Width;
Rect rect = new Rect(left, line.Top, width, line.Height);
RectangleGeometry geometry = new RectangleGeometry(rect);
GeometryDrawing drawing = new GeometryDrawing(brush, new Pen(), geometry);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
Image image = new Image();
image.Source = drawingImage;
Canvas.SetLeft(image, geometry.Bounds.Left);
Canvas.SetTop(image, geometry.Bounds.Top);
_layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
}
示例5: CreateImageToHighlightLine
private Image CreateImageToHighlightLine(Geometry geometry, LineResultMarker marker)
{
GeometryDrawing backgroundGeometry = new GeometryDrawing(marker.Fill, marker.Outline, geometry);
backgroundGeometry.Freeze();
DrawingImage backgroundDrawning = new DrawingImage(backgroundGeometry);
backgroundDrawning.Freeze();
return new Image {Source = backgroundDrawning};
}
示例6: CreateImage
/// <summary>
/// Freezes and then creates an image object from a GeometryGroup.
/// </summary>
/// <param name="brush">The fill brush for the group.</param>
/// <param name="pen">The Border pen for the group.</param>
/// <param name="group">The group to create an image from.</param>
/// <returns>An image object that can be added to the canvas.</returns>
public static Image CreateImage(this GeometryGroup group, Brush brush, Pen pen)
{
group.Freeze();
var drawing = new GeometryDrawing(brush, pen, group);
drawing.Freeze();
var drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
return new Image { Source = drawingImage };
}
示例7: DoorPicture
internal DoorPicture()
{
_pen = new Pen(Brushes.Black, 2);
_pen.Freeze();
_geometry = new PathGeometry()
{
Figures = new PathFigureCollection()
{
new PathFigure()
{
IsClosed = true,
IsFilled = true,
Segments = new PathSegmentCollection()
{
new LineSegment(new Point(-40,0),true),
new LineSegment(new Point(-40,100),true),
new LineSegment(new Point(0,100),true),
}
}
}
};
_geometry.Freeze();
_geometryDrawing = new GeometryDrawing()
{
Brush = new SolidColorBrush(Colors.DarkOrange),
Pen = _pen,
Geometry = new PathGeometry()
{
Figures = new PathFigureCollection()
{
new PathFigure()
{
IsClosed = true,
IsFilled = true,
Segments = new PathSegmentCollection()
{
new LineSegment(new Point(20,40),true),
new LineSegment(new Point(20,140),true),
new LineSegment(new Point(0,100),true),
}
}
}
}
};
_geometryDrawing.Freeze();
_brushes = new Dictionary<Brush, Brush>();
}
示例8: AddMarker
private void AddMarker(SnapshotSpan span, Geometry markerGeometry, FormatInfo formatInfo)
{
GeometryDrawing drawing = new GeometryDrawing(formatInfo.Background, formatInfo.Outline, markerGeometry);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
Image image = new Image();
image.Source = drawingImage;
// Align the image with the top of the bounds of the text geometry
Canvas.SetLeft(image, markerGeometry.Bounds.Left);
Canvas.SetTop(image, markerGeometry.Bounds.Top);
adornmentLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
}
示例9: DoCreateAdornment
// Unlike the LineAdornment extension we do not add a border (a border adds a bit too much
// visual noise and makes it hard to see the insertion point when it is in the first column).
private Image DoCreateAdornment(Rect area)
{
// Create the brush we'll used to highlight the current line. The color will be
// the CurrentLine property from the Fonts and Colors panel in the Options dialog.
if (m_fillBrush == null)
{
TextFormattingRunProperties format = m_formatMap.GetTextProperties(m_formatType);
m_fillBrush = format.BackgroundBrush;
}
var drawing = new GeometryDrawing();
drawing.Brush = m_fillBrush;
drawing.Geometry = new RectangleGeometry(area, 1.0, 1.0);
drawing.Freeze();
var drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
var image = new Image();
image.UseLayoutRounding = false; // work around WPF rounding bug
image.Source = drawingImage;
return image;
}
示例10: CreateVisuals
private void CreateVisuals(ITextViewLine line)
{
{
var text = line.Extent.GetText();
if (!regex.IsMatch(text)) return;
}
IWpfTextViewLineCollection textViewLines = this.view.TextViewLines;
// Loop through each character, and place a box around any 'a'
for (int charIndex = line.Start; charIndex < line.End; charIndex++)
{
if (this.view.TextSnapshot[charIndex] == 'a')
{
SnapshotSpan span = new SnapshotSpan(this.view.TextSnapshot, Span.FromBounds(charIndex, charIndex + 1));
Geometry geometry = textViewLines.GetMarkerGeometry(span);
if (geometry != null)
{
var drawing = new GeometryDrawing(this.brush, this.pen, geometry);
drawing.Freeze();
var drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
var image = new Image
{
Source = drawingImage,
};
// Align the image with the top of the bounds of the text geometry
Canvas.SetLeft(image, geometry.Bounds.Left);
Canvas.SetTop(image, geometry.Bounds.Top);
this.layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
}
}
}
}
示例11: Explode
public async System.Threading.Tasks.Task Explode()
{
if (ParticleCount > MaxParticleCount)
return;
ParticleCount++;
// TODO: rewrite this part for better design & performance
// store service & package as static member.
var service = ServiceProvider.GlobalProvider.GetService(typeof(SPowerMode));
var pm_service = service as IPowerMode;
var package = pm_service.Package;
var page = package.General;
ExplosionParticle.Color = page.Color;
ExplosionParticle.AlphaRemoveAmount = page.AlphaRemoveAmount;
ExplosionParticle.bGetColorFromEnvironment = bGetColorFromEnvironment;
ExplosionParticle.RandomColor = page.RandomColor;
ExplosionParticle.FrameDelay = page.FrameDelay;
ExplosionParticle.Gravity = page.Gravity;
ExplosionParticle.MaxParticleCount = page.MaxParticleCount;
ExplosionParticle.MaxSideVelocity = page.MaxSideVelocity;
ExplosionParticle.MaxUpVelocity = page.MaxUpVelocity;
//ExplosionParticle.ParticlesEnabled = page.ParticlesEnabled;
//ExplosionParticle.ShakeEnabled = page.ShakeEnabled;
ExplosionParticle.StartAlpha = page.StartAlpha;
// End of TODO.
var alpha = StartAlpha;
var upVelocity = Random.NextDouble() * MaxUpVelocity;
var leftVelocity = Random.NextDouble() * MaxSideVelocity * Random.NextSignSwap();
SolidColorBrush brush = null;
if (bGetColorFromEnvironment)
{
var svc = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(Microsoft.VisualStudio.Shell.Interop.SVsUIShell)) as Microsoft.VisualStudio.Shell.Interop.IVsUIShell5;
brush = new SolidColorBrush(Microsoft.VisualStudio.Shell.VsColors.GetThemedWPFColor(svc, Microsoft.VisualStudio.PlatformUI.EnvironmentColors.PanelTextColorKey));
}
else if (RandomColor)
{
brush = new SolidColorBrush(Random.NextColor());
}
else
{
brush = new SolidColorBrush(Color);
}
brush.Freeze();
var drawing = new GeometryDrawing(brush, null, geometry);
drawing.Freeze();
var drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
var image = new Image
{
Source = drawingImage,
};
while (alpha >= AlphaRemoveAmount)
{
_left -= leftVelocity;
_top -= upVelocity;
upVelocity -= Gravity;
alpha -= AlphaRemoveAmount;
image.Opacity = alpha;
Canvas.SetLeft(image, _left);
Canvas.SetTop(image, _top);
try
{
// Add the image to the adornment layer and make it relative to the viewport
adornmentLayer.AddAdornment(AdornmentPositioningBehavior.ViewportRelative,
null,
null,
image,
null);
await System.Threading.Tasks.Task.Delay(FrameDelay);
adornmentLayer.RemoveAdornment(image);
}
catch
{
break;
}
}
try
{
adornmentLayer.RemoveAdornment(image);
}
catch
{
//Ignore all errors, not critical
}
ParticleCount--;
}
示例12: CreateAdornment
private void CreateAdornment()
{
var lines = view.VisualSnapshot.Lines;
if (codeOrigin == null)
return;
var startLine = lines.FirstOrDefault(a => a.LineNumber == codeOrigin.From.Line - 1);
var endLine = lines.FirstOrDefault(a => a.LineNumber == codeOrigin.To.Line - 1);
if (startLine == null || endLine == null)
return;
var startPosition = startLine.Start + codeOrigin.From.Column - 1;
var endPosition = endLine.Start + codeOrigin.To.Column - 1;
var span = new SnapshotSpan(view.TextSnapshot, Span.FromBounds(startPosition, endPosition));
try
{
layer.TextView.ViewScroller.EnsureSpanVisible(span, EnsureSpanVisibleOptions.AlwaysCenter);
}
catch (InvalidOperationException)
{
// Intentionally ignored.
}
var g = view.TextViewLines.GetMarkerGeometry(span);
if (g != null)
{
var drawing = new GeometryDrawing(brush, pen, g);
drawing.Freeze();
var drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
var image = new Image
{
Source = drawingImage
};
// Align the image with the top of the bounds of the text geometry.
Canvas.SetLeft(image, g.Bounds.Left);
Canvas.SetTop(image, g.Bounds.Top);
Canvas.SetLeft(achievementUiElement, g.Bounds.Right + 50);
Canvas.SetTop(achievementUiElement, g.Bounds.Top);
achievementUiElement.MouseDown += (sender, args) => Reset();
adornmentVisible = true;
try
{
layer.AddAdornment(AdornmentPositioningBehavior.TextRelative,
span, null, image, (tag, element) => adornmentVisible = false);
descriptionLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative,
span, null, achievementUiElement, null);
}
catch (ArgumentException)
{
// Intentionally ignored.
}
}
}
示例13: SetColor
/// <summary>
/// Setta il colore usato dall'evidenziatore.
/// </summary>
private static void SetColor()
{
// Create the pen and brush to color the box behind the a's
Brush myBrush = null;
if (AlmaStyleFixPackage.Page == null)
{
myBrush = new SolidColorBrush(Color.FromArgb(0x20, 0x00, 0x00, 0xff));
}
else
{
myBrush = new SolidColorBrush(Color.FromArgb(
Convert.ToByte(AlmaStyleFixPackage.Page.A),
Convert.ToByte(AlmaStyleFixPackage.Page.R),
Convert.ToByte(AlmaStyleFixPackage.Page.G),
Convert.ToByte(AlmaStyleFixPackage.Page.B)));
}
// myBrush.Freeze();
Brush penBrush = new SolidColorBrush(Colors.Red);
penBrush.Freeze();
Pen myPen = new Pen(penBrush, 0.5);
myPen.Freeze();
// draw a square with the created brush and pen
System.Windows.Rect r = new System.Windows.Rect(0, 0, 5, 5);
Geometry g = new RectangleGeometry(r);
GeometryDrawing drawing = new GeometryDrawing(myBrush, myPen, g);
drawing.Freeze();
image = new DrawingImage(drawing);
image.Freeze();
}
示例14: CreateSensitiveCodeMarkerVisuals
private void CreateSensitiveCodeMarkerVisuals(NormalizedSnapshotSpanCollection sensitiveTextSpans, ITextSnapshot newSnapshot)
{
_layer.RemoveAllAdornments();
foreach (var span in sensitiveTextSpans)
{
IWpfTextViewLineCollection textViewLines = _view.TextViewLines;
var geometry = textViewLines.GetMarkerGeometry(span);
if (geometry != null)
{
var drawing = new GeometryDrawing(_brush, _pen, geometry);
drawing.Freeze();
var drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
var image = new Image
{
Source = drawingImage,
};
// Align the image with the top of the bounds of the text geometry
Canvas.SetLeft(image, geometry.Bounds.Left);
Canvas.SetTop(image, geometry.Bounds.Top);
_layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
}
}
}
示例15: ReGenImage
public void ReGenImage(double theight)
{
Brush brush = new SolidColorBrush(Colors.LemonChiffon);
brush.Freeze();
Brush penBrush = new SolidColorBrush(Colors.White); //no paddings
penBrush.Freeze();
Pen pen = new Pen(penBrush, 0.5);
pen.Freeze();
//draw a square with the created brush and pen, specify the start point and width, length of the rect
System.Windows.Rect r = new System.Windows.Rect(0, 0, _view.ViewportWidth, theight);
Geometry g = new RectangleGeometry(r);
GeometryDrawing drawing = new GeometryDrawing(brush, pen, g);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
_image = new Image();//
_image.Source = drawingImage;
}