Added example of actor depth order change 93/132993/3
authorDavid Steele <david.steele@samsung.com>
Thu, 8 Jun 2017 15:47:47 +0000 (16:47 +0100)
committerDavid Steele <david.steele@samsung.com>
Fri, 9 Jun 2017 15:16:19 +0000 (16:16 +0100)
Fixed up SVG example to ensure actor sibling order is set after
adding to the stage.

Change-Id: Ib532eba27be23afd636e34cc9776ae4fd2c5ca48

com.samsung.dali-demo.xml
examples-reel/dali-examples-reel.cpp
examples/image-view-svg/image-view-svg-example.cpp
examples/text-overlap/text-overlap-example.cpp [new file with mode: 0644]
examples/text-overlap/text-overlap-example.h [new file with mode: 0644]
resources/po/en_GB.po
resources/po/en_US.po
shared/dali-demo-strings.h

index a71c9a3c6a28e56fc96f7e7471e563b79e601323..b0887b8746633ca5330489f5d8b8e7dedd64be96 100644 (file)
        <ui-application appid="rendering-skybox.example" exec="/usr/apps/com.samsung.dali-demo/bin/rendering-skybox.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
                <label>Skybox</label>
        </ui-application>
+       <ui-application appid="text-overlap.example" exec="/usr/apps/com.samsung.dali-demo/bin/text-overlap.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
+               <label>Text Overlap</label>
+       </ui-application>
 </manifest>
index af4b9d0f695e9ebe1aded33316bb96f673904122..0c3f7cfe0dc75ea9b622c3334662acb95478d669 100644 (file)
@@ -79,6 +79,7 @@ int DALI_EXPORT_API main(int argc, char **argv)
   demo.AddExample(Example("text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL));
   demo.AddExample(Example("text-label-multi-language.example", DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE));
   demo.AddExample(Example("text-label-emojis.example", DALI_DEMO_STR_TITLE_EMOJI_TEXT));
+  demo.AddExample(Example("text-overlap.example", DALI_DEMO_STR_TITLE_TEXT_OVERLAP));
   demo.AddExample(Example("text-scrolling.example", DALI_DEMO_STR_TITLE_TEXT_SCROLLING));
   demo.AddExample(Example("textured-mesh.example", DALI_DEMO_STR_TITLE_TEXTURED_MESH));
   demo.AddExample(Example("tilt.example", DALI_DEMO_STR_TITLE_TILT_SENSOR));
index 613ecb752c49939a7a5046f8c6ef8a6a779fef35..a264ca510cbdf26934827951bd559d625957a037 100644 (file)
@@ -87,7 +87,6 @@ public:
     changeButton.SetParentOrigin( ParentOrigin::TOP_RIGHT );
     stage.Add( changeButton );
     changeButton.ClickedSignal().Connect( this, &ImageSvgController::OnChangeButtonClicked );
-    changeButton.SetProperty( DevelActor::Property::SIBLING_ORDER, 1 );
 
     // Push button, for resetting the actor size and position
     Toolkit::PushButton resetButton = Toolkit::PushButton::New();
@@ -96,7 +95,6 @@ public:
     resetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
     stage.Add( resetButton );
     resetButton.ClickedSignal().Connect( this, &ImageSvgController::OnResetButtonClicked );
-    resetButton.SetProperty( DevelActor::Property::SIBLING_ORDER, 1 );
 
     // Create and put imageViews to stage
     for( unsigned int i=0; i<4u; i++)
@@ -124,6 +122,9 @@ public:
     mPinchGestureDetector = PinchGestureDetector::New();
     mPinchGestureDetector.Attach( mStageBackground);
     mPinchGestureDetector.DetectedSignal().Connect(this, &ImageSvgController::OnPinch);
+
+    DevelActor::RaiseToTop(changeButton);
+    DevelActor::RaiseToTop(resetButton);
   }
 
   // Callback of push button, for changing image set
diff --git a/examples/text-overlap/text-overlap-example.cpp b/examples/text-overlap/text-overlap-example.cpp
new file mode 100644 (file)
index 0000000..560ebe0
--- /dev/null
@@ -0,0 +1,149 @@
+
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali/devel-api/actors/actor-devel.h>
+#include "text-overlap-example.h"
+
+#include <iostream>
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+static const int NUMBER_OF_LABELS(2);
+
+
+
+namespace Demo
+{
+
+TextOverlapController::TextOverlapController( Application& app )
+: mApplication( app ),
+  mTopmostLabel( 1 )
+{
+  app.InitSignal().Connect( this, &TextOverlapController::Create );
+  app.TerminateSignal().Connect( this, &TextOverlapController::Destroy );
+}
+
+void TextOverlapController::Create( Application& app )
+{
+  Stage stage = Stage::GetCurrent();
+  stage.KeyEventSignal().Connect( this, &TextOverlapController::OnKeyEvent );
+
+  Vector2 stageSize = stage.GetSize();
+
+  mLabels[0] = TextLabel::New("Text Label 1");
+  mLabels[1] = TextLabel::New("Text Label 2");
+
+  mLabels[0].SetName("Label1");
+  mLabels[1].SetName("Label2");
+
+  mLabels[0].SetProperty( DevelActor::Property::SIBLING_ORDER, 1 );
+  mLabels[1].SetProperty( DevelActor::Property::SIBLING_ORDER, 2 );
+
+  mLabels[0].SetProperty( Control::Property::BACKGROUND, Color::RED );
+  mLabels[1].SetProperty( Control::Property::BACKGROUND, Color::YELLOW );
+
+  for(int i=0; i<NUMBER_OF_LABELS; ++i )
+  {
+    mLabels[i].SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+    mLabels[i].SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    mLabels[i].SetParentOrigin( ParentOrigin::TOP_LEFT );
+    mLabels[i].SetPosition( 0, (i*2+1) * stageSize.height * 0.25f );
+  }
+
+  stage.Add( mLabels[0] );
+  stage.Add( mLabels[1] );
+
+  mSwapButton = PushButton::New();
+  mSwapButton.SetProperty( Button::Property::LABEL, "Swap depth order");
+  mSwapButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+  mSwapButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+  mSwapButton.ClickedSignal().Connect( this, &TextOverlapController::OnClicked );
+  mSwapButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+  mSwapButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
+  stage.Add( mSwapButton );
+
+
+  Layer rootLayer = stage.GetRootLayer();
+  rootLayer.SetName("RootLayer");
+
+  mPanDetector = PanGestureDetector::New();
+  mPanDetector.Attach( rootLayer );
+  mPanDetector.AddAngle( Radian(-0.5f * Math::PI ));
+  mPanDetector.AddAngle( Radian( 0.5f * Math::PI ));
+  mPanDetector.DetectedSignal().Connect( this, &TextOverlapController::OnPan );
+}
+
+void TextOverlapController::OnPan( Actor actor, const PanGesture& gesture )
+{
+  if( ! mGrabbedActor || gesture.state == PanGesture::Started )
+  {
+    for( int i=0; i<NUMBER_OF_LABELS; ++i )
+    {
+      Vector3 position = mLabels[i].GetCurrentPosition();
+      Vector3 size = mLabels[i].GetCurrentSize();
+      if( gesture.position.y > position.y - size.y * 0.5f &&
+          gesture.position.y <= position.y + size.y * 0.5f )
+      {
+        mGrabbedActor = mLabels[i];
+        break;
+      }
+    }
+  }
+  else if( mGrabbedActor && gesture.state == PanGesture::Continuing )
+  {
+    Vector2 stageSize = Stage::GetCurrent().GetSize();
+    Vector3 size = mGrabbedActor.GetCurrentSize();
+    float y = Clamp( gesture.position.y, size.y * 0.5f, stageSize.y - size.y*0.5f );
+    mGrabbedActor.SetPosition( 0, y );
+  }
+  else
+  {
+    mGrabbedActor.Reset();
+  }
+}
+
+void TextOverlapController::Destroy( Application& app )
+{
+  mPanDetector.DetachAll();
+  UnparentAndReset(mLabels[0]);
+  UnparentAndReset(mLabels[1]);
+  mGrabbedActor.Reset();
+}
+
+bool TextOverlapController::OnClicked( Button button )
+{
+  mTopmostLabel = 1-mTopmostLabel; // toggles between 0 and 1
+  DevelActor::RaiseToTop(mLabels[mTopmostLabel]);
+  return false;
+}
+
+
+void TextOverlapController::OnKeyEvent( const KeyEvent& keyEvent )
+{
+  if( keyEvent.state == KeyEvent::Down &&
+      ( IsKey( keyEvent, DALI_KEY_BACK ) ||
+        IsKey( keyEvent, DALI_KEY_ESCAPE ) ) )
+  {
+    mApplication.Quit();
+  }
+  else
+  {
+    Dali::Layer l = Dali::Stage::GetCurrent().GetRootLayer();
+    int so = l.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER);
+    l.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, so+1);
+  }
+}
+
+
+} // namespace Demo
+
+
+int main( int argc, char** argv )
+{
+  {
+    Application app = Application::New( &argc, &argv );
+    Demo::TextOverlapController controller( app );
+    app.MainLoop();
+  }
+  exit( 0 );
+}
diff --git a/examples/text-overlap/text-overlap-example.h b/examples/text-overlap/text-overlap-example.h
new file mode 100644 (file)
index 0000000..b15f67d
--- /dev/null
@@ -0,0 +1,28 @@
+#pragma once
+
+namespace Demo
+{
+
+class TextOverlapController : public Dali::ConnectionTracker
+{
+public:
+  TextOverlapController( Dali::Application& app );
+
+private:
+  void Create( Dali::Application& app );
+  void Create2();
+  void Destroy( Dali::Application& app );
+  void OnPan( Dali::Actor actor, const Dali::PanGesture& gesture );
+  void OnKeyEvent( const Dali::KeyEvent& keyEvent );
+  bool OnClicked( Dali::Toolkit::Button button );
+
+private:
+  Dali::Application& mApplication;
+  Dali::Toolkit::TextLabel mLabels[2];
+  Dali::PanGestureDetector mPanDetector;
+  Dali::Actor mGrabbedActor;
+  Dali::Toolkit::Button mSwapButton;
+  int mTopmostLabel;
+};
+
+}
index 7bd406512897ce5fdaf583dafa8e2f811faed4f9..d3110d96013a66ea5b25c35625075deba7b5f00d 100755 (executable)
@@ -145,6 +145,9 @@ msgstr "Text Field"
 msgid "DALI_DEMO_STR_TITLE_TEXT_LABEL"
 msgstr "Text Label"
 
+msgid "DALI_DEMO_STR_TITLE_TEXT_OVERLAP"
+msgstr "Text Overlap"
+
 msgid "DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE"
 msgstr "Text Scripts"
 
index a1f44eaf4375622a9b29dd81156bbe5522c1649e..2fe350f81650e9e07a09bb0380f8f35b378e17df 100755 (executable)
@@ -145,6 +145,9 @@ msgstr "Text Field"
 msgid "DALI_DEMO_STR_TITLE_TEXT_LABEL"
 msgstr "Text Label"
 
+msgid "DALI_DEMO_STR_TITLE_TEXT_OVERLAP"
+msgstr "Text Overlap"
+
 msgid "DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE"
 msgstr "Text Scripts"
 
index ab83d1f1a79752dfa0623e888dd05ce2fe397b1d..4f6bac61a206be5a9a66925e7f54ee22f85991e2 100644 (file)
@@ -89,6 +89,7 @@ extern "C"
 #define DALI_DEMO_STR_TITLE_TEXT_EDITOR                 dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_EDITOR")
 #define DALI_DEMO_STR_TITLE_TEXT_FIELD                  dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_FIELD")
 #define DALI_DEMO_STR_TITLE_TEXT_LABEL                  dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL")
+#define DALI_DEMO_STR_TITLE_TEXT_OVERLAP                dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_OVERLAP")
 #define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE   dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE")
 #define DALI_DEMO_STR_TITLE_TEXT_SCROLLING              dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_SCROLLING")
 #define DALI_DEMO_STR_TITLE_TILT_SENSOR                 dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TILT_SENSOR")
@@ -154,6 +155,7 @@ extern "C"
 #define DALI_DEMO_STR_TITLE_TEXT_EDITOR                 "Text Editor"
 #define DALI_DEMO_STR_TITLE_TEXT_FIELD                  "Text Field"
 #define DALI_DEMO_STR_TITLE_TEXT_LABEL                  "Text Label"
+#define DALI_DEMO_STR_TITLE_TEXT_OVERLAP                "Text Overlap"
 #define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE   "Text Scripts"
 #define DALI_DEMO_STR_TITLE_TEXT_SCROLLING              "Text Scrolling"
 #define DALI_DEMO_STR_TITLE_TILT_SENSOR                 "Tilt Sensor"