本文整理汇总了C#中System.Drawing.RectangleF.IntersectsWith方法的典型用法代码示例。如果您正苦于以下问题:C# RectangleF.IntersectsWith方法的具体用法?C# RectangleF.IntersectsWith怎么用?C# RectangleF.IntersectsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.RectangleF
的用法示例。
在下文中一共展示了RectangleF.IntersectsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoesLineIntersectRectangle
public static bool DoesLineIntersectRectangle(RectangleF pobjRectangle, Line pobjLine, ref Line pobjIntersectingPortionOfLine)
{
RectangleF objLineAsRectangle = default(RectangleF);
objLineAsRectangle = pobjLine.ToRectangle();
if (!pobjRectangle.IntersectsWith(objLineAsRectangle))
{
return false;
}
else
{
bool blnIsPointAIn = false;
bool blnIsPointBIn = false;
blnIsPointAIn = pobjRectangle.Contains(pobjLine.PointA);
blnIsPointBIn = pobjRectangle.Contains(pobjLine.PointB);
if (blnIsPointAIn && blnIsPointBIn)
{
pobjIntersectingPortionOfLine = pobjLine;
}
else
{
PointF[] colIntersections = new PointF[2];
// Either one or two intersections.
List<Line> colLines = null;
colLines = GeometryHelper.RectangleTo4Lines(pobjRectangle);
foreach (Line objLine in colLines)
{
if (colIntersections[0].IsEmpty)
{
DoLinesIntersect(objLine, pobjLine, ref colIntersections[0]);
}
else if (colIntersections[1].IsEmpty)
{
DoLinesIntersect(objLine, pobjLine, ref colIntersections[1]);
}
}
if (!blnIsPointAIn && !blnIsPointBIn)
{
pobjIntersectingPortionOfLine = new Line(colIntersections[0], colIntersections[1]);
}
else
{
if (blnIsPointAIn)
{
pobjIntersectingPortionOfLine = new Line(colIntersections[0], pobjLine.PointA);
}
else
{
pobjIntersectingPortionOfLine = new Line(colIntersections[0], pobjLine.PointB);
}
}
}
return true;
}
}
示例2: IsSelected
/// <summary>
/// Check if a given rectangle would be selected by another rectangle.
/// By default, checks whether the selection rectangle intersects with the bounding rectangle.
/// If Alt is pressed, the selection rectangle has to contain the complete bounding rectangle.
/// </summary>
/// <param name="selectionRectangle">The rectangle that represents the selection.</param>
/// <param name="boundingRectangle">The rectangle that should be tested whether it is selected.</param>
/// <param name="modifierKeys">The modifier keys that are currently pressed.</param>
/// <returns>
/// <see langword="true" /> if the rectangle is selected; <see langword="false" /> otherwise.
/// </returns>
public static bool IsSelected( RectangleF selectionRectangle, RectangleF boundingRectangle, Keys modifierKeys )
{
if( ( modifierKeys & Keys.Alt ) != 0 ) {
return selectionRectangle.Contains( boundingRectangle );
} else {
return selectionRectangle.IntersectsWith( boundingRectangle );
}
}
示例3: Collision
private static bool Collision(Position bullet, Position enemy)
{
if (bullet == null || enemy == null) return false;
var bulletBounding = new RectangleF(new PointF(bullet.X, bullet.Y), new SizeF(1.5f, 1.5f));
var enemyBounding = new RectangleF(new PointF(enemy.X - 32, enemy.Y - 32), new SizeF(64, 64));
return bulletBounding.IntersectsWith(enemyBounding);
}
示例4: OnMouseClick
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
var mouseRect = new RectangleF(e.X, e.Y, 1, 1);
if (mouseRect.IntersectsWith(ButtonPlusRect))
{
OnPlusButtonClick(e);
}
}
示例5: RefreshTooFarAway
private void RefreshTooFarAway(View view,ref RectangleF windowFrame,bool forceRender = false)
{
if (forceRender)
{
//TooFarAway = false;
return;
}
Vector2 position = ((PositionTopLeft + (CenterOfMass / (View.MaxTextureSize/View.MaxTextureSize)) - Velocity));
RectangleF renderFrame = new RectangleF(
(position.X - ((Width / 2) / view.Zoom)), (position.Y - ((Height / 2) / view.Zoom)),
(Width / view.Zoom), (Height / view.Zoom));
if (windowFrame.IntersectsWith(renderFrame))
{
TooFarAway = false;
}
else
{
TooFarAway = true;
}
}
示例6: DrawSegments
void DrawSegments(Graphics grfx, RectangleF rectClip)
{
int penWidth = 3;
if (LicenseManager.UsageMode == LicenseUsageMode.Runtime)
{
//рисование границ кубов
if (PresentationController.Instance != null && PresentationController.Instance.CurrentSlideLayout != null)
{
ISegmentationSupport disp = PresentationController.Instance.CurrentSlideLayout.Display as ISegmentationSupport;
if (disp != null)
{
float x = 0;
float y = 0;
List<RectangleF> rects = new List<RectangleF>();
for (int i = 0; i < disp.SegmentColumns; ++i)
{
for (int j = 0; j < disp.SegmentRows; j++)
{
RectangleF rect = new RectangleF(x, y, disp.SegmentWidth, disp.SegmentHeight);
if (rect.IntersectsWith(rectClip))
rects.Add(rect);
y += disp.SegmentHeight + penWidth + 1;
}
x += disp.SegmentWidth + penWidth + 1;
y = 0;
}
if (rects.Count > 0)
{
Pen p = new Pen(new SolidBrush(Color.FromArgb(180, Color.Indigo)), penWidth);
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
grfx.DrawRectangles(p, rects.ToArray());
}
}
}
}
}
示例7: FwInvertRect
/// -----------------------------------------------------------------------------------
/// <summary>Member FwInvertRect</summary>
/// <param name='xLeft'>xLeft</param>
/// <param name='yTop'>yTop</param>
/// <param name='xRight'>xRight</param>
/// <param name='yBottom'>yBottom</param>
/// -----------------------------------------------------------------------------------
public void FwInvertRect(int xLeft, int yTop, int xRight, int yBottom)
{
Debug.Assert(m_bitmapGraphics != null);
RectangleF rc = new RectangleF(xLeft, yTop, xRight - xLeft,
yBottom - yTop);
if (!rc.IntersectsWith(m_bitmapGraphics.VisibleClipBounds))
return;
rc.Intersect(m_bitmapGraphics.VisibleClipBounds);
//RectangleF rect = new RectangleF(xLeft, yTop, xRight - xLeft + 1, yBottom - yTop + 1);
//rect.Intersect(m_bitmapGraphics.VisibleClipBounds);
//Rectangle rc = new Rectangle(
// m_parent.PointToScreen(new Point((int)rect.X, (int)rect.Y)),
// new Size((int)rect.Width, (int)rect.Height));
//ControlPaint.FillReversibleRectangle(rc, m_backColor);
m_backColor = Color.FromArgb(150, SystemColors.Highlight);
m_bitmapGraphics.FillRectangle(new SolidBrush(m_backColor), rc);
}
示例8: GetModuloRect
// PointF drawSpiralPoint (double scale, double revolutions, int centreX, int centreY, object st, int width, int heigh)
// {
// throw new NotImplementedException ();
// }
public static RectangleF GetModuloRect(RectangleF currentRect, RectangleF outer, int ic)
{
// const double scale = 0.01;
// //const double delta = 1;
// const int degreesPerIteration = 30;
// double revolutions = iterationCount * degreesPerIteration;
// int centreX = (int)center.X;
// int centreY = (int)center.Y;
//
// int width = (int)frameSize.Width;
// int heigh = (int)frameSize.Height;
//
// return drawSpiralPoint (scale, revolutions, centreX, centreY, st, width, heigh);
PointF center = IndexerUtils.findcenter (outer);
// int direction = ic % 4;
//
// if (direction == 0) { // NEGATIVE NEGATIVE
// currentRect = new RectangleF (center.X - ic, center.Y - ic, currentRect.Width, currentRect.Height);
// if(outer.IntersectsWith(currentRect)){
// return currentRect;
// }
// }
//
// if (direction == 1) { // POSITIVE POSITIVE
// currentRect = new RectangleF (center.X + ic, center.X + ic, currentRect.Width, currentRect.Height);
// if(outer.IntersectsWith(currentRect)){
// return currentRect;
// }
// }
//
// if (direction == 2) { // POSITIVE NEGATIVE
// currentRect = new RectangleF (center.X + ic, center.X - ic, currentRect.Width, currentRect.Height);
// if(outer.IntersectsWith(currentRect)){
// return currentRect;
// }
// }
//
// if (direction == 3) { // NEGATIVE POSTIVE
// currentRect = new RectangleF (center.X - ic, center.X + ic, currentRect.Width, currentRect.Height);
// if(outer.IntersectsWith(currentRect)){
// return currentRect;
// }
// }
// if (direction == 0) { // NEGATIVE NEGATIVE
currentRect = new RectangleF (center.X - ic, center.Y - ic, currentRect.Width, currentRect.Height);
if(outer.IntersectsWith(currentRect)){
return currentRect;
}
// }
// if (direction == 1) { // POSITIVE POSITIVE
currentRect = new RectangleF (center.X + ic, center.X + ic, currentRect.Width, currentRect.Height);
if(outer.IntersectsWith(currentRect)){
return currentRect;
}
// }
// if (direction == 2) { // POSITIVE NEGATIVE
currentRect = new RectangleF (center.X + ic, center.X - ic, currentRect.Width, currentRect.Height);
if(outer.IntersectsWith(currentRect)){
return currentRect;
}
// }
// if (direction == 3) { // NEGATIVE POSTIVE
currentRect = new RectangleF (center.X - ic, center.X + ic, currentRect.Width, currentRect.Height);
if(outer.IntersectsWith(currentRect)){
return currentRect;
}
// }
return GetModuloRect (currentRect, outer, ++ic);
}
示例9: Draw
public override void Draw(GraphicsWrapper g, PointF? mousePosition, RectangleF clippingRectangle, RectangleF drawingSpace)
{
if (Visible == false)
{
return;
}
if (_controlPoints.Count < 1)
{
return;
}
PointF point1 = _controlPoints[0];
PointF point2;
if (_controlPoints.Count < 2)
{
point2 = mousePosition.Value;
}
else
{
point2 = _controlPoints[1];
}
// Clipping opitmization.
RectangleF rectangle = new RectangleF(
Math.Min(point1.X, point2.X), Math.Min(point1.Y, point2.Y),
Math.Abs(point2.X - point1.X), Math.Abs(point2.Y - point1.Y));
if (rectangle.IntersectsWith(clippingRectangle) == false)
{
return;
}
// Draw base line.
g.DrawLine(_dashedLinePen, point1, point2);
float baseLevel = point1.Y;
float height = point2.Y - point1.Y;
// Draw fibbonacci levels.
float[] levels = new float[] { 0, 23.6f, 38.2f, 50, 61.8f, 100 };
for (int i = 0; i < levels.Length; i++)
{
float actualLevel = baseLevel + height * levels[i] / 100f;
g.DrawLine(_solidLinePen, point1.X, actualLevel, point2.X, actualLevel);
g.DrawString(levels[i].ToString(), DefaultDynamicObjectFont, Brushes.White, point1.X, actualLevel);
}
if (Selected)
{
DrawControlPoints(g);
}
}
示例10: Scrolled
void Scrolled(object sender, EventArgs args)
{
if (UICardPlace.Decelerating)
GetCenteredBlock ();
var proposedContentOffset = UICardPlace.ContentOffset;
float horizontalCenter = (float)(proposedContentOffset.X + (UICardPlace.Bounds.Size.Width / 2.0));
RectangleF pointer = new RectangleF (horizontalCenter, 10, 10, 10);
var matched = _words.FirstOrDefault(x=>pointer.IntersectsWith (x.Frame));
if (matched!=null) {
switch (matched.Status) {
case 3:
View.BackgroundColor = UIColor.Red;
break;
case 1:
View.BackgroundColor = UIColor.Green;
break;
case 2:
View.BackgroundColor = UIColor.Yellow;
break;
default:
View.BackgroundColor = UIColor.Gray;
break;
}
}
}
示例11: DoPrintPage
//.........这里部分代码省略.........
PageMargins.Left - nXDelta,
PageMargins.Top - nYDelta,
e.PageBounds.Width - PageMargins.Left - PageMargins.Right,
e.PageBounds.Height - PageMargins.Top - PageMargins.Bottom);
#endif
e.Graphics.DrawRectangle(pen,
(float)PageMargins.Left - nXDelta,
(float)PageMargins.Top - nYDelta,
(float)nPageWidth - (float)PageMargins.Left - (float)PageMargins.Right,
(float)nPageHeight - (float)PageMargins.Top - (float)PageMargins.Bottom);
}
}
bool bEOF = false;
float y = (float)PageMargins.Top;
// 每一行的循环
for (int i = 0; i < nYCount; i++)
{
bool bDisplay = true;
if (this.IsDesignMode == true)
{
RectangleF rectLine = new RectangleF(
(float)0 - nXDelta,
(float)y - nYDelta,
(float)label_param.LabelWidth * nXCount,
(float)label_param.LabelHeight);
if (rectLine.Top > e.Graphics.ClipBounds.Bottom)
{
// Debug.WriteLine("break line loop at " + i.ToString());
break; // 当前行在剪裁区域的下方,可以中断循环了
}
if (rectLine.IntersectsWith(e.Graphics.ClipBounds) == false)
{
// Debug.WriteLine("skip line " + i.ToString());
bDisplay = false;
}
}
float x = (float)PageMargins.Left;
// 每一列的循环
for (int j = 0; j < nXCount; j++)
{
List<string> lines = null;
nRet = this.GetLabelLines(out lines,
out strError);
if (nRet == -1)
goto ERROR1;
if (nRet == 1)
bEOF = true;
if (bOutput == true && bDisplay == true)
{
// 标签
RectangleF rectLabel = new RectangleF(
(float)x - nXDelta,
(float)y - nYDelta,
(float)label_param.LabelWidth,
(float)label_param.LabelHeight);
if (rectLabel.Left > e.Graphics.ClipBounds.Right)
{
// Debug.WriteLine("break label loop at i=" + i.ToString() + " j=" + j.ToString());
// 当前标签在剪裁区域的右方,可以不要显示后面的标签了
bDisplay = false;
示例12: Ruler_DrawVert
private void Ruler_DrawVert(Graphics g)
{
StringFormat df = null;
Font f = null;
SolidBrush sb = null; // brush for non-ruler portions of ruler
SolidBrush bb = null; // brush for drawing the areas next to band separator
try
{
g.PageUnit = GraphicsUnit.Point;
// create some drawing resources
df = new StringFormat();
df.FormatFlags |= StringFormatFlags.NoWrap;
df.Alignment = StringAlignment.Near;
f = new Font("Arial", 8, FontStyle.Regular);
sb = new SolidBrush(GAPCOLOR);
bb = new SolidBrush(Design.SepColor);
// Go thru the regions
float sp = Design.PointsY(this.ScrollPosition);
// 1) Offset
RectangleF rf;
float off = 0;
float offset = Design.PointsY(this.Offset);
float width = Design.PointsX(this.Width);
if (this.Offset > 0)
{
rf = new RectangleF(0, 0, width, offset); // scrolling doesn't affect offset
if (rf.IntersectsWith(g.ClipBounds))
{
LinearGradientBrush lgb = new LinearGradientBrush(rf, BEGINCOLOR, ENDCOLOR, LinearGradientMode.ForwardDiagonal);
g.FillRectangle(lgb, rf);
lgb.Dispose();
lgb = null;
// g.FillRectangle(sb, rf);
}
off = offset;
}
// 2) PageHeader
if (Design.PageHeaderHeight > 0)
{
Ruler_DrawVertPart(g, f, df, off, Design.PageHeaderHeight);
off += Design.PageHeaderHeight;
}
// 3) PageHeader separator
rf = new RectangleF(0, off-sp, width, Design.SepHeight);
if (rf.IntersectsWith(g.ClipBounds))
g.FillRectangle(bb, rf);
off += Design.SepHeight;
// 4) Body
if (Design.BodyHeight > 0)
{
Ruler_DrawVertPart(g, f, df, off, Design.BodyHeight);
off += Design.BodyHeight;
}
// 5) Body separator
rf = new RectangleF(0, off - sp, width, Design.SepHeight);
if (rf.IntersectsWith(g.ClipBounds))
g.FillRectangle(bb, rf);
off += Design.SepHeight;
// 6) PageFooter
if (Design.PageFooterHeight > 0)
{
Ruler_DrawVertPart(g, f, df, off, Design.PageFooterHeight);
off += Design.PageFooterHeight;
}
// 7) PageFooter separator
rf = new RectangleF(0, off - sp, width, Design.SepHeight);
if (rf.IntersectsWith(g.ClipBounds))
g.FillRectangle(bb, rf);
off += Design.SepHeight;
// 8) The rest to end
rf = new RectangleF(0, off - sp, width, Design.PointsY(this.Height) - (off - sp));
if (rf.IntersectsWith(g.ClipBounds))
g.FillRectangle(sb, rf);
}
finally
{
if (df != null)
df.Dispose();
if (f != null)
f.Dispose();
if (sb != null)
sb.Dispose();
if (bb != null)
bb.Dispose();
}
}
示例13: Ruler_DrawHorz
private void Ruler_DrawHorz(Graphics g)
{
float xoff, yoff, xinc;
StringFormat drawFormat=null;
Font f = null;
LinearGradientBrush lgb=null;
try
{
drawFormat = new StringFormat();
drawFormat.FormatFlags |= StringFormatFlags.NoWrap;
drawFormat.Alignment = StringAlignment.Near;
float mod;
yoff = this.Height/2 -2;
mod = g.DpiX;
if (_IsMetric)
mod = mod / 2.54f;
xinc = mod / _Intervals;
float scroll = ScrollPosition;
if (scroll == 0)
xoff = 0;
else
xoff = scroll + (xinc - scroll % xinc);
RectangleF rf;
if (Offset > 0) // Fill in the left gap; if any
{
rf = new RectangleF(0, 0, Offset, this.Height);
if (rf.IntersectsWith(g.ClipBounds))
{
lgb = new LinearGradientBrush(rf, BEGINCOLOR, ENDCOLOR, LinearGradientMode.ForwardDiagonal);
g.FillRectangle(lgb, rf);
lgb.Dispose();
lgb = null;
// g.FillRectangle(new SolidBrush(GAPCOLOR), rf);
}
}
// Fill in the background for the entire ruler
rf = new RectangleF(this.Offset, 0, this.Width, this.Height);
if (rf.IntersectsWith(g.ClipBounds))
{
lgb = new LinearGradientBrush(rf, BEGINCOLOR, ENDCOLOR, LinearGradientMode.Vertical);
g.FillRectangle(lgb, rf);
lgb.Dispose();
lgb = null;
}
else // nothing to draw
return;
f = new Font("Arial", 8, FontStyle.Regular);
// Loop thru and draw the ruler
while (xoff - scroll < this.Width-Offset)
{
// if (xoff % mod < .001f )
if (xoff % mod < .1f || Math.Abs((xoff % mod) - mod) < .1f)
{
if (xoff != 0) // Don't draw the zero
{
string l = string.Format("{0:0}", xoff / mod);
SizeF sz = g.MeasureString(l, f);
g.DrawString(l, f, Brushes.Black,
Offset + xoff - (sz.Width / 2) - scroll, yoff - (sz.Height / 2), drawFormat);
}
g.DrawLine(Pens.Black, Offset + xoff - scroll, this.Height, Offset + xoff - scroll, this.Height - 2);
}
else
{
g.DrawLine(Pens.Black, Offset + xoff - scroll, yoff, Offset + xoff - scroll, yoff + 2);
}
xoff += xinc;
}
}
finally
{
if (lgb != null)
lgb.Dispose();
if (drawFormat != null)
drawFormat.Dispose();
if (f != null)
f.Dispose();
}
}
示例14: Pick
/// <summary>
/// Finds hits on a marker, given a picking rectangle</summary>
/// <param name="marker">Marker</param>
/// <param name="bounds">Bounding rectangle, computed during layout phase</param>
/// <param name="pickRect">Picking rectangle</param>
/// <param name="c">Drawing context</param>
/// <returns>Type of hit</returns>
protected virtual HitType Pick(IMarker marker, RectangleF bounds, RectangleF pickRect, Context c)
{
return bounds.IntersectsWith(pickRect) ? HitType.Marker : HitType.None;
}
示例15: DrawAlignerAreas
private void DrawAlignerAreas(Graphics g, RectangleF screen)
{
foreach (var area in _areaAlignerWrapper)
{
var areaRect = new RectangleF(area.Area.Location.X, area.Area.Location.Y, area.Area.Width, area.Area.Height);
if (areaRect.IntersectsWith(screen))
{
using(Pen p = new Pen(Color.Red))
{
g.DrawRectangle(p, (int)(areaRect.X - screen.X) * Scaler.ScaleFactor,
(int)(areaRect.Y - screen.Y) * Scaler.ScaleFactor,
areaRect.Width * Scaler.ScaleFactor, areaRect.Height * Scaler.ScaleFactor);
}
}
}
DrawPoints(g, screen, _areaAlignerWrapper.Where(x => x.SelectedPoint != null).Select(x => x.SelectedPoint.Location));
}