Commit 9a38745c71d57fe4d8926c3d776a835f946d025e

Authored by Chu Hoang
1 parent f9c08e2e

Adding Image View example demostrating changing, adding and removing ImageViews.

Change-Id: I4a0238a90a26201086e412369da0170435e1a86b
com.samsung.dali-demo.xml
... ... @@ -115,4 +115,7 @@
115 115 <ui-application appid="gradients.example" exec="/usr/apps/com.samsung.dali-demo/bin/gradients.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
116 116 <label>Color Gradient</label>
117 117 </ui-application>
  118 + <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">
  119 + <label>Image View</label>
  120 + </ui-application>
118 121 </manifest>
... ...
demo/dali-demo.cpp
... ... @@ -66,6 +66,7 @@ int main(int argc, char **argv)
66 66 demo.AddExample(Example("textured-mesh.example", DALI_DEMO_STR_TITLE_TEXTURED_MESH));
67 67 demo.AddExample(Example("line-mesh.example", DALI_DEMO_STR_TITLE_LINE_MESH));
68 68 demo.AddExample(Example("gradients.example", DALI_DEMO_STR_TITLE_COLOR_GRADIENT));
  69 + demo.AddExample(Example("image-view.example", DALI_DEMO_STR_TITLE_IMAGE_VIEW));
69 70  
70 71 demo.SortAlphabetically( true );
71 72  
... ...
examples/image-view/image-view-example.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + *
  16 + */
  17 +
  18 +#include "shared/view.h"
  19 +#include <dali/dali.h>
  20 +#include <dali-toolkit/dali-toolkit.h>
  21 +#include <dali-toolkit/devel-api/controls/slider/slider.h>
  22 +
  23 +using namespace Dali;
  24 +
  25 +namespace
  26 +{
  27 +
  28 +const char* BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-gradient.jpg" );
  29 +const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
  30 +const char* APPLICATION_TITLE( "Image view" );
  31 +
  32 +const char* IMAGE_PATH[] = {
  33 + DALI_IMAGE_DIR "blocks-ball.png",
  34 + DALI_IMAGE_DIR "gallery-small-23.jpg",
  35 + DALI_IMAGE_DIR "selection-popup-bg.2.9.png",
  36 + DALI_IMAGE_DIR "heartsframe.9.png",
  37 +};
  38 +
  39 +const char* RESOURCE_IMAGE_PATH[] = {
  40 + DALI_IMAGE_DIR "contacts-image.png",
  41 + DALI_IMAGE_DIR "gallery-small-27.jpg",
  42 + DALI_IMAGE_DIR "selection-popup-bg.8.9.png",
  43 + DALI_IMAGE_DIR "heartsframe.9.png",
  44 +};
  45 +
  46 +const unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*);
  47 +const unsigned int NUM_RESOURCE_IMAGES = sizeof(RESOURCE_IMAGE_PATH) / sizeof(char*);
  48 +
  49 +const unsigned int COLUMNS = 3;
  50 +const unsigned int ROWS = 4;
  51 +
  52 +} // namespace
  53 +
  54 +class ImageViewController: public ConnectionTracker
  55 +{
  56 + public:
  57 +
  58 + ImageViewController( Application& application )
  59 + : mApplication( application ),
  60 + mCurrentPositionToggle( 0, 0 ),
  61 + mCurrentPositionImage( 0, 0 ),
  62 + mToggleOff( true ),
  63 + mUseResource( false ),
  64 + mImageIdx( 1 )
  65 + {
  66 + // Connect to the Application's Init signal
  67 + mApplication.InitSignal().Connect( this, &ImageViewController::Create );
  68 + }
  69 +
  70 + ~ImageViewController()
  71 + {
  72 + // Nothing to do here
  73 + }
  74 +
  75 + void Create( Application& application )
  76 + {
  77 + // The Init signal is received once (only) during the Application lifetime
  78 +
  79 + // Creates a default view with a default tool bar.
  80 + // The view is added to the stage.
  81 + mContentLayer = DemoHelper::CreateView( application,
  82 + mView,
  83 + mToolBar,
  84 + BACKGROUND_IMAGE,
  85 + TOOLBAR_IMAGE,
  86 + APPLICATION_TITLE );
  87 +
  88 +
  89 + mTable = Toolkit::TableView::New( ROWS, COLUMNS );
  90 + mTable.SetAnchorPoint( AnchorPoint::CENTER );
  91 + mTable.SetParentOrigin( ParentOrigin::CENTER );
  92 + mTable.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
  93 + Vector3 offset( -50.0f, -350.0f, 0.0f );
  94 + mTable.SetSizeModeFactor( offset );
  95 +
  96 + mContentLayer.Add( mTable );
  97 +
  98 + for( unsigned int y = 0; y < ROWS; ++y )
  99 + {
  100 + for( unsigned int x = 0; x < COLUMNS; ++x )
  101 + {
  102 + mImageViews[x][y] = Toolkit::ImageView::New( IMAGE_PATH[ 0 ] );
  103 + mImageViews[x][y].SetParentOrigin( ParentOrigin::CENTER );
  104 + mImageViews[x][y].SetAnchorPoint( AnchorPoint::CENTER );
  105 + mImageViews[x][y].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
  106 +
  107 + mTable.AddChild( mImageViews[x][y], Toolkit::TableView::CellPosition( y, x ) );
  108 + }
  109 + }
  110 +
  111 + Toolkit::TableView buttonsTable = Toolkit::TableView::New( 3, 1 );
  112 + buttonsTable.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  113 + buttonsTable.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
  114 + buttonsTable.SetFitHeight( 0 );
  115 + buttonsTable.SetFitHeight( 1 );
  116 + buttonsTable.SetFitHeight( 2 );
  117 + buttonsTable.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
  118 +
  119 + Toolkit::PushButton button = Toolkit::PushButton::New();
  120 + button.SetLabelText( "Toggle on/off stage" );
  121 + button.SetParentOrigin( ParentOrigin::CENTER );
  122 + button.SetAnchorPoint( AnchorPoint::CENTER );
  123 + button.ClickedSignal().Connect( this, &ImageViewController::ToggleImageOnStage );
  124 + button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
  125 + buttonsTable.AddChild( button, Toolkit::TableView::CellPosition( 0, 0 ) );
  126 +
  127 + Toolkit::PushButton button2 = Toolkit::PushButton::New();
  128 + button2.SetLabelText( "Change Image" );
  129 + button2.SetParentOrigin( ParentOrigin::CENTER );
  130 + button2.SetAnchorPoint( AnchorPoint::CENTER );
  131 + button2.ClickedSignal().Connect( this, &ImageViewController::ChangeImageClicked );
  132 + button2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
  133 + buttonsTable.AddChild( button2, Toolkit::TableView::CellPosition( 1, 0 ) );
  134 +
  135 + Toolkit::CheckBoxButton button3 = Toolkit::CheckBoxButton::New();
  136 + button3.SetLabelText( "Use Resource Images" );
  137 + button3.SetParentOrigin( ParentOrigin::CENTER );
  138 + button3.SetAnchorPoint( AnchorPoint::CENTER );
  139 + button3.ClickedSignal().Connect( this, &ImageViewController::UseResourceImagesClicked );
  140 + button3.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
  141 + buttonsTable.AddChild( button3, Toolkit::TableView::CellPosition( 2, 0 ) );
  142 +
  143 + mContentLayer.Add(buttonsTable);
  144 + }
  145 +
  146 +private:
  147 + bool ToggleImageOnStage( Toolkit::Button button )
  148 + {
  149 + Toolkit::ImageView imageView = mImageViews[ mCurrentPositionToggle.columnIndex ][ mCurrentPositionToggle.rowIndex ];
  150 +
  151 + if( mToggleOff )
  152 + {
  153 + imageView.Unparent();
  154 + }
  155 + else
  156 + {
  157 + mTable.AddChild( imageView, mCurrentPositionToggle );
  158 + }
  159 +
  160 + ++mCurrentPositionToggle.columnIndex;
  161 + if( mCurrentPositionToggle.columnIndex == COLUMNS )
  162 + {
  163 + mCurrentPositionToggle.columnIndex = 0;
  164 + ++mCurrentPositionToggle.rowIndex;
  165 + }
  166 + if( mCurrentPositionToggle.rowIndex == ROWS )
  167 + {
  168 + mCurrentPositionToggle.rowIndex = 0;
  169 + mToggleOff = !mToggleOff;
  170 + }
  171 +
  172 + return true;
  173 + }
  174 +
  175 + bool ChangeImageClicked( Toolkit::Button button )
  176 + {
  177 + Toolkit::ImageView imageView = mImageViews[ mCurrentPositionImage.columnIndex ][ mCurrentPositionImage.rowIndex ];
  178 +
  179 + if( mUseResource )
  180 + {
  181 + ResourceImage image = ResourceImage::New( RESOURCE_IMAGE_PATH[ mImageIdx ] );
  182 + imageView.SetImage( image );
  183 + }
  184 + else
  185 + {
  186 + imageView.SetImage( IMAGE_PATH[ mImageIdx ] );
  187 + }
  188 +
  189 + ++mCurrentPositionImage.columnIndex;
  190 + if( mCurrentPositionImage.columnIndex == COLUMNS )
  191 + {
  192 + mCurrentPositionImage.columnIndex = 0;
  193 + ++mCurrentPositionImage.rowIndex;
  194 + }
  195 + if( mCurrentPositionImage.rowIndex == ROWS )
  196 + {
  197 + mCurrentPositionImage.rowIndex = 0;
  198 + ++mImageIdx;
  199 +
  200 + int numImages = mUseResource ? NUM_RESOURCE_IMAGES : NUM_IMAGES;
  201 + if( mImageIdx == numImages )
  202 + {
  203 + mImageIdx = 0;
  204 + }
  205 + }
  206 +
  207 + return true;
  208 + }
  209 +
  210 + bool UseResourceImagesClicked( Toolkit::Button button )
  211 + {
  212 + mUseResource = !mUseResource;
  213 +
  214 + int numImages = mUseResource ? NUM_RESOURCE_IMAGES : NUM_IMAGES;
  215 + if( mImageIdx >= numImages )
  216 + {
  217 + mImageIdx = 0;
  218 + }
  219 +
  220 + return true;
  221 + }
  222 +
  223 +private:
  224 + Application& mApplication;
  225 +
  226 + Toolkit::Control mView; ///< The View instance.
  227 + Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
  228 + Layer mContentLayer; ///< Content layer
  229 + Toolkit::TableView mTable;
  230 + Toolkit::ImageView mImageViews[ COLUMNS ][ ROWS ];
  231 +
  232 + Toolkit::TableView::CellPosition mCurrentPositionToggle;
  233 + Toolkit::TableView::CellPosition mCurrentPositionImage;
  234 +
  235 + bool mToggleOff;
  236 + bool mUseResource;
  237 + int mImageIdx;
  238 +
  239 +};
  240 +
  241 +void RunTest( Application& application )
  242 +{
  243 + ImageViewController test( application );
  244 +
  245 + application.MainLoop();
  246 +}
  247 +
  248 +// Entry point for Linux & Tizen applications
  249 +//
  250 +int main( int argc, char **argv )
  251 +{
  252 + Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH );
  253 +
  254 + RunTest( application );
  255 +
  256 + return 0;
  257 +}
... ...
resources/images/heartsframe.9.png 0 → 100644

21.2 KB

shared/dali-demo-strings.h
... ... @@ -94,6 +94,7 @@ extern &quot;C&quot;
94 94 #define DALI_DEMO_STR_TITLE_TEXTURED_MESH "Mesh Texture"
95 95 #define DALI_DEMO_STR_TITLE_LINE_MESH "Mesh Line"
96 96 #define DALI_DEMO_STR_TITLE_COLOR_GRADIENT "Color Gradient"
  97 +#define DALI_DEMO_STR_TITLE_IMAGE_VIEW "Image View"
97 98  
98 99 #endif
99 100  
... ...