Commit e9aaf3f540deba0fbb97a0c1289e534132018c08

Authored by Heeyong Song
1 parent 5f14daa1

Add buttons for the corner radius of the ImageView

Change-Id: I6ef15d0ad48dc59a4d9e4dc72466df925bb080ea
examples/image-view/image-view-example.cpp
1 1 /*
2   - * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  2 + * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3 3 *
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
... ... @@ -21,6 +21,7 @@
21 21 #include <dali-toolkit/dali-toolkit.h>
22 22 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
23 23 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
  24 +#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
24 25  
25 26 using namespace Dali;
26 27  
... ... @@ -34,6 +35,7 @@ const char* APPLICATION_TITLE( &quot;Image view&quot; );
34 35 const char* IMAGE_PATH[] = {
35 36 DEMO_IMAGE_DIR "gallery-small-23.jpg",
36 37 DEMO_IMAGE_DIR "woodEffect.jpg",
  38 + DEMO_IMAGE_DIR "wood.png", // 32bits image
37 39 DEMO_IMAGE_DIR "heartsframe.9.png",
38 40 DEMO_IMAGE_DIR "World.svg"
39 41 };
... ... @@ -43,6 +45,7 @@ const unsigned int NUMBER_OF_IMAGES = 3;
43 45 enum CellPlacement
44 46 {
45 47 TOP_BUTTON,
  48 + MID_BUTTON,
46 49 LOWER_BUTTON,
47 50 IMAGE,
48 51 NUMBER_OF_ROWS
... ... @@ -68,6 +71,8 @@ const unsigned int NUMBER_OF_RESOURCES = sizeof(IMAGE_PATH) / sizeof(char*);
68 71 std::string EXAMPLE_INSTRUCTIONS = "Instructions: Change button cycles through different image visuals, "
69 72 "on/off takes the ImageView and it's current visual on or off stage.";
70 73  
  74 +const float CORNER_RADIUS_VALUE( 20.0f );
  75 +
71 76 } // namespace
72 77  
73 78 class ImageViewController: public ConnectionTracker
... ... @@ -110,6 +115,7 @@ class ImageViewController: public ConnectionTracker
110 115 Vector3 offset( 0.9f, 0.70f, 0.0f );
111 116 mTable.SetSizeModeFactor( offset );
112 117 mTable.SetFitHeight(CellPlacement::TOP_BUTTON);
  118 + mTable.SetFitHeight(CellPlacement::MID_BUTTON);
113 119 mTable.SetFitHeight(CellPlacement::LOWER_BUTTON);
114 120 mContentLayer.Add( mTable );
115 121  
... ... @@ -142,7 +148,17 @@ class ImageViewController: public ConnectionTracker
142 148 button2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
143 149 button2.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
144 150 button2.SetName( s );
145   - mTable.AddChild( button2, Toolkit::TableView::CellPosition( CellPlacement::LOWER_BUTTON, x ) );
  151 + mTable.AddChild( button2, Toolkit::TableView::CellPosition( CellPlacement::MID_BUTTON, x ) );
  152 +
  153 + Toolkit::PushButton button3 = Toolkit::PushButton::New();
  154 + button3.SetProperty( Toolkit::Button::Property::LABEL, "Round" );
  155 + button3.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
  156 + button3.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  157 + button3.ClickedSignal().Connect( this, &ImageViewController::RoundedCornerClicked );
  158 + button3.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
  159 + button3.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
  160 + button3.SetName( s );
  161 + mTable.AddChild( button3, Toolkit::TableView::CellPosition( CellPlacement::LOWER_BUTTON, x ) );
146 162  
147 163 mImageViews[x] = Toolkit::ImageView::New( );
148 164 Property::Map imagePropertyMap;
... ... @@ -157,8 +173,9 @@ class ImageViewController: public ConnectionTracker
157 173 mTable.AddChild( mImageViews[x], Toolkit::TableView::CellPosition( CellPlacement::IMAGE, x ) );
158 174  
159 175 // Set changeable counter and toggle for each ImageView
160   - mImageViewImageIndexStatus[x] = true;
  176 + mImageViewImageIndexStatus[x] = 0;
161 177 mImageViewToggleStatus[x] = true;
  178 + mImageViewRoundedCornerStatus[x] = false;
162 179 }
163 180  
164 181 Stage::GetCurrent().KeyEventSignal().Connect(this, &ImageViewController::OnKeyEvent);
... ... @@ -187,7 +204,7 @@ private:
187 204 }
188 205 else
189 206 {
190   - mTable.AddChild( imageView, Toolkit::TableView::CellPosition( 2, GetButtonIndex( button ) ) );
  207 + mTable.AddChild( imageView, Toolkit::TableView::CellPosition( CellPlacement::IMAGE, GetButtonIndex( button ) ) );
191 208 }
192 209  
193 210 mImageViewToggleStatus[ buttonIndex ] = !mImageViewToggleStatus[ buttonIndex ];
... ... @@ -199,19 +216,40 @@ private:
199 216 {
200 217 unsigned int buttonIndex = GetButtonIndex( button );
201 218  
202   - if ( mImageViews[buttonIndex].OnStage() )
  219 + if( mImageViews[buttonIndex].OnStage() )
203 220 {
204   - Property::Map imagePropertyMap;
205   - imagePropertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
206   - imagePropertyMap.Insert( Toolkit::ImageVisual::Property::URL, IMAGE_PATH[ mImageViewImageIndexStatus[buttonIndex] ] );
207   - mImageViews[buttonIndex].SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
208   -
209 221 ++mImageViewImageIndexStatus[buttonIndex];
210 222  
211 223 if( mImageViewImageIndexStatus[buttonIndex] == NUMBER_OF_RESOURCES )
212 224 {
213 225 mImageViewImageIndexStatus[buttonIndex] = 0;
214 226 }
  227 +
  228 + // Reset corner radius state value
  229 + mImageViewRoundedCornerStatus[buttonIndex] = false;
  230 +
  231 + Property::Map imagePropertyMap;
  232 + imagePropertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
  233 + imagePropertyMap.Insert( Toolkit::ImageVisual::Property::URL, IMAGE_PATH[ mImageViewImageIndexStatus[buttonIndex] ] );
  234 + mImageViews[buttonIndex].SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
  235 + }
  236 + return true;
  237 + }
  238 +
  239 + bool RoundedCornerClicked( Toolkit::Button button )
  240 + {
  241 + unsigned int buttonIndex = GetButtonIndex( button );
  242 +
  243 + if( mImageViews[buttonIndex].OnStage() )
  244 + {
  245 + mImageViewRoundedCornerStatus[ buttonIndex ] = !mImageViewRoundedCornerStatus[ buttonIndex ];
  246 +
  247 + Property::Map imagePropertyMap;
  248 + imagePropertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
  249 + imagePropertyMap.Insert( Toolkit::ImageVisual::Property::URL, IMAGE_PATH[ mImageViewImageIndexStatus[buttonIndex] ] );
  250 + imagePropertyMap.Insert( Toolkit::DevelVisual::Property::CORNER_RADIUS, mImageViewRoundedCornerStatus[buttonIndex] ? CORNER_RADIUS_VALUE : 0.0f );
  251 +
  252 + mImageViews[buttonIndex].SetProperty( Toolkit::ImageView::Property::IMAGE, imagePropertyMap );
215 253 }
216 254 return true;
217 255 }
... ... @@ -239,6 +277,7 @@ private:
239 277 Toolkit::TableView mTable;
240 278 Toolkit::ImageView mImageViews[ NUMBER_OF_IMAGES ];
241 279 bool mImageViewToggleStatus[ NUMBER_OF_IMAGES ];
  280 + bool mImageViewRoundedCornerStatus[ NUMBER_OF_IMAGES ];
242 281 unsigned int mImageViewImageIndexStatus[ NUMBER_OF_IMAGES ];
243 282  
244 283 Toolkit::TableView::CellPosition mCurrentPositionToggle;
... ...