X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Ftext-label%2Ftext-label-example.cpp;h=85c51eb58cef09efda4802a5d9e2614ce5fddb8d;hb=92599bec00306761453eeaaa2a212fbc44ec0ba8;hp=0636177188857e81ff23660883585a3cfdf520c3;hpb=c55660c249e1ebe67719430e59face412974e475;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 0636177..85c51eb 100644 --- a/examples/text-label/text-label-example.cpp +++ b/examples/text-label/text-label-example.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -21,6 +21,7 @@ */ // EXTERNAL INCLUDES +#include #include #include @@ -34,42 +35,69 @@ 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 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_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] ); - const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof( H_ALIGNMENT_STRING_TABLE ) / sizeof( H_ALIGNMENT_STRING_TABLE[0u] ); +int ConvertToEven(int value) +{ + return (value % 2 == 0) ? value : (value + 1); +} - const char* V_ALIGNMENT_STRING_TABLE[] = +struct HSVColorConstraint +{ + HSVColorConstraint(float hue, float saturation, float value) + : hue(hue), + saturation(saturation), + value(value) { - "TOP", - "CENTER", - "BOTTOM" - }; + } - const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof( V_ALIGNMENT_STRING_TABLE ) / sizeof( V_ALIGNMENT_STRING_TABLE[0u] ); + void operator()(Vector3& current, const PropertyInputContainer& inputs ) + { + current = hsv2rgb(Vector3(inputs[0]->GetFloat(), saturation, value)); + } - int ConvertToEven(int value) + Vector3 hsv2rgb(Vector3 colorHSV) { - return (value % 2 == 0) ? value : (value + 1); + 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; +}; + +} // anonymous namespace /** * @brief The main class of the demo. @@ -80,8 +108,15 @@ public: TextLabelExample( Application& application ) : mApplication( application ), + mLabel(), + mContainer(), + mGrabCorner(), + 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 ); @@ -111,11 +146,10 @@ public: stage.Add( mContainer ); // Resize the center layout when the corner is grabbed - mGrabCorner = Control::New(); + mGrabCorner = ImageView::New( BACKGROUND_IMAGE ); 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 ); @@ -135,6 +169,20 @@ public: mLabel.SetBackgroundColor( Color::WHITE ); mContainer.Add( mLabel ); + mHueAngleIndex = mLabel.RegisterProperty( "hue", 0.0f ); + Renderer bgRenderer = mLabel.GetRendererAt(0); + mOverrideMixColorIndex = DevelHandle::GetPropertyIndex( bgRenderer, ColorVisual::Property::MIX_COLOR ); + + Constraint constraint = Constraint::New( 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(); + Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT ); std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl; } @@ -285,6 +333,8 @@ private: unsigned int mLanguageId; unsigned int mAlignment; + Property::Index mHueAngleIndex; + Property::Index mOverrideMixColorIndex; }; void RunTest( Application& application ) @@ -295,9 +345,9 @@ 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, DALI_DEMO_THEME_PATH ); + Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); RunTest( application );