X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=docs%2Fcontent%2Fprogramming-guide%2Fhello-world.h;h=d0cabd740ca26a9e13cdf96829a6eb6fd6b726d3;hp=8031d998376be0641ff32d8078870a003ebce83c;hb=e4a3c7b18f3a6168ec3967d4881663f7ed54f8d5;hpb=01864cd4216d958c5f0e95643dbbeca7c9937716 diff --git a/docs/content/programming-guide/hello-world.h b/docs/content/programming-guide/hello-world.h index 8031d99..d0cabd7 100644 --- a/docs/content/programming-guide/hello-world.h +++ b/docs/content/programming-guide/hello-world.h @@ -1,67 +1,82 @@ /*! \page hello-world Hello World - explained -The following steps are required for displaying the sentence 'Hello World' with Dali: +The following steps are required for displaying the sentence 'Hello World' with DALi: -- initialize the Dali library +- initialize the DALi library - create an Actor showing text - add it to the Stage -To understand the basic building blocks of the UI make sure to read the chapter on \link fundamentals Dali Fundamentals\endlink first. +To understand the basic building blocks of the UI make sure to read the chapter on \link fundamentals DALi Fundamentals\endlink first. Let's take a look at the code for this test application.

Example code

\code -#include -using namespace Dali; +#include -/****************************************************** - * Demonstrates how to display "Hello World" on screen - ******************************************************/ +using namespace Dali; +using Dali::Toolkit::TextLabel; -class ExampleApp +// This example shows how to create and display Hello World! using a simple TextActor +// +class HelloWorldController : public ConnectionTracker { public: - ExampleApp(Application &app) - : mApp(app) + + HelloWorldController( Application& application ) + : mApplication( application ) { - // Connect to Dali::Application init signal. Do not make calls to Dali before this signal is received. - app.SignalInit().Connect(this, &ExampleApp::Create); + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &HelloWorldController::Create ); } - ~ExampleApp() + ~HelloWorldController() { - // Remove Hello World TextActor from stage - Stage::GetCurrent().Remove(mTextActor); + // Remove Hello World actor from stage + Stage::GetCurrent().Remove(mTextLabel); } -public: - - void Create(Application& app) + // The Init signal is received once (only) during the Application lifetime + void Create( Application& application ) { - // Initialize the actor - mTextActor = TextActor::New("Hello World"); + // Get a handle to the stage + Stage stage = Stage::GetCurrent(); + + mTextLabel = TextLabel::New( "Hello World" ); + mTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + stage.Add( mTextLabel ); - // Center the actor. Note: default anchor point is CENTER - mTextActor.SetParentOrigin(ParentOrigin::CENTER); + // Respond to a click anywhere on the stage + stage.GetRootLayer().TouchedSignal().Connect( this, &HelloWorldController::OnTouch ); + } - // Display the actor on the stage - Stage::GetCurrent().Add(mTextActor); + bool OnTouch( Actor actor, const TouchEvent& touch ) + { + // quit the application + mApplication.Quit(); + return true; } private: - Application& mApp; - TextActor mTextActor; + Application& mApplication; + TextLabel mTextLabel; }; -int -main(int argc, char **argv) +void RunTest( Application& application ) +{ + HelloWorldController test( application ); + + application.MainLoop(); +} + +// Entry point for Linux & Tizen applications +// +int main( int argc, char **argv ) { - Application daliApp(&argc, &argv); + Application application = Application::New( &argc, &argv ); - ExampleApp helloApp (daliApp); - daliApp.MainLoop(); + RunTest( application ); return 0; } @@ -70,8 +85,8 @@ main(int argc, char **argv) There are a couple of steps which are very important to understand. -

Initializing Dali

- The application should not use the Dali library until it has sent the init complete signal! +

Initializing DALi

+ The application should not use the DALi library until it has sent the init complete signal! That's why we connect our ExampleApp::Create callback to Dali::Application's SignalInit signal: \code ... @@ -81,14 +96,14 @@ main(int argc, char **argv)

Reference counting

The application should store Actors' and resources' handles. - Dali objects are reference counted, which makes sure they exist only as long as they are needed. + DALi objects are reference counted, which makes sure they exist only as long as they are needed. That's why we store the Actor's handle: \code ... - mTextActor = TextActor::New("Hello World"); + mTextLabel = TextLabel::New("Hello World"); ... \endcode - Even if the TextActor is removed from the stage, it will be kept alive through our reference.\n + Even if the TextLabel is removed from the stage, it will be kept alive through our reference.\n You can read more about implicit smart-pointer semantics in chapter \link handle-body-idiom Handle – body\endlink.

Main loop

@@ -107,6 +122,12 @@ main(int argc, char **argv) After running './hello' this should be visible on the screen: - \image html Text-Actor.png "Hello world example" + + + + +
+ \image html Text-Label.png "Hello world example" +
*/