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


C# Rectangle.Contains方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Rectangle.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.Contains方法的具体用法?C# Rectangle.Contains怎么用?C# Rectangle.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Rectangle的用法示例。


在下文中一共展示了Rectangle.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleEvent

        public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
        {
            var mousePressEvent = @event as MousePressEvent;
            if (mousePressEvent != null)
            {
                if (!layout.Contains(mousePressEvent.MouseState.X, mousePressEvent.MouseState.Y))
                {
                    return false;
                }

                State = LinkState.Clicked;

                Click?.Invoke(this, new EventArgs());

                return true;
            }

            var mouseReleaseEvent = @event as MouseReleaseEvent;
            if (mouseReleaseEvent != null)
            {
                if (!layout.Contains(mouseReleaseEvent.MouseState.X, mouseReleaseEvent.MouseState.Y))
                {
                    return false;
                }

                State = LinkState.None;
            }

            return false;
        }
开发者ID:RedpointGames,项目名称:Protogame,代码行数:30,代码来源:Link.cs

示例2: ContainsPoint

        public void ContainsPoint()
        {
            Rectangle rectangle = new Rectangle(0,0,64,64);

            var p1 = new Point(-1, -1);
            var p2 = new Point(0, 0);
            var p3 = new Point(32, 32);
            var p4 = new Point(63, 63);
            var p5 = new Point(64, 64);

            bool result;

            rectangle.Contains(ref p1, out result);
            Assert.AreEqual(false, result);
            rectangle.Contains(ref p2, out result);
            Assert.AreEqual(true, result);
            rectangle.Contains(ref p3, out result);
            Assert.AreEqual(true, result);
            rectangle.Contains(ref p4, out result);
            Assert.AreEqual(true, result);
            rectangle.Contains(ref p5, out result);
            Assert.AreEqual(false, result);

            Assert.AreEqual(false, rectangle.Contains(p1));
            Assert.AreEqual(true, rectangle.Contains(p2));
            Assert.AreEqual(true, rectangle.Contains(p3));
            Assert.AreEqual(true, rectangle.Contains(p4));
            Assert.AreEqual(false, rectangle.Contains(p5));
        }
开发者ID:BrainSlugs83,项目名称:MonoGame,代码行数:29,代码来源:RectangleTest.cs

示例3: LineIntersectsRect

 public static bool LineIntersectsRect(Point p1, Point p2, Rectangle r)
 {
     return LineIntersectsLine(p1, p2, new Point(r.X, r.Y), new Point(r.X + r.Width, r.Y)) ||
            LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y), new Point(r.X + r.Width, r.Y + r.Height)) ||
            LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y + r.Height), new Point(r.X, r.Y + r.Height)) ||
            LineIntersectsLine(p1, p2, new Point(r.X, r.Y + r.Height), new Point(r.X, r.Y)) ||
            (r.Contains(p1) && r.Contains(p2));
 }
开发者ID:KGabson,项目名称:testmono,代码行数:8,代码来源:InterLiRec.cs

示例4: LineIntersectsRect

 public bool LineIntersectsRect(Vector2 p1, Vector2 p2, Rectangle r)
 {
     return LineIntersectsLine(p1, p2, new Vector2(r.X, r.Y), new Vector2(r.X + r.Width, r.Y)) ||
            LineIntersectsLine(p1, p2, new Vector2(r.X + r.Width, r.Y), new Vector2(r.X + r.Width, r.Y + r.Height)) ||
            LineIntersectsLine(p1, p2, new Vector2(r.X + r.Width, r.Y + r.Height), new Vector2(r.X, r.Y + r.Height)) ||
            LineIntersectsLine(p1, p2, new Vector2(r.X, r.Y + r.Height), new Vector2(r.X, r.Y)) ||
            (r.Contains(p1) && r.Contains(p2));
 }
开发者ID:Caresilabs,项目名称:MAH_Artificial_Intelligence,代码行数:8,代码来源:Segment.cs

示例5: LineIntersectsRect

 //adapted from http://stackoverflow.com/questions/5514366/how-to-know-if-a-line-intersects-a-rectangle
 public static bool LineIntersectsRect(Vector2 p1, Vector2 p2, Rectangle r)
 {
     return LineIntersectsLine(p1, p2, new Vector2(r.X, r.Y), new Vector2(r.X + r.Width, r.Y)) ||
            LineIntersectsLine(p1, p2, new Vector2(r.X + r.Width, r.Y), new Vector2(r.X + r.Width, r.Y + r.Height)) ||
            LineIntersectsLine(p1, p2, new Vector2(r.X + r.Width, r.Y + r.Height), new Vector2(r.X, r.Y + r.Height)) ||
            LineIntersectsLine(p1, p2, new Vector2(r.X, r.Y + r.Height), new Vector2(r.X, r.Y)) ||
            (r.Contains(new Point((int)p1.X, (int)p1.Y)) && r.Contains(new Point((int)p2.X, (int)p2.Y)));
 }
开发者ID:Cesque,项目名称:NeonTactics,代码行数:9,代码来源:Globals.cs

示例6: HandleEvent

        public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
        {
            var mousePressEvent = @event as MousePressEvent;
            var touchPressEvent = @event as TouchPressEvent;

            if (mousePressEvent != null && mousePressEvent.Button == MouseButton.Left)
            {
                if (layout.Contains(mousePressEvent.MouseState.X, mousePressEvent.MouseState.Y))
                {
                    this.Focus();

                    return true;
                }
            }

            if (touchPressEvent != null)
            {
                if (layout.Contains((int)touchPressEvent.X, (int)touchPressEvent.Y))
                {
                    this.Focus();

#if PLATFORM_ANDROID
                    var manager = (InputMethodManager)Game.Activity.GetSystemService(Context.InputMethodService);
                    manager.ShowSoftInput(((Microsoft.Xna.Framework.AndroidGameWindow)context.Game.Window).GameViewAsView, ShowFlags.Forced);
#endif

                    return true;
                }
                else
                {
#if PLATFORM_ANDROID
                    var manager = (InputMethodManager)Game.Activity.GetSystemService(Context.InputMethodService);
                    manager.HideSoftInputFromWindow(((Microsoft.Xna.Framework.AndroidGameWindow)context.Game.Window).GameViewAsView.WindowToken, HideSoftInputFlags.None);
#endif
                }
            }

            var keyEvent = @event as KeyboardEvent;

            if (keyEvent != null)
            {
                var keyboard = keyEvent.KeyboardState;
                if (Focused)
                {
                    _keyboardReader.Process(keyboard, context.GameTime, _textBuilder);
                    if (_textBuilder.ToString() != _previousValue)
                    {
                        TextChanged?.Invoke(this, new EventArgs());
                    }

                    _previousValue = _textBuilder.ToString();

                    return true;
                }
            }

            return false;
        }
开发者ID:RedpointGames,项目名称:Protogame,代码行数:58,代码来源:TextBox.cs

示例7: LineIntersectsRect

 public static bool LineIntersectsRect(Vector2 pp1, Vector2 pp2, Rectangle r)
 {
     Point p1 = new Point((int)pp1.X, (int)pp1.Y);
     Point p2 = new Point((int)pp2.X, (int)pp2.Y);
     return LineIntersectsLine(p1, p2, new Point(r.X, r.Y), new Point(r.X + r.Width, r.Y)) ||
            LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y), new Point(r.X + r.Width, r.Y + r.Height)) ||
            LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y + r.Height), new Point(r.X, r.Y + r.Height)) ||
            LineIntersectsLine(p1, p2, new Point(r.X, r.Y + r.Height), new Point(r.X, r.Y)) ||
            (r.Contains(p1) && r.Contains(p2));
 }
开发者ID:XZelnar,项目名称:MicroWorld,代码行数:10,代码来源:MathHelper.cs

示例8: setCameraBounds

 public void setCameraBounds(Vector2 cameraXBounds, Vector2 cameraYBounds)
 {
     cameraRect = new Rectangle(-1 * (int)cameraXBounds.X, -1 * (int)cameraYBounds.X,
         -1 * ((int)cameraXBounds.Y - (int)cameraXBounds.X), -1 * ((int)cameraYBounds.Y - (int)cameraYBounds.X));
     Console.WriteLine(cameraRect + " CAMERARECT");
     Console.WriteLine(cameraRect.Contains(new Vector2(145, 320)));
 }
开发者ID:andrewbarry1,项目名称:8p4c,代码行数:7,代码来源:Camera.cs

示例9: Update

 public void Update(bool isMuteButton, GameTime gameTime)
 {
     MouseState mouse = Mouse.GetState();
     rectangle = new Rectangle((int)(position.X), (int)(position.Y), (int)(Size.X), (int)(Size.Y));
     Point mousePos = new Point(mouse.X, mouse.Y);
     if ((rectangle.Contains(mousePos) && mouse.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released)|| clickDetected)
     {
         clickDetected = true;
         if (normalTimer.CallTimer(gameTime) && !isMuteButton)
         {
             IsClicked = true;
             clickDetected = false;
         }
         else
         {
             if (isMuteButton && muteTimer.CallTimer(gameTime))
             {
                 IsClicked = true;
                 clickDetected = false;
             }
         }
     }
     else IsClicked = false;
     oldMouseState = mouse;
 }
开发者ID:TDRubikCube,项目名称:RubicCubeMain,代码行数:25,代码来源:Button.cs

示例10: ContainsPoint

 public bool ContainsPoint(Point _point)
 {
     Rectangle r = new Rectangle((int)position.X,(int)position.Y,sideLength,sideLength);
        if(r.Contains(_point))
        return true;
        return false;
 }
开发者ID:magmi,项目名称:GraphColoring,代码行数:7,代码来源:Flower.cs

示例11: AddToButtonGroup

        /// <summary>
        /// Checks to see if a button group's rectangle is big enough to contain the button and if not expands it
        /// </summary>
        /// <param name="lButtonGroupArea">The current rectangle of the button group</param>
        public void AddToButtonGroup(ref Rectangle lButtonGroupArea)
        {
            if (!lButtonGroupArea.Contains(mLocation))
            {
                {
                    int xDist = mLocation.X - lButtonGroupArea.X;
                    if (xDist < 0)
                    {
                        lButtonGroupArea.X = mLocation.X;
                        lButtonGroupArea.Width -= xDist;
                    }

                    xDist = mLocation.Right - lButtonGroupArea.Right;
                    if (xDist > 0)
                    {
                        lButtonGroupArea.Width += xDist;
                    }
                }
                {
                    int yDist = mLocation.Y - lButtonGroupArea.Y;
                    if (yDist < 0)
                    {
                        lButtonGroupArea.Y = mLocation.Y;
                        lButtonGroupArea.Height -= yDist;
                    }

                    yDist = mLocation.Bottom - lButtonGroupArea.Bottom;
                    if (yDist > 0)
                    {
                        lButtonGroupArea.Height += yDist;
                    }
                }
            }
        }
开发者ID:thk123,项目名称:XGT,代码行数:38,代码来源:PCButton.cs

示例12: CollisionWithMouse

        /// <summary>
        /// This is a collision detection algorithom that tracks collisions between
        /// the mouse and any arbitrary 2D sprite
        /// </summary>
        /// <param name="rect"> Rectangle the sprite is in.</param>
        /// <param name="state">The current mouse state</param>
        /// <returns>bool stating if a collision occured</returns>
        public static bool CollisionWithMouse(Rectangle rect, MouseState state)
        {
            if (!rect.Contains(state.X, state.Y))
                return false;

            return true;
        }
开发者ID:oh-team-machine,项目名称:Target-Tapping,代码行数:14,代码来源:Collisions.cs

示例13: IsNewMouseLeftButtonPressed

        /// <summary>
        /// 鼠标左键是否刚刚按下
        /// </summary>
        public bool IsNewMouseLeftButtonPressed(Rectangle rect)
        {
            if (!rect.Contains(CurrentMouseState.X, CurrentMouseState.Y)) return false;

            return (LastMouseState.LeftButton == ButtonState.Released)
                   && (CurrentMouseState.LeftButton == ButtonState.Pressed);
        }
开发者ID:xupefei,项目名称:EAGSS,代码行数:10,代码来源:InputState.cs

示例14: GetMouseLocationOffset

        /// <summary>
        /// 得到鼠标位置的变化量
        /// </summary>
        public Point GetMouseLocationOffset(Rectangle rect)
        {
            if (!rect.Contains(CurrentMouseState.X, CurrentMouseState.Y)) return new Point();

            return new Point(CurrentMouseState.X - LastMouseState.X,
                             CurrentMouseState.Y - LastMouseState.Y);
        }
开发者ID:xupefei,项目名称:EAGSS,代码行数:10,代码来源:InputState.cs

示例15: CollisionCheck

        public static CollisionResponse CollisionCheck(BoundingCircle c, Rectangle r) {
            CollisionResponse result = new CollisionResponse();

            Vector2 closestPoint = ClosestPointPointRectangle(c.center, r);
	
	        float distanceSquared = Vector2.DistanceSquared(closestPoint,c.center);
            bool contained = r.Contains(c.center);
	        if(distanceSquared < c.radius * c.radius || contained){
		        result.collided = true;
		        result.normal = c.center - closestPoint;
		        result.normal.Normalize();
                //Special case for a circle with center inside the rectangle
                if (contained)
                {
                    result.normal = -result.normal;
                    result.penetrationDepth = c.radius + (float)Math.Sqrt(distanceSquared);
                }
                else {
                    result.penetrationDepth = c.radius - (float)Math.Sqrt(distanceSquared);
                }
                    
	        } else {
		        result.collided = false;
	        }

            return result;
        }
开发者ID:alexdbaldwin,项目名称:AI_RTS_MonoGame,代码行数:27,代码来源:CollisionDetection.cs


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