# View

Module hilo/view/View Requires hilo/core/Hilo, hilo/core/Class, hilo/event/EventMixin, hilo/geom/Matrix, hilo/util/util Source View.js
View View is the base class of all display objects

### Properties

| Property | Defined
--- | --- | ---
| align:String|Function The alignment of the view, the value must be one of Hilo.align enum. | View
| alpha:Number The opacity of the view, default value is 1. | View
| background:Object The background style to fill the view, can be css color, gradient or pattern of canvas | View
| boundsArea:Array The vertex points of the view, the points are relative to the center point. | View
| depth:Number The z index of the view, readonly! | View
| drawable:Drawable The drawable object of the view. | View
| height:Number The height of the view, default value is 0. | View
| id:String The identifier for the view. | View
| mask:Graphics Sets a mask for the view. | View
| onUpdate:Function This method will call while the view need update(usually caused by ticker update). | View
| parent:Container The parent view of this view, readonly! | View
| pivotX:Number Position of the center point on the x axis of the view, default value is 0. | View
| pivotY:Number Position of the center point on the y axis of the view, default value is 0. | View
| pointerEnabled:Boolean Is the view can receive DOM events, default value is true. | View
| rotation:Number The rotation of the view in angles, default value is 0. | View
| scaleX:Number The x axis scale factor of the view, default value is 1. | View
| scaleY:Number The y axis scale factor of the view, default value is 1. | View
| tint:Number The tint applied to the view，default is 0xFFFFFF.Only support in WebGL mode. | View
| transform:Matrix The transform of the view.If set the transform, x, y, scaleX, scaleY, rotation, pivotX, pivotY will be ignored.default is null. | View
| visible:Boolean The visibility of the view. | View
| width:Number The width of the view, default value is 0. | View
| x:Number The position of the view on the x axis relative to the local coordinates of the parent, default value is 0. | View
| y:Number The position of the view on the y axis relative to the local coordinates of the parent, default value is 0. | View

### Methods

| Method | Defined
--- | --- | ---
| View(properties:Object) Constructor | View
| addTo(container:Container, index:Uint):View Add current view to a Contaner. | View
| fire(type:String, detail:Object):Boolean Send events. | View
| getBounds():Array Get the bounds of the view as a circumscribed rectangle and all vertex points relative to the coordinates of the stage. | View
| getScaledHeight():Number Get the scaled height of the view. | View
| getScaledWidth():Number Get the scaled width of the view. | View
| getStage():Stage Get the stage object of the view. | View
| hitTestObject(object:View, usePolyCollision:Boolean) Determining whether an object is in the circumscribed rectangle of current view. | View
| hitTestPoint(x:Number, y:Number, usePolyCollision:Boolean):Boolean Determining whether a point is in the circumscribed rectangle of current view. | View
| off(type:String, listener:Function):Object Remove one event listener. | View
| on(type:String, listener:Function, once:Boolean):Object Add an event listenser. | View
| removeFromParent():View Remove current view from it's parent container | View
| render(renderer:Renderer, delta:Number) The render method of current view. | View
| toString():String Get a string representing current view. | View

### Property Detail

align:String|Function
The alignment of the view, the value must be one of Hilo.align enum.
alpha:Number
The opacity of the view, default value is 1.
background:Object
The background style to fill the view, can be css color, gradient or pattern of canvas
boundsArea:Array
The vertex points of the view, the points are relative to the center point. This is a example: [{x:10, y:10}, {x:20, y:20}].
depth:Number
The z index of the view, readonly!
drawable:Drawable
The drawable object of the view. Only for advanced develop.
height:Number
The height of the view, default value is 0.
id:String
The identifier for the view.
mask:Graphics
Sets a mask for the view. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. A regular mask must be a Hilo.Graphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null.
onUpdate:Function
This method will call while the view need update(usually caused by ticker update). This method can return a Boolean value, if return false, the view will not be drawn. Limit: If you change the index in it's parent, it will not be drawn correct in current frame but next frame is correct.

  Default: null

parent:Container
The parent view of this view, readonly!
pivotX:Number
Position of the center point on the x axis of the view, default value is 0.
pivotY:Number
Position of the center point on the y axis of the view, default value is 0.
pointerEnabled:Boolean
Is the view can receive DOM events, default value is true.
rotation:Number
The rotation of the view in angles, default value is 0.
scaleX:Number
The x axis scale factor of the view, default value is 1.
scaleY:Number
The y axis scale factor of the view, default value is 1.
tint:Number
The tint applied to the view，default is 0xFFFFFF.Only support in WebGL mode.
transform:Matrix
The transform of the view.If set the transform, x, y, scaleX, scaleY, rotation, pivotX, pivotY will be ignored.default is null.
visible:Boolean
The visibility of the view. If false the vew will not be drawn, default value is true.
width:Number
The width of the view, default value is 0.
x:Number
The position of the view on the x axis relative to the local coordinates of the parent, default value is 0.
y:Number
The position of the view on the y axis relative to the local coordinates of the parent, default value is 0.

### Constructor

View(properties:Object)

parameters
properties:Object — The properties to create a view object, contains all writeable props of this class

### Method Detail

addTo(container:Container, index:Uint):View
Add current view to a Contaner.

parameters
container:Container — Container object.
index:Uint — The index of the view in container.

return
  View — Current view.

fire(type:String, detail:Object):Boolean
Send events. If the first parameter is an Object, take it as an Event Object.

parameters
type:String — Event type to send.
detail:Object — The detail (parameters go with the event) of Event to send.

return
  Boolean — Whether Event call successfully.

getBounds():Array
Get the bounds of the view as a circumscribed rectangle and all vertex points relative to the coordinates of the stage.

return
  Array — The vertex points array, and the array contains the following properties:
  - x - The position of the view on the x axis relative to the coordinates of the stage.
  - y - The position of the view on the y axis relative to the coordinates of the stage.
  - width - The width of circumscribed rectangle of the view.
  - height - The height of circumscribed rectangle of the view

getScaledHeight():Number
Get the scaled height of the view.

return
  Number — scaled height of the view.

getScaledWidth():Number
Get the scaled width of the view.

return
  Number — scaled width of the view.

getStage():Stage
Get the stage object of the view. If the view doesn't add to any stage, null will be returned.

return
  Stage — The stage object of the view.

hitTestObject(object:View, usePolyCollision:Boolean)
Determining whether an object is in the circumscribed rectangle of current view.

parameters
object:View — The object need to determining.
usePolyCollision:Boolean — Is use polygon collision, default value is false.

hitTestPoint(x:Number, y:Number, usePolyCollision:Boolean):Boolean
Determining whether a point is in the circumscribed rectangle of current view.

parameters
x:Number — The x axis relative to the stage coordinates.
y:Number — The y axis relative to the stage coordinates.
usePolyCollision:Boolean — Is use polygon collision, default value is false.

return
  Boolean — the point is in the circumscribed rectangle of current view.

off(type:String, listener:Function):Object
Remove one event listener. Remove all event listeners if no parameter provided, and remove all event listeners on one type which is provided as the only parameter.

parameters
type:String — The type of event listener that want to remove.
listener:Function — Event listener callback function to be removed.

return
  Object — The Event itself. Functions chain call supported.

on(type:String, listener:Function, once:Boolean):Object
Add an event listenser.

parameters
type:String — Event type to listen.
listener:Function — Callback function of event listening.
once:Boolean — Listen on event only once and no more response after the first response?

return
  Object — The Event itself. Functions chain call supported.

removeFromParent():View
Remove current view from it's parent container

return
  View — Current view.

render(renderer:Renderer, delta:Number)
The render method of current view. The subclass can implement it's own render logic by rewrite this function.

parameters
renderer:Renderer — Renderer object.
delta:Number — The delta time of render.

toString():String
Get a string representing current view.

return
  String — string representing current view.