X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Ftext-label%2Ftext-label-example.cpp;h=c7e8555e58935fa39f41aaae0b4a6502b9015321;hb=efd80d70751b976b58c37997ca82f5bee9910e03;hp=666579ad44fdc18b5685001aa0783daf9240683f;hpb=020cc51564a0ee0b4bb74b4cdafc246787478b56;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/text-label/text-label-example.cpp b/examples/text-label/text-label-example.cpp index 666579a..c7e8555 100644 --- a/examples/text-label/text-label-example.cpp +++ b/examples/text-label/text-label-example.cpp @@ -22,11 +22,11 @@ // EXTERNAL INCLUDES #include -#include +#include // INTERNAL INCLUDES -#include "center-layout.h" #include "shared/multi-language-strings.h" +#include "shared/view.h" using namespace Dali; using namespace Dali::Toolkit; @@ -34,10 +34,41 @@ using namespace MultiLanguageStrings; namespace { + const char* const BACKGROUND_IMAGE = DALI_IMAGE_DIR "grab-handle.png"; + const unsigned int KEY_ZERO = 10; const unsigned int KEY_ONE = 11; + const unsigned int KEY_F = 41; + 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[] = + { + "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); + } } /** @@ -49,7 +80,8 @@ public: TextLabelExample( Application& application ) : mApplication( application ), - mLanguageId( 0u ) + mLanguageId( 0u ), + mAlignment( 0u ) { // Connect to the Application's Init signal mApplication.InitSignal().Connect( this, &TextLabelExample::Create ); @@ -67,26 +99,63 @@ public: { Stage stage = Stage::GetCurrent(); - stage.SetBackgroundColor( Color::BLUE ); 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 ); + 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 = Control::New(); + mGrabCorner.SetName( "GrabCorner" ); + mGrabCorner.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT ); + mGrabCorner.SetBackgroundImage( ResourceImage::New( BACKGROUND_IMAGE ) ); + mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + mContainer.Add( mGrabCorner ); - mLabel = TextLabel::New(); - mLabel.SetBackgroundColor( Color::BLACK ); - centerLayout.Add( mLabel ); + 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.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + mLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true ); - mLabel.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); + mLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE ); + 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 ); 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 ) + { + 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( ConvertToEven(static_cast(mLayoutSize.x)), + ConvertToEven(static_cast(mLayoutSize.y)) ); + + mContainer.SetSize( clampedSize ); + } + } + /** * Main key event handler */ @@ -102,19 +171,52 @@ public: { 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_M: + 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 ) + { + mAlignment = 0u; + } + + mLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, H_ALIGNMENT_STRING_TABLE[ mAlignment ] ); + break; + } + case KEY_V: // Vertical alignment + { + if( ++mAlignment >= V_ALIGNMENT_STRING_COUNT ) + { + mAlignment = 0u; + } + + mLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, V_ALIGNMENT_STRING_TABLE[ mAlignment ] ); + break; + } + case KEY_M: // Multi-line { bool multiLine = mLabel.GetProperty( TextLabel::Property::MULTI_LINE ); mLabel.SetProperty( TextLabel::Property::MULTI_LINE, !multiLine ); break; } - case KEY_L: + case KEY_L: // Language { const Language& language = LANGUAGES[ mLanguageId ]; @@ -124,7 +226,31 @@ public: { mLanguageId = 0u; } + break; } + case KEY_S: // Shadow color + { + if( Color::BLACK == mLabel.GetProperty( TextLabel::Property::SHADOW_COLOR ) ) + { + mLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::RED ); + } + else + { + mLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLACK ); + } + break; + } + case KEY_PLUS: // Increase shadow offset + { + mLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, mLabel.GetProperty( TextLabel::Property::SHADOW_OFFSET ) + Vector2( 1.0f, 1.0f ) ); + break; + } + case KEY_MINUS: // Decrease shadow offset + { + mLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, mLabel.GetProperty( TextLabel::Property::SHADOW_OFFSET ) - Vector2( 1.0f, 1.0f ) ); + break; + } + } } } @@ -136,7 +262,15 @@ private: TextLabel mLabel; + Control mContainer; + Control mGrabCorner; + + PanGestureDetector mPanGestureDetector; + + Vector2 mLayoutSize; + unsigned int mLanguageId; + unsigned int mAlignment; }; void RunTest( Application& application ) @@ -149,7 +283,7 @@ void RunTest( Application& application ) /** Entry point for Linux & Tizen applications */ int main( int argc, char **argv ) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH ); RunTest( application );