Commit 45ee15fa0cf9e522ac0072c5d35596dfdda59561

Authored by David Steele
2 parents 73b9e0ad c46c2895

[dali_1.2.58] Merge branch 'devel/master'

Change-Id: I6f90d9f3fdf65d10e004df91ca1bef31d7344cba
examples/text-label/text-label-example.cpp
... ... @@ -24,6 +24,7 @@
24 24 #include <dali/devel-api/object/handle-devel.h>
25 25 #include <dali/devel-api/actors/actor-devel.h>
26 26 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
  27 +#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
27 28 #include <dali-toolkit/dali-toolkit.h>
28 29 #include <iostream>
29 30  
... ... @@ -38,6 +39,16 @@ using namespace MultiLanguageStrings;
38 39 namespace
39 40 {
40 41 const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "grab-handle.png";
  42 +const char* const STYLES_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_Main.png";
  43 +const char* const TICK_IMAGE_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_OK_02.png";
  44 +const char* const STYLE_SELECTED_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_OK_03.png";
  45 +
  46 +const char* BUTTON_IMAGES[] =
  47 +{
  48 + DEMO_IMAGE_DIR "FontStyleButton_Colour.png",
  49 + DEMO_IMAGE_DIR "FontStyleButton_Outline.png",
  50 + DEMO_IMAGE_DIR "FontStyleButton_Shadow.png"
  51 +};
41 52  
42 53 const unsigned int KEY_ZERO = 10;
43 54 const unsigned int KEY_ONE = 11;
... ... @@ -70,6 +81,24 @@ const char* V_ALIGNMENT_STRING_TABLE[] =
70 81  
71 82 const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof( V_ALIGNMENT_STRING_TABLE ) / sizeof( V_ALIGNMENT_STRING_TABLE[0u] );
72 83  
  84 +enum StyleType
  85 +{
  86 + TEXT_COLOR = 0,
  87 + OUTLINE,
  88 + SHADOW,
  89 + NUMBER_OF_STYLES
  90 +};
  91 +
  92 +const Vector4 AVAILABLE_COLORS[] =
  93 +{
  94 + Color::GREEN,
  95 + Color::BLUE,
  96 + Color::RED,
  97 + Color::CYAN
  98 +};
  99 +
  100 +const unsigned int NUMBER_OF_COLORS = sizeof( AVAILABLE_COLORS ) / sizeof( AVAILABLE_COLORS[0u] );
  101 +
73 102 int ConvertToEven(int value)
74 103 {
75 104 return (value % 2 == 0) ? value : (value + 1);
... ... @@ -101,6 +130,12 @@ struct HSVColorConstraint
101 130 float value;
102 131 };
103 132  
  133 +const float STYLE_BUTTON_POSTION_RELATIVE_TO_STAGE = 0.9f;
  134 +const float BUTTON_SIZE_RATIO_TO_STAGE = 0.1f;
  135 +const float OUTLINE_WIDTH = 2.0f;
  136 +const Vector2 SHADOW_OFFSET = Vector2( 2.0f, 2.0f );
  137 +
  138 +
104 139 } // anonymous namespace
105 140  
106 141 /**
... ... @@ -113,6 +148,9 @@ public:
113 148 TextLabelExample( Application& application )
114 149 : mApplication( application ),
115 150 mLabel(),
  151 + mShadowActive( false ),
  152 + mOutlineActive( false ),
  153 + mSelectedColor(AVAILABLE_COLORS[0]),
116 154 mContainer(),
117 155 mGrabCorner(),
118 156 mBorder(),
... ... @@ -122,6 +160,7 @@ public:
122 160 mAlignment( 0u ),
123 161 mHueAngleIndex( Property::INVALID_INDEX ),
124 162 mOverrideMixColorIndex( Property::INVALID_INDEX )
  163 +
125 164 {
126 165 // Connect to the Application's Init signal
127 166 mApplication.InitSignal().Connect( this, &TextLabelExample::Create );
... ... @@ -140,12 +179,14 @@ public:
140 179 Stage stage = Stage::GetCurrent();
141 180  
142 181 stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent);
143   - Vector2 stageSize = stage.GetSize();
  182 + mStageSize = stage.GetSize();
  183 +
  184 + mButtonSize = Size( mStageSize.height * 0.1, mStageSize.height * 0.1 ); // Button size 1/10 of stage height
144 185  
145 186 mContainer = Control::New();
146 187 mContainer.SetName( "Container" );
147 188 mContainer.SetParentOrigin( ParentOrigin::CENTER );
148   - mLayoutSize = Vector2(stageSize.width*0.6f, stageSize.width*0.6f);
  189 + mLayoutSize = Vector2(mStageSize.width*0.6f, mStageSize.width*0.6f);
149 190 mContainer.SetSize( mLayoutSize );
150 191 mContainer.SetDrawMode( DrawMode::OVERLAY_2D );
151 192 stage.Add( mContainer );
... ... @@ -162,18 +203,27 @@ public:
162 203 mPanGestureDetector.Attach( mGrabCorner );
163 204 mPanGestureDetector.DetectedSignal().Connect( this, &TextLabelExample::OnPan );
164 205  
165   - mLabel = TextLabel::New( "A Quick Brown Fox Jumps Over The Lazy Dog" );
  206 + mLabel = TextLabel::New( "\xF0\x9F\x98\x89 A Quick Brown Fox Jumps Over The Lazy Dog" );
166 207  
167 208 mLabel.SetName( "TextLabel" );
168 209 mLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
169 210 mLabel.SetSize(mLayoutSize);
170 211 mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
171 212 mLabel.SetProperty( DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE, Color::GREEN );
172   - mLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 1.0f, 1.0f ) );
173   - mLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLACK );
174 213 mLabel.SetBackgroundColor( Color::WHITE );
175 214 mContainer.Add( mLabel );
176 215  
  216 + // Create style activate button
  217 + mStyleMenuButton = PushButton::New();
  218 + mStyleMenuButton.SetPosition( mButtonSize.width, mStageSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_STAGE );
  219 + mStyleMenuButton.SetSize( mButtonSize );
  220 + mStyleMenuButton.SetProperty( Button::Property::TOGGLABLE, true );
  221 + mStyleMenuButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, STYLES_IMAGE );
  222 + mStyleMenuButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, TICK_IMAGE_IMAGE );
  223 +
  224 + mStyleMenuButton.ClickedSignal().Connect( this, &TextLabelExample::OnStyleButtonClicked );
  225 + stage.Add( mStyleMenuButton );
  226 +
177 227 // Add a border for the container so you can see the container is being resized while grabbing the handle.
178 228 mBorder = Control::New();
179 229 mBorder.SetAnchorPoint( AnchorPoint::TOP_LEFT );
... ... @@ -204,7 +254,7 @@ public:
204 254 anim.SetLooping(true);
205 255 anim.Play();
206 256  
207   - // Animate the text color 3 times from source color to RED
  257 + // Animate the text color 3 times from source color to Yellow
208 258 Animation animation = Animation::New( 2.f );
209 259 animation.AnimateTo( Property( mLabel, DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE ), Color::YELLOW, AlphaFunction::SIN );
210 260 animation.SetLoopCount( 3 );
... ... @@ -214,6 +264,136 @@ public:
214 264 std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl;
215 265 }
216 266  
  267 + // Depending on button pressed, apply the style to the text label
  268 + bool OnStyleSelected( Toolkit::Button button )
  269 + {
  270 + if( button == mStyleButtons[ StyleType::TEXT_COLOR ] )
  271 + {
  272 + Animation animation = Animation::New( 2.f );
  273 + animation.AnimateTo( Property( mLabel, DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE ), mSelectedColor, AlphaFunction::LINEAR );
  274 + animation.Play();
  275 + }
  276 + else if( button == mStyleButtons[ StyleType::OUTLINE ] )
  277 + {
  278 + Property::Map outlineMap;
  279 + float outlineWidth = OUTLINE_WIDTH;
  280 +
  281 + if( mOutlineActive )
  282 + {
  283 + outlineWidth = ( mOutlineColor == mSelectedColor ) ? 0.0f : OUTLINE_WIDTH ; // toggles outline on/off
  284 + }
  285 + mOutlineActive = ( outlineWidth > 0.0f ) ? true : false;
  286 +
  287 + mOutlineColor = mSelectedColor;
  288 + outlineMap["color"] = mOutlineColor;
  289 + outlineMap["width"] = outlineWidth;
  290 + mLabel.SetProperty( TextLabel::Property::OUTLINE, outlineMap );
  291 + }
  292 + else if( button == mStyleButtons[ StyleType::SHADOW ] )
  293 + {
  294 + Vector2 shadowOffset( SHADOW_OFFSET ); // Will be set to zeros if color already set
  295 + Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW_COLOR );
  296 + Vector4 currentShadowColor;
  297 + value.Get( currentShadowColor );
  298 +
  299 + if ( mShadowActive )
  300 + {
  301 + // toggle shadow off ( zero offset ) if color is already set
  302 + shadowOffset = ( currentShadowColor == mSelectedColor ) ? Vector2::ZERO : Vector2( SHADOW_OFFSET );
  303 + }
  304 +
  305 + mShadowActive = ( shadowOffset == Vector2::ZERO ) ? false : true;
  306 +
  307 + mLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, shadowOffset );
  308 + mLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, mSelectedColor );
  309 + }
  310 + return true;
  311 + }
  312 +
  313 + bool OnColorSelected( Toolkit::Button button )
  314 + {
  315 + for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
  316 + {
  317 + if ( mColorButtons[index] == button )
  318 + {
  319 + mSelectedColor = AVAILABLE_COLORS[ index ];
  320 + return true;
  321 + }
  322 + }
  323 + return true;
  324 + }
  325 +
  326 + void ShowColorButtons()
  327 + {
  328 + for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
  329 + {
  330 + mColorButtons[index] = RadioButton::New();
  331 + mColorButtons[index].SetPosition( mButtonSize.width, mStageSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_STAGE - ( mButtonSize.width * (index+1) ) );
  332 + mColorButtons[index].SetSize( mButtonSize );
  333 + mColorButtons[index].ClickedSignal().Connect( this, &TextLabelExample::OnColorSelected );
  334 + mColorButtons[index].SetProperty( Button::Property::TOGGLABLE, true );
  335 + Property::Map propertyMap;
  336 + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
  337 + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[ index ]);
  338 + mColorButtons[index].SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
  339 + mColorButtons[index].SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, propertyMap );
  340 +
  341 + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
  342 + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[ index ]);
  343 + mColorButtons[index].SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, propertyMap );
  344 +
  345 + mColorButtons[index].SetProperty( Toolkit::DevelButton::Property::SELECTED_VISUAL,
  346 + Property::Map().Add( Visual::Property::TYPE, Visual::BORDER )
  347 + .Add( BorderVisual::Property::COLOR, Color::WHITE )
  348 + .Add( BorderVisual::Property::SIZE, 2.0f )
  349 + .Add( BorderVisual::Property::ANTI_ALIASING, true ) );
  350 +
  351 + Stage::GetCurrent().Add( mColorButtons[index] );
  352 + }
  353 + }
  354 +
  355 +
  356 + void HideColorButtons()
  357 + {
  358 + for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++)
  359 + {
  360 + UnparentAndReset( mColorButtons[index] );
  361 + }
  362 + }
  363 +
  364 + void HideStyleButtons()
  365 + {
  366 + for( unsigned int index = 0; index < NUMBER_OF_STYLES; index++)
  367 + {
  368 + UnparentAndReset( mStyleButtons[index] );
  369 + }
  370 + }
  371 +
  372 + bool OnStyleButtonClicked( Toolkit::Button button )
  373 + {
  374 + if ( button.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>() )
  375 + {
  376 + for ( unsigned int index = 0; index < NUMBER_OF_STYLES; index++ )
  377 + {
  378 + mStyleButtons[index] = PushButton::New();
  379 + mStyleButtons[index].SetPosition( mButtonSize.width + ( mButtonSize.width * (index+1) ), mStageSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_STAGE );
  380 + mStyleButtons[index].SetSize( mButtonSize );
  381 + mStyleButtons[index].SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGES[ index ] );
  382 + mStyleButtons[index].SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, STYLE_SELECTED_IMAGE );
  383 + mStyleButtons[index].ClickedSignal().Connect( this, &TextLabelExample::OnStyleSelected );
  384 + Stage::GetCurrent().Add( mStyleButtons[index] );
  385 + }
  386 + ShowColorButtons();
  387 + }
  388 + else
  389 + {
  390 + // hide menu and colors
  391 + HideColorButtons();
  392 + HideStyleButtons();
  393 + }
  394 + return true;
  395 + }
  396 +
217 397 // Resize the text-label with pan gesture
218 398 void OnPan( Actor actor, const PanGesture& gesture )
219 399 {
... ... @@ -240,6 +420,9 @@ public:
240 420 if( mLayoutSize.x >= 2.0f ||
241 421 mLayoutSize.y >= 2.0f )
242 422 {
  423 + mLayoutSize.x = std::min ( mLayoutSize.x, mStageSize.width );
  424 + mLayoutSize.y = std::min ( mLayoutSize.y, mStageSize.height*.9f );
  425 +
243 426 // Avoid pixel mis-alignment issue
244 427 Vector2 clampedSize = Vector2( std::max( ConvertToEven( static_cast<int>( mLayoutSize.x )), 2 ),
245 428 std::max( ConvertToEven( static_cast<int>( mLayoutSize.y )), 2 ) );
... ... @@ -375,6 +558,14 @@ private:
375 558  
376 559 TextLabel mLabel;
377 560  
  561 + PushButton mStyleMenuButton;
  562 + PushButton mStyleButtons[ NUMBER_OF_STYLES ];
  563 + bool mShadowActive;
  564 + bool mOutlineActive;
  565 + Vector4 mSelectedColor;
  566 + Vector4 mOutlineColor; // Store outline as Vector4 whilst TextLabel Outline Property returns a string when using GetProperty
  567 + Button mColorButtons[ NUMBER_OF_COLORS ];
  568 +
378 569 Control mContainer;
379 570 Control mGrabCorner;
380 571 Control mBorder;
... ... @@ -383,6 +574,9 @@ private:
383 574  
384 575 Vector2 mLayoutSize;
385 576  
  577 + Size mStageSize;
  578 + Size mButtonSize;
  579 +
386 580 unsigned int mLanguageId;
387 581 unsigned int mAlignment;
388 582 Property::Index mHueAngleIndex;
... ...
packaging/com.samsung.dali-demo.spec
... ... @@ -2,7 +2,7 @@
2 2  
3 3 Name: com.samsung.dali-demo
4 4 Summary: The OpenGLES Canvas Core Demo
5   -Version: 1.2.57
  5 +Version: 1.2.58
6 6 Release: 1
7 7 Group: System/Libraries
8 8 License: Apache-2.0
... ...
resources/images/FontStyleButton_Colour.png 0 → 100755

7.23 KB

resources/images/FontStyleButton_Main.png 0 → 100755

9.19 KB

resources/images/FontStyleButton_OK_02.png 0 → 100755

8.23 KB

resources/images/FontStyleButton_OK_03.png 0 → 100755

7.11 KB

resources/images/FontStyleButton_Outline.png 0 → 100755

6.18 KB

resources/images/FontStyleButton_Shadow.png 0 → 100755

6.5 KB