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.
CRect:Offset( CRect2 ) CRect:Offset( x ) CRect:Offset( x, y ) CRect:Offset( x1, x2, y1, y2 )
|
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:
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.
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.
|
-- create a CRect object R |
|
|
|
-- result: 100:200, 300:600. |
|
|
|
-- move and resize the rectangle R |
|
-- result: 102:210, 304:620. |
|
|
|
-- resize the rectangle R |
|
-- result: 102:240, 310:660. |
|
|
|
-- move the rectangle R |
|
-- result: 202:340, 110:460. |
|
|
|
-- move the rectangle R |
|
-- result: 212:350, 120:470. |
|
|
|
-- create another CRect object |
|
-- resize R using another rectangle |
|
-- result: 212:410, 120:550. |