All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
HelloWorld.js

This example is an equivalent of HelloWorldExample.cpp written entirely in JavaScript. It can be run as a separate program with ScriptRunner or executed as a script through Scripting::JSContext.

HelloWorld-screenshot.png
Screenshot of the HelloWorld example

The difference between C++- and JavaScript-version is that in JavaScript one doesn't have to initialize MultiWidgets::Application, since it is automatically constructed, initialized and started. So the only thing that is left for for the programmer is to create and position the widgets.

Inside the loop we first create new Widget. Note that C++-namespaces are transformed to the global JavaScript-objects.

var w = new MultiWidgets.Widget();

After this the created widget is added to the child of the main layer of application. The application is accessed through $-object as its member variable app.

$.app.mainLayer().addChild(w);

The rest of the loop body just sets the size, position and color of the widget. The full source code is shown below:

/* Copyright (C) 2007-2013 Multi Touch Oy, Finland, http://www.multitaction.com
*
* This file is part of MultiTouch Cornerstone.
*
* All rights reserved. You may use this file only for purposes for which you
* have a specific, written permission from Multi Touch Oy.
*
*/
for (var i = 0; i < 5; ++i) {
var w = new MultiWidgets.Widget();
$.app.mainLayer().addChild(w);
w.setSize(100, 100);
w.setLocation(i * 50, i * 50);
w.setBackgroundColor(1.0, 1.0 - i * 0.2, 0.3, 0.9);
}