本文整理汇总了C#中Rect.Union方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Union方法的具体用法?C# Rect.Union怎么用?C# Rect.Union使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rect
的用法示例。
在下文中一共展示了Rect.Union方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TransformBounds
public override Rect TransformBounds (Rect rect)
{
Point p1 = new Point (rect.Left, rect.Top);
Point p2 = new Point (rect.Right, rect.Top);
Point p3 = new Point (rect.Left, rect.Bottom);
Point p4 = new Point (rect.Right, rect.Bottom);
Rect r1 = new Rect (Transform (p1), Transform (p2));
Rect r2 = new Rect (Transform (p3), Transform (p4));
r1.Union (r2);
return r1;
}
示例2: COMException
void UnsafeNativeMethods.ITextStoreACP.GetTextExt(int viewCookie, int startIndex, int endIndex, out UnsafeNativeMethods.RECT rect, out bool clipped)
{
PresentationSource source;
IWin32Window win32Window;
CompositionTarget compositionTarget;
ITextView view;
ITextPointer startPointer;
ITextPointer endPointer;
GeneralTransform transform;
Point milPointTopLeft;
Point milPointBottomRight;
// We need to update the layout before getting rect. It could be dirty by SetText call of TIP.
_isInUpdateLayout = true;
UiScope.UpdateLayout();
_isInUpdateLayout = false;
// (Dev11 721274) if UpdateLayout caused a text change, startIndex
// and endIndex are no longer valid. Handling this correctly is quite
// difficult - Cicero assumes that the text can't change while it
// owns the lock. Instead, we artificially reset the char count (to
// keep VerifyTextStoreConsistency happy), and return TS_R_NOLAYOUT
// to the caller; this seems to be good enough (i.e. avoids crashes)
// in practice.
if (_hasTextChangedInUpdateLayout)
{
_netCharCount = this.TextContainer.IMECharCount;
throw new COMException(SR.Get(SRID.TextStore_TS_E_NOLAYOUT), UnsafeNativeMethods.TS_E_NOLAYOUT);
}
rect = new UnsafeNativeMethods.RECT();
clipped = false;
GetVisualInfo(out source, out win32Window, out view);
compositionTarget = source.CompositionTarget;
// We use local coordinates.
startPointer = CreatePointerAtCharOffset(startIndex, LogicalDirection.Forward);
startPointer.MoveToInsertionPosition(LogicalDirection.Forward);
if (!this.TextView.IsValid)
{
// We can not get the visual. Return TS_R_NOLAYOUT to the caller.
throw new COMException(SR.Get(SRID.TextStore_TS_E_NOLAYOUT), UnsafeNativeMethods.TS_E_NOLAYOUT);
}
if (startIndex == endIndex)
{
Rect rectStart = startPointer.GetCharacterRect(LogicalDirection.Forward);
milPointTopLeft = rectStart.TopLeft;
milPointBottomRight = rectStart.BottomRight;
}
else
{
Rect rectBound = new Rect(Size.Empty);
ITextPointer navigator = startPointer.CreatePointer();
endPointer = CreatePointerAtCharOffset(endIndex, LogicalDirection.Backward);
endPointer.MoveToInsertionPosition(LogicalDirection.Backward);
bool moved;
do
{
// Compute the textSegment bounds line by line.
TextSegment lineRange = this.TextView.GetLineRange(navigator);
ITextPointer end;
Rect lineRect;
// Skip any BlockUIContainer or any other content that is not treated as a line by TextView.
if (!lineRange.IsNull)
{
ITextPointer start = (lineRange.Start.CompareTo(startPointer) <= 0) ? startPointer : lineRange.Start;
end = (lineRange.End.CompareTo(endPointer) >= 0) ? endPointer : lineRange.End;
lineRect = GetLineBounds(start, end);
moved = (navigator.MoveToLineBoundary(1) != 0) ? true : false;
}
else
{
lineRect = navigator.GetCharacterRect(LogicalDirection.Forward);
moved = navigator.MoveToNextInsertionPosition(LogicalDirection.Forward);
end = navigator;
}
if (lineRect.IsEmpty == false)
{
rectBound.Union(lineRect);
}
if (end.CompareTo(endPointer) == 0)
{
break;
}
}
while (moved);
// Invariant.Assert(rectBound.IsEmpty == false);
milPointTopLeft = rectBound.TopLeft;
milPointBottomRight = rectBound.BottomRight;
}
//.........这里部分代码省略.........
示例3: BringPointIntoView
/// <summary>
/// Brings specified point into view.
/// </summary>
/// <param name="point">Point in the viewer's coordinate system.</param>
/// <returns>Whether operation is pending or not.</returns>
/// <remarks>
/// It is guaranteed that Point is not over any existing pages.
/// </remarks>
internal bool BringPointIntoView(Point point)
{
int index;
Rect[] pageRects;
Rect pageRect;
ReadOnlyCollection<DocumentPageView> pageViews = this.PageViews;
bool bringIntoViewPending = false;
if (pageViews.Count > 0)
{
// Calculate rectangles for all pages.
pageRects = new Rect[pageViews.Count];
for (index = 0; index < pageViews.Count; index++)
{
pageRect = new Rect(pageViews[index].RenderSize);
pageRect = pageViews[index].TransformToAncestor(this).TransformBounds(pageRect);
pageRects[index] = pageRect;
}
// Try to find exact hit
for (index = 0; index < pageRects.Length; index++)
{
if (pageRects[index].Contains(point))
{
break;
}
}
if (index >= pageRects.Length)
{
// Union all rects.
pageRect = pageRects[0];
for (index = 1; index < pageRects.Length; index++)
{
pageRect.Union(pageRects[index]);
}
//
if (DoubleUtil.LessThan(point.X, pageRect.Left))
{
if (this.CanGoToPreviousPage)
{
OnPreviousPageCommand();
bringIntoViewPending = true;
}
}
else if (DoubleUtil.GreaterThan(point.X, pageRect.Right))
{
if (this.CanGoToNextPage)
{
OnNextPageCommand();
bringIntoViewPending = true;
}
}
else if (DoubleUtil.LessThan(point.Y, pageRect.Top))
{
if (this.CanGoToPreviousPage)
{
OnPreviousPageCommand();
bringIntoViewPending = true;
}
}
else if (DoubleUtil.GreaterThan(point.Y, pageRect.Bottom))
{
if (this.CanGoToNextPage)
{
OnNextPageCommand();
bringIntoViewPending = true;
}
}
}
}
return bringIntoViewPending;
}
示例4: GetVisualInfo
void UnsafeNativeMethods.ITextStoreACP.GetTextExt(int viewCookie, int startIndex, int endIndex, out UnsafeNativeMethods.RECT rect, out bool clipped)
{
PresentationSource source;
IWin32Window win32Window;
CompositionTarget compositionTarget;
ITextView view;
ITextPointer startPointer;
ITextPointer endPointer;
GeneralTransform transform;
Point milPointTopLeft;
Point milPointBottomRight;
// We need to update the layout before getting rect. It could be dirty by SetText call of TIP.
UiScope.UpdateLayout();
rect = new UnsafeNativeMethods.RECT();
clipped = false;
GetVisualInfo(out source, out win32Window, out view);
compositionTarget = source.CompositionTarget;
// We use local coordinates.
startPointer = CreatePointerAtCharOffset(startIndex, LogicalDirection.Forward);
startPointer.MoveToInsertionPosition(LogicalDirection.Forward);
if (!this.TextView.IsValid)
{
// We can not get the visual. Return TS_R_NOLAYOUT to the caller.
throw new COMException(SR.Get(SRID.TextStore_TS_E_NOLAYOUT), UnsafeNativeMethods.TS_E_NOLAYOUT);
}
if (startIndex == endIndex)
{
Rect rectStart = startPointer.GetCharacterRect(LogicalDirection.Forward);
milPointTopLeft = rectStart.TopLeft;
milPointBottomRight = rectStart.BottomRight;
}
else
{
Rect rectBound = new Rect(Size.Empty);
ITextPointer navigator = startPointer.CreatePointer();
endPointer = CreatePointerAtCharOffset(endIndex, LogicalDirection.Backward);
endPointer.MoveToInsertionPosition(LogicalDirection.Backward);
bool moved;
do
{
// Compute the textSegment bounds line by line.
TextSegment lineRange = this.TextView.GetLineRange(navigator);
ITextPointer end;
Rect lineRect;
// Skip any BlockUIContainer or any other content that is not treated as a line by TextView.
if (!lineRange.IsNull)
{
ITextPointer start = (lineRange.Start.CompareTo(startPointer) <= 0) ? startPointer : lineRange.Start;
end = (lineRange.End.CompareTo(endPointer) >= 0) ? endPointer : lineRange.End;
lineRect = GetLineBounds(start, end);
moved = (navigator.MoveToLineBoundary(1) != 0) ? true : false;
}
else
{
lineRect = navigator.GetCharacterRect(LogicalDirection.Forward);
moved = navigator.MoveToNextInsertionPosition(LogicalDirection.Forward);
end = navigator;
}
if (lineRect.IsEmpty == false)
{
rectBound.Union(lineRect);
}
if (end.CompareTo(endPointer) == 0)
{
break;
}
}
while (moved);
// Invariant.Assert(rectBound.IsEmpty == false);
milPointTopLeft = rectBound.TopLeft;
milPointBottomRight = rectBound.BottomRight;
}
// Transform to root visual coordinates.
transform = UiScope.TransformToAncestor(compositionTarget.RootVisual);
//
transform.TryTransform(milPointTopLeft, out milPointTopLeft);
transform.TryTransform(milPointBottomRight, out milPointBottomRight);
rect = TransformRootRectToScreenCoordinates(milPointTopLeft, milPointBottomRight, win32Window, source);
}
示例5: ArrangeOverride
/// <summary>
/// Arranges the content of a <see cref="ZoomableCanvas"/> element.
/// </summary>
/// <param name="finalSize">The size that this <see cref="ZoomableCanvas"/> element should use to arrange its child elements.</param>
/// <returns>A <see cref="Size"/> that represents the arranged size of this <see cref="ZoomableCanvas"/> element and its descendants.</returns>
protected override Size ArrangeOverride(Size finalSize)
{
bool applyTransform = ApplyTransform;
Point offset = applyTransform ? new Point() : Offset;
double scale = applyTransform ? 1.0 : Scale;
ChildrenExtent = Rect.Empty;
foreach (UIElement child in InternalChildren)
{
if (child != null)
{
// Get bounds information from the element.
Rect bounds = new Rect(Canvas.GetLeft(child).GetValueOrDefault(), Canvas.GetTop(child).GetValueOrDefault(), child.DesiredSize.Width / scale, child.DesiredSize.Height / scale);
// If we are maintaining our own spatial wrapper then update its bounds.
if (PrivateIndex != null)
{
int index = IndexFromContainer(child);
Rect oldBounds = PrivateIndex[index];
const double tolerance = .001; // The exact values during arrange can vary slightly.
if (Math.Abs(oldBounds.Top - bounds.Top) > tolerance ||
Math.Abs(oldBounds.Left - bounds.Left) > tolerance ||
Math.Abs(oldBounds.Width - bounds.Width) > tolerance ||
Math.Abs(oldBounds.Height - bounds.Height) > tolerance)
{
PrivateIndex[index] = bounds;
}
}
// Update the children extent for scrolling.
ChildrenExtent.Union(bounds);
// So far everything has been in canvas coordinates. Here we adjust the result for the final call to Arrange.
bounds.X *= scale;
bounds.X -= offset.X;
bounds.Y *= scale;
bounds.Y -= offset.Y;
bounds.Width *= scale;
bounds.Height *= scale;
// WPF Arrange will crash if the values are too large.
bounds.X = bounds.X.AtLeast(Single.MinValue / 2);
bounds.Y = bounds.Y.AtLeast(Single.MinValue / 2);
bounds.Width = bounds.Width.AtMost(Single.MaxValue);
bounds.Height = bounds.Height.AtMost(Single.MaxValue);
child.Arrange(bounds);
}
}
InvalidateExtent();
return finalSize;
}
示例6: UnionTest2
public void UnionTest2()
{
double minValue = -100000;
double maxValue = 100000;
Action test = () => {
var rect1 = new Rect (TestHelper.NextDouble(minValue),
TestHelper.NextDouble(minValue),
TestHelper.NextDouble(maxValue),
TestHelper.NextDouble(maxValue));
var rect2 = new Rect (TestHelper.NextDouble(minValue),
TestHelper.NextDouble(minValue),
TestHelper.NextDouble(maxValue),
TestHelper.NextDouble(maxValue));
var rect3 = rect1.Union (rect2);
TestHelper.AlmostEqual(rect3.X,Math.Min(rect1.X,rect2.X));
TestHelper.AlmostEqual(rect3.Y,Math.Min(rect1.Y,rect2.Y));
TestHelper.AlmostEqual(rect3.Right,Math.Max(rect1.Right,rect2.Right));
TestHelper.AlmostEqual(rect3.Bottom,Math.Max(rect1.Bottom,rect2.Bottom));
Assert.LessOrEqual (rect3.Left,rect1.Left + 1e-5);
Assert.GreaterOrEqual (rect3.Right + 1e-5,rect1.Right);
Assert.LessOrEqual (rect3.Top,rect1.Top + 1e-5);
Assert.GreaterOrEqual (rect3.Bottom + 1e-5,rect1.Bottom);
Assert.LessOrEqual (rect3.Left,rect2.Left + 1e-5);
Assert.GreaterOrEqual (rect3.Right + 1e-5,rect2.Right);
Assert.LessOrEqual (rect3.Top,rect2.Top + 1e-5);
Assert.GreaterOrEqual (rect3.Bottom + 1e-5,rect2.Bottom);
};
test.RunBatch (batchCount);
}
示例7: UnionTest1
public void UnionTest1()
{
var rect1 = new Rect (0, 0, 100, 100);
var rect2 = new Rect (50, 50, 100, 100);
var rect3 = rect1.Union (rect2);
Assert.AreEqual (0, rect3.X);
Assert.AreEqual (0, rect3.Y);
Assert.AreEqual (150, rect3.Width);
Assert.AreEqual (150, rect3.Height);
}