2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "indicator-impl.h"
25 #include <sys/types.h>
31 #include <dali/public-api/images/bitmap-image.h>
32 #include <pixmap-image.h>
33 #include <dali/public-api/actors/image-actor.h>
34 #include <dali/public-api/events/touch-event.h>
35 #include <dali/public-api/events/touch-point.h>
36 #include <dali/public-api/common/stage.h>
37 #include <dali/public-api/actors/blending.h>
38 #include <dali/public-api/shader-effects/shader-effect.h>
40 #include <dali/integration-api/debug.h>
43 #include <adaptor-impl.h>
44 #include <accessibility-manager-impl.h>
48 #if defined(DEBUG_ENABLED)
49 #define STATE_DEBUG_STRING(state) (state==DISCONNECTED?"DISCONNECTED":state==CONNECTED?"CONNECTED":"UNKNOWN")
55 const float SLIDING_ANIMATION_DURATION( 0.2f ); // 200 milli seconds
56 const float AUTO_INDICATOR_STAY_DURATION(3.0f); // 3 seconds
57 const float SHOWING_DISTANCE_HEIGHT_RATE(0.34f); // 20 pixels
65 const int NUM_GRADIENT_INTERVALS(5); // Number of gradient intervals
66 const Dali::Vector4 GRADIENT_COLORS[NUM_GRADIENT_INTERVALS+1] =
68 Vector4(0.0f, 0.0f, 0.0f, 0.6f),
69 Vector4(0.0f, 0.0f, 0.0f, 0.38f),
70 Vector4(0.0f, 0.0f, 0.0f, 0.20f),
71 Vector4(0.0f, 0.0f, 0.0f, 0.08f),
72 Vector4(0.0f, 0.0f, 0.0f, 0.0f),
73 Vector4(0.0f, 0.0f, 0.0f, 0.0f),
76 const float OPAQUE_THRESHOLD(0.99f);
77 const float TRANSPARENT_THRESHOLD(0.05f);
79 // Indicator orientation
80 const char* ELM_INDICATOR_PORTRAIT("elm_indicator_portrait");
81 const char* ELM_INDICATOR_LANDSCAPE("elm_indicator_landscape");
82 const char* ELM_INDICATOR_PORTRAIT_FIXED_COLOR_STYLE("elm_indicator_portrait_fixed");
83 const char* ELM_INDICATOR_LANDSCAPE_FIXED_COLOR_STYLE("elm_indicator_landscape_fixed");
85 const char* MESH_VERTEX_SHADER =
86 "attribute lowp vec3 aColor;\n"
87 "varying mediump vec4 vColor;\n"
90 " gl_Position = uMvpMatrix * vec4(aPosition, 1.0);\n"
91 " vColor = vec4(aColor.r, aColor.g, aColor.b, aTexCoord.x);\n"
94 const char* MESH_FRAGMENT_SHADER =
95 "varying mediump vec4 vColor;\n"
98 " gl_FragColor = vColor*uColor;\n"
101 // Copied from elm_win.h
104 * Defines the type modes of indicator that can be shown
105 * If the indicator can support several type of indicator,
106 * you can use this enum value to deal with different type of indicator
110 ELM_WIN_INDICATOR_TYPE_UNKNOWN, /**< Unknown indicator type mode */
111 ELM_WIN_INDICATOR_TYPE_1, /**< Type 0 the the indicator */
112 ELM_WIN_INDICATOR_TYPE_2, /**< Type 1 the indicator */
113 } Elm_Win_Indicator_Type_Mode;
115 // Copied from ecore_evas_extn.c
145 // Copied from elm_conform.c
147 const int MSG_DOMAIN_CONTROL_INDICATOR(0x10001);
148 const int MSG_ID_INDICATOR_REPEAT_EVENT(0x10002);
149 const int MSG_ID_INDICATOR_ROTATION(0x10003);
150 const int MSG_ID_INDICATOR_OPACITY(0X1004);
151 const int MSG_ID_INDICATOR_TYPE(0X1005);
152 const int MSG_ID_INDICATOR_START_ANIMATION(0X10006);
164 struct IpcIndicatorDataAnimation
170 struct IpcDataEvMouseUp
173 Evas_Button_Flags flags;
175 unsigned int timestamp;
176 Evas_Event_Flags event_flags;
178 IpcDataEvMouseUp(unsigned long timestamp)
180 flags(EVAS_BUTTON_NONE),
182 timestamp(static_cast<unsigned int>(timestamp)),
183 event_flags(EVAS_EVENT_FLAG_NONE)
188 struct IpcDataEvMouseDown
191 Evas_Button_Flags flags;
193 unsigned int timestamp;
194 Evas_Event_Flags event_flags;
196 IpcDataEvMouseDown(unsigned long timestamp)
198 flags(EVAS_BUTTON_NONE),
200 timestamp(static_cast<unsigned int>(timestamp)),
201 event_flags(EVAS_EVENT_FLAG_NONE)
206 struct IpcDataEvMouseMove
209 Evas_Button_Flags flags;
211 unsigned int timestamp;
212 Evas_Event_Flags event_flags;
214 IpcDataEvMouseMove(const Dali::TouchPoint& touchPoint, unsigned long timestamp)
215 : x(static_cast<Evas_Coord>(touchPoint.local.x)),
216 y(static_cast<Evas_Coord>(touchPoint.local.y)),
217 flags(EVAS_BUTTON_NONE),
219 timestamp(static_cast<unsigned int>(timestamp)),
220 event_flags(EVAS_EVENT_FLAG_NONE)
225 struct IpcDataEvMouseOut
227 unsigned int timestamp;
229 Evas_Event_Flags event_flags;
231 IpcDataEvMouseOut(unsigned long timestamp)
232 : timestamp(static_cast<unsigned int>(timestamp)),
234 event_flags(EVAS_EVENT_FLAG_NONE)
239 void SetMeshDataColors(Dali::AnimatableMesh mesh, const Vector4 (&colors)[NUM_GRADIENT_INTERVALS+1])
241 for( size_t i=0; i<NUM_GRADIENT_INTERVALS+1; i++ )
244 mesh[j].SetColor(colors[i]);
245 mesh[j+1].SetColor(colors[i]);
246 mesh[j].SetTextureCoords(Dali::Vector2(colors[i].a, colors[i].a));
247 mesh[j+1].SetTextureCoords(Dali::Vector2(colors[i].a, colors[i].a));
251 void SetMeshDataColors(Dali::AnimatableMesh mesh, const Vector4& color)
253 for( size_t i=0, length=NUM_GRADIENT_INTERVALS+1 ; i<length; i++ )
256 mesh[j].SetColor(color);
257 mesh[j+1].SetColor(color);
258 mesh[j].SetTextureCoords(Dali::Vector2(color.a, color.a));
259 mesh[j+1].SetTextureCoords(Dali::Vector2(color.a, color.a));
263 } // anonymous namespace
272 #if defined(DEBUG_ENABLED)
273 Debug::Filter* gIndicatorLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_INDICATOR");
277 Indicator::LockFile::LockFile(const char* filename)
278 : mFilename(filename),
281 mFileDescriptor = open(filename, O_RDWR);
282 if( mFileDescriptor == -1 )
286 DALI_LOG_ERROR( "### Cannot open %s for indicator lock ###\n", mFilename.c_str() );
290 Indicator::LockFile::~LockFile()
292 // Closing file descriptor also unlocks file.
293 close( mFileDescriptor );
296 bool Indicator::LockFile::Lock()
298 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
301 if( mFileDescriptor > 0 )
303 if( lockf( mFileDescriptor, F_LOCK, 0 ) == 0 ) // Note, operation may block.
311 // file descriptor is no longer valid or not writable
314 DALI_LOG_ERROR( "### Cannot lock indicator: bad file descriptor for %s ###\n", mFilename.c_str() );
322 void Indicator::LockFile::Unlock()
324 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
325 if( lockf( mFileDescriptor, F_ULOCK, 0 ) != 0 )
329 // file descriptor is no longer valid or not writable
332 DALI_LOG_ERROR( "### Cannot unlock indicator: bad file descriptor for %s\n", mFilename.c_str() );
337 bool Indicator::LockFile::RetrieveAndClearErrorStatus()
339 bool error = mErrorThrown;
340 mErrorThrown = false;
344 Indicator::ScopedLock::ScopedLock(LockFile* lockFile)
345 : mLockFile(lockFile),
350 mLocked = mLockFile->Lock();
354 Indicator::ScopedLock::~ScopedLock()
362 bool Indicator::ScopedLock::IsLocked()
367 Indicator::Indicator( Adaptor* adaptor, Dali::Window::WindowOrientation orientation, Dali::Window::IndicatorStyle style, Observer* observer )
369 mGestureDetected( false ),
372 mOpacityMode( Dali::Window::OPAQUE ),
373 mState( DISCONNECTED ),
375 mServerConnection( NULL ),
378 mObserver( observer ),
379 mOrientation( orientation ),
383 mVisible( Dali::Window::VISIBLE ),
385 mIsAnimationPlaying( false )
387 mIndicatorImageActor = Dali::ImageActor::New();
388 mIndicatorImageActor.SetBlendFunc( Dali::BlendingFactor::ONE, Dali::BlendingFactor::ONE_MINUS_SRC_ALPHA,
389 Dali::BlendingFactor::ONE, Dali::BlendingFactor::ONE );
391 mIndicatorImageActor.SetParentOrigin( ParentOrigin::TOP_CENTER );
392 mIndicatorImageActor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
394 // Indicator image handles the touch event including "leave"
395 mIndicatorImageActor.SetLeaveRequired( true );
396 mIndicatorImageActor.TouchedSignal().Connect( this, &Indicator::OnTouched );
399 mBackgroundActor.SetParentOrigin( ParentOrigin::TOP_CENTER );
400 mBackgroundActor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
401 mBackgroundActor.SetZ( -0.02f );
403 // add background to image actor to move it with indicator image
404 mIndicatorImageActor.Add( mBackgroundActor );
406 mIndicatorActor = Dali::Actor::New();
407 mIndicatorActor.Add( mIndicatorImageActor );
409 if( mOrientation == Dali::Window::LANDSCAPE || mOrientation == Dali::Window::LANDSCAPE_INVERSE )
411 mBackgroundActor.SetVisible( false );
414 // Event handler to find out flick down gesture
415 mEventActor = Dali::Actor::New();
416 mEventActor.SetParentOrigin( ParentOrigin::TOP_CENTER );
417 mEventActor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
418 mEventActor.SetZ( -0.01f );
419 mIndicatorActor.Add( mEventActor );
421 // Attach pan gesture to find flick down during hiding.
422 // It can prevent the problem that scrollview gets pan gesture even indicator area is touched,
423 // since it consumes the pan gesture in advance.
424 mPanDetector = Dali::PanGestureDetector::New();
425 mPanDetector.DetectedSignal().Connect( this, &Indicator::OnPan );
426 mPanDetector.Attach( mEventActor );
430 // register indicator to accessibility manager
431 Dali::AccessibilityManager accessibilityManager = AccessibilityManager::Get();
432 if(accessibilityManager)
434 AccessibilityManager::GetImplementation( accessibilityManager ).SetIndicator( this );
438 Indicator::~Indicator()
442 mEventActor.TouchedSignal().Disconnect( this, &Indicator::OnTouched );
447 void Indicator::SetAdaptor(Adaptor* adaptor)
450 mIndicatorBuffer->SetAdaptor( adaptor );
453 Dali::Actor Indicator::GetActor()
455 return mIndicatorActor;
458 void Indicator::Open( Dali::Window::WindowOrientation orientation )
460 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
462 // Calls from Window should be set up to ensure we are in a
463 // disconnected state before opening a second time.
464 DALI_ASSERT_DEBUG( mState == DISCONNECTED );
466 Connect( orientation );
468 // Change background visibility depending on orientation
469 if(mOrientation == Dali::Window::PORTRAIT || mOrientation == Dali::Window::PORTRAIT_INVERSE)
471 mBackgroundActor.SetVisible(true);
475 mBackgroundActor.SetVisible(false);
479 void Indicator::Close()
481 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "State: %s\n", STATE_DEBUG_STRING(mState) );
483 if( mState == CONNECTED )
486 if( mObserver != NULL )
488 mObserver->IndicatorClosed( this );
492 Dali::Image emptyImage;
493 mIndicatorImageActor.SetImage(emptyImage);
496 void Indicator::SetOpacityMode( Dali::Window::IndicatorBgOpacity mode )
502 void Indicator::SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate )
504 if ( visibleMode != mVisible || forceUpdate )
506 // If we were previously hidden, then we should update the image data before we display the indicator
507 if ( mVisible == Dali::Window::INVISIBLE )
512 mVisible = visibleMode;
514 if( mIndicatorImageActor.GetImage() )
516 if( CheckVisibleState() && mVisible == Dali::Window::AUTO )
519 ShowIndicator( AUTO_INDICATOR_STAY_DURATION /* stay n sec */ );
521 else if( CheckVisibleState() && mVisible == Dali::Window::VISIBLE )
524 ShowIndicator( KEEP_SHOWING );
529 ShowIndicator( HIDE_NOW );
535 bool Indicator::IsConnected()
537 return ( mState == CONNECTED );
540 bool Indicator::SendMessage( int messageDomain, int messageId, const void *data, int size )
544 return mServerConnection->SendEvent( OP_MSG, messageDomain, messageId, data, size );
552 bool Indicator::OnTouched(Dali::Actor indicator, const Dali::TouchEvent& touchEvent)
554 if( mServerConnection )
556 const TouchPoint& touchPoint = touchEvent.GetPoint( 0 );
558 // Send touch event to indicator server when indicator is showing
559 if( CheckVisibleState() || mIsShowing )
561 switch( touchPoint.state )
563 case Dali::TouchPoint::Down:
565 IpcDataEvMouseMove ipcMove( touchPoint, touchEvent.time );
566 IpcDataEvMouseDown ipcDown( touchEvent.time );
567 mServerConnection->SendEvent( OP_EV_MOUSE_MOVE, &ipcMove, sizeof(ipcMove) );
568 mServerConnection->SendEvent( OP_EV_MOUSE_DOWN, &ipcDown, sizeof(ipcDown) );
570 if( mVisible == Dali::Window::AUTO )
572 // Stop hiding indicator
573 ShowIndicator( KEEP_SHOWING );
578 case Dali::TouchPoint::Motion:
580 IpcDataEvMouseMove ipcMove( touchPoint, touchEvent.time );
581 mServerConnection->SendEvent( OP_EV_MOUSE_MOVE, &ipcMove, sizeof(ipcMove) );
585 case Dali::TouchPoint::Up:
587 IpcDataEvMouseUp ipcUp( touchEvent.time );
588 mServerConnection->SendEvent( OP_EV_MOUSE_UP, &ipcUp, sizeof(ipcUp) );
590 if( mVisible == Dali::Window::AUTO )
593 ShowIndicator( 0.5f /* hide after 0.5 sec */ );
598 case Dali::TouchPoint::Leave:
600 IpcDataEvMouseMove ipcMove( touchPoint, touchEvent.time );
601 mServerConnection->SendEvent( OP_EV_MOUSE_MOVE, &ipcMove, sizeof(ipcMove) );
602 IpcDataEvMouseUp ipcOut( touchEvent.time );
603 mServerConnection->SendEvent( OP_EV_MOUSE_OUT, &ipcOut, sizeof(ipcOut) );
619 * Return the current orientation in degrees
620 * @return value of 0, 90, 180 or 270
622 int Indicator::OrientationToDegrees( Dali::Window::WindowOrientation orientation )
626 switch( orientation )
628 case Dali::Window::PORTRAIT:
631 case Dali::Window::PORTRAIT_INVERSE:
634 case Dali::Window::LANDSCAPE:
637 case Dali::Window::LANDSCAPE_INVERSE:
644 bool Indicator::Connect( Dali::Window::WindowOrientation orientation )
646 DALI_ASSERT_DEBUG( mState == DISCONNECTED );
648 bool connected = false;
649 mOrientation = orientation;
650 mRotation = OrientationToDegrees(mOrientation);
652 switch( orientation )
654 case Dali::Window::PORTRAIT:
655 if(mStyle == Dali::Window::FIXED_COLOR)
657 connected = Connect( ELM_INDICATOR_PORTRAIT_FIXED_COLOR_STYLE );
661 connected = Connect( ELM_INDICATOR_PORTRAIT );
664 case Dali::Window::PORTRAIT_INVERSE:
665 if(mStyle == Dali::Window::FIXED_COLOR)
667 connected = Connect( ELM_INDICATOR_PORTRAIT_FIXED_COLOR_STYLE );
671 connected = Connect( ELM_INDICATOR_PORTRAIT );
674 case Dali::Window::LANDSCAPE:
675 if(mStyle == Dali::Window::FIXED_COLOR)
677 connected = Connect( ELM_INDICATOR_LANDSCAPE_FIXED_COLOR_STYLE );
681 connected = Connect( ELM_INDICATOR_LANDSCAPE );
684 case Dali::Window::LANDSCAPE_INVERSE:
685 if(mStyle == Dali::Window::FIXED_COLOR)
687 connected = Connect( ELM_INDICATOR_LANDSCAPE_FIXED_COLOR_STYLE );
691 connected = Connect( ELM_INDICATOR_LANDSCAPE );
699 bool Indicator::Connect( const char *serviceName )
701 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
703 bool connected = false;
705 mServerConnection = new ServerConnection( serviceName, 0, false, this );
706 if( mServerConnection )
708 connected = mServerConnection->IsConnected();
711 delete mServerConnection;
712 mServerConnection = NULL;
718 StartReconnectionTimer();
728 void Indicator::StartReconnectionTimer()
730 if( ! mReconnectTimer )
732 mReconnectTimer = Dali::Timer::New(1000);
733 mConnection.DisconnectAll();
734 mReconnectTimer.TickSignal().Connect( mConnection, &Indicator::OnReconnectTimer );
736 mReconnectTimer.Start();
739 bool Indicator::OnReconnectTimer()
743 if( mState == DISCONNECTED )
745 if( ! Connect( mOrientation ) )
754 void Indicator::Disconnect()
756 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
758 mState = DISCONNECTED;
766 delete mServerConnection;
767 mServerConnection = NULL;
770 void Indicator::NewLockFile( Ecore_Ipc_Event_Server_Data *epcEvent )
772 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
777 if ( (epcEvent->data) &&
778 (epcEvent->size > 0) &&
779 (((unsigned char *)epcEvent->data)[epcEvent->size - 1] == 0) )
781 const char* lockFile = static_cast< const char* >( epcEvent->data );
782 mLock = new Indicator::LockFile( lockFile );
783 if( mLock->RetrieveAndClearErrorStatus() )
785 DALI_LOG_ERROR( "### Indicator error: Cannot open lock file %s ###\n", lockFile );
790 void Indicator::Resize( int width, int height )
801 if( mImageWidth != width || mImageHeight != height )
804 mImageHeight = height;
806 // We don't currently handle the pixel buffer size being changed. Create a new image instead
814 void Indicator::LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent )
816 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
818 // epcEvent->ref == w
819 // epcEvent->ref_to == h
820 // epcEvent->response == alpha
821 // epcEvent->data = pixmap id
822 if( ( epcEvent->data ) &&
823 (epcEvent->size >= (int)sizeof(PixmapId)) )
825 if( mSharedFile != NULL )
831 if( (epcEvent->ref > 0) && (epcEvent->ref_to > 0) )
833 mImageWidth = epcEvent->ref;
834 mImageHeight = epcEvent->ref_to;
836 mPixmap = *(static_cast<PixmapId*>(epcEvent->data));
837 CreateNewPixmapImage();
839 if( CheckVisibleState() )
841 // set default indicator type (enable the quick panel)
842 OnIndicatorTypeChanged( INDICATOR_TYPE_1 );
846 // set default indicator type (disable the quick panel)
847 OnIndicatorTypeChanged( INDICATOR_TYPE_2 );
850 SetVisible(mVisible, true);
855 void Indicator::LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent )
857 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
859 // epcEvent->ref == w
860 // epcEvent->ref_to == h
861 // epcEvent->response == alpha
862 // epcEvent->data = shm ref string + nul byte
863 if( ( epcEvent->data ) &&
864 ( ( unsigned char * ) epcEvent->data)[ epcEvent->size - 1 ] == 0 )
866 if( mSharedFile != NULL )
872 if( (epcEvent->ref > 0) && (epcEvent->ref_to > 0) )
874 mImageWidth = epcEvent->ref;
875 mImageHeight = epcEvent->ref_to;
877 char* sharedFilename = static_cast<char*>(epcEvent->data);
879 mSharedFile = SharedFile::New( sharedFilename, mImageWidth * mImageWidth * 4, true );
880 if( mSharedFile != NULL )
883 mEventActor.SetSize(mImageWidth, mImageHeight);
885 if( CheckVisibleState() )
887 // set default indicator type (enable the quick panel)
888 OnIndicatorTypeChanged( INDICATOR_TYPE_1 );
892 // set default indicator type (disable the quick panel)
893 OnIndicatorTypeChanged( INDICATOR_TYPE_2 );
896 SetVisible(mVisible, true);
902 void Indicator::UpdateImageData()
904 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "State: %s mVisible: %s\n", STATE_DEBUG_STRING(mState), mVisible?"T":"F" );
906 if( mState == CONNECTED && mVisible )
910 // in case of shm indicator (not pixmap), not sure we can skip it when mIsShowing is false
917 mAdaptor->RequestUpdateOnce();
923 bool Indicator::CopyToBuffer()
925 bool success = false;
929 Indicator::ScopedLock scopedLock(mLock);
930 if( mLock->RetrieveAndClearErrorStatus() )
934 else if( scopedLock.IsLocked() )
936 unsigned char *src = mSharedFile->GetAddress();
937 size_t size = mImageWidth * mImageHeight * 4;
939 if( mIndicatorBuffer->UpdatePixels( src, size ) )
941 mAdaptor->RequestUpdateOnce();
950 void Indicator::SetBackground()
952 if( ! mBackgroundActor )
954 ConstructBackgroundMesh();
957 switch( mOpacityMode )
959 case Dali::Window::TRANSLUCENT:
961 SetMeshDataColors( mBackgroundMesh, GRADIENT_COLORS );
965 case Dali::Window::TRANSPARENT:
967 SetMeshDataColors( mBackgroundMesh, Color::TRANSPARENT );
971 case Dali::Window::OPAQUE:
974 SetMeshDataColors( mBackgroundMesh, Color::BLACK );
980 void Indicator::CreateNewPixmapImage()
982 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "W:%d H:%d\n", mImageWidth, mImageHeight );
983 Dali::PixmapImagePtr pixmapImage = Dali::PixmapImage::New(mPixmap, Dali::Adaptor::Get());
987 mIndicatorImageActor.SetImage( Dali::Image::New(*pixmapImage) );
988 mIndicatorImageActor.SetSize( mImageWidth, mImageHeight );
989 mIndicatorActor.SetSize( mImageWidth, mImageHeight );
990 mEventActor.SetSize(mImageWidth, mImageHeight);
993 if( mBackgroundActor )
995 mBackgroundActor.SetSize( mImageWidth, mImageHeight );
1000 DALI_LOG_WARNING("### Cannot create indicator image - disconnecting ###\n");
1002 if( mObserver != NULL )
1004 mObserver->IndicatorClosed( this );
1006 // Don't do connection in this callback - strange things happen!
1007 StartReconnectionTimer();
1011 void Indicator::CreateNewImage()
1013 DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "W:%d H:%d\n", mImageWidth, mImageHeight );
1014 mIndicatorBuffer = new IndicatorBuffer( mAdaptor, mImageWidth, mImageHeight, Pixel::BGRA8888 );
1015 Dali::Image image = Dali::Image::New( mIndicatorBuffer->GetNativeImage() );
1017 if( CopyToBuffer() ) // Only create images if we have valid image buffer
1019 mIndicatorImageActor.SetImage( image );
1020 mIndicatorImageActor.SetSize( mImageWidth, mImageHeight );
1021 mIndicatorActor.SetSize( mImageWidth, mImageHeight );
1022 mEventActor.SetSize(mImageWidth, mImageHeight);
1025 if( mBackgroundActor )
1027 mBackgroundActor.SetSize( mImageWidth, mImageHeight );
1032 DALI_LOG_WARNING("### Cannot create indicator image - disconnecting ###\n");
1034 if( mObserver != NULL )
1036 mObserver->IndicatorClosed( this );
1038 // Don't do connection in this callback - strange things happen!
1039 StartReconnectionTimer();
1043 void Indicator::OnIndicatorTypeChanged( Type indicatorType )
1045 if( mObserver != NULL )
1047 mObserver->IndicatorTypeChanged( indicatorType );
1051 void Indicator::DataReceived( void* event )
1053 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
1054 Ecore_Ipc_Event_Server_Data *epcEvent = static_cast<Ecore_Ipc_Event_Server_Data *>( event );
1056 switch( epcEvent->minor )
1059 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_UPDATE\n" );
1060 if(mPixmap != 0 && mIsShowing)
1062 mAdaptor->RequestUpdateOnce();
1066 case OP_UPDATE_DONE:
1067 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_UPDATE_DONE\n" );
1072 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_LOCK_FILE\n" );
1073 NewLockFile( epcEvent );
1077 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_SHM_REF\n" );
1078 LoadSharedImage( epcEvent );
1082 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_PIXMAP_REF\n" );
1083 LoadPixmapImage( epcEvent );
1087 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_RESIZE\n" );
1089 if( (epcEvent->data) && (epcEvent->size >= (int)sizeof(IpcDataResize)) )
1091 IpcDataResize *newSize = static_cast<IpcDataResize*>( epcEvent->data );
1092 Resize( newSize->w, newSize->h );
1098 int msgDomain = epcEvent->ref;
1099 int msgId = epcEvent->ref_to;
1101 void *msgData = NULL;
1102 int msgDataSize = 0;
1103 msgData = epcEvent->data;
1104 msgDataSize = epcEvent->size;
1106 if( msgDomain == MSG_DOMAIN_CONTROL_INDICATOR )
1110 case MSG_ID_INDICATOR_TYPE:
1112 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "Indicator client received: OP_MSG_PARENT, INDICATOR_TYPE\n" );
1113 Type* indicatorType = static_cast<Type*>( epcEvent->data );
1114 OnIndicatorTypeChanged( *indicatorType );
1118 case MSG_ID_INDICATOR_START_ANIMATION:
1120 if (msgDataSize != (int)sizeof(IpcIndicatorDataAnimation))
1122 DALI_LOG_ERROR("Message data is incorrect");
1126 IpcIndicatorDataAnimation *animData = static_cast<IpcIndicatorDataAnimation*>(msgData);
1128 if(!CheckVisibleState())
1130 ShowIndicator( animData->duration /* n sec */ );
1142 void Indicator::ConnectionClosed()
1144 DALI_LOG_TRACE_METHOD( gIndicatorLogFilter );
1146 // Will get this callback if the server connection failed to start up.
1147 delete mServerConnection;
1148 mServerConnection = NULL;
1149 mState = DISCONNECTED;
1151 // Attempt to re-connect
1152 Connect(mOrientation);
1155 bool Indicator::CheckVisibleState()
1157 if( mOrientation == Dali::Window::LANDSCAPE
1158 || mOrientation == Dali::Window::LANDSCAPE_INVERSE
1159 || (mVisible != Dali::Window::VISIBLE) )
1167 void Indicator::ConstructBackgroundMesh()
1169 // Construct 5 interval mesh
1181 Dali::AnimatableMesh::Faces faces;
1182 faces.reserve(NUM_GRADIENT_INTERVALS * 6); // 2 tris per interval
1183 for(int i=0; i<NUM_GRADIENT_INTERVALS; i++)
1186 faces.push_back(j); faces.push_back(j+3); faces.push_back(j+1);
1187 faces.push_back(j); faces.push_back(j+2); faces.push_back(j+3);
1190 mBackgroundMesh = Dali::AnimatableMesh::New((NUM_GRADIENT_INTERVALS+1)*2, faces);
1191 float interval=1.0f / (float)NUM_GRADIENT_INTERVALS;
1192 for(int i=0;i<NUM_GRADIENT_INTERVALS+1;i++)
1195 mBackgroundMesh[j ].SetPosition(Vector3(-0.5f, -0.5f+(interval*(float)i), 0.0f));
1196 mBackgroundMesh[j+1].SetPosition(Vector3( 0.5f, -0.5f+(interval*(float)i), 0.0f));
1199 mBackgroundActor = Dali::MeshActor::New(mBackgroundMesh);
1200 mBackgroundActor.SetAffectedByLighting(false);
1201 Dali::ShaderEffect shaderEffect = Dali::ShaderEffect::New( MESH_VERTEX_SHADER, MESH_FRAGMENT_SHADER,
1202 GEOMETRY_TYPE_MESH, // Using vertex color
1203 Dali::ShaderEffect::HINT_BLENDING );
1204 mBackgroundActor.SetShaderEffect(shaderEffect);
1208 * duration can be this
1212 * KEEP_SHOWING = -1,
1216 void Indicator::ShowIndicator(float duration)
1218 if( !mIndicatorAnimation )
1220 mIndicatorAnimation = Dali::Animation::New(SLIDING_ANIMATION_DURATION);
1221 mIndicatorAnimation.FinishedSignal().Connect(this, &Indicator::OnAnimationFinished);
1224 if(mIsShowing && !EqualsZero(duration))
1226 // If need to show during showing, do nothing.
1227 // In 2nd phase (below) will update timer
1229 else if(!mIsShowing && mIsAnimationPlaying && EqualsZero(duration))
1231 // If need to hide during hiding or hidden already, do nothing
1235 if( EqualsZero(duration) )
1237 mIndicatorAnimation.MoveTo(mIndicatorImageActor, Vector3(0, -mImageHeight, 0), Dali::AlphaFunctions::EaseOut);
1241 OnIndicatorTypeChanged( INDICATOR_TYPE_2 ); // un-toucable
1245 mIndicatorAnimation.MoveTo(mIndicatorImageActor, Vector3(0, 0, 0), Dali::AlphaFunctions::EaseOut);
1249 OnIndicatorTypeChanged( INDICATOR_TYPE_1 ); // touchable
1252 mIndicatorAnimation.Play();
1253 mIsAnimationPlaying = true;
1260 mShowTimer = Dali::Timer::New(1000 * duration);
1261 mShowTimer.TickSignal().Connect(this, &Indicator::OnShowTimer);
1263 mShowTimer.SetInterval(1000* duration);
1266 if( mVisible == Dali::Window::AUTO )
1268 // check the stage touch
1269 Dali::Stage::GetCurrent().TouchedSignal().Connect( this, &Indicator::OnStageTouched );
1274 if(mShowTimer && mShowTimer.IsRunning())
1279 if( mVisible == Dali::Window::AUTO )
1281 // check the stage touch
1282 Dali::Stage::GetCurrent().TouchedSignal().Disconnect( this, &Indicator::OnStageTouched );
1287 bool Indicator::OnShowTimer()
1289 // after time up, hide indicator
1290 ShowIndicator( HIDE_NOW );
1295 void Indicator::OnAnimationFinished(Dali::Animation& animation)
1297 mIsAnimationPlaying = false;
1300 void Indicator::OnPan( Dali::Actor actor, Dali::PanGesture gesture )
1302 if( mServerConnection )
1304 switch( gesture.state )
1306 case Gesture::Started:
1308 mGestureDetected = false;
1310 // The gesture position is the current position after it has moved by the displacement.
1311 // We want to reference the original position.
1312 mGestureDeltaY = gesture.position.y - gesture.displacement.y;
1315 // No break, Fall through
1316 case Gesture::Continuing:
1318 if( mVisible == Dali::Window::AUTO && !mIsShowing )
1320 // Only take one touch point
1321 if( gesture.numberOfTouches == 1 && mGestureDetected == false )
1323 mGestureDeltaY += gesture.displacement.y;
1325 if( mGestureDeltaY >= mImageHeight * SHOWING_DISTANCE_HEIGHT_RATE )
1327 ShowIndicator( AUTO_INDICATOR_STAY_DURATION );
1328 mGestureDetected = true;
1336 case Gesture::Finished:
1337 case Gesture::Cancelled:
1339 // if indicator is showing, hide again when touching is finished (Since touch leave is activated, checking it in gesture::finish instead of touch::up)
1340 if( mVisible == Dali::Window::AUTO && mIsShowing )
1342 ShowIndicator( AUTO_INDICATOR_STAY_DURATION );
1354 void Indicator::OnStageTouched(const Dali::TouchEvent& touchEvent)
1356 const TouchPoint& touchPoint = touchEvent.GetPoint( 0 );
1358 // when stage is touched while indicator is showing temporary, hide it
1359 if( mIsShowing && ( CheckVisibleState() == false || mVisible == Dali::Window::AUTO ) )
1361 switch( touchPoint.state )
1363 case Dali::TouchPoint::Down:
1365 ShowIndicator( HIDE_NOW );