本文整理汇总了C#中System.Windows.Rect.Inflate方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Inflate方法的具体用法?C# Rect.Inflate怎么用?C# Rect.Inflate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Rect
的用法示例。
在下文中一共展示了Rect.Inflate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public void Draw(LayerPropertiesModel props, LayerPropertiesModel applied, DrawingContext c)
{
if (applied?.Brush == null)
return;
const int scale = 4;
// Set up variables for this frame
var rect = props.Contain
? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale)
: new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale);
var clip = new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale);
// Take an offset of 4 to allow layers to slightly leave their bounds
var progress = (6.0 - props.AnimationProgress)*10.0;
if (progress < 0)
{
// Can't meddle with the original brush because it's frozen.
var brush = applied.Brush.Clone();
brush.Opacity = 1 + 0.025*progress;
if (brush.Opacity < 0)
brush.Opacity = 0;
if (brush.Opacity > 1)
brush.Opacity = 1;
applied.Brush = brush;
}
rect.Inflate(-rect.Width/100.0*progress, -rect.Height/100.0*progress);
clip.Inflate(-clip.Width/100.0*progress, -clip.Height/100.0*progress);
c.PushClip(new RectangleGeometry(clip));
c.DrawRectangle(applied.Brush, null, rect);
c.Pop();
}
示例2: AdjustPosition
/// <summary>
/// Sets the item's position according to its tikzitem's value
/// </summary>
public override bool AdjustPosition(double Resolution)
{
Rect r = new Rect(0, 0, 0, 0);
bool hasone = false;
foreach (OverlayShape o in children)
{
o.AdjustPosition(Resolution);
Rect rr = o.View.GetBB();
if (hasone)
r.Union(rr);
else
{
r = rr;
hasone = true;
}
}
if (hasone)
{
r.Inflate(20, 20);
//r = new Rect(10, 10, 100, 100);
View.SetSize( r.Width, r.Height);
View.SetPosition(r.X, r.Y);
return true;
}
else return false;
}
示例3: DiagramPaginator
/// <summary>Creates a new <see cref=""/> instance.</summary>
public DiagramPaginator(DiagramCanvas source, Size printSize) {
PageSize = printSize;
_contentSize = new Size(printSize.Width - 2 * Margin, printSize.Height - 2 * Margin);
_frameRect = new Rect(new Point(Margin, Margin), _contentSize);
_frameRect.Inflate(1, 1);
_framePen = new Pen(Brushes.Black, 0.1);
var scale = 0.25; // hardcoded zoom for printing
var bounds = new Rect(0, 0, source.ActualWidth, source.ActualHeight);
_pageCountX = (int)((bounds.Width * scale) / _contentSize.Width) + 1;
_pageCountY = (int)((bounds.Height * scale) / _contentSize.Height) + 1;
// Transformation to borderless print size
var matrix = new Matrix();
matrix.Translate(-bounds.Left, -bounds.Top);
matrix.Scale(scale, scale);
matrix.Translate((_pageCountX * _contentSize.Width - bounds.Width * scale) / 2, (_pageCountY * _contentSize.Height - bounds.Height * scale) / 2);
// Create a new visual
var printImage = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, 96, 96, PixelFormats.Pbgra32);
printImage.Render(source);
var printVisual = new DrawingVisual();
var printContext = printVisual.RenderOpen();
printContext.PushTransform(new MatrixTransform(matrix));
printContext.DrawImage(printImage, bounds);
printContext.Close();
_printDiagram = printVisual.Drawing;
}
示例4: ScrollIntoViewCentered
public static void ScrollIntoViewCentered(this SurfaceListBox listBox, object item)
{
Debug.Assert(!VirtualizingStackPanel.GetIsVirtualizing(listBox),
"VirtualizingStackPanel.IsVirtualizing must be disabled for ScrollIntoViewCentered to work.");
Debug.Assert(!ScrollViewer.GetCanContentScroll(listBox),
"ScrollViewer.GetCanContentScroll must be disabled for ScrollIntoViewCentered to work.");
// Get the container for the specified item
var container = listBox.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement;
if (null != container)
{
// Get the bounds of the item container
var rect = new Rect(new Point(), container.RenderSize);
// Find constraining parent (either the nearest ScrollContentPresenter or the ListBox itself)
FrameworkElement constrainingParent = container;
do
{
constrainingParent = VisualTreeHelper.GetParent(constrainingParent) as FrameworkElement;
} while ((null != constrainingParent) &&
(listBox != constrainingParent) &&
!(constrainingParent is ScrollContentPresenter));
if (null != constrainingParent)
{
// Inflate rect to fill the constraining parent
rect.Inflate(
Math.Max((constrainingParent.ActualWidth - rect.Width)/2, 0),
Math.Max((constrainingParent.ActualHeight - rect.Height)/2, 0));
}
// Bring the (inflated) bounds into view
container.BringIntoView(rect);
}
}
示例5: OnRender
protected override void OnRender( DrawingContext dc )
{
Rect rect;
if ( myLocation == DropLocation.InPlace )
{
rect = new Rect( new Size( myOwner.ActualWidth, myOwner.ActualHeight ) );
rect.Inflate( -1, -1 );
}
else
{
rect = new Rect( new Size( myOwner.ActualWidth, myOwner.ActualHeight * 0.2 ) );
if ( myLocation == DropLocation.Before )
{
rect.Offset( 0, -myOwner.ActualHeight * 0.1 );
}
else if ( myLocation == DropLocation.After )
{
rect.Offset( 0, myOwner.ActualHeight * 0.9 );
}
rect.Inflate( -1, 0 );
}
var brush = new SolidColorBrush( Colors.LightSkyBlue );
brush.Opacity = 0.5;
var pen = new Pen( new SolidColorBrush( Colors.White ), 1 );
dc.DrawRectangle( brush, pen, rect );
}
示例6: GetRectWithMargin
internal static Rect GetRectWithMargin(ConnectorInfo connectorThumb, double margin)
{
Rect rect = new Rect(connectorThumb.DesignerItemLeft,
connectorThumb.DesignerItemTop,
connectorThumb.DesignerItemSize.Width,
connectorThumb.DesignerItemSize.Height);
rect.Inflate(margin, margin);
return rect;
}
示例7: MapCubeToRenderPointRect
public Rect MapCubeToRenderPointRect(IntGrid3 grid)
{
var p1 = MapLocationToScreenTile(grid.Corner1);
var p2 = MapLocationToScreenTile(grid.Corner2);
var r = new Rect(p1, p2);
r.Inflate(0.5, 0.5);
p1 = ScreenToRenderPoint(r.TopLeft);
p2 = ScreenToRenderPoint(r.BottomRight);
return new Rect(p1, p2);
}
示例8: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
Rect adornedElementRect = new Rect(this.AdornedElement.DesiredSize);
Rect newRect = new Rect(adornedElementRect.Right - App.StrokeThinkness * 2, adornedElementRect.Bottom - App.StrokeThinkness * 2,
adornedElementRect.Right, adornedElementRect.Bottom);
newRect.Inflate(1, 1);
// Some arbitrary drawing implements.
SolidColorBrush renderBrush = new SolidColorBrush(Colors.Red);
renderBrush.Opacity = 0.2;
Pen renderPen = new Pen(new SolidColorBrush(Colors.Navy), 1.5);
//drawingContext.DrawRectangle(renderBrush, renderPen, newRect);
}
示例9: ColorCell
public ColorCell(Color clr)
{
visColor = new DrawingVisual();
DrawingContext dc = visColor.RenderOpen();
Rect rect = new Rect(new Point(0,0), sizeCell);
rect.Inflate(-4, -4);
Pen pen = new Pen(SystemColors.ControlTextBrush, 1);
brush = new SolidColorBrush(clr);
dc.DrawRectangle(brush, pen, rect);
dc.Close();
AddVisualChild(visColor);
AddLogicalChild(visColor);
}
示例10: ColorCell
// Constructor requires Color argument.
public ColorCell(Color clr)
{
// Create a new DrawingVisual and store as field.
visColor = new DrawingVisual();
DrawingContext dc = visColor.RenderOpen();
// Draw a rectangle with the color argument.
Rect rect = new Rect(new Point(0, 0), sizeCell);
rect.Inflate(-4, -4);
Pen pen = new Pen(SystemColors.ControlTextBrush, 1);
brush = new SolidColorBrush(clr);
dc.DrawRectangle(brush, pen, rect);
dc.Close();
// AddVisualChild is necessary for event routing!
AddVisualChild(visColor);
AddLogicalChild(visColor);
}
示例11: UIElement_MouseLeftButtonUp
private static void UIElement_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
var element = sender as UIElement;
if (element == null)
{
return;
}
var lastClickLocation = element.GetValue(LastClickLocationProperty) as Point?;
var lastClickTime = element.GetValue(LastClickTimeProperty) as int?;
if (lastClickLocation.HasValue && lastClickTime.HasValue)
{
if (e.Timestamp - lastClickTime.Value > SystemInformation.DoubleClickTime)
{
element.SetValue(LastClickLocationProperty, e.GetPosition(element));
element.SetValue(LastClickTimeProperty, e.Timestamp);
return;
}
var size = SystemInformation.DoubleClickSize;
var rect = new Rect(lastClickLocation.Value, lastClickLocation.Value);
rect.Inflate(size.Width / 2, size.Height / 2);
if (rect.Contains(e.GetPosition(element)))
{
var contentControl = element as ContentControl;
if (contentControl != null)
{
Debug.WriteLine($"Clipboard set to: \"{contentControl.Content.ToString()}\"");
System.Windows.Clipboard.SetText(contentControl.Content.ToString());
}
var textBlock = element as TextBlock;
if (textBlock != null)
{
Debug.WriteLine($"Clipboard set to: \"{textBlock.Text}\"");
System.Windows.Clipboard.SetText(textBlock.Text);
}
ClearDoubleClickProperties(element);
return;
}
}
element.SetValue(LastClickLocationProperty, e.GetPosition(element));
element.SetValue(LastClickTimeProperty, e.Timestamp);
}
示例12: GraphPaginator
internal GraphPaginator( DrawingVisual source, Size printSize )
{
PageSize = printSize;
contentSize = new Size( printSize.Width - 2 * Margin, printSize.Height - 2 * Margin );
myFrameRect = new Rect( new Point( Margin, Margin ), contentSize );
myFrameRect.Inflate( 1, 1 );
myFramePen = new Pen( Brushes.Black, 0.1 );
// Transformation to borderless print size
var bounds = source.DescendantBounds;
bounds.Union( source.ContentBounds );
var m = new Matrix();
m.Translate( -bounds.Left, -bounds.Top );
double scale = 16; // hardcoded zoom for printing
myPageCountX = ( int )( ( bounds.Width * scale ) / contentSize.Width ) + 1;
myPageCountY = ( int )( ( bounds.Height * scale ) / contentSize.Height ) + 1;
m.Scale( scale, scale );
// Center on available pages
m.Translate( ( myPageCountX * contentSize.Width - bounds.Width * scale ) / 2, ( myPageCountY * contentSize.Height - bounds.Height * scale ) / 2 );
var target = new DrawingVisual();
using( var dc = target.RenderOpen() )
{
dc.PushTransform( new MatrixTransform( m ) );
dc.DrawDrawing( source.Drawing );
foreach( DrawingVisual child in source.Children )
{
dc.DrawDrawing( child.Drawing );
}
}
myGraph = target.Drawing;
}
示例13: OnRenderSizeChanged
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
{
base.OnRenderSizeChanged(sizeInfo);
Size s = sizeInfo.NewSize;
Rect inner = new Rect(0, 0, s.Width, s.Height);
double radius = s.Width - this.BorderThickness.Left;
double sinX = radius / Math.Sqrt(2);
double margin = (int)(s.Width - sinX);
inner.Inflate(-margin, -margin);
Path p = (Path)Template.FindName("CrossShape", this);
p.Data = new PathGeometry(new PathFigure[]
{
new PathFigure(new Point(inner.Left, inner.Top),
new PathSegment[] {
new LineSegment(new Point(inner.Right, inner.Bottom), true),
new LineSegment(new Point(inner.Left, inner.Bottom), false),
new LineSegment(new Point(inner.Right, inner.Top), true),
}, false)
});
}
示例14: GetDockTabItemAtMouse
/// <summary>
/// Gets the <see cref="DockTabItem"/> at the mouse position by testing against the
/// <see cref="DockTabItem"/> tabs in the specified pane.
/// </summary>
/// <param name="dockTabPane">The <see cref="DockTabPane"/>.</param>
/// <param name="verticalTolerance">
/// The tolerance (margin at top and bottom) in pixels.
/// </param>
/// <returns>The <see cref="DockTabItem"/> under the mouse cursor.</returns>
private static DockTabItem GetDockTabItemAtMouse(DockTabPane dockTabPane, double verticalTolerance = 0)
{
Debug.Assert(dockTabPane != null);
if (dockTabPane.Items.Count == 0)
return null; // Empty DockTabPane.
var itemsPanel = dockTabPane.GetItemsPanel();
if (itemsPanel == null)
return null; // ItemsPanel missing.
Point mousePosition = WindowsHelper.GetMousePosition(itemsPanel);
Rect bounds = new Rect(itemsPanel.RenderSize);
bounds.Inflate(0, verticalTolerance);
if (!bounds.Contains(mousePosition))
return null; // Mouse position outside ItemsPanel.
// Test mouse position against DockTabItems bounds.
double height = itemsPanel.RenderSize.Height;
double x = 0;
for (int i = 0; i < dockTabPane.Items.Count; i++)
{
var dockTabItem = dockTabPane.ItemContainerGenerator.ContainerFromIndex(i) as DockTabItem;
if (dockTabItem == null)
break;
bounds = new Rect(new Point(x, 0), new Size(dockTabItem.RenderSize.Width, height));
bounds.Inflate(0, verticalTolerance);
if (bounds.Contains(mousePosition))
return dockTabItem;
x += bounds.Width;
}
return null;
}
示例15: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
if (this.Frame != null)
{
double windowWidth = (this.ActualWidth / this.Frame.ColumnCount);
double windowHeight = (this.ActualHeight / this.Frame.RowCount);
double spaceX = 0.1 * windowWidth;
double spaceY = 0.1 * windowHeight;
// draw the background
drawingContext.DrawRectangle(new SolidColorBrush(new System.Windows.Media.Color() { R = 179, G = 123, B = 123, A = 255 }), null, new Rect(0, 0, this.ActualWidth, this.ActualHeight));
for (int row = 0; row < this.Frame.RowCount; row++)
{
for (int col = 0; col < this.Frame.ColumnCount; col++)
{
double x = col * (windowWidth);
double y = row * (windowHeight);
System.Windows.Media.Color color = new System.Windows.Media.Color();
color.R = this.Frame.Get(row, col).Red;
color.G = this.Frame.Get(row, col).Green;
color.B = this.Frame.Get(row, col).Blue;
color.A = 255;
Rect window = new Rect(x, y, windowWidth, windowHeight);
//window.Scale(0.9, 0.9);
//window.Offset(spaceX, spaceY);
window.Inflate(-spaceX, -spaceY);
drawingContext.DrawRectangle(new SolidColorBrush(color), null, window);
}
}
}
}