本文整理汇总了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));
}
示例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);
}
示例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]);
}
}
示例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]);
}
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}
示例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));
}
示例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));
}
示例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);
//.........这里部分代码省略.........
示例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);
}