Adding Image View example demostrating changing, adding and removing ImageViews. 31/46731/20
authorChu Hoang <c.hoang@samsung.com>
Tue, 25 Aug 2015 10:27:09 +0000 (11:27 +0100)
committerChu Hoang <c.hoang@samsung.com>
Mon, 26 Oct 2015 13:57:14 +0000 (13:57 +0000)
Change-Id: I4a0238a90a26201086e412369da0170435e1a86b

com.samsung.dali-demo.xml
demo/dali-demo.cpp
examples/image-view/image-view-example.cpp [new file with mode: 0644]
resources/images/heartsframe.9.png [new file with mode: 0644]
shared/dali-demo-strings.h

index 238b33849e488f34df697c049523f2d63108025b..43daadd799b4cee21c5083341fdd7c51cf6f7313 100644 (file)
        <ui-application appid="gradients.example" exec="/usr/apps/com.samsung.dali-demo/bin/gradients.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
                <label>Color Gradient</label>
        </ui-application>
+       <ui-application appid="image-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/image-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
+               <label>Image View</label>
+       </ui-application>
 </manifest>
index 35eb91767a290520abfd9477526cf7c7d1dd7199..05aa4c307aa19a920566c2199956937aeae9e5dd 100644 (file)
@@ -66,6 +66,7 @@ int main(int argc, char **argv)
   demo.AddExample(Example("textured-mesh.example", DALI_DEMO_STR_TITLE_TEXTURED_MESH));
   demo.AddExample(Example("line-mesh.example", DALI_DEMO_STR_TITLE_LINE_MESH));
   demo.AddExample(Example("gradients.example", DALI_DEMO_STR_TITLE_COLOR_GRADIENT));
+  demo.AddExample(Example("image-view.example", DALI_DEMO_STR_TITLE_IMAGE_VIEW));
 
   demo.SortAlphabetically( true );
 
diff --git a/examples/image-view/image-view-example.cpp b/examples/image-view/image-view-example.cpp
new file mode 100644 (file)
index 0000000..e2779c2
--- /dev/null
@@ -0,0 +1,257 @@
+/*
+ * 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.
+ *
+ */
+
+#include "shared/view.h"
+#include <dali/dali.h>
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/slider/slider.h>
+
+using namespace Dali;
+
+namespace
+{
+
+const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" );
+const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
+const char* APPLICATION_TITLE( "Image view" );
+
+const char* IMAGE_PATH[] = {
+    DALI_IMAGE_DIR "blocks-ball.png",
+    DALI_IMAGE_DIR "gallery-small-23.jpg",
+    DALI_IMAGE_DIR "selection-popup-bg.2.9.png",
+    DALI_IMAGE_DIR "heartsframe.9.png",
+};
+
+const char* RESOURCE_IMAGE_PATH[] = {
+    DALI_IMAGE_DIR "contacts-image.png",
+    DALI_IMAGE_DIR "gallery-small-27.jpg",
+    DALI_IMAGE_DIR "selection-popup-bg.8.9.png",
+    DALI_IMAGE_DIR "heartsframe.9.png",
+};
+
+const unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*);
+const unsigned int NUM_RESOURCE_IMAGES = sizeof(RESOURCE_IMAGE_PATH) / sizeof(char*);
+
+const unsigned int COLUMNS = 3;
+const unsigned int ROWS = 4;
+
+}  // namespace
+
+class ImageViewController: public ConnectionTracker
+{
+ public:
+
+  ImageViewController( Application& application )
+    : mApplication( application ),
+      mCurrentPositionToggle( 0, 0 ),
+      mCurrentPositionImage( 0, 0 ),
+      mToggleOff( true ),
+      mUseResource( false ),
+      mImageIdx( 1 )
+  {
+    // Connect to the Application's Init signal
+    mApplication.InitSignal().Connect( this, &ImageViewController::Create );
+  }
+
+  ~ImageViewController()
+  {
+    // Nothing to do here
+  }
+
+  void Create( Application& application )
+  {
+    // The Init signal is received once (only) during the Application lifetime
+
+    // Creates a default view with a default tool bar.
+    // The view is added to the stage.
+    mContentLayer = DemoHelper::CreateView( application,
+                                            mView,
+                                            mToolBar,
+                                            BACKGROUND_IMAGE,
+                                            TOOLBAR_IMAGE,
+                                            APPLICATION_TITLE );
+
+
+    mTable = Toolkit::TableView::New( ROWS, COLUMNS );
+    mTable.SetAnchorPoint( AnchorPoint::CENTER );
+    mTable.SetParentOrigin( ParentOrigin::CENTER );
+    mTable.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
+    Vector3 offset( -50.0f, -350.0f, 0.0f );
+    mTable.SetSizeModeFactor( offset );
+
+    mContentLayer.Add( mTable );
+
+    for( unsigned int y = 0; y < ROWS; ++y )
+    {
+      for( unsigned int x = 0; x < COLUMNS; ++x )
+      {
+        mImageViews[x][y] = Toolkit::ImageView::New( IMAGE_PATH[ 0 ] );
+        mImageViews[x][y].SetParentOrigin( ParentOrigin::CENTER );
+        mImageViews[x][y].SetAnchorPoint( AnchorPoint::CENTER );
+        mImageViews[x][y].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+
+        mTable.AddChild( mImageViews[x][y], Toolkit::TableView::CellPosition( y, x ) );
+      }
+    }
+
+    Toolkit::TableView buttonsTable = Toolkit::TableView::New( 3, 1 );
+    buttonsTable.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+    buttonsTable.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+    buttonsTable.SetFitHeight( 0 );
+    buttonsTable.SetFitHeight( 1 );
+    buttonsTable.SetFitHeight( 2 );
+    buttonsTable.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+
+    Toolkit::PushButton button = Toolkit::PushButton::New();
+    button.SetLabelText( "Toggle on/off stage" );
+    button.SetParentOrigin( ParentOrigin::CENTER );
+    button.SetAnchorPoint( AnchorPoint::CENTER );
+    button.ClickedSignal().Connect( this, &ImageViewController::ToggleImageOnStage );
+    button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+    buttonsTable.AddChild( button, Toolkit::TableView::CellPosition( 0, 0 ) );
+
+    Toolkit::PushButton button2 = Toolkit::PushButton::New();
+    button2.SetLabelText( "Change Image" );
+    button2.SetParentOrigin( ParentOrigin::CENTER );
+    button2.SetAnchorPoint( AnchorPoint::CENTER );
+    button2.ClickedSignal().Connect( this, &ImageViewController::ChangeImageClicked );
+    button2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+    buttonsTable.AddChild( button2, Toolkit::TableView::CellPosition( 1, 0 ) );
+
+    Toolkit::CheckBoxButton button3 = Toolkit::CheckBoxButton::New();
+    button3.SetLabelText( "Use Resource Images" );
+    button3.SetParentOrigin( ParentOrigin::CENTER );
+    button3.SetAnchorPoint( AnchorPoint::CENTER );
+    button3.ClickedSignal().Connect( this, &ImageViewController::UseResourceImagesClicked );
+    button3.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+    buttonsTable.AddChild( button3, Toolkit::TableView::CellPosition( 2, 0 ) );
+
+    mContentLayer.Add(buttonsTable);
+  }
+
+private:
+  bool ToggleImageOnStage( Toolkit::Button button )
+  {
+    Toolkit::ImageView imageView =  mImageViews[ mCurrentPositionToggle.columnIndex ][ mCurrentPositionToggle.rowIndex ];
+
+    if( mToggleOff )
+    {
+      imageView.Unparent();
+    }
+    else
+    {
+      mTable.AddChild( imageView, mCurrentPositionToggle );
+    }
+
+    ++mCurrentPositionToggle.columnIndex;
+    if( mCurrentPositionToggle.columnIndex == COLUMNS )
+    {
+      mCurrentPositionToggle.columnIndex = 0;
+      ++mCurrentPositionToggle.rowIndex;
+    }
+    if( mCurrentPositionToggle.rowIndex == ROWS )
+    {
+      mCurrentPositionToggle.rowIndex = 0;
+      mToggleOff = !mToggleOff;
+    }
+
+    return true;
+  }
+
+  bool ChangeImageClicked( Toolkit::Button button )
+  {
+    Toolkit::ImageView imageView =  mImageViews[ mCurrentPositionImage.columnIndex ][ mCurrentPositionImage.rowIndex ];
+
+    if( mUseResource )
+    {
+      ResourceImage image = ResourceImage::New( RESOURCE_IMAGE_PATH[ mImageIdx ] );
+      imageView.SetImage( image );
+    }
+    else
+    {
+      imageView.SetImage( IMAGE_PATH[ mImageIdx ] );
+    }
+
+    ++mCurrentPositionImage.columnIndex;
+    if( mCurrentPositionImage.columnIndex == COLUMNS )
+    {
+      mCurrentPositionImage.columnIndex = 0;
+      ++mCurrentPositionImage.rowIndex;
+    }
+    if( mCurrentPositionImage.rowIndex == ROWS )
+    {
+      mCurrentPositionImage.rowIndex = 0;
+      ++mImageIdx;
+
+      int numImages = mUseResource ? NUM_RESOURCE_IMAGES : NUM_IMAGES;
+      if( mImageIdx == numImages )
+      {
+        mImageIdx = 0;
+      }
+    }
+
+    return true;
+  }
+
+  bool UseResourceImagesClicked( Toolkit::Button button )
+  {
+    mUseResource = !mUseResource;
+
+    int numImages = mUseResource ? NUM_RESOURCE_IMAGES : NUM_IMAGES;
+    if( mImageIdx >= numImages )
+    {
+      mImageIdx = 0;
+    }
+
+    return true;
+  }
+
+private:
+  Application&  mApplication;
+
+  Toolkit::Control           mView;                              ///< The View instance.
+  Toolkit::ToolBar           mToolBar;                           ///< The View's Toolbar.
+  Layer                      mContentLayer;                      ///< Content layer
+  Toolkit::TableView         mTable;
+  Toolkit::ImageView        mImageViews[ COLUMNS ][ ROWS ];
+
+  Toolkit::TableView::CellPosition mCurrentPositionToggle;
+  Toolkit::TableView::CellPosition mCurrentPositionImage;
+
+  bool mToggleOff;
+  bool mUseResource;
+  int mImageIdx;
+
+};
+
+void RunTest( Application& application )
+{
+  ImageViewController test( application );
+
+  application.MainLoop();
+}
+
+// Entry point for Linux & Tizen applications
+//
+int main( int argc, char **argv )
+{
+  Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH );
+
+  RunTest( application );
+
+  return 0;
+}
diff --git a/resources/images/heartsframe.9.png b/resources/images/heartsframe.9.png
new file mode 100644 (file)
index 0000000..9313d47
Binary files /dev/null and b/resources/images/heartsframe.9.png differ
index 9c624083a45897d52dcbce1972f97df09d647022..b2b10d92ef06b2cebfd69d6a24381122fe3f2730 100644 (file)
@@ -94,6 +94,7 @@ extern "C"
 #define DALI_DEMO_STR_TITLE_TEXTURED_MESH             "Mesh Texture"
 #define DALI_DEMO_STR_TITLE_LINE_MESH                 "Mesh Line"
 #define DALI_DEMO_STR_TITLE_COLOR_GRADIENT            "Color Gradient"
+#define DALI_DEMO_STR_TITLE_IMAGE_VIEW                "Image View"
 
 #endif