Haiku API Bindings
Rect
Not logged in

Documentation | InterfaceKit | Rect

SYNOPSIS

Perl

use HaikuR1::Rect;

my $rect = HaikuR1::Rect->new($left, $top, $right, $bottom);

Python

from HaikuR1.InterfaceKit import Rect

rect = Rect(left, top, right, bottom)

DESCRIPTION

Exposes the BRect object.

As a convenience, wherever a method expects a Rect as input, you may pass a four-item native list or native map instead. In addition, you may treat a Rect object like a native list.

For more information on Rect, see the Be Book class description, the Be Book overview, and the Haiku Book class description.

Perl

# input converters
$message->AddRect("rect", [$left, $top, $right, $bottom]);
$message->AddRect("rect", {
    left   => $left,
    top    => $top,
    right  => $right,
    bottom => $bottom
});

# list accessors
$rect->[0] = $left;
$rect->[1] = $top;
$rect->[2] = $right;
$rect->[3] = $bottom;

Python

# input converters
message.AddRect("rect", [left, top, right, bottom])
message.AddRect("rect", {
    left   = left,
    top    = top,
    right  = right,
    bottom = bottom
})

# list accessors
rect[0] = left
rect[1] = top
rect[2] = right
rect[3] = bottom

PROPERTIES

left

Left coordinate

top

Top coordinate

right

Right coordinate

bottom

Bottom coordinate

METHODS

Constructor

Creates a Rect.

Perl

HaikuR1::Rect->new($left,$top,$right,$bottom);
HaikuR1::Rect->new($copy_from);
HaikuR1::Rect->new($leftTop, $rightBottom);
HaikuR1::Rect->new($leftTop, $size);
HaikuR1::Rect->new($side);
HaikuR1::Rect->new();

Python

Rect(left,top,right,bottom)
Rect(copy_from)
Rect(leftTop, rightBottom)
Rect(leftTop, size)
Rect(side)
Rect()

copy

Copies the contents of another object into this object.

Perl

$rect->copy($copy_from);

Python

rect.copy(copy_from)

Contains

Returns true if the given Point or Rect is inside this Rect.

When testing Rects, sides and corners may overlap - identical rectangles contain each other.

Perl

$rect->Contains($point);
$rect->Contains($rect);

Python

rect.Contains(point)
rect.Contains(rect)

Corners

LeftTop

SetLeftTop

RightBottom

SetRightBottom

LeftBottom

SetLeftBottom

RightTop

SetRightTop

Gets or sets the given Point.

Perl

$rect->LeftTop();
$rect->SetLeftTop($leftTop);
$rect->RightBottom();
$rect->SetRightBottom($rightBottom);
$rect->LeftBottom();
$rect->SetLeftBottom($leftBottom);
$rect->RightTop();
$rect->SetRightTop($rightTop);

Python

rect.LeftTop()
rect.SetLeftTop(leftTop)
rect.RightBottom()
rect.SetRightBottom(rightBottom)
rect.LeftBottom()
rect.SetLeftBottom(leftBottom)
rect.RightTop()
rect.SetRightTop(rightTop)

Insets and Offsets

InsetBy

InsetByCopy

InsetBySelf

OffsetBy

OffsetByCopy

OffsetBySelf

OffsetTo

OffsetToCopy

OffsetToSelf

The InsetBy methods move the sides of the Rect inward, toward the center. The left and right sides move by the x coordinate; the top and bottom sides move by the y coordinate.

The OffsetBy methods move the Rect by the amounts given. A positive x moves it left; a negative x moves it right. Similarly, a positive y moves it down and a negative y moves it up.

The OffsetTo methods move the upper left corner of the Rect to the coordinates given.

The unadorned versions operate directly on the object and do not return anything.

The *Copy versions operate on a copy of the object and return that copy; the object itself does not change.

The *Self versions operate on the object and also return a copy.

Perl

$rect->InsetBy($point);
$rect->InsetBy($x, $y);
$rect->InsetByCopy($point);
$rect->InsetByCopy($x, $y);
$rect->InsetBySelf($point);
$rect->InsetBySelf($x, $y);

$rect->OffsetBy($point);
$rect->OffsetBy($x, $y);
$rect->OffsetByCopy($point);
$rect->OffsetByCopy($x, $y);
$rect->OffsetBySelf($point);
$rect->OffsetBySelf($x, $y);

$rect->OffsetTo($point);
$rect->OffsetTo($x, $y);
$rect->OffsetToCopy($point);
$rect->OffsetToCopy($x, $y);
$rect->OffsetToSelf($point);
$rect->OffsetToSelf($x, $y);

Python

rect.InsetBy(point)
rect.InsetBy(x, y)
rect.InsetByCopy(point)
rect.InsetByCopy(x, y)
rect.InsetBySelf(point)
rect.InsetBySelf(x, y)

rect.OffsetBy(point)
rect.OffsetBy(x, y)
rect.OffsetByCopy(point)
rect.OffsetByCopy(x, y)
rect.OffsetBySelf(point)
rect.OffsetBySelf(x, y)

rect.OffsetTo(point)
rect.OffsetTo(x, y)
rect.OffsetToCopy(point)
rect.OffsetToCopy(x, y)
rect.OffsetToSelf(point)
rect.OffsetToSelf(x, y)

Intersects

Returns true if the given Rect has any overlap with this Rect - even if it's just a corner - with this Rect.

Perl

$rect->Intersects($rect);

Python

rect.Intersects(rect)

IsValid

Returns true if the Rect is valid. "Valid" means right >= left and bottom >= top.

Perl

$rect->IsValid();

Python

rect.IsValid()

PrintToStream

Prints the contents to standard out as BRect(left, top, right, bottom)

Perl

$rect->PrintToStream();

Python

rect.PrintToStream()

Set

Sets the properties of the Rect.

Perl

$rect->Set($left,$top,$right,$bottom);

Python

rect.Set(left,top,right,bottom)

Width and Height

Width

IntegerWidth

Height

IntegerHeight

Size

These methods do what you expect; Size returns a Size.

Perl

$rect->Width();
$rect->IntegerWidth();
$rect->Height();
$rect->IntegerHeight();
$rect->Size();

Python

rect.Width()
rect.IntegerWidth()
rect.Height()
rect.IntegerHeight()
rect.Size()

OPERATORS

==

Returns true if the Rect objects refer to the same rectangle.

!=

Returns true if the Rect objects do not refer to the same rectangle.

&

Returns the union of two Rects.

|

Returns the intersection of two Rects.