Moscrif API Docs for: 2012q3
Show:

Moscrif.Window Class

Library: ui

This class encapsulates top level window (application).

Methods

this

(
  • [name]
)
Moscrif.Window

Constructor - creates new instance of Window class.

Parameters:

  • [name] String optional

    Window's name.

Returns:

Example:

var app = new Moscrif.Window();

app.onStart = function()
{
    ...
}

app.onProcess = function(sender)
{
    return 1;
    // return 0 to quit application
}
app.init().run();

add

(
  • view
  • [order]
)
Window chainable

Function adds existing view object into this window.

Parameters:

  • view View

    View to add. View/ScrollView/TextView are supported.

  • [order] Symbol optional

    Default is #back. Value is

        * #front
        * #back
    

Returns:

Window: Return instance of itself.

Example:

    var container = new Moscrif.View("container");
    ... width, height, onDraw ...
    app.add(container);

    var itemA = new Moscrif.View("itemA");
    ... width, height (60), top (0), onDraw ...
    container.add(itemA);

    var itemB = new Moscrif.View("itemB");
    ... width, height (60), top (60), onDraw ...
    container.add(itemB);

find

(
  • name
)
View

Search for child view, which name is same as name from function's param.

Parameters:

  • name String

    Name of the child view to search

Returns:

View: Instance of found child view, or null if not found.

Example:

var btnView = new Moscrif.View();
btnView.name = "button";

var imgView = new Moscrif.View();
imgView.name = "image";
app.add(imgView);

// find button view
var button = this.find("button");
// detach button view
button.detach();

init

(
  • enableFPS=true
)
chainable

Initialize window object.

Parameters:

  • enableFPS=true Boolean

    Default is false (FPS counting is disabled).

Example:

var app = new Moscrif.Window();
app.terminate = false;
app.onStart = function()
{

}
app.onProcess = function(sender)
{

    return this.terminate ? 0 : 1;
}

app.init();
app.run();

invalidate

(
  • [left]
  • [top]
  • [right]
  • [bottom]
)

This function ensure redrawing a rectangle, determined by parameters. If no parameters are set, whole object will be redraw. Redrawing manages the function, which is set to onDraw event.

Parameters:

  • [left] Boolean optional

    Left border of the rectangle to be invalidated

  • [top] Boolean optional

    Top border of the rectangle to be invalidated.

  • [right] Boolean optional

    Right border of the rectangle to be invalidated.

  • [bottom] Boolean optional

    Bottom border of the rectangle to be invalidated.

Example:

var app = new Moscrif.Window();
app.terminate = false;
...
app.onProcess = function(sender)
{
    // redraw window every call of onProcess event, usally used at games
    app.invalidate();

    return this.terminate ? 0 : 1;
}

performLayout

() Window

Performs (force) layout calculations.

Returns:

Window:

removeAll

() chainable

Removes all object from the window.

resumeLayout

() Window

Resume layer's recalculating.

Returns:

Window:

run

() Window chainable

Runs the main application loop. This function is blocking.

Returns:

Window:

suspendLayout

() Window

Pause layer's recalculating. This function is useful when a lot of items are inserted into view in short time. When resumeLayout is called, all items will be inserted at once .

Returns:

Window:

Properties

childredCount

Integer

Count of the childs.

layout

Integer

StackLayout used to organize elements into the window.

name

String

Name offset the window.

orientation

Symbol

This property sets supported device orientations. If there are more supported orientations event onOrientationChanged is called, when device orientation change. Supported are:

  • #portrait
  • #landscape-left
  • #landscape-right

Events

onBackground

This event appears, when application moves to background.

Event Payload:

  • sender Object

    Object which caused this event.

onChar

This event is raised by release an UNICODE character key.

Event Payload:

  • sender Object

    Object which caused this event.

  • key Integer

    Code from unicode table.

onDraw

This event occurs, when it is necessary to redraw object. onDraw event is usually managed by skin.

Event Payload:

  • sender Object

    Object which caused this event.

  • canvas Canvas

    Canvas object enabling drawing to the TextView.

onForeground

This event appears, when application moves to foreground.

Event Payload:

  • sender Object

    Object which caused this event.

onKeyPressed

This event is raised by press the key.

Event Payload:

  • sender Object

    Object which caused this event.

  • key Symbol

    Pressed key.

    • #leftSoftKey
    • #rightSoftKey
    • #home
    • #back
    • #send
    • #end
    • #num0 - #num9
    • #star - the * key
    • #hash - the # key
    • #up
    • #down
    • #left
    • #right
    • #ok
    • #volumeUp
    • #volumeDown
    • #power
    • #camera

onKeyReleased

This event is raised by release the key.

Event Payload:

  • sender Object

    Object which caused this event.

  • key Symbol

    Pressed key.

    • #leftSoftKey
    • #rightSoftKey
    • #home
    • #back
    • #send
    • #end
    • #num0 - #num9
    • #star - the * key
    • #hash - the # key
    • #up
    • #down
    • #left
    • #right
    • #ok
    • #volumeUp
    • #volumeDown
    • #power
    • #camera

onOrientationChanged

This event is raised by change device orientation.

Event Payload:

  • orientation Symbol

    New orientation of device

Example:

game.onOrientationChanged = function(orientation)
{
    // resize all photos to current orientation
    logI("new orientation is : ", orientation);
}

onPointerDragged

Called when touch (click) is moved.

Event Payload:

  • sender Object

    Object which caused this event.

  • x Integer

    X coordinates of pointer.

  • y Integer

    Y coordinates of pointer.

onPointerPressed

Called when touch (click) is stared.

Event Payload:

  • sender Object

    Object which caused this event.

  • x Integer

    X coordinates of pointer.

  • y Integer

    Y coordinates of pointer.

onPointerReleased

Called when touch (click) is finished.

Event Payload:

  • sender Object

    Object which caused this event.

  • x Integer

    X coordinates of pointer.

  • y Integer

    Y coordinates of pointer.

onProcess

Callback function, which is which is called from the object every 25ms.

onQuit

This event appears, when application ends - only once during the application life cycle.

Event Payload:

  • sender Object

    Object which caused this event.

onResize

Occurs when the control is resized.

Event Payload:

  • sender Object

    Object which caused this event.

  • width Integer

    New width of resized view.

  • height Integer

    New height of resized view.

onStart

This event appears, when application starts - only once during the application life cycle.

Event Payload:

  • sender Object

    Object which caused this event.