本文整理汇总了C#中Rect.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Intersect方法的具体用法?C# Rect.Intersect怎么用?C# Rect.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rect
的用法示例。
在下文中一共展示了Rect.Intersect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Blit
/// <summary>
/// Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).
/// </summary>
/// <param name="bmp">The destination WriteableBitmap.</param>
/// <param name="destRect">The rectangle that defines the destination region.</param>
/// <param name="source">The source WriteableBitmap.</param>
/// <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>
/// <param name="color">If not Colors.White, will tint the source image. A partially transparent color and the image will be drawn partially transparent.</param>
/// <param name="BlendMode">The blending mode <see cref="BlendMode"/>.</param>
public static void Blit(this WriteableBitmap bmp, Rect destRect, WriteableBitmap source, Rect sourceRect, Color color, BlendMode BlendMode)
{
if (color.A == 0)
{
return;
}
int dw = (int)destRect.Width;
int dh = (int)destRect.Height;
int dpw = bmp.PixelWidth;
int dph = bmp.PixelHeight;
Rect intersect = new Rect(0, 0, dpw, dph);
intersect.Intersect(destRect);
if (intersect.IsEmpty)
{
return;
}
int sourceWidth = source.PixelWidth;
int[] sourcePixels = source.Pixels;
int[] destPixels = bmp.Pixels;
int sourceLength = sourcePixels.Length;
int destLength = destPixels.Length;
int sourceIdx = -1;
int px = (int)destRect.X;
int py = (int)destRect.Y;
int right = px + dw;
int bottom = py + dh;
int x;
int y;
int idx;
double ii;
double jj;
int sr = 0;
int sg = 0;
int sb = 0;
int dr, dg, db;
int sourcePixel;
int sa = 0;
int da;
int ca = color.A;
int cr = color.R;
int cg = color.G;
int cb = color.B;
bool tinted = color != Colors.White;
double sdx = sourceRect.Width / destRect.Width;
double sdy = sourceRect.Height / destRect.Height;
int sourceStartX = (int)sourceRect.X;
int sourceStartY = (int)sourceRect.Y;
int lastii, lastjj;
lastii = -1;
lastjj = -1;
jj = sourceStartY;
y = py;
for (int j = 0; j < dh; j++)
{
if (y >= 0 && y < dph)
{
ii = sourceStartX;
idx = px + y * dpw;
x = px;
sourcePixel = sourcePixels[0];
for (int i = 0; i < dw; i++)
{
if (x >= 0 && x < dpw)
{
if ((int)ii != lastii || (int)jj != lastjj)
{
sourceIdx = (int)ii + (int)jj * sourceWidth;
if (sourceIdx >= 0 && sourceIdx < sourceLength)
{
sourcePixel = sourcePixels[sourceIdx];
sa = ((sourcePixel >> 24) & 0xff);
sr = ((sourcePixel >> 16) & 0xff);
sg = ((sourcePixel >> 8) & 0xff);
sb = ((sourcePixel) & 0xff);
if (tinted && sa != 0)
{
sa = (((sa * ca) * 0x8081) >> 23);
sr = ((((((sr * cr) * 0x8081) >> 23) * ca) * 0x8081) >> 23);
sg = ((((((sg * cg) * 0x8081) >> 23) * ca) * 0x8081) >> 23);
sb = ((((((sb * cb) * 0x8081) >> 23) * ca) * 0x8081) >> 23);
sourcePixel = (sa << 24) | (sr << 16) | (sg << 8) | sb;
}
}
else
{
sa = 0;
}
}
if (BlendMode == BlendMode.None)
//.........这里部分代码省略.........
示例2: PrecomputeRecursive
internal void PrecomputeRecursive(out Rect bboxSubgraph)
{
// Simple loop detection to avoid stack overflow in cyclic Visual
// scenarios. This fix is only aimed at mitigating a very common
// VisualBrush scenario.
bool canEnter = Enter();
if (canEnter)
{
try
{
if (CheckFlagsAnd(VisualFlags.IsSubtreeDirtyForPrecompute))
{
PrecomputeContent();
int childCount = VisualChildrenCount;
for (int i = 0; i < childCount; i++)
{
Visual child = GetVisualChild(i);
if (child != null)
{
Rect bboxSubgraphChild;
child.PrecomputeRecursive(out bboxSubgraphChild);
_bboxSubgraph.Union(bboxSubgraphChild);
}
}
SetFlags(false, VisualFlags.IsSubtreeDirtyForPrecompute);
}
// Bounding boxes are cached in inner space (below offset, transform, and clip).
// Before returning them we need
// to transform them into outer space.
bboxSubgraph = _bboxSubgraph;
Geometry clip = ClipField.GetValue(this);
if (clip != null)
{
bboxSubgraph.Intersect(clip.Bounds);
}
Transform transform = TransformField.GetValue(this);
if ((transform != null) && (!transform.IsIdentity))
{
Matrix m = transform.Value;
MatrixUtil.TransformRect(ref bboxSubgraph, ref m);
}
if (!bboxSubgraph.IsEmpty)
{
bboxSubgraph.X += _offset.X;
bboxSubgraph.Y += _offset.Y;
}
Rect? scrollClip = ScrollableAreaClipField.GetValue(this);
if (scrollClip.HasValue)
{
bboxSubgraph.Intersect(scrollClip.Value);
}
// If child's bounding box has NaN, then we set the bounding box to infinity.
if (DoubleUtil.RectHasNaN(bboxSubgraph))
{
bboxSubgraph.X = Double.NegativeInfinity;
bboxSubgraph.Y = Double.NegativeInfinity;
bboxSubgraph.Width = Double.PositiveInfinity;
bboxSubgraph.Height = Double.PositiveInfinity;
}
}
finally
{
Exit();
}
}
else
{
bboxSubgraph = new Rect();
}
}
示例3: Rect
Rect IScrollInfo.MakeVisible(Visual visual, Rect rectangle)
{
if (rectangle.IsEmpty || visual == null || !IsAncestorOf(visual))
{
return Rect.Empty;
}
rectangle = visual.TransformToAncestor(this).TransformBounds(rectangle);
rectangle = RenderTransform.TransformBounds(rectangle);
var width = ((IScrollInfo)this).ViewportWidth;
var height = ((IScrollInfo)this).ViewportHeight;
var left = -rectangle.X;
var right = left + width - rectangle.Width;
var top = -rectangle.Y;
var bottom = top + height - rectangle.Height;
var deltaX = left > 0 && right > 0 ? Math.Min(left, right) : left < 0 && right < 0 ? Math.Max(left, right) : 0.0;
var deltaY = top > 0 && bottom > 0 ? Math.Min(top, bottom) : top < 0 && bottom < 0 ? Math.Max(top, bottom) : 0.0;
var offset = Offset;
offset.X -= deltaX;
offset.Y -= deltaY;
Offset = offset;
rectangle.X += deltaX;
rectangle.Y += deltaY;
rectangle.Intersect(new Rect(0, 0, width, height));
return rectangle;
}
示例4: TryIntersectViewport
public bool TryIntersectViewport(ref Rect clippingRect)
{
if (clippingRect.IsEmpty)
{
return true;
}
clippingRect.Intersect(this.spriteBatch.GraphicsDevice.Viewport.ToRect());
return !clippingRect.IsEmpty;
}
示例5: CalculateBoundingRect
/// <summary>
/// Calculate visible rectangle.
/// </summary>
private Rect CalculateBoundingRect(bool clipToVisible, out UIElement uiScope)
{
uiScope = null;
Rect boundingRect = Rect.Empty;
if (Owner is IServiceProvider)
{
ITextContainer textContainer = ((IServiceProvider)Owner).GetService(typeof(ITextContainer)) as ITextContainer;
ITextView textView = (textContainer != null) ? textContainer.TextView : null;
if (textView != null)
{
// Make sure TextView is updated
if (!textView.IsValid)
{
if (!textView.Validate())
{
textView = null;
}
if (textView != null && !textView.IsValid)
{
textView = null;
}
}
// Get bounding rect from TextView.
if (textView != null)
{
boundingRect = new Rect(textView.RenderScope.RenderSize);
uiScope = textView.RenderScope;
// Compute visible portion of the rectangle.
if (clipToVisible)
{
Visual visual = textView.RenderScope;
while (visual != null && boundingRect != Rect.Empty)
{
if (VisualTreeHelper.GetClip(visual) != null)
{
GeneralTransform transform = textView.RenderScope.TransformToAncestor(visual).Inverse;
// Safer version of transform to descendent (doing the inverse ourself),
// we want the rect inside of our space. (Which is always rectangular and much nicer to work with)
if (transform != null)
{
Rect clipBounds = VisualTreeHelper.GetClip(visual).Bounds;
clipBounds = transform.TransformBounds(clipBounds);
boundingRect.Intersect(clipBounds);
}
else
{
// No visibility if non-invertable transform exists.
boundingRect = Rect.Empty;
}
}
visual = VisualTreeHelper.GetParent(visual) as Visual;
}
}
}
}
}
return boundingRect;
}
示例6: GetClippingRect
protected virtual Rect GetClippingRect(Size finalSize)
{
if (!this.isClippingRequired)
{
return Rect.Empty;
}
var max = new MinMax(this);
Size renderSize = this.RenderSize;
double maxWidth = double.IsPositiveInfinity(max.MaxWidth) ? renderSize.Width : max.MaxWidth;
double maxHeight = double.IsPositiveInfinity(max.MaxHeight) ? renderSize.Height : max.MaxHeight;
bool isClippingRequiredDueToMaxSize = maxWidth.IsLessThan(renderSize.Width) ||
maxHeight.IsLessThan(renderSize.Height);
renderSize.Width = Math.Min(renderSize.Width, max.MaxWidth);
renderSize.Height = Math.Min(renderSize.Height, max.MaxHeight);
Thickness margin = this.Margin;
double horizontalMargins = margin.Left + margin.Right;
double verticalMargins = margin.Top + margin.Bottom;
var clientSize = new Size(
(finalSize.Width - horizontalMargins).EnsurePositive(),
(finalSize.Height - verticalMargins).EnsurePositive());
bool isClippingRequiredDueToClientSize = clientSize.Width.IsLessThan(renderSize.Width) ||
clientSize.Height.IsLessThan(renderSize.Height);
if (isClippingRequiredDueToMaxSize && !isClippingRequiredDueToClientSize)
{
return new Rect(0d, 0d, maxWidth, maxHeight);
}
if (!isClippingRequiredDueToClientSize)
{
return Rect.Empty;
}
Vector offset = this.ComputeAlignmentOffset(clientSize, renderSize);
var clipRect = new Rect(-offset.X, -offset.Y, clientSize.Width, clientSize.Height);
if (isClippingRequiredDueToMaxSize)
{
clipRect.Intersect(new Rect(0d, 0d, maxWidth, maxHeight));
}
return clipRect;
}