Realbasic.Rect.Contains
From Xojo Documentation
This item was deprecated in version 2019r2. Please use Rect.Contains as a replacement. |
Method
Realbasic.Rect.Contains(p As Realbasic.Point) As Boolean
New in 2011r2
Supported for all project types and targets.
New in 2011r2
Supported for all project types and targets.
True if the Rect contains the passed point.
Method
Realbasic.Rect.Contains(Other As Realbasic.Rect) As Boolean
New in 2011r2
Supported for all project types and targets.
New in 2011r2
Supported for all project types and targets.
True if the Rect completely contains the passed Rect.
Sample Code
This example is from the CanvasDragRect example that comes with Xojo (Examples/Graphics and Multimedia/CanvasDragRect).
The Paint event contains code that handles all the cases in which the two rectangles interact. The code uses the Union, Contains, and Intersect methods to detect these conditions and applies a color to the picture, buffer. This code is in the Paint event of the Canvas.
Const RedColor = &cFF0000
Const GreenColor = &c00FF00
Const BlueColor = &c0000FF
Const CyanColor = &c00FFFF
Const WhiteColor = &cFFFFFF
// Create a pure white picture, to prevent flicker on Windows.
Dim buffer As New Picture(g.Width, g.Height, 32)
buffer.Graphics.ForeColor = WhiteColor
// To demonstrate the Union feature, we'll draw a Cyan rectangle
// around both the draggable rects.
Dim u As Realbasic.Rect = rectOne.Union(rectTwo)
buffer.Graphics.ForeColor = CyanColor
buffer.Graphics.DrawRect(u.Left, u.Top, u.Width, u.Height)
// If the cursor is inside RectOne, and we're not dragging
// RectTwo, then we'll use blue. Otherwise, the rect will be red.
If rectOne.Contains(MousePosition) And DraggingRect <> rectTwo Then
buffer.Graphics.ForeColor = BlueColor
Else
buffer.Graphics.ForeColor = RedColor
End If
buffer.Graphics.FillRect(rectOne.Left, rectOne.Top, rectOne.Width, rectOne.Height)
// Same as above, but for RectTwo
If rectTwo.Contains(MousePosition) And DraggingRect <> rectOne Then
buffer.Graphics.ForeColor = BlueColor
Else
buffer.Graphics.ForeColor = RedColor
End If
buffer.Graphics.FillRect(rectTwo.Left, rectTwo.Top, rectTwo.Width, rectTwo.Height)
// To demonstrate the Intersection feature, we'll draw a green rectangle
// where the two draggable rects overlap. The Intersection function will
// always return a rect, even if the two provided do not actually intersect.
// That's why we use the Intersects function first. Remove the "If" block to
// see a neat trick.
If rectOne.Intersects(rectTwo) Then
Dim r As Realbasic.Rect = rectOne.Intersection(rectTwo)
buffer.Graphics.ForeColor = GreenColor
buffer.Graphics.FillCect(r.Left, r.Top, r.Width, r.Height)
End If
g.DrawPicture(buffer, 0, 0)
Const GreenColor = &c00FF00
Const BlueColor = &c0000FF
Const CyanColor = &c00FFFF
Const WhiteColor = &cFFFFFF
// Create a pure white picture, to prevent flicker on Windows.
Dim buffer As New Picture(g.Width, g.Height, 32)
buffer.Graphics.ForeColor = WhiteColor
// To demonstrate the Union feature, we'll draw a Cyan rectangle
// around both the draggable rects.
Dim u As Realbasic.Rect = rectOne.Union(rectTwo)
buffer.Graphics.ForeColor = CyanColor
buffer.Graphics.DrawRect(u.Left, u.Top, u.Width, u.Height)
// If the cursor is inside RectOne, and we're not dragging
// RectTwo, then we'll use blue. Otherwise, the rect will be red.
If rectOne.Contains(MousePosition) And DraggingRect <> rectTwo Then
buffer.Graphics.ForeColor = BlueColor
Else
buffer.Graphics.ForeColor = RedColor
End If
buffer.Graphics.FillRect(rectOne.Left, rectOne.Top, rectOne.Width, rectOne.Height)
// Same as above, but for RectTwo
If rectTwo.Contains(MousePosition) And DraggingRect <> rectOne Then
buffer.Graphics.ForeColor = BlueColor
Else
buffer.Graphics.ForeColor = RedColor
End If
buffer.Graphics.FillRect(rectTwo.Left, rectTwo.Top, rectTwo.Width, rectTwo.Height)
// To demonstrate the Intersection feature, we'll draw a green rectangle
// where the two draggable rects overlap. The Intersection function will
// always return a rect, even if the two provided do not actually intersect.
// That's why we use the Intersects function first. Remove the "If" block to
// see a neat trick.
If rectOne.Intersects(rectTwo) Then
Dim r As Realbasic.Rect = rectOne.Intersection(rectTwo)
buffer.Graphics.ForeColor = GreenColor
buffer.Graphics.FillCect(r.Left, r.Top, r.Width, r.Height)
End If
g.DrawPicture(buffer, 0, 0)