X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Fpublic-api%2Ftext%2Ftext-controller.cpp;h=58fd536176d3b972cec91cee5b0cf03b882c95cf;hp=7d0b95639880c80a687f6b9fe552a3c9cb2962eb;hb=09e2475439f1d40c576df0fdc0bc9e26a9661758;hpb=0ae54c139d553cd05ba466a102ec18cf2cf11e81 diff --git a/dali-toolkit/public-api/text/text-controller.cpp b/dali-toolkit/public-api/text/text-controller.cpp index 7d0b956..58fd536 100644 --- a/dali-toolkit/public-api/text/text-controller.cpp +++ b/dali-toolkit/public-api/text/text-controller.cpp @@ -85,8 +85,12 @@ struct Controller::TextInput EDITING }; - TextInput( DecoratorPtr decorator ) - : mDecorator( decorator ), + TextInput( LogicalModelPtr logicalModel, + VisualModelPtr visualModel, + DecoratorPtr decorator ) + : mLogicalModel( logicalModel ), + mVisualModel( visualModel ), + mDecorator( decorator ), mState( INACTIVE ) { } @@ -143,8 +147,16 @@ struct Controller::TextInput if( 1u == event.p1.mUint ) { mState = TextInput::EDITING; + mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + mDecorator->StartCursorBlink(); mDecorator->SetGrabHandleActive( true ); - mDecorator->SetPosition( PRIMARY_CURSOR, 0, 0, 10 ); + + float xPosition = event.p2.mFloat; + float yPosition = event.p3.mFloat; + float height(0.0f); + GetClosestCursorPosition( xPosition, yPosition, height ); + mDecorator->SetPosition( PRIMARY_CURSOR, xPosition, yPosition, height ); + mDecoratorUpdated = true; } else if( 2u == event.p1.mUint ) @@ -158,11 +170,68 @@ struct Controller::TextInput void OnGrabHandleEvent( const Event& event ) { - // TODO + unsigned int state = event.p1.mUint; + + if( GRAB_HANDLE_PRESSED == state ) + { + float xPosition = event.p2.mFloat; + float yPosition = event.p3.mFloat; + float height(0.0f); + + GetClosestCursorPosition( xPosition, yPosition, height ); + + mDecorator->SetPosition( PRIMARY_CURSOR, xPosition, yPosition, height ); + mDecoratorUpdated = true; + } } - DecoratorPtr mDecorator; - bool mDecoratorUpdated; + void GetClosestCursorPosition( float& x, float& y, float& height ) + { + // TODO - Look at LineRuns first + + Text::Length numberOfGlyphs = mVisualModel->GetNumberOfGlyphs(); + if( 0 == numberOfGlyphs ) + { + return; + } + + Vector glyphs; + glyphs.Resize( numberOfGlyphs ); + mVisualModel->GetGlyphs( &glyphs[0], 0, numberOfGlyphs ); + + std::vector positions; + positions.resize( numberOfGlyphs ); + mVisualModel->GetGlyphPositions( &positions[0], 0, numberOfGlyphs ); + + unsigned int closestGlyph = 0; + float closestDistance = std::numeric_limits::max(); + + for( unsigned int i=0; i mEventQueue; ///< The queue of touch events etc. + + bool mDecoratorUpdated; }; struct Controller::Impl @@ -240,7 +311,7 @@ void Controller::EnableTextInput( DecoratorPtr decorator ) { if( !mImpl->mTextInput ) { - mImpl->mTextInput = new TextInput( decorator ); + mImpl->mTextInput = new TextInput( mImpl->mLogicalModel, mImpl->mVisualModel, decorator ); } } @@ -368,7 +439,7 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations ) if( GET_GLYPH_METRICS & operations ) { - TextAbstraction::FontClient::Get().GetGlyphMetrics( glyphs.Begin(), glyphs.Count() ); + mImpl->mFontClient.GetGlyphMetrics( glyphs.Begin(), glyphs.Count() ); } if( LAYOUT & operations ) @@ -521,15 +592,16 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y ) } } -void Controller::GrabHandleEvent( GrabHandleState state, float x ) +void Controller::GrabHandleEvent( GrabHandleState state, float x, float y ) { DALI_ASSERT_DEBUG( mImpl->mTextInput && "Unexpected GrabHandleEvent" ); if( mImpl->mTextInput ) { TextInput::Event event( TextInput::GRAB_HANDLE_EVENT ); - event.p1.mInt = state; + event.p1.mUint = state; event.p2.mFloat = x; + event.p3.mFloat = y; mImpl->mTextInput->mEventQueue.push_back( event ); RequestRelayout();