From c24e97fce74115f16793a88dfbf5db2bbb73ccb1 Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Mon, 2 Mar 2015 17:08:44 +0000 Subject: [PATCH] Decorator to show cursor Change-Id: I178d1f99ccc1246984cada7e0bf15c66435d1b1d Signed-off-by: Agnelo Vaz --- dali-toolkit/images/decorator-cursor.png | Bin 0 -> 2802 bytes .../public-api/text/decorator/text-decorator.cpp | 128 +++++++++++++++++++-- dali-toolkit/public-api/text/text-controller.cpp | 4 +- 3 files changed, 122 insertions(+), 10 deletions(-) create mode 100644 dali-toolkit/images/decorator-cursor.png diff --git a/dali-toolkit/images/decorator-cursor.png b/dali-toolkit/images/decorator-cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..bbb993fbefd60843ce61e8172c76fc3d653f6f37 GIT binary patch literal 2802 zcmVOz@Z0f2-7z;ux~O9+4z06=<WDR*FRcSTFz- zW=q650N5=6FiBTtNC2?60Km==3$g$R3;-}uh=nNt1bYBr$Ri_o0EC$U6h`t_Jn<{8 z5a%iY0C<_QJh>z}MS)ugEpZ1|S1ukX&Pf+56gFW3VVXcL!g-k)GJ!M?;PcD?0HBc- z5#WRK{dmp}uFlRjj{U%*%WZ25jX z{P*?XzTzZ-GF^d31o+^>%=Ap99M6&ogks$0k4OBs3;+Bb(;~!4V!2o<6ys46agIcq zjPo+3B8fthDa9qy|77CdEc*jK-!%ZRYCZvbku9iQV*~a}ClFY4z~c7+0P?$U!PF=S z1Au6Q;m>#f??3%Vpd|o+W=WE9003S@Bra6Svp>fO002awfhw>;8}z{#EWidF!3EsG z3;bXU&9EIRU@z1_9W=mEXoiz;4lcq~xDGvV5BgyU zp1~-*fe8db$Osc*A=-!mVv1NJjtCc-h4>-CNCXm#Bp}I%6j35eku^v$Qi@a{RY)E3 zJ#qp$hg?Rwkvqr$GJ^buyhkyVfwECO)C{#lxu`c9ghrwZ&}4KmnvWKso6vH!8a<3Q zq36)6Xb;+tK10Vaz~~qUGsJ8#F2=(`u{bOVlV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+q;9dL%E~B zJh;4Nr^(LEJ3myURP{Rblsw%57T)g973R8o)DE9*xN#~;4_o$q%o z4K@u`jhx2fBXC4{U8Qn{*%*B$Ge=nny$HAYq{=vy|sI0 z_vss+H_qMky?OB#|JK!>IX&II^LlUh#rO5!7TtbwC;iULyV-Xq?ybB}ykGP{?LpZ? z-G|jbTmIbG@7#ZCz;~eY(cDM(28Dyq{*m>M4?_iynUBkc4TkHUI6gT!;y-fz>HMcd z&t%Ugo)`Y2{>!cx7B7DI)$7;J(U{Spm-3gBzioV_{p!H$8L!*M!p0uH$#^p{Ui4P` z?ZJ24cOCDe-w#jZd?0@)|7iKK^;6KN`;!@ylm7$*nDhK&GcDTy000JJOGiWi{{a60 z|De66lK=n!32;bRa{vGf6951U69E94oEQKA00(qQO+^Ra0vio865Vb9j{pDwBuPX; zR2b7^WPpJG3<$u;`2YWZWB~?7Mn(oE1}tDykoJO%0PTncCsnmM!2kdN07*qoM6N<$ Ef(9KmX8-^I literal 0 HcmV?d00001 diff --git a/dali-toolkit/public-api/text/decorator/text-decorator.cpp b/dali-toolkit/public-api/text/decorator/text-decorator.cpp index 0503635..ce93854 100644 --- a/dali-toolkit/public-api/text/decorator/text-decorator.cpp +++ b/dali-toolkit/public-api/text/decorator/text-decorator.cpp @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include #include #include #include @@ -49,10 +50,13 @@ const char* DEFAULT_SELECTION_HANDLE_ONE( DALI_IMAGE_DIR "text-input-selection-h const char* DEFAULT_SELECTION_HANDLE_TWO( DALI_IMAGE_DIR "text-input-selection-handle-right.png" ); //const char* DEFAULT_SELECTION_HANDLE_ONE_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-left-press.png" ); //const char* DEFAULT_SELECTION_HANDLE_TWO_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-right-press.png" ); +const char* DEFAULT_CURSOR_IMAGE( DALI_IMAGE_DIR "decorator-cursor.png"); const Dali::Vector3 DEFAULT_GRAB_HANDLE_RELATIVE_SIZE( 1.5f, 2.0f, 1.0f ); const Dali::Vector3 DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE( 1.5f, 1.5f, 1.0f ); +const std::size_t CURSOR_BLINK_INTERVAL = 500; // Cursor blink interval + } // end of namespace namespace Dali @@ -110,13 +114,21 @@ struct Decorator::Impl : public ConnectionTracker mObserver(observer), mActiveCursor(ACTIVE_CURSOR_NONE), mActiveGrabHandle(false), - mCursorBlinkInterval(0.5f), - mCursorBlinkDuration(0.0f) + mActiveSelection( false ), + mCursorBlinkInterval( CURSOR_BLINK_INTERVAL ), + mCursorBlinkDuration(0.0f), + mCursorBlinkStatus( true ) { } + /** + * Relayout of the decorations owned by the decorator. + * @param[in] size The Size of the UI control the decorater is adding it's decorations to. + */ void Relayout( const Vector2& size ) { + SetCursors(); + // Show or hide the grab handle if( mActiveGrabHandle ) { @@ -153,8 +165,81 @@ struct Decorator::Impl : public ConnectionTracker UnparentAndReset( mSelectionHandle[ PRIMARY_SELECTION_HANDLE ].actor ); UnparentAndReset( mSelectionHandle[ SECONDARY_SELECTION_HANDLE ].actor ); } + } - // TODO + /** + * Creates a cursor + */ + void CreateCursor( ImageActor& cursor ) + { + if ( !mCursorImage ) + { + mCursorImage = ResourceImage::New( DEFAULT_CURSOR_IMAGE ); + } + cursor = ImageActor::New( mCursorImage ); + cursor.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + } + + /** + * Add / Remove cursor(s) from parent + */ + void SetCursors() + { + Actor parent = mParent.Self(); + /* Create Primary and or Secondary Cursor(s) if active and add to parent */ + if ( mActiveCursor == ACTIVE_CURSOR_PRIMARY ) + { + if ( !mPrimaryCursor ) + { + CreateCursor( mPrimaryCursor ); +#ifdef DECORATOR_DEBUG + mPrimaryCursor.SetName( "PrimaryCursorActor" ); +#endif + parent.Add( mPrimaryCursor); + } + } + else if ( mActiveCursor == ACTIVE_CURSOR_BOTH ) + { + if ( !mSecondaryCursor ) + { + CreateCursor( mSecondaryCursor ); +#ifdef DECORATOR_DEBUG + mSecondaryCursor.SetName( "SecondaryCursorActor" ); +#endif + parent.Add( mSecondaryCursor); + } + } + else + { + /* ACTIVE_CURSOR_NONE so unparent cursors*/ + if ( mPrimaryCursor ) + { + UnparentAndReset( mPrimaryCursor ); + } + + if ( mSecondaryCursor ) + { + UnparentAndReset( mSecondaryCursor ); + } + } + } + + bool OnCursorBlinkTimerTick() + { + // Cursor blinking + if ( ACTIVE_CURSOR_PRIMARY ) + { + mPrimaryCursor.SetVisible( mCursorBlinkStatus ); + } + else if ( ACTIVE_CURSOR_BOTH ) + { + mPrimaryCursor.SetVisible( mCursorBlinkStatus ); + mSecondaryCursor.SetVisible( mCursorBlinkStatus ); + } + + mCursorBlinkStatus = !mCursorBlinkStatus; + + return true; } void SetupTouchEvents() @@ -329,7 +414,7 @@ struct Decorator::Impl : public ConnectionTracker Internal::Control& mParent; Observer& mObserver; - Layer mActiveLayer; ///< Layer for active handles and alike that ensures they are above all else. + Layer mActiveLayer; // Layer for active handles and alike that ensures they are above all else. unsigned int mActiveCursor; bool mActiveGrabHandle; @@ -337,6 +422,14 @@ struct Decorator::Impl : public ConnectionTracker CursorImpl mCursor[CURSOR_COUNT]; + Timer mCursorBlinkTimer; // Timer to signal cursor to blink + unsigned int mCursorBlinkInterval; + float mCursorBlinkDuration; + bool mCursorBlinkStatus; // Flag to switch between blink on and blink off + + ImageActor mPrimaryCursor; + ImageActor mSecondaryCursor; + ImageActor mGrabHandle; Actor mGrabArea; @@ -348,8 +441,7 @@ struct Decorator::Impl : public ConnectionTracker TapGestureDetector mTapDetector; PanGestureDetector mPanGestureDetector; - float mCursorBlinkInterval; - float mCursorBlinkDuration; + }; DecoratorPtr Decorator::New( Internal::Control& parent, Observer& observer ) @@ -362,6 +454,8 @@ void Decorator::Relayout( const Vector2& size ) mImpl->Relayout( size ); } +/** Cursor **/ + void Decorator::SetActiveCursor( ActiveCursor activeCursor ) { mImpl->mActiveCursor = activeCursor; @@ -408,17 +502,29 @@ const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const void Decorator::StartCursorBlink() { - // TODO + if ( !mImpl->mCursorBlinkTimer ) + { + mImpl->mCursorBlinkTimer = Timer::New( mImpl->mCursorBlinkInterval ); + mImpl->mCursorBlinkTimer.TickSignal().Connect( mImpl, &Decorator::Impl::OnCursorBlinkTimerTick ); + } + + if ( !mImpl->mCursorBlinkTimer.IsRunning() ) + { + mImpl->mCursorBlinkTimer.Start(); + } } void Decorator::StopCursorBlink() { - // TODO + if ( mImpl->mCursorBlinkTimer ) + { + mImpl->mCursorBlinkTimer.Stop(); + } } void Decorator::SetCursorBlinkInterval( float seconds ) { - mImpl->mCursorBlinkInterval = seconds; + mImpl->mCursorBlinkInterval = seconds*1000; // Convert to milliseconds } float Decorator::GetCursorBlinkInterval() const @@ -436,6 +542,8 @@ float Decorator::GetCursorBlinkDuration() const return mImpl->mCursorBlinkDuration; } +/** GrabHandle **/ + void Decorator::SetGrabHandleActive( bool active ) { mImpl->mActiveGrabHandle = active; @@ -456,6 +564,8 @@ Dali::Image Decorator::GetGrabHandleImage() const return mImpl->mGrabHandleImage; } +/** Selection **/ + void Decorator::SetSelectionActive( bool active ) { mImpl->mActiveSelection = active; diff --git a/dali-toolkit/public-api/text/text-controller.cpp b/dali-toolkit/public-api/text/text-controller.cpp index 7d0b956..878272c 100644 --- a/dali-toolkit/public-api/text/text-controller.cpp +++ b/dali-toolkit/public-api/text/text-controller.cpp @@ -143,8 +143,10 @@ 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 ); + mDecorator->SetPosition( PRIMARY_CURSOR, 10, 0, 18 ); mDecoratorUpdated = true; } else if( 2u == event.p1.mUint ) -- 2.7.4