当前位置: 首页>>代码示例>>C#>>正文


C# System.Drawing.RectangleF.IntersectsWith方法代码示例

本文整理汇总了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;
        }
开发者ID:yuzhantao,项目名称:ColorEditor,代码行数:36,代码来源:EditorObjectRectangle.cs

示例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);
                        }
                    }
                }
//.........这里部分代码省略.........
开发者ID:CheeseSoftware,项目名称:RTS-test,代码行数:101,代码来源:UnitController.cs


注:本文中的System.Drawing.RectangleF.IntersectsWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。