Include <cstdio> to compensate for core inclusion cleanup
[platform/core/uifw/dali-demo.git] / examples / builder / examples.cpp
index d3c7f05..e93a072 100644 (file)
@@ -33,6 +33,7 @@
 #include <boost/scoped_ptr.hpp>
 #include <dirent.h>
 #include <stdio.h>
+#include <iostream>
 
 //#include <boost/regex.hpp>
 #include "sys/stat.h"
@@ -280,6 +281,9 @@ public:
   {
     Stage stage = Stage::GetCurrent();
 
+    mTapDetector = TapGestureDetector::New();
+    mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap );
+
     if( mItemView )
     {
       stage.Remove( mItemView );
@@ -361,15 +365,6 @@ public:
       }
     }
 
-    mTapDetector = TapGestureDetector::New();
-
-    for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
-    {
-      mTapDetector.Attach( mItemView.GetChildAt(i) );
-    }
-
-    mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap );
-
     // Display item view on the stage
     stage.Add( mItemView );
 
@@ -393,7 +388,7 @@ public:
     SetTitle("View");
   }
 
-  void OnTap( Actor actor, TapGesture tap )
+  void OnTap( Actor actor, const TapGesture& tap )
   {
     ItemId id = mItemView.GetItemId( actor );
 
@@ -404,8 +399,19 @@ public:
   {
     TextView t = TextView::New();
     t.SetMarkupProcessingEnabled(true);
-    t.SetText( std::string("<font size=6>") + ShortName( text ) + std::string("</font>") );
+
+    int size = static_cast<int>(DemoHelper::ScalePointSize(6));
+
+    std::ostringstream fontString;
+    fontString << "<font size="<< size <<">"<<  ShortName( text ) << "</font>";
+
+    t.SetText( fontString.str() );
+
     t.SetTextAlignment( Alignment::HorizontalLeft );
+
+    // Hook up tap detector
+    mTapDetector.Attach( t );
+
     return t;
   }
 
@@ -424,8 +430,9 @@ public:
     Stage stage = Stage::GetCurrent();
 
     builder = Builder::New();
+    builder.QuitSignal().Connect( this, &ExampleApp::OnBuilderQuit );
 
-    PropertyValueMap defaultDirs;
+    Property::Map defaultDirs;
     defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ]  = DALI_IMAGE_DIR;
     defaultDirs[ TOKEN_STRING(DALI_MODEL_DIR) ]  = DALI_MODEL_DIR;
     defaultDirs[ TOKEN_STRING(DALI_SCRIPT_DIR) ] = DALI_SCRIPT_DIR;
@@ -526,7 +533,7 @@ public:
 
     // Create an edit mode button. (left of toolbar)
     Toolkit::PushButton editButton = Toolkit::PushButton::New();
-    editButton.SetBackgroundImage( Image::New( EDIT_IMAGE ) );
+    editButton.SetBackgroundImage( ResourceImage::New( EDIT_IMAGE ) );
     editButton.ClickedSignal().Connect( this, &ExampleApp::OnToolSelectLayout);
     editButton.SetLeaveRequired( true );
     mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING  );
@@ -559,11 +566,33 @@ public:
     {
       if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
       {
-        mApp.Quit();
+        if ( mItemView.IsVisible() )
+        {
+          mApp.Quit();
+        }
+        else
+        {
+          EnterSelection();
+        }
       }
     }
   }
 
+  /**
+   * Event handler when Builder wants to quit (we only want to close the shown json unless we're at the top-level)
+   */
+  void OnBuilderQuit()
+  {
+    if ( mItemView.IsVisible() )
+    {
+      mApp.Quit();
+    }
+    else
+    {
+      EnterSelection();
+    }
+  }
+
 private:
   Application& mApp;
 
@@ -600,9 +629,12 @@ private:
 //------------------------------------------------------------------------------
 int main(int argc, char **argv)
 {
-  if(argc > 1)
+  if(argc > 2)
   {
-    USER_DIRECTORY = argv[1];
+    if(strcmp(argv[1], "-f") == 0)
+    {
+      USER_DIRECTORY = argv[2];
+    }
   }
 
   Application app = Application::New(&argc, &argv);