Text Field Scrolling Message Demo 98/38198/3
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Tue, 24 Mar 2015 11:00:52 +0000 (11:00 +0000)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Wed, 15 Apr 2015 15:10:15 +0000 (16:10 +0100)
Change-Id: I71b1150a76099b136e1157734269f78ebc7e47a0
Signed-off-by: Agnelo Vaz <agnelo.vaz@samsung.com>
com.samsung.dali-demo.xml
examples/text-field/text-field-example.cpp
examples/text-message-field/text-message-field-example.cpp [new file with mode: 0644]
resources/images/message-field-box.png [new file with mode: 0644]
resources/images/woodEffect.jpg [new file with mode: 0644]

index c47a615..c68fba7 100644 (file)
@@ -85,6 +85,9 @@
        <ui-application appid="text-field.example" exec="/usr/apps/com.samsung.dali-demo/bin/text-field.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
                <label>Text Label</label>
        </ui-application>
+       <ui-application appid="text-message-field.example" exec="/usr/apps/com.samsung.dali-demo/bin/text-message-field.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
+               <label>Text Label</label>
+       </ui-application>
        <ui-application appid="logging.example" exec="/usr/apps/com.samsung.dali-demo/bin/logging.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
                <label>Logging</label>
        </ui-application>
index 0bc8e70..dfcd06a 100644 (file)
@@ -87,8 +87,10 @@ public:
     mContainer.Add( field );
 
     field.SetProperty( TextField::Property::TEXT, "Hello" );
+    field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( BORDER_WIDTH, BORDER_WIDTH, stageSize.width - BORDER_WIDTH*2, stageSize.height - BORDER_WIDTH*2 ) );
 
     Property::Value fieldText = field.GetProperty( TextField::Property::TEXT );
+
     std::cout << "Displaying text: " << fieldText.Get< std::string >() << std::endl;
   }
 
diff --git a/examples/text-message-field/text-message-field-example.cpp b/examples/text-message-field/text-message-field-example.cpp
new file mode 100644 (file)
index 0000000..37eb6a1
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * @file message-field-example.cpp
+ * @brief Basic usage of TextField control
+ */
+
+// EXTERNAL INCLUDES
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali/public-api/text-abstraction/text-abstraction.h>
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+namespace
+{
+  const char* DESKTOP_IMAGE( DALI_IMAGE_DIR "woodEffect.jpg" );
+  const Vector2 DESKTOP_SIZE( Vector2( 1440, 1600 ) );
+  const Vector2 PHOTOBOX_SIZE( Vector2(330.0f, 80.0f ) );
+  const float MAX_OFFSCREEN_RENDERING_SIZE = 2048.f;
+  const float SCREEN_BORDER = 5.0f; // Border around screen that Popups and handles will not exceed
+}
+/**
+ * @brief The main class of the demo.
+ */
+class TextMessageFieldExample : public ConnectionTracker
+{
+public:
+
+  TextMessageFieldExample( Application& application )
+  : mApplication( application ),
+    mTargetActorPosition(),
+    mTargetActorSize()
+  {
+    // Connect to the Application's Init signal
+    mApplication.InitSignal().Connect( this, &TextMessageFieldExample::Create );
+  }
+
+  ~TextMessageFieldExample()
+  {
+    // Nothing to do here.
+  }
+
+  /**
+   * One-time setup in response to Application InitSignal.
+   */
+  void Create( Application& application )
+  {
+    Stage stage = Stage::GetCurrent();
+    mStageSize = stage.GetSize();
+
+    stage.KeyEventSignal().Connect(this, &TextMessageFieldExample::OnKeyEvent);
+
+    // Create Root actor
+    Actor rootActor = Actor::New();
+    rootActor.SetName("rootActor");
+    rootActor.SetResizePolicy( ResizePolicy::FIXED,  Dimension::ALL_DIMENSIONS );
+    rootActor.SetSize( mStageSize );
+    rootActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+    stage.Add( rootActor );
+
+    const Size mTargetActorSize( mStageSize.width, DESKTOP_SIZE.height );
+
+    // Create Desktop
+    ResourceImage backgroundImage = ResourceImage::New( DESKTOP_IMAGE );
+    ImageActor desktop = ImageActor::New( backgroundImage );
+    desktop.SetName("desktopActor");
+    desktop.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    desktop.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+    desktop.SetSize( mTargetActorSize );
+
+    rootActor.Add( desktop ); // Add desktop (content) to offscreen actor
+
+    // Create Photo Box A
+    ImageActor photoBoxA = CreateSolidColorActor( Vector4(0,0,0,0), true, Color::WHITE, 1 );
+    photoBoxA.SetName("photoBoxA");
+    photoBoxA.SetAnchorPoint( AnchorPoint::CENTER );
+    photoBoxA.SetParentOrigin( ParentOrigin::CENTER );
+    photoBoxA.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+    photoBoxA.SetSize( PHOTOBOX_SIZE );
+    photoBoxA.SetPosition( 0.0f, -500.0f, 1.0f );
+    desktop.Add( photoBoxA );
+
+    // Create TextField
+    TextField field = TextField::New();
+    field.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+    field.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+    field.SetPadding( Padding( 1.0f, 1.0f, 1.0f, 1.0f ) );
+    field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    field.SetZ( 1.0f );
+    field.SetProperty( TextField::Property::TEXT, "Enter Title name"  );
+    field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( SCREEN_BORDER, SCREEN_BORDER, mStageSize.width - SCREEN_BORDER*2, mStageSize.height - SCREEN_BORDER*2 ) );
+    photoBoxA.Add( field );
+
+    mPanGestureDetector = PanGestureDetector::New();
+    mPanGestureDetector.DetectedSignal().Connect(this, &TextMessageFieldExample::OnPanGesture );
+    mPanGestureDetector.Attach( desktop );
+  }
+
+  /**
+   * Main key event handler
+   */
+  void OnKeyEvent(const KeyEvent& event)
+  {
+    if(event.state == KeyEvent::Down)
+    {
+      if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
+      {
+        mApplication.Quit();
+      }
+    }
+  }
+
+  void OnPanGesture( Actor actor, const PanGesture& gesture )
+  {
+    if( gesture.state == Gesture::Continuing )
+    {
+      Vector2 position = Vector2( gesture.displacement );
+      mTargetActorPosition.y = mTargetActorPosition.y + position.y;
+      mTargetActorPosition.y = std::min( mTargetActorPosition.y, -mTargetActorSize.height );
+      mTargetActorPosition.y = std::max( mTargetActorPosition.y, ( mTargetActorSize.height - mStageSize.height*0.25f ) );
+      actor.SetPosition( 0.0f, mTargetActorPosition.y );
+    }
+  }
+
+private:
+
+  Application& mApplication;
+  PanGestureDetector mPanGestureDetector;
+
+  Vector2 mTargetActorPosition;
+  Vector2 mTargetActorSize;
+  Vector2 mStageSize;
+};
+
+void RunTest( Application& application )
+{
+  TextMessageFieldExample test( application );
+
+  application.MainLoop();
+}
+
+/** Entry point for Linux & Tizen applications */
+int main( int argc, char **argv )
+{
+  Application application = Application::New( &argc, &argv );
+
+  RunTest( application );
+
+  return 0;
+}
diff --git a/resources/images/message-field-box.png b/resources/images/message-field-box.png
new file mode 100644 (file)
index 0000000..71cddc6
Binary files /dev/null and b/resources/images/message-field-box.png differ
diff --git a/resources/images/woodEffect.jpg b/resources/images/woodEffect.jpg
new file mode 100644 (file)
index 0000000..cb086be
Binary files /dev/null and b/resources/images/woodEffect.jpg differ