Commit 339c999ee52243b5d22cef793e18efdcbac8f605
1 parent
0ba76b77
Changed Item View example to no longer use ImageActor or a custom texture atlas.
Change-Id: I819cd9de6ff49c0d86046aa4f2738f87f21c4a16
Showing
1 changed file
with
45 additions
and
72 deletions
examples/item-view/item-view-example.cpp
| ... | ... | @@ -16,17 +16,10 @@ |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | #include <sstream> |
| 19 | -#include <iostream> | |
| 20 | -#include <vector> | |
| 21 | -#include <string> | |
| 22 | -#include <algorithm> | |
| 23 | -#include <cstdlib> // rand | |
| 24 | 19 | #include "shared/view.h" |
| 25 | 20 | |
| 26 | 21 | #include <dali/dali.h> |
| 27 | 22 | #include <dali-toolkit/dali-toolkit.h> |
| 28 | -#include <dali/devel-api/images/atlas.h> | |
| 29 | -#include <dali/devel-api/rendering/cull-face.h> | |
| 30 | 23 | |
| 31 | 24 | using namespace Dali; |
| 32 | 25 | using namespace Dali::Toolkit; |
| ... | ... | @@ -101,10 +94,6 @@ const char* IMAGE_PATHS[] = { |
| 101 | 94 | |
| 102 | 95 | const unsigned int NUM_IMAGES = sizeof(IMAGE_PATHS) / sizeof(char*); |
| 103 | 96 | |
| 104 | -const unsigned int IMAGE_WIDTH = 256; | |
| 105 | -const unsigned int IMAGE_HEIGHT = 256; | |
| 106 | -const unsigned int NUM_IMAGE_PER_ROW_IN_ATLAS = 8; | |
| 107 | - | |
| 108 | 97 | const char* BACKGROUND_IMAGE( "" ); |
| 109 | 98 | const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); |
| 110 | 99 | const char* EDIT_IMAGE( DALI_IMAGE_DIR "icon-edit.png" ); |
| ... | ... | @@ -128,14 +117,7 @@ const char* SPIRAL_LABEL("Spiral"); |
| 128 | 117 | const char* GRID_LABEL("Grid"); |
| 129 | 118 | const char* DEPTH_LABEL("Depth"); |
| 130 | 119 | |
| 131 | -const char* ITEM_BORDER_IMAGE_PATH( DALI_IMAGE_DIR "frame-128x128.png" ); | |
| 132 | -const Vector3 ITEM_BORDER_MARGIN_SIZE(24, 24, 0); | |
| 133 | - | |
| 134 | -// These values depend on the border image | |
| 135 | -const float ITEM_IMAGE_BORDER_LEFT = 13.0f; | |
| 136 | -const float ITEM_IMAGE_BORDER_RIGHT = 13.0f; | |
| 137 | -const float ITEM_IMAGE_BORDER_TOP = 13.0f; | |
| 138 | -const float ITEM_IMAGE_BORDER_BOTTOM = 13.0f; | |
| 120 | +const float ITEM_BORDER_SIZE = 2.0f; | |
| 139 | 121 | |
| 140 | 122 | const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f; |
| 141 | 123 | const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE = 0.8f; |
| ... | ... | @@ -217,11 +199,9 @@ public: |
| 217 | 199 | |
| 218 | 200 | Vector2 stageSize = Stage::GetCurrent().GetSize(); |
| 219 | 201 | |
| 220 | - // Create a border image shared by all the item actors | |
| 221 | - mBorderImage = ResourceImage::New(ITEM_BORDER_IMAGE_PATH); | |
| 222 | - | |
| 223 | 202 | // Creates a default view with a default tool bar. |
| 224 | 203 | // The view is added to the stage. |
| 204 | + | |
| 225 | 205 | Layer contents = DemoHelper::CreateView( mApplication, |
| 226 | 206 | mView, |
| 227 | 207 | mToolBar, |
| ... | ... | @@ -292,11 +272,7 @@ public: |
| 292 | 272 | mReplaceButton.SetVisible( false ); |
| 293 | 273 | stage.Add( mReplaceButton ); |
| 294 | 274 | |
| 295 | - // Store one 1x1 white image for multiple items to share for backgrounds: | |
| 296 | - mWhiteImage = BufferImage::WHITE(); | |
| 297 | - | |
| 298 | 275 | // Create the item view actor |
| 299 | - mImageAtlas = CreateImageAtlas(); | |
| 300 | 276 | mItemView = ItemView::New(*this); |
| 301 | 277 | mItemView.SetParentOrigin(ParentOrigin::CENTER); |
| 302 | 278 | mItemView.SetAnchorPoint(AnchorPoint::CENTER); |
| ... | ... | @@ -363,6 +339,22 @@ public: |
| 363 | 339 | */ |
| 364 | 340 | void SetLayout( int layoutId ) |
| 365 | 341 | { |
| 342 | + Stage stage = Dali::Stage::GetCurrent(); | |
| 343 | + switch( mCurrentLayout ) | |
| 344 | + { | |
| 345 | + case SPIRAL_LAYOUT: | |
| 346 | + case DEPTH_LAYOUT: | |
| 347 | + { | |
| 348 | + stage.GetRootLayer().SetBehavior(Layer::LAYER_3D); | |
| 349 | + break; | |
| 350 | + } | |
| 351 | + case GRID_LAYOUT: | |
| 352 | + { | |
| 353 | + stage.GetRootLayer().SetBehavior(Layer::LAYER_2D); | |
| 354 | + break; | |
| 355 | + } | |
| 356 | + } | |
| 357 | + | |
| 366 | 358 | // Set the new orientation to the layout |
| 367 | 359 | mItemView.GetLayout(layoutId)->SetOrientation(static_cast<ControlOrientation::Type>(mOrientation / 90)); |
| 368 | 360 | |
| ... | ... | @@ -857,61 +849,63 @@ public: // From ItemFactory |
| 857 | 849 | */ |
| 858 | 850 | virtual Actor NewItem(unsigned int itemId) |
| 859 | 851 | { |
| 860 | - // Create an image actor for this item | |
| 861 | - unsigned int imageId = itemId % NUM_IMAGES; | |
| 862 | - ImageActor::PixelArea pixelArea( (imageId%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH, | |
| 863 | - (imageId/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT, | |
| 864 | - IMAGE_WIDTH, | |
| 865 | - IMAGE_HEIGHT ); | |
| 866 | - Actor actor = ImageActor::New(mImageAtlas, pixelArea); | |
| 852 | + // Create an image view for this item | |
| 853 | + ImageView actor = ImageView::New( IMAGE_PATHS[ itemId % NUM_IMAGES ] ); | |
| 854 | + actor.SetZ( 0.0f ); | |
| 867 | 855 | actor.SetPosition( INITIAL_OFFSCREEN_POSITION ); |
| 868 | 856 | |
| 869 | 857 | // Add a border image child actor |
| 870 | - ImageActor borderActor = ImageActor::New(mBorderImage); | |
| 858 | + ImageView borderActor = ImageView::New(); | |
| 871 | 859 | borderActor.SetParentOrigin( ParentOrigin::CENTER ); |
| 872 | 860 | borderActor.SetAnchorPoint( AnchorPoint::CENTER ); |
| 873 | - borderActor.SetPosition( 0.f, 0.f, 1.f ); | |
| 874 | - borderActor.SetStyle( ImageActor::STYLE_NINE_PATCH ); | |
| 875 | - borderActor.SetNinePatchBorder( Vector4( ITEM_IMAGE_BORDER_LEFT, ITEM_IMAGE_BORDER_TOP, ITEM_IMAGE_BORDER_RIGHT, ITEM_IMAGE_BORDER_BOTTOM ) ); | |
| 876 | - borderActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); // darken with parent image-actor | |
| 877 | 861 | borderActor.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS ); |
| 878 | - borderActor.SetSizeModeFactor( ITEM_BORDER_MARGIN_SIZE ); | |
| 862 | + borderActor.SetSizeModeFactor( Vector3( 2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f ) ); | |
| 863 | + borderActor.SetColorMode( USE_PARENT_COLOR ); | |
| 864 | + | |
| 865 | + Property::Map borderProperty; | |
| 866 | + borderProperty.Insert( "rendererType", "borderRenderer" ); | |
| 867 | + borderProperty.Insert( "borderColor", Color::WHITE ); | |
| 868 | + borderProperty.Insert( "borderSize", ITEM_BORDER_SIZE ); | |
| 869 | + borderActor.SetProperty( ImageView::Property::IMAGE, borderProperty ); | |
| 870 | + | |
| 879 | 871 | actor.Add(borderActor); |
| 872 | + | |
| 880 | 873 | actor.SetKeyboardFocusable( true ); |
| 881 | 874 | |
| 882 | 875 | Vector3 spiralItemSize; |
| 883 | 876 | static_cast<ItemLayout&>(*mSpiralLayout).GetItemSize( 0u, Vector3( Stage::GetCurrent().GetSize() ), spiralItemSize ); |
| 884 | 877 | |
| 885 | 878 | // Add a checkbox child actor; invisible until edit-mode is enabled |
| 886 | - | |
| 887 | - ImageActor checkbox = ImageActor::New( mWhiteImage ); | |
| 879 | + ImageView checkbox = ImageView::New(); | |
| 888 | 880 | checkbox.SetName( "CheckBox" ); |
| 889 | - checkbox.SetColor( Vector4(0.0f,0.0f,0.0f,0.6f) ); | |
| 881 | + checkbox.SetColorMode( USE_PARENT_COLOR ); | |
| 890 | 882 | checkbox.SetParentOrigin( ParentOrigin::TOP_RIGHT ); |
| 891 | 883 | checkbox.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); |
| 892 | 884 | checkbox.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f ); |
| 893 | 885 | checkbox.SetPosition( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH ); |
| 894 | - checkbox.SetZ( 1.0f ); | |
| 895 | - SetCullFace(checkbox, Dali::CullBack); | |
| 896 | - checkbox.SetSortModifier( 150.0f ); | |
| 886 | + checkbox.SetZ( 0.1f ); | |
| 887 | + | |
| 888 | + Property::Map solidColorProperty; | |
| 889 | + solidColorProperty.Insert( "rendererType", "colorRenderer" ); | |
| 890 | + solidColorProperty.Insert( "blendColor", Vector4(0.f, 0.f, 0.f, 0.6f) ); | |
| 891 | + checkbox.SetProperty( ImageView::Property::IMAGE, solidColorProperty ); | |
| 892 | + | |
| 897 | 893 | if( MODE_REMOVE_MANY != mMode && |
| 898 | 894 | MODE_INSERT_MANY != mMode && |
| 899 | 895 | MODE_REPLACE_MANY != mMode ) |
| 900 | 896 | { |
| 901 | 897 | checkbox.SetVisible( false ); |
| 902 | 898 | } |
| 903 | - actor.Add( checkbox ); | |
| 899 | + borderActor.Add( checkbox ); | |
| 904 | 900 | |
| 905 | - ImageActor tick = ImageActor::New( ResourceImage::New(SELECTED_IMAGE) ); | |
| 906 | - tick.SetColorMode( USE_OWN_COLOR ); | |
| 901 | + ImageView tick = ImageView::New( SELECTED_IMAGE ); | |
| 907 | 902 | tick.SetName( "Tick" ); |
| 903 | + tick.SetColorMode( USE_PARENT_COLOR ); | |
| 908 | 904 | tick.SetParentOrigin( ParentOrigin::TOP_RIGHT ); |
| 909 | 905 | tick.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); |
| 910 | 906 | tick.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f ); |
| 911 | - tick.SetZ( 1.0f ); | |
| 912 | - tick.SetSortModifier( 150.0f ); | |
| 907 | + tick.SetZ( 0.2f ); | |
| 913 | 908 | tick.SetVisible( false ); |
| 914 | - SetCullFace(tick, Dali::CullBack); | |
| 915 | 909 | checkbox.Add( tick ); |
| 916 | 910 | |
| 917 | 911 | // Connect new items for various editing modes |
| ... | ... | @@ -926,23 +920,6 @@ public: // From ItemFactory |
| 926 | 920 | private: |
| 927 | 921 | |
| 928 | 922 | /** |
| 929 | - * Create an Atlas to tile the images inside. | |
| 930 | - */ | |
| 931 | - Atlas CreateImageAtlas() | |
| 932 | - { | |
| 933 | - const unsigned int atlas_width = IMAGE_WIDTH*NUM_IMAGE_PER_ROW_IN_ATLAS; | |
| 934 | - const unsigned int atlas_height = IMAGE_HEIGHT*ceil( static_cast<float>(NUM_IMAGES)/ static_cast<float>(NUM_IMAGE_PER_ROW_IN_ATLAS)); | |
| 935 | - Atlas atlas = Atlas::New(atlas_width, atlas_height, Pixel::RGB888); | |
| 936 | - | |
| 937 | - for( unsigned int i = 0; i < NUM_IMAGES; i++ ) | |
| 938 | - { | |
| 939 | - atlas.Upload( IMAGE_PATHS[i], (i%NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_WIDTH, (i/NUM_IMAGE_PER_ROW_IN_ATLAS)*IMAGE_HEIGHT ); | |
| 940 | - } | |
| 941 | - | |
| 942 | - return atlas; | |
| 943 | - } | |
| 944 | - | |
| 945 | - /** | |
| 946 | 923 | * Sets/Updates the title of the View |
| 947 | 924 | * @param[in] title The new title for the view. |
| 948 | 925 | */ |
| ... | ... | @@ -984,8 +961,6 @@ private: |
| 984 | 961 | TextLabel mTitleActor; ///< The Toolbar's Title. |
| 985 | 962 | |
| 986 | 963 | ItemView mItemView; |
| 987 | - Image mBorderImage; | |
| 988 | - Atlas mImageAtlas; | |
| 989 | 964 | unsigned int mCurrentLayout; |
| 990 | 965 | float mDurationSeconds; |
| 991 | 966 | |
| ... | ... | @@ -998,8 +973,6 @@ private: |
| 998 | 973 | Toolkit::PushButton mDeleteButton; |
| 999 | 974 | Toolkit::PushButton mInsertButton; |
| 1000 | 975 | Toolkit::PushButton mReplaceButton; |
| 1001 | - | |
| 1002 | - BufferImage mWhiteImage; | |
| 1003 | 976 | }; |
| 1004 | 977 | |
| 1005 | 978 | void RunTest(Application& app) | ... | ... |