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

The AutoRotate example will show you how to add a simple operator to a widget.

AutoRotate-screenshot.png
Screenshot of the AutoRotate example, initially widgets are upside down.

We will start by creating five TextWidgets and adding them to the scene.

for(int i = 0; i < 5; i++) {
MultiWidgets::TextWidgetPtr textwidget = MultiWidgets::create<MultiWidgets::TextWidget>(
"Put one hand on the widget and "
"keep it there. The widget will rotate "
"automatically to match your hand.");
app.mainLayer()->addChild(textwidget);

Next we will add a RotateTowardsHandsOperator to each one of the widgets. As the name implies, this operator is used to make widget automatically rotate towards the users hand, if the hand and widget rotation differ enough. Operators are added as shared pointers to make sure that they will get deleted automatically after no longer referenced.

textwidget->addOperator(
std::make_shared<MultiWidgets::RotateTowardsHandsOperator>());

There is no limit how many operators widget can have. See MultiWidgets-namespace for more operators.

The full source code for the 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>
#include <MultiWidgets/RotateTowardsHandsOperator.hpp>
#include <MultiWidgets/TextWidget.hpp>
int main(int argc, char ** argv)
{
if(!app.init(argc, argv))
return 1;
for(int i = 0; i < 5; i++) {
MultiWidgets::TextWidgetPtr textwidget = MultiWidgets::create<MultiWidgets::TextWidget>(
"Put one hand on the widget and "
"keep it there. The widget will rotate "
"automatically to match your hand.");
app.mainLayer()->addChild(textwidget);
textwidget->addOperator(
std::make_shared<MultiWidgets::RotateTowardsHandsOperator>());
textwidget->setBackgroundColor(0, 0, 1, 0.8f);
textwidget->setSize(300, 300);
textwidget->setLocation(i * 70, i * 70);
// Rotate widgets 180 degrees
textwidget->setRotationAboutCenter(Nimble::Math::PI);
}
app.run();
return 0;
}