/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
*/
// EXTERNAL INCLUDES
+#include <dali/devel-api/object/handle-devel.h>
+#include <dali/devel-api/actors/actor-devel.h>
+#include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
#include <dali-toolkit/dali-toolkit.h>
-#include <dali/public-api/text-abstraction/text-abstraction.h>
+#include <iostream>
// INTERNAL INCLUDES
-#include "center-layout.h"
#include "shared/multi-language-strings.h"
+#include "shared/view.h"
using namespace Dali;
using namespace Dali::Toolkit;
namespace
{
- const unsigned int KEY_ZERO = 10;
- const unsigned int KEY_ONE = 11;
- const unsigned int KEY_H = 43;
- const unsigned int KEY_V = 55;
- const unsigned int KEY_M = 58;
- const unsigned int KEY_L = 46;
- const unsigned int KEY_S = 39;
- const unsigned int KEY_PLUS = 21;
- const unsigned int KEY_MINUS = 20;
-
- const char* H_ALIGNMENT_STRING_TABLE[] =
+const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "grab-handle.png";
+
+const unsigned int KEY_ZERO = 10;
+const unsigned int KEY_ONE = 11;
+const unsigned int KEY_A = 38;
+const unsigned int KEY_F = 41;
+const unsigned int KEY_H = 43;
+const unsigned int KEY_U = 30;
+const unsigned int KEY_V = 55;
+const unsigned int KEY_M = 58;
+const unsigned int KEY_L = 46;
+const unsigned int KEY_S = 39;
+const unsigned int KEY_PLUS = 21;
+const unsigned int KEY_MINUS = 20;
+
+const char* H_ALIGNMENT_STRING_TABLE[] =
+{
+ "BEGIN",
+ "CENTER",
+ "END"
+};
+
+const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof( H_ALIGNMENT_STRING_TABLE ) / sizeof( H_ALIGNMENT_STRING_TABLE[0u] );
+
+const char* V_ALIGNMENT_STRING_TABLE[] =
+{
+ "TOP",
+ "CENTER",
+ "BOTTOM"
+};
+
+const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof( V_ALIGNMENT_STRING_TABLE ) / sizeof( V_ALIGNMENT_STRING_TABLE[0u] );
+
+int ConvertToEven(int value)
+{
+ return (value % 2 == 0) ? value : (value + 1);
+}
+
+struct HSVColorConstraint
+{
+ HSVColorConstraint(float hue, float saturation, float value)
+ : hue(hue),
+ saturation(saturation),
+ value(value)
{
- "BEGIN",
- "CENTER",
- "END"
- };
+ }
- const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof( H_ALIGNMENT_STRING_TABLE ) / sizeof( H_ALIGNMENT_STRING_TABLE[0u] );
+ void operator()(Vector3& current, const PropertyInputContainer& inputs )
+ {
+ current = hsv2rgb(Vector3(inputs[0]->GetFloat(), saturation, value));
+ }
- const char* V_ALIGNMENT_STRING_TABLE[] =
+ Vector3 hsv2rgb(Vector3 colorHSV)
{
- "TOP",
- "CENTER",
- "BOTTOM"
- };
+ float r=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x)-1));
+ float g=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x-2.09439)-1));
+ float b=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x+2.09439)-1));
+ return Vector3(r, g, b);
+ }
+ float hue;
+ float saturation;
+ float value;
+};
- const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof( V_ALIGNMENT_STRING_TABLE ) / sizeof( V_ALIGNMENT_STRING_TABLE[0u] );
-}
+} // anonymous namespace
/**
* @brief The main class of the demo.
TextLabelExample( Application& application )
: mApplication( application ),
+ mLabel(),
+ mContainer(),
+ mGrabCorner(),
+ mBorder(),
+ mPanGestureDetector(),
+ mLayoutSize(),
mLanguageId( 0u ),
- mAlignment( 0u )
+ mAlignment( 0u ),
+ mHueAngleIndex( Property::INVALID_INDEX ),
+ mOverrideMixColorIndex( Property::INVALID_INDEX )
{
// Connect to the Application's Init signal
mApplication.InitSignal().Connect( this, &TextLabelExample::Create );
{
Stage stage = Stage::GetCurrent();
- stage.SetBackgroundColor( Color::BLACK );
stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent);
Vector2 stageSize = stage.GetSize();
- CenterLayout centerLayout = CenterLayout::New();
- centerLayout.SetParentOrigin( ParentOrigin::CENTER );
- centerLayout.SetSize( stageSize.width*0.6f, stageSize.width*0.6f );
- stage.Add( centerLayout );
-
- mLabel = TextLabel::New();
- mLabel.SetBackgroundColor( Vector4(0.3f,0.3f,0.6f,1.0f) );
- centerLayout.Add( mLabel );
-
+ mContainer = Control::New();
+ mContainer.SetName( "Container" );
+ mContainer.SetParentOrigin( ParentOrigin::CENTER );
+ mLayoutSize = Vector2(stageSize.width*0.6f, stageSize.width*0.6f);
+ mContainer.SetSize( mLayoutSize );
+ mContainer.SetDrawMode( DrawMode::OVERLAY_2D );
+ stage.Add( mContainer );
+
+ // Resize the center layout when the corner is grabbed
+ mGrabCorner = ImageView::New( BACKGROUND_IMAGE );
+ mGrabCorner.SetName( "GrabCorner" );
+ mGrabCorner.SetAnchorPoint( AnchorPoint::TOP_CENTER );
+ mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT );
+ mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+ mContainer.Add( mGrabCorner );
+
+ mPanGestureDetector = PanGestureDetector::New();
+ mPanGestureDetector.Attach( mGrabCorner );
+ mPanGestureDetector.DetectedSignal().Connect( this, &TextLabelExample::OnPan );
+
+ mLabel = TextLabel::New( "A Quick Brown Fox Jumps Over The Lazy Dog" );
+
+ mLabel.SetName( "TextLabel" );
+ mLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mLabel.SetSize(mLayoutSize);
mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
- mLabel.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
+ mLabel.SetProperty( DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE, Color::GREEN );
mLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 1.0f, 1.0f ) );
mLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLACK );
+ mLabel.SetBackgroundColor( Color::WHITE );
+ mContainer.Add( mLabel );
+
+ // Add a border for the container so you can see the container is being resized while grabbing the handle.
+ mBorder = Control::New();
+ mBorder.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ mBorder.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+ mBorder.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
+
+ Dali::Property::Map border;
+ border.Insert( Visual::Property::TYPE, Visual::BORDER );
+ border.Insert( BorderVisual::Property::COLOR, Color::WHITE );
+ border.Insert( BorderVisual::Property::SIZE, 2.f );
+ mBorder.SetProperty( Control::Property::BACKGROUND, border );
+ mContainer.Add( mBorder );
+ mBorder.SetVisible(false);
+
+ DevelActor::RaiseToTop(mGrabCorner);
+
+ mHueAngleIndex = mLabel.RegisterProperty( "hue", 0.0f );
+ Renderer bgRenderer = mLabel.GetRendererAt(0);
+ mOverrideMixColorIndex = DevelHandle::GetPropertyIndex( bgRenderer, ColorVisual::Property::MIX_COLOR );
+
+ Constraint constraint = Constraint::New<Vector3>( bgRenderer, mOverrideMixColorIndex, HSVColorConstraint(0.0f, 0.5f, 0.8f));
+ constraint.AddSource( Source( mLabel, mHueAngleIndex ) );
+ constraint.SetRemoveAction( Constraint::Discard );
+ constraint.Apply();
+
+ Animation anim = Animation::New(50.0f);
+ anim.AnimateTo(Property(mLabel, mHueAngleIndex), 6.28318f);
+ anim.SetLooping(true);
+ anim.Play();
+
+ // Animate the text color 3 times from source color to RED
+ Animation animation = Animation::New( 2.f );
+ animation.AnimateTo( Property( mLabel, DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE ), Color::YELLOW, AlphaFunction::SIN );
+ animation.SetLoopCount( 3 );
+ animation.Play();
Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT );
std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl;
}
+ // Resize the text-label with pan gesture
+ void OnPan( Actor actor, const PanGesture& gesture )
+ {
+ // Reset mLayoutSize when the pan starts
+ if( gesture.state == Gesture::Started )
+ {
+ if( mLayoutSize.x < 2.0f )
+ {
+ mLayoutSize.x = 2.0f;
+ }
+
+ if( mLayoutSize.y < 2.0f )
+ {
+ mLayoutSize.y = 2.0f;
+ }
+
+ // Only show the border during the panning
+ mBorder.SetVisible(true);
+ }
+
+ mLayoutSize.x += gesture.displacement.x * 2.0f;
+ mLayoutSize.y += gesture.displacement.y * 2.0f;
+
+ if( mLayoutSize.x >= 2.0f ||
+ mLayoutSize.y >= 2.0f )
+ {
+ // Avoid pixel mis-alignment issue
+ Vector2 clampedSize = Vector2( std::max( ConvertToEven( static_cast<int>( mLayoutSize.x )), 2 ),
+ std::max( ConvertToEven( static_cast<int>( mLayoutSize.y )), 2 ) );
+
+ mContainer.SetSize( clampedSize );
+ }
+
+ if( gesture.state == Gesture::Cancelled || gesture.state == Gesture::Finished )
+ {
+ // Resize the text label to match the container size when panning is finished
+ mLabel.SetSize(mLayoutSize);
+ mBorder.SetVisible(false);
+ }
+ }
+
/**
* Main key event handler
*/
{
switch( event.keyCode )
{
+ // Select rendering back-end
case KEY_ZERO: // fall through
case KEY_ONE:
{
mLabel.SetProperty( TextLabel::Property::RENDERING_BACKEND, event.keyCode - 10 );
break;
}
- case KEY_H:
+ case KEY_A: // Animate text colour
+ {
+ Animation animation = Animation::New( 2.f );
+ animation.AnimateTo( Property( mLabel, DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE ), Color::RED, AlphaFunction::SIN );
+ animation.SetLoopCount( 3 );
+ animation.Play();
+ break;
+ }
+ case KEY_F: // Fill vertically
+ {
+ if( ResizePolicy::DIMENSION_DEPENDENCY == mLabel.GetResizePolicy(Dimension::HEIGHT) )
+ {
+ mLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
+ }
+ else
+ {
+ mLabel.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
+ }
+ break;
+ }
+ case KEY_H: // Horizontal alignment
{
if( ++mAlignment >= H_ALIGNMENT_STRING_COUNT )
{
mLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, H_ALIGNMENT_STRING_TABLE[ mAlignment ] );
break;
}
- case KEY_V:
+ case KEY_V: // Vertical alignment
{
if( ++mAlignment >= V_ALIGNMENT_STRING_COUNT )
{
mLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, V_ALIGNMENT_STRING_TABLE[ mAlignment ] );
break;
}
- case KEY_M:
+ case KEY_M: // Multi-line
{
bool multiLine = mLabel.GetProperty<bool>( TextLabel::Property::MULTI_LINE );
mLabel.SetProperty( TextLabel::Property::MULTI_LINE, !multiLine );
break;
}
- case KEY_L:
+ case KEY_L: // Language
{
const Language& language = LANGUAGES[ mLanguageId ];
}
break;
}
- case KEY_S:
+ case KEY_S: // Shadow color
{
if( Color::BLACK == mLabel.GetProperty<Vector4>( TextLabel::Property::SHADOW_COLOR ) )
{
}
break;
}
- case KEY_PLUS:
+ case KEY_U: // Markup
+ {
+ mLabel.SetProperty( TextLabel::Property::ENABLE_MARKUP, true );
+ mLabel.SetProperty( TextLabel::Property::TEXT, "<font family='DejaVuSerif' size='18'>H<color value='blue'>ello</color> <font weight='bold'>world</font> demo</font>" );
+ break;
+ }
+ case KEY_PLUS: // Increase shadow offset
{
mLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, mLabel.GetProperty<Vector2>( TextLabel::Property::SHADOW_OFFSET ) + Vector2( 1.0f, 1.0f ) );
break;
}
- case KEY_MINUS:
+ case KEY_MINUS: // Decrease shadow offset
{
mLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, mLabel.GetProperty<Vector2>( TextLabel::Property::SHADOW_OFFSET ) - Vector2( 1.0f, 1.0f ) );
break;
TextLabel mLabel;
+ Control mContainer;
+ Control mGrabCorner;
+ Control mBorder;
+
+ PanGestureDetector mPanGestureDetector;
+
+ Vector2 mLayoutSize;
+
unsigned int mLanguageId;
unsigned int mAlignment;
+ Property::Index mHueAngleIndex;
+ Property::Index mOverrideMixColorIndex;
};
void RunTest( Application& application )
}
/** Entry point for Linux & Tizen applications */
-int main( int argc, char **argv )
+int DALI_EXPORT_API main( int argc, char **argv )
{
- Application application = Application::New( &argc, &argv );
+ Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
RunTest( application );