CRect:Normalize CRect:PtInsideInt

CRect:Offset


The Offset method moves a rectangle to new coordinates. The offset can be specified in several different ways so that this method can work as a move, resize, or addition of the corresponding edge coordinates. The offsets can be positive or negative.

Syntax

CRect:Offset( CRect2 )

CRect:Offset( x )

CRect:Offset( x, y )

CRect:Offset( x1, x2, y1, y2 )

bullet.gif    CRect2 is another CRect object.

bullet.gif    x is a single offset applied to all edges.

bullet.gif    x and y are offsets applied equally to parallel sides.

bullet.gif    x1, x2, y1, y2 are applied independently to all 4 sides.

Remarks

The specified offset values are added to the edge coordinates of the rectangle. Using the 3 different argument lists gives great flexibility in changing the rectangle dimensions:

bullet.gif    Use the 1 argument form with a CRect to add the coordinates of one rectangle to another, edge by edge.

bullet.gif    Use the 1 argument version with a number argument to move the rectangule using equal offsets for all 4 edges.

bullet.gif    Use the 2 argument version to move the rectangle by offsetting opposite sides equally.

bullet.gif    Use the 4 argument version to resize the rectangle or to do a combination of move and resize. If the x1 and y1 arguments are both 0, the rectangle is only resized. This version works like the CRect version except that the offsets are given as numbers rather than by using another CRect.

The difference between Offset and Inflate is that Offset adds positive offsets to all 4 edges, whereas Inflate subtracts positive offsets from the minimum edges while adding positive offsets to the maximum edges.

Example

The following script moves and resizes the CRect R using various argument lists. Note that CRect:Get returns 4 arguments, which can be automatically filled into the 4 fields of the Printf function as shown.

R = new_rect()

-- create a CRect object R

R:Set(100, 200, 300, 600)

 

Printf("%lg:%lg, %lg:%lg\n", R:Get())

-- result: 100:200, 300:600.

 

 

R:Offset( 2, 10, 4, 20 )

-- move and resize the rectangle R

Printf("%lg:%lg, %lg:%lg\n", R:Get())

-- result: 102:210, 304:620.

 

 

R:Offset( 0, 30, 0, 40 )

-- resize the rectangle R

Printf("%lg:%lg, %lg:%lg\n", R:Get())

-- result: 102:240, 310:660.

 

 

R:Offset( 100, -200 )

-- move the rectangle R

Printf("%lg:%lg, %lg:%lg\n", R:Get())

-- result: 202:340, 110:460.

 

 

R:Offset( 10 )

-- move the rectangle R

Printf("%lg:%lg, %lg:%lg\n", R:Get())

-- result: 212:350, 120:470.

 

 

Rnew = new_rect( 0, 60, 0, 80 )

-- create another CRect object

R:Offset( Rnew )

-- resize R using another rectangle

Printf("%lg:%lg, %lg:%lg\n", R:Get())

-- result: 212:410, 120:550.

Related Topics

CRect class, Union, Intersection, Inflate


Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.