本文整理汇总了C#中System.Drawing.RectangleF.IntersectsWith方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.RectangleF.IntersectsWith方法的具体用法?C# System.Drawing.RectangleF.IntersectsWith怎么用?C# System.Drawing.RectangleF.IntersectsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.RectangleF
的用法示例。
在下文中一共展示了System.Drawing.RectangleF.IntersectsWith方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsCross
/// <summary>
/// 获取编辑器对象的宽度
/// </summary>
/// <returns></returns>
//public float GetWidth()
//{
// return Math.Abs(this.Left - this.Right);
//}
///// <summary>
///// 获取编辑器对象的高度
///// </summary>
///// <returns></returns>
//public float GetHeight()
//{
// return Math.Abs(this.Top - this.Bottom);
//}
/// <summary>
/// 矩形区域与形参中的区域是否重叠交叉
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="right"></param>
/// <param name="bottom"></param>
/// <returns></returns>
public bool IsCross(float x,float y,float right,float bottom)
{
bool isCoross = false;
System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF(this.Left, this.Top, this.Width, this.Height);
System.Drawing.RectangleF destRect = new System.Drawing.RectangleF(x, y, right, bottom);
if (srcRect.IntersectsWith(destRect)) isCoross = true;
return isCoross;
}
示例2: update
public void update()
{
MouseState mouseState;
if (entitiesInSelection.Count > 0)
{
if (inputState.IsNewRightMouseClick(out mouseState))
{
if (Global.Viewport.Contains(mouseState.Position))
{
Vector2 pos = Global.Camera.ScreenToWorld(mouseState.Position.ToVector2());
//Bag<Entity> entities = entityWorld.EntityManager.GetEntities(Aspect.All(typeof(component.Goal), typeof(component.Physics), typeof(component.Formation)));
int2 goalPos = new int2((int)pos.X / Global.tileSize, (int)pos.Y / Global.tileSize);
Bag<Entity> bag = new Bag<Entity>();
PathGoal pathGoal = new PathGoal(entitiesInSelection, disFieldMixer, new int2(Global.mapWidth, Global.mapHeight), goalPos);
setPathGoal(pathGoal);
pathGoal.updatePath();
EntityFormation formation = new EntityFormation(entitiesInSelection, disFieldMixer, goalPos);
foreach (Entity e in entitiesInSelection)
{
e.GetComponent<component.Formation>().EntityFormation = formation;
}
formation.update();
}
}
}
if (Mouse.GetState().LeftButton == ButtonState.Pressed && !isSelecting)
{
isSelecting = true;
firstCorner = Global.Camera.ScreenToWorld(Mouse.GetState().Position.ToVector2());
foreach (Entity old in entitiesInSelection)
{
old.GetComponent<component.HealthComponent>().Visible = false;
}
entitiesInSelection.Clear();
}
else if (Mouse.GetState().LeftButton == ButtonState.Released && isSelecting)
{
isSelecting = false;
Vector2 secondCorner = Global.Camera.ScreenToWorld(Mouse.GetState().Position.ToVector2());
Vector2 topLeft = new Vector2(Math.Min(firstCorner.X, secondCorner.X), Math.Min(firstCorner.Y, secondCorner.Y));
Vector2 bottomRight = new Vector2(Math.Max(firstCorner.X, secondCorner.X), Math.Max(firstCorner.Y, secondCorner.Y));
RectangleF rect = new RectangleF(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y);
Console.WriteLine(rect.X / 32 + " - " + rect.Y / 32);
if (rect.Width > 0 && rect.Height > 0)
{
Bag<Entity> entities = entityWorld.EntityManager.GetEntities(Aspect.All(typeof(component.Physics), typeof(component.Formation), typeof(component.HealthComponent), typeof(component.Unit)));
foreach (Entity e in entities)
{
if (e.GetComponent<component.Unit>().Lord != lord)
continue;
component.Physics phys = e.GetComponent<component.Physics>();
Vector2 newPos = new Vector2(phys.Position.X * Global.tileSize, phys.Position.Y * Global.tileSize);
RectangleF entityRect = new RectangleF(newPos.X - 0.5f * 32f, newPos.Y - 0.5f * 32f, 1f * 32f, 1f * 32f);
if (rect.IntersectsWith(entityRect))
{
e.GetComponent<component.HealthComponent>().Visible = true;
entitiesInSelection.Add(e);
}
}
if (onSelectUnit != null)
onSelectUnit();
}
}
if (isSelecting)
{
Vector2 secondCorner = Global.Camera.ScreenToWorld(Mouse.GetState().Position.ToVector2());
Vector2 topLeft = new Vector2(Math.Min(firstCorner.X, secondCorner.X), Math.Min(firstCorner.Y, secondCorner.Y));
Vector2 bottomRight = new Vector2(Math.Max(firstCorner.X, secondCorner.X), Math.Max(firstCorner.Y, secondCorner.Y));
RectangleF rect = new RectangleF(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y);
foreach (Entity e in tempEntitiesInSelection)
{
e.GetComponent<component.HealthComponent>().Visible = false;
}
tempEntitiesInSelection.Clear();
if (rect.Width > 0 && rect.Height > 0)
{
Bag<Entity> entities = entityWorld.EntityManager.GetEntities(Aspect.All(typeof(component.Physics), typeof(component.Formation), typeof(component.HealthComponent)));
foreach (Entity e in entities)
{
component.Physics phys = e.GetComponent<component.Physics>();
Vector2 newPos = new Vector2(phys.Position.X * Global.tileSize, phys.Position.Y * Global.tileSize);
RectangleF entityRect = new RectangleF(newPos.X - 0.5f * 32f, newPos.Y - 0.5f * 32f, 1f * 32f, 1f * 32f);
if (rect.IntersectsWith(entityRect))
{
e.GetComponent<component.HealthComponent>().Visible = true;
tempEntitiesInSelection.Add(e);
}
}
}
//.........这里部分代码省略.........