Class
Realbasic.Rect
Warning
This item was deprecated in version 2019r2. Please use Rect as a replacement.
Description
A way to represent an axis-aligned rectangular area. Rect can be used for window size/position, control size/position and drawing of controls.
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
Realbasic.Rect |
|||
X As Integer, Y As Integer, Width As Integer, Height As Integer |
|||
Other As Realbasic.Rect |
Realbasic.Rect |
||
Other As Realbasic.Rect |
|||
P As Point |
|||
P As Realbasic.Rect |
Realbasic.Rect |
||
X As Integer |
Realbasic.Rect |
||
Y As Integer |
Realbasic.Rect |
||
Other As Realbasic.Rect |
Realbasic.Rect |
Property descriptions
Realbasic.Rect.Bottom
Bottom As Integer
The bottom edge of the rect on the Y axis. Changing this value will resize the rect.
This example enlarges the rect by 50 pixels:
myRect.Bottom = myRect.Bottom + 50
Realbasic.Rect.Center
Center As Realbasic.point
The center of the rect. Changing this value will move the rect.
This sample works in a Canvas.Paint event. It computes the center of a rect that represents the union of two rects.
Dim i, j As Integer
' To demonstrate the Union feature, 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)
theSize = u.Size
Dim theCenter As Realbasic.Point = u.Center
i = theCenter.X
j = theCenter.Y
Realbasic.Rect.Height
Height As Integer
The height of the Rect.
This example increases the height of rectone by 50 pixels.
myRect.Height = myRect.Height + 50
Realbasic.Rect.HorizontalCenter
HorizontalCenter As Integer
The center of the Rect on the X axis. Changing this value will move the Rect.
This example is in the MouseDrag event. It gets the horizontal and vertical centers of the rect being dragged.
Dim i, j As Double
i = DraggingRect.HorizontalCenter
j = DraggingRect.VerticalCenter
Realbasic.Rect.Left
Left As Integer
The left edge of the Rect on the X axis.
This example moves the rect to the left by 50 pixels, keeping its height and width intact.
myRect.Left = myRect.Left + 50
Realbasic.Rect.Origin
Origin As Realbasic.point
The upper left coordinate of the rect.
This example is in the MouseDrag event. The position of the Rect being dragged is updated via by reseting the value of the Origin property.
' Update our mouse position.
mouseposition = New Realbasic.Point(x, y)
' If we're actually dragging something, move the rect.
' We update the rect's origin with a CLONE of the mouse position,
' because MousePosition is an instance of the REALbasic.Point class.
' Without the clone, when we call the offset function, we'll also update
' the MousePosition property, since both DraggingRect.Origin and MousePosition
' would point to the same variable.
' The offset function shifts the rect. Positive for right/down,
' negative for left/up.
If draggingrect <> Nil Then
draggingrect.Origin = mouseposition.Clone
draggingrect.Offset(mouseoffset.x, mouseoffset.y)
End If
' refresh, without erasing the background
Me.Invalidate(False)
Realbasic.Rect.Right
Right As Integer
The right edge of the rect on the X axis. Changing this value will resize the rect.
This example moves the rect to the right by 50 pixels, keeping its height and width intact:
myRect.Left = myRect.Right + 50
Realbasic.Rect.Size
Size As Realbasic.Size
The dimensions of the Rect.
This example is in the Paint event of a project. It computes the Size of the union of two rects.
' To demonstrate the Union feature, we'll draw a Cyan rectangle
' around both the draggable rects.
Dim theSize As New REALbasic.Size
Dim u As Realbasic.Rect = rectone.Union(recttwo)
buffer.Graphics.ForeColor = CyanColor
buffer.Graphics.DrawRect(u.Left, u.Top, u.Width, u.Height)
theSize = u.Size
Realbasic.Rect.Top
Top As Integer
The top edge of the rect on the Y axis.
This example is in the Paint event. It computes the top of a rect that represents the union of two rects.
Dim i, j As Integer
' 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)
theSize = u.Size
Dim theTop As Realbasic.Point = u.Top
i = theTop.x
j = theTop.y
Realbasic.Rect.VerticalCenter
VerticalCenter As Integer
The center of the rect on the Y axis. Changing this value will move the Rect.
This example is in the MouseDrag event. It gets the horizontal and vertical centers of the rect being dragged.
Dim i, j As Double
i = DraggingRect.HorizontalCenter
j = DraggingRect.VerticalCenter
Realbasic.Rect.Width
Width As Integer
The width of the rect.
This example increases the width by 50 pixels:
myRect.Width = myWidth.Width + 50
Method descriptions
Realbasic.Rect.Clone
Clone As Realbasic.Rect
Creates a duplicate of the Rect.
Realbasic.Rect.Constructor
Constructor(X As Integer, Y As Integer, Width As Integer, Height As Integer)
Note
Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.
Creates a Realbasic.Rect object at X,Y and the passed width and height.
This example is from the Rects example that is covered in the Notes section of the Realbasic.Rect class. The Open event of the main window contains constructors that appear in the top-left and bottom-right corners of the main window.
' Start by defining our two rectangles. Both will be 100 x 75.
' RectOne will be in the upper left. RectTwo will be in the lower right.
rectOne = New Realbasic.Rect(0, 0, 100, 75)
rectTwo = New Realbasic.Rect(Self.Width - 100, Self.Height - 75, 100, 75)
' Fill our point classes to avoid NilObjectException errors.
mousePosition = New Realbasic.Point(-1, -1)
mouseOffset = New Realbasic.Point(0, 0)
Realbasic.Rect.Intersection
Intersection(Other As Realbasic.Rect) As Realbasic.Rect
Returns a new Rect representing the area the two Rects overlap.
Realbasic.Rect.Intersects
Intersects(Other As Realbasic.Rect) As Boolean
Returns True if the Rect overlaps the passed rect.
Realbasic.Rect.LocalPoint
LocalPoint(P As Point) As Point
Returns a new Point whose coordinates are local to the calling Rect.
Realbasic.Rect.LocalRect
LocalRect(P As Realbasic.Rect) As Realbasic.Rect
Returns a new Rect whose coordinates are local to the calling Rect.
Realbasic.Rect.Offset
Offset(DeltaX As Integer, DeltaY As Integer)
Moves the point the passed number of pixels. Positive numbers move the point down or to the right, negative move it up or to the left.
Realbasic.Rect.SplitHorizontal
SplitHorizontal(X As Integer) As Realbasic.Rect
Divides the rect into two rects at the given point on the X axis.
For example, imagine a rect that is 200 pixels wide by 100 pixels tall. With a call to SplitHorizontal(50), the rect will become 50 pixels wide, and a new rect will be returned that is 150x100, positioned exactly to the right of the original rect.
This example is taken from the Paint event of a Canvas. It takes a rect and splits it horizontally at the midpoint of the width.
Dim uright As Realbasic.Rect = u.SplitHorizontal(theSize.Width / 2)
Realbasic.Rect.SplitVertical
SplitVertical(Y As Integer) As Realbasic.Rect
Divides the rect into two rects at the given point on the Y axis.
For example, imagine a Rect that is 200 pixels wide by 100 pixels tall. A call to SplitVertical (50) on this rect, the rect will become 50 pixels wide, and a new rect will be returned that is 150x100, positioned exactly to the top of the original rect.
This example is taken from the Paint event of a Canvas. It takes a rect and splits it horizontally at the midpoint of the height.
Dim utop As Realbasic.Rect = u.SplitVertical(theSize.Height / 2)
Realbasic.Rect.Union
Union(Other As Realbasic.Rect) As Realbasic.Rect
Creates a new Rect containing both rects.
Notes
You must prefix the classic Rect with "Realbasic" like this:
Realbasic.Rect
.
Sample code
Dim myRect As New Realbasic.Rect(10, 10, 100, 50)
Compatibility
All project types on all supported operating systems.
See also
Object parent class; Canvas control; Window, DesktopContainer, Point, Size classes.