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


C# RectangleF.Contains方法代码示例

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


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

示例1: TestContainsWithPoint

        public void TestContainsWithPoint()
        {
            RectangleF testRectangle = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f);

            Vector2 insidePoint = new Vector2(3.4f, 5.6f);
            Assert.IsTrue(testRectangle.Contains(insidePoint));

            Vector2 outsidePoint = Vector2.Zero;
            Assert.IsFalse(testRectangle.Contains(outsidePoint));

            Vector2 upperLeftBorderPoint = new Vector2(testRectangle.X, testRectangle.Y);
            Assert.IsTrue(testRectangle.Contains(upperLeftBorderPoint));

            Vector2 lowerRightBorderPoint = new Vector2(testRectangle.Right, testRectangle.Bottom);
            Assert.IsFalse(testRectangle.Contains(lowerRightBorderPoint));
        }
开发者ID:GeekyMonkey,项目名称:ScratchyXNA,代码行数:16,代码来源:RectangleFTests.cs

示例2: TestContainsWithPointReference

        public void TestContainsWithPointReference()
        {
            RectangleF testRectangle = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f);
            bool result;

            Vector2 insidePoint = new Vector2(3.4f, 5.6f);
            testRectangle.Contains(ref insidePoint, out result);
            Assert.IsTrue(result);

            Vector2 outsidePoint = Vector2.Zero;
            testRectangle.Contains(ref outsidePoint, out result);
            Assert.IsFalse(result);

            Vector2 upperLeftBorderPoint = new Vector2(testRectangle.X, testRectangle.Y);
            testRectangle.Contains(ref upperLeftBorderPoint, out result);
            Assert.IsTrue(result);

            Vector2 lowerRightBorderPoint = new Vector2(testRectangle.Right, testRectangle.Bottom);
            testRectangle.Contains(ref lowerRightBorderPoint, out result);
            Assert.IsFalse(result);
        }
开发者ID:GeekyMonkey,项目名称:ScratchyXNA,代码行数:21,代码来源:RectangleFTests.cs

示例3: HandleGesture

        public void HandleGesture(GestureSample gesture, BaseControl control)
        {
            var r = new RectangleF(control.Position, control.Size);
            if (r.Contains(gesture.Position))
            {
                switch (gesture.GestureType)
                {
                    case GestureType.Tap:
                        control.Trigger();
                        break;

                    case GestureType.DoubleTap:
                        control.Trigger();
                        break;
                }

                for (int i = 0; i < control.Children.Count; ++i)
                    HandleGesture(gesture, control.Children[i]);
            }
        }
开发者ID:quandtm,项目名称:XNInterface,代码行数:20,代码来源:WP7Touch.cs

示例4: HandleMouseControl

        protected void HandleMouseControl(MouseState current, BaseControl control)
        {
            var r = new RectangleF(control.Position, control.Size);
            if (r.Contains(current.X, current.Y))
            {
                if (IsJustPressed(_prevState.LeftButton, current.LeftButton))
                {
                    if (LeftDown != null)
                        LeftDown(control);
                }
                else if (IsJustReleased(_prevState.LeftButton, current.LeftButton))
                {
                    if (LeftUp != null)
                        LeftUp(control);
                    control.Trigger();
                }

                for (int i = 0; i < control.Children.Count; i++)
                    HandleMouseControl(current, control.Children[i]);
            }
        }
开发者ID:quandtm,项目名称:XNInterface,代码行数:21,代码来源:MouseInput.cs

示例5: ContainsTest

        public void ContainsTest(float x, float y, float width, float height)
        {
            RectangleF rect = new RectangleF(x, y, width, height);
            float X = (x + width) / 2;
            float Y = (y + height) / 2;
            PointF p = new PointF(X, Y);
            RectangleF r = new RectangleF(X, Y, width / 2, height / 2);

            Assert.False(rect.Contains(X, Y));
            Assert.False(rect.Contains(p));
            Assert.False(rect.Contains(r));
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:12,代码来源:RectangleFTests.cs

示例6: HandleMouseMove

        private void HandleMouseMove(MouseMessage msg)
        {
            var fact = VisibleSize / TotalSize;
            var scrollStart = (mScrollOffset / TotalSize) * Size;
            var knobRect = new RectangleF(Position.X + (Vertical ? 0 : scrollStart),
                Position.Y + (Vertical ? scrollStart : 0), Vertical ? Thickness : (Size * fact),
                Vertical ? (Size * fact) : Thickness);

            mIsKnobHovered = knobRect.Contains(msg.Position);

            if (mIsKnobDown == false)
                return;

            var knoby = msg.Position.Y - mKnobOffset.Y - Position.Y;
            if (knoby < 0)
                knoby = 0;

            scrollStart = knoby;
            scrollStart /= Size;
            scrollStart *= TotalSize;
            mScrollOffset = scrollStart;
            if (mScrollOffset + VisibleSize > TotalSize)
                mScrollOffset = TotalSize - VisibleSize;

            if (ScrollChanged != null)
                ScrollChanged(mScrollOffset);
        }
开发者ID:Linrasis,项目名称:WoWEditor,代码行数:27,代码来源:Scrollbar.cs

示例7: HandleMouseDown

        private void HandleMouseDown(MouseMessage msg)
        {
            var fact = VisibleSize / TotalSize;
            var scrollStart = (mScrollOffset / TotalSize) * Size;
            var knobRect = new RectangleF(Position.X + (Vertical ? 0 : scrollStart),
                Position.Y + (Vertical ? scrollStart : 0), Vertical ? Thickness : (Size * fact),
                Vertical ? (Size * fact) : Thickness);

            mIsKnobDown = knobRect.Contains(msg.Position);
            mKnobOffset = new Vector2(msg.Position.X - knobRect.X, msg.Position.Y - knobRect.Y);
        }
开发者ID:Linrasis,项目名称:WoWEditor,代码行数:11,代码来源:Scrollbar.cs

示例8: TestContainsWithRectangleReference

    public void TestContainsWithRectangleReference() {
      RectangleF testRectangle = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f);
      bool result;

      RectangleF insideRectangle = new RectangleF(3.0f, 6.0f, 3.7f, 5.2f);
      testRectangle.Contains(ref insideRectangle, out result);
      Assert.IsTrue(result);

      RectangleF outsideRectangle = new RectangleF(1.1f, 3.3f, 5.8f, 8.0f);
      testRectangle.Contains(ref outsideRectangle, out result);
      Assert.IsFalse(result);

      RectangleF upperLeftQuadrant = new RectangleF(1.2f, 3.4f, 2.8f, 3.9f);
      testRectangle.Contains(ref upperLeftQuadrant, out result);
      Assert.IsTrue(result);

      RectangleF lowerRightQuadrant = new RectangleF(4.0f, 7.3f, 2.8f, 3.9f);
      testRectangle.Contains(ref lowerRightQuadrant, out result);
      Assert.IsTrue(result);
    }
开发者ID:pr0gramm3r1,项目名称:AngryTanks,代码行数:20,代码来源:RectangleF.Test.cs

示例9: TestContainsWithRectangle

    public void TestContainsWithRectangle() {
      RectangleF testRectangle = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f);

      RectangleF insideRectangle = new RectangleF(3.0f, 6.0f, 3.7f, 5.2f);
      Assert.IsTrue(testRectangle.Contains(insideRectangle));

      RectangleF outsideRectangle = new RectangleF(1.1f, 3.3f, 5.8f, 8.0f);
      Assert.IsFalse(testRectangle.Contains(outsideRectangle));

      RectangleF upperLeftQuadrant = new RectangleF(1.2f, 3.4f, 2.8f, 3.9f);
      Assert.IsTrue(testRectangle.Contains(upperLeftQuadrant));

      RectangleF lowerRightQuadrant = new RectangleF(4.0f, 7.3f, 2.8f, 3.9f);
      Assert.IsTrue(testRectangle.Contains(lowerRightQuadrant));
    }
开发者ID:pr0gramm3r1,项目名称:AngryTanks,代码行数:15,代码来源:RectangleF.Test.cs

示例10: TestHitWith

        public bool TestHitWith(PointF position)
        {
            foreach (Tree tree in trees) {
                RectangleF rect = new RectangleF(
                    (float)(tree.position - px),
                    (float)(py - tree.height + 1),
                    (float)(1 + dx),
                    (float)tree.height);
                if (rect.Contains(position))
                    return true;
            }

            return false;
        }
开发者ID:oxyflour,项目名称:old-repos,代码行数:14,代码来源:game.cs

示例11: TouchesEnded

                public override IUIControl TouchesEnded( PointF touch )
                {
                    // create an expanded bounding box and see if the touch fell within that.
                    // we expand the height by 50% in both directions
                    RectangleF boundingBox = new RectangleF( PlatformLabel.Frame.Left,
                                                             PlatformLabel.Frame.Top - (PlatformLabel.Bounds.Height / 2),
                                                             PlatformLabel.Bounds.Right,
                                                             PlatformLabel.Bounds.Bottom + PlatformLabel.Bounds.Height );
                    if( boundingBox.Contains( touch ) )
                    {
                        Revealed = !Revealed;

                        float targetFade = 1.0f - PlatformLabel.GetFade( );

                        PlatformLabel.AnimateToFade( targetFade );
                        return this;
                    }

                    return null;
                }
开发者ID:jhawkzz,项目名称:CCVApp,代码行数:20,代码来源:RevealBox.cs

示例12: ContainsTest

        public void ContainsTest()
        {
            RectangleF targetInside = new RectangleF(10f, 10f, 1f, 1f);
            RectangleF targetOutside = new RectangleF(100f, 100f, 1f, 1f);
            RectangleF targetIntersects = new RectangleF(20f, 20f, 40f, 40f);

            RectangleF source = new RectangleF(0f, 0f, 21f, 21f);

            Assert.IsTrue(source.Contains(targetInside));
            Assert.IsFalse(source.Contains(targetOutside));
            Assert.IsFalse(source.Contains(targetIntersects));
        }
开发者ID:shadercoder,项目名称:Icicle-Framework,代码行数:12,代码来源:RectangleFTest.cs

示例13: ContainsTest1

        public void ContainsTest1()
        {
            RectangleF source = new RectangleF(0f, 0f, 100f, 100f);

            Vector2 targetInside = new Vector2(5f, 5f);
            Vector2 targetOutside = new Vector2(101f, 101f);
            Vector2 targetOnLine = new Vector2(100f, 100f);

            Assert.IsTrue(source.Contains(targetInside));
            Assert.IsFalse(source.Contains(targetOutside));
            Assert.IsFalse(source.Contains(targetOnLine));
        }
开发者ID:shadercoder,项目名称:Icicle-Framework,代码行数:12,代码来源:RectangleFTest.cs

示例14: OnMouseButtonRelease

    public void OnMouseButtonRelease(Vector mousePos, int button, ModifierType Modifiers)
    {
        if (button == 1) {
            switch(state)
            {
            case State.NONE:
                break;

            case State.SELECTING:
                // Add objects in the selected area to selectedObjects

                                // Flush selected objects if it's not CTRL+select
                if ((Modifiers & ModifierType.ControlMask) == 0)
                {
                    selectedObjects.Clear();
                }

                RectangleF selectedArea = new RectangleF(pressPoint, mousePos);
                foreach(IObject Object in sector.GetObjects(typeof(IObject)))
                {
                    if (selectedArea.Contains(Object.Area))
                    {
                        if (selectedObjects.Contains(Object))
                        {
                            selectedObjects.Remove(Object);
                        }
                        else
                        {
                            selectedObjects.Add(Object);
                        }
                    }
                }

                if (selectedObjects.Count == 1)
                {
                    //show properties
                    MakeActive(selectedObjects[0]);
                    //application.EditProperties(selectedObjects[0], selectedObjects[0].GetType().Name);
                }
                else
                {
                    // resizing is unavailable if more objects are selected
                    activeObject = null;
                    controlPoints.Clear();
                    application.EditProperties(selectedObjects, "Group of " + selectedObjects.Count.ToString() + " objects");
                }
                break;

            case State.DRAGGING:
                // Finish dragging and register undo command
                Vector newPosition = new Vector (activeObject.Area.Left, activeObject.Area.Top);//Area is up to date, no need to calculate it again
                if (newPosition != originalPosition) // FIXME: is that ok in C# or do we compare the reference here?
                {
                    Vector totalShift = newPosition - originalPosition;
                    MultiCommand multi_command = new MultiCommand("Moved " + selectedObjects.Count + " objects");

                    foreach (IObject selectedObject in selectedObjects)
                    {
                        // copy new area to variable
                        RectangleF oldArea = selectedObject.Area;

                        // and shift it to it's oreginal location
                        oldArea.Move(-totalShift);

                        multi_command.Add(new ObjectAreaChangeCommand(
                                      "Moved Object " + selectedObject,
                                      oldArea,
                                      selectedObject.Area, // We are already on new area
                                      selectedObject));
                    }

                    UndoManager.AddCommand(multi_command);
                }

                break;
            }

            state = State.NONE;
            Redraw();
        }

        /*if (false)
        {
            if (button == 1 && state == State.DRAGGING) {
                state = State.NONE;

                Vector newPosition = new Vector (activeObject.Area.Left, activeObject.Area.Top);//Area is up to date, no need to calculate it again
                if (originalPosition != newPosition) {
                    Command command = null;
                    List<Command> commandList = new List<Command>();
                    Vector totalShift = newPosition - originalPosition;
                    foreach (IObject selectedObject in selectedObjects) {
                        RectangleF oldArea = selectedObject.Area;			//copy new area to variable
                        oldArea.Move(-totalShift);					//	and shift it to it's oreginal location
                        command = new ObjectAreaChangeCommand(
                            "Moved Object " + selectedObject,
                            oldArea,
                            selectedObject.Area,					//We are already on new area
                            selectedObject);
                        commandList.Add(command);
//.........这里部分代码省略.........
开发者ID:Karkus476,项目名称:supertux-editor,代码行数:101,代码来源:ObjectSelectTool.cs

示例15: Update

        public override void Update()
        {
            if (Input.PointerEvents.Count == 0) 
                return;

            var destinationRectangle = new RectangleF(0, 0, GraphicsDevice.Presenter.BackBuffer.Width, GraphicsDevice.Presenter.BackBuffer.Height);

            // Process pointer event
            foreach (var pointerEvent in Input.PointerEvents)
            {
                var pixelPosition = pointerEvent.Position * new Vector2(GraphicsDevice.Presenter.BackBuffer.Width, GraphicsDevice.Presenter.BackBuffer.Height);

                if (pointerEvent.State != PointerState.Down || !destinationRectangle.Contains(pixelPosition)) continue;

                var relativePosition = (pixelPosition - destinationRectangle.TopLeft);

                var pixelX = (int)((relativePosition.X / destinationRectangle.Width) * RenderTextureSize);
                var pixelY = (int)((relativePosition.Y / destinationRectangle.Height) * RenderTextureSize);

                TogglePixel(pixelX, pixelY);
            }

            renderTexture.SetData(Game.GraphicsContext.CommandList, textureData);
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:24,代码来源:TextureUpdateScript.cs


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