All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
HelloWorldExample.cpp

The Hello World tutorial is a great first step into developing for MultiTouch cells. In this tutorial, you will learn how to create a simple application that displays several squares on the screen. The squares can be manipulated with standard translate, rotate, and scale gestures.

HelloWorld-screenshot.png
Screenshot of the HelloWorld example

We begin the application by including a header file that declares the standard Cornerstone application that we are using:

#include <MultiWidgets/Application.hpp>

We then declare our main function which acts as the entry point for the application:

int main(int argc, char ** argv)
{

Next, we create an instance of our application and initialize it. The MultiWidgets::Application::init function parses any command line arguments, starts up the multi-touch tracker, and sets up the graphics system:

bool ok = app.init(argc, argv);
if(!ok)
return 1;

Now that we have an instance of the application, we create five squares that we place on the screen. The MultiWidgets library contains generic widgets that can be used to create MultiTouch applications. The core Widget class is a simple rectangle with an optional border. Here we also specify the size, location and color of each widget, so that they don't appear on top of each other. The widgets are added to the scene as children of the application main layer widget:

// Create 5 widgets, with different colors.
for(int i = 0; i < 5; i++) {
// Create a blank widget, with the application main widget as parent
auto w = MultiWidgets::create<MultiWidgets::Widget>(app.mainLayer());
// Set widget parameters:
w->setSize(Nimble::SizeF(100, 100));
w->setLocation(Nimble::Vector2(i * 50, i * 50));
// Create random colors for the widgets:
w->setBackgroundColor(Nimble::Vector4(1.0f, 1.0f - i * 0.2f, 0.3f, 0.97f));
}

Finally, we are ready to run the application and finish the block making up the main function:

// Run the application:
return app.run();
}

The full source code for the complete application is listed 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.
*
*/
#include <MultiWidgets/Application.hpp>
int main(int argc, char ** argv)
{
bool ok = app.init(argc, argv);
if(!ok)
return 1;
// Create 5 widgets, with different colors.
for(int i = 0; i < 5; i++) {
// Create a blank widget, with the application main widget as parent
auto w = MultiWidgets::create<MultiWidgets::Widget>(app.mainLayer());
// Set widget parameters:
w->setSize(Nimble::SizeF(100, 100));
w->setLocation(Nimble::Vector2(i * 50, i * 50));
// Create random colors for the widgets:
w->setBackgroundColor(Nimble::Vector4(1.0f, 1.0f - i * 0.2f, 0.3f, 0.97f));
}
// Run the application:
return app.run();
}