HRect

Description

A Rect object represents a rectangle. Rects are used throughout the Components to define the frames of windows, views, bitmaps even the screen itself. A HRect is defined by its four sides, expressed as the public data members left, top, right, and bottom.

If you change a component's rect, you should call its HView.drawRect method.

Instance Variables

type '[HRect]'
top The position of the rect's top side (from parent top)
left The position of the rect's left side (from parent left)
bottom The position of the rect's bottom side (from parent top)
right The position of the rect's right side (from parent left)
leftTop A HPoint representing the coordinate of the rect's left top corner
leftBottom A HPoint representing the coordinate of the rect's left bottom corner
rightTop A HPoint representing the coordinate of the rect's right top corner
rightBottom A HPoint representing the coordinate of the rect's right bottom corner
width The width of the rect.
height The height of the rect.

Inherits from:

Constructor Method

The constructor is invoked, when a new instance of HRect is created.

To create a new instance use HRect.nu( ) or new HRect( ).

constructor( )

Description

Initializes a Rect as four sides, as two diametrically opposed corners, or as a copy of some other Rect object. A rectangle that's not assigned any initial values is invalid, until a specific assignment is made, either through a set() function or by setting the object's data members directly.

Parameters

using a HRect instance:
rect Another HRect.

using two HPoint instances:

leftTop Coordinates of the left top corner.
rightBottom Coordinates of the right bottom corner.

using separate numeric coordinates:

left The coordinate of left side.
top The coordinate of top side.
right The coordinate of right side.
bottom The coordinate of bottom side.

Usage

var myLeftTopPoint = new HPoint(100,200);
var myBottomRightPoint = new HPoint(300,400);
var myRectFromOppositeCornerPoints = new HRect( myLeftTopPoint, myBottomRightPoint );
var myRectFromSideCoordinates = new HRect(100,200,300,400);
var myRectFromAnotherRect = new HRect( myRectFromEdgeCoordinates );

Class Methods

implement( interface )

Inherited from: HClass

Description

Copies the members of interface to a HClass or a class inherited from HClass.

Usage:

Defines an interface:
// Create an interface class that calculates the area
var AreaInterface = HClass.extend({
  constructor: null,
  area: function() {
    return this.getWidth() * this.getHeight();
  }
});

// Create a class that contains the coordinates of a rectangle. var Rectangle = HClass.extend({ constructor: function( x, y, width, height ) { this.x = x; this.y = y; this.width = width; this.height = height; }, getWidth: function() { return this.width; }, getHeight: function() { return this.height; } });

// Makes the Rectangle class implement the AreaInterface Rectangle.implement( AreaInterface );

nu( )

Inherited from: HClass

Class members:

Description

nu is a protected class method.

It does the same thing as the new keyword, but it is a class method.

Parameters:

Any parameters are passed on to the constructor method.

Usage:

Creates a class MyClass, then creates two instances of it: myClassInstance1 and myClassInstance2. The end result is the same.
var MyClass = HClass.extend({
  name: 'Foo',
  constructor: function( param1, param2 ){
    var logMsg = [ 'param1:', param1,
                   'param2:', param2,
                   'name:', this.name ];
    console.log( logMsg.join(' ') );
  }
});
// Construction using the new keyword:
var myClassInstance1 = new MyClass( 'one', 'two' );
// Construction using the nu method:
var myClassInstance2 = MyClass.nu( 'one', 'two' );
However, when extending in place, the benefits of the nu method become obvious.

// Extending in place with the new keyword:
var myExtendedClassInstance1 = new (
  MyClass.extend({
    name: 'Bar'
  })
)( 'one', 'two' );
// The same as above, but using the nu method:
var myExtendedClassInstance2 = MyClass.extend({
  name: 'Bar'
}).nu( 'one', 'two' );

extend( instance, static )

Inherited from: HClass

Description

The class method used to extend a class.

If the member name constructor is defined as null instead of a function block in the instance object block, the class is defined as a singleton (single instance class).

Parameters:

instance The object that defines the class instance members.
static The object that defines the static class members.

Returns:

Returns the extended class object.

Usage:

var Point = HClass.extend({
  constructor: function( x, y ) {
    this.x = x;
    this.y = y;
  }
});
var Rectangle = Point.extend({
  // Instance members:
  constructor: function( x, y, width, height ) {
    this.base( x, y );
    this.width = width;
    this.height = height;
  },
  getWidth: function() {
    return this.width;
  },
  getHeight: function() {
    return this.height;
  }
},

// Class Members { description: "this is a Rectangle", getClass: function() { return this; } });


Instance Methods

setLeft( left )

Description

Moves the rect's left side to a new coordinate.

Parameters

left The new left side coordinate (in px)


setHeight( height )

Description

Moves the rects bottom side to a new coordinate. Does not affect the position.

Parameters

height A numeric value representing the new target height of the rect.


insetBy( )

Description

Insets the sides of the Rect's rectangle by x units (left and right sides) and y units (top and bottom). Positive inset values shrink the rectangle; negative values expand it. Note that both sides of each pair moves the full amount. For example, if you inset a Rect by (4,4), the left side moves (to the right) four units and the right side moves (to the left) four units (and similarly with the top and bottom).

Parameters

using a HPoint:
point A HPoint to inset by.

using separate x and y coordinates:

x x Coordinate
y y Coordinate


set( )

Description

Sets the object's rectangle by defining the coordinates of all four sides.

The other set...() functions move one of the rectangle's corners to the Point argument; the other corners and sides are modified concomittantly.

None of these methods prevents you from creating an invalid rectangle.

Parameters

left The coordinate of the left side.
top The coordinate of the top side.
right The coordinate of the right side.
bottom The coordinate of the bottom side.


setLeftBottom( point )

Description

Moves the rects left and bottom sides to a new point. Affects the left position, width and height.

Parameters

point A HPoint instance to mode the sides to.


intersects( rect )

Description

Returns true if the Rect has any area even a corner or part of a side in common with rect, and false if it doesn't.

Parameters

rect A HRect instance to intersect this rect with

Returns

A Boolean (true/false) depending on the result.


setLeftTop( point )

Description

Moves the rects left and top sides to a new point. Affects the position, width and height.

Parameters

point A HPoint instance to mode the sides to.


setSize( )

Description

Moves the rects right and bottom sides to new coordinates. Does not affect the position.

Parameters

by separate numeric values:
width A numeric value representing the new target width of the rect.
height A numeric value representing the new target height of the rect.

by HPoint used as "HSize":

point.x A numeric value representing the new target width of the rect.
point.y A numeric value representing the new target height of the rect.


offsetBy( )

Description

Moves the Rect horizontally by x units and vertically by y units. The rectangle's size doesn't change.

Parameters

using a HPoint:
point A HPoint to offset by.

using separate x and y coordinates

x X coordinate
y Y coordinate


updateSecondaryValues( )

Description

You should call this on the instance to update secondary values, like width and height, if you change a primary (left/top/right/bottom) value straight through the property.

Do not change properties other than the primaries through properties.

Use the accompanied methods instead.


setBottom( bottom )

Description

Moves the rect's bottom side to a new coordinate.

Parameters

bottom The new bottom side coordinate (in px)


setWidth( width )

Description

Moves the rects right side to a new coordinate. Does not affect the position.

Parameters

width A numeric value representing the new target width of the rect.


union( rect )

Description

Creates and returns a new Rect that minimally but completely encloses the area defined by this Rect and the specified Rect.

Parameters

rect A HRect instance to compare to.

Returns

A new HRect instance.


setValue( value, srcViewId )

Description

setValue function

Parameters

value value
srcViewId srcViewId


setRightTop( point )

Description

Moves the rects right and top sides to a new point. Affects the top position, width and height.

Parameters

point A HPoint instance to mode the sides to.


setRightBottom( point )

Description

Moves the rects right and bottom sides to a new point. Affects the width and height. Does not affect the position.

Parameters

point A HPoint instance to mode the sides to.


offsetTo( )

Description

Moves the Rect to the location (x,y).

Parameters

using a HPoint:
point A HPoint to offset to.

using separate x and y coordinates):

x X coordinate
y Y coordinate


bind( view )

Description

Bind function

Parameters

view view


setRight( right )

Description

Moves the rect's right side to a new coordinate.

Parameters

right The new right side coordinate (in px)


setTop( top )

Description

Moves the rect's top side to a new coordinate.

Parameters

top The new top side coordinate (in px)


contains( obj )

Description

Returns true if point or rect lies entirely within the Rect's rectangle (and false if not). A rectangle contains the points that lie along its edges; for example, two identical rectangles contain each other.

Also works with HPoint instances.

Parameters

obj A HRect or HPoint to check the containment with.

Returns

A Boolean (true/false) depending on the result.


equals( rect )

Description

Returns true if the two objects' rectangles exactly coincide.

Parameters

rect A HRect instance to compare to.

Returns

A Boolean (true/false) depending on the result.


intersection( rect )

Description

Creates and returns a new Rect that's the intersection of this Rect and the specified Rect. The new Rect encloses the area that the two Rects have in common. If the two Rects don't intersect, the new Rect will be invalid.

Parameters

rect A HRect instance to compare to.

Returns

A new HRect instance.


release( view )

Description

Release function


setValueObj( valueObj )

Description

Sets valueObj for this component given as parameter.

Parameters

valueObj valueObj to use


toString( )

Inherited from: HClass

Protected instance method, returns the instance represented as a String.


valueOf( )

Inherited from: HClass

Protected instance method, returns the value of an instance.


base( )

Inherited from: HClass

This method can be called from any other method to invoke that method's parent



Other Instance Members

valueObj = null

HValue and HView support


prototype = { }

Inherited from: Object

Description

The prototype member of Object defines the instance members. These are copied to the instance object when the new keyword is called.