Merge "ImageView ResourceReady logic update" into devel/master
[platform/core/uifw/dali-toolkit.git] / docs / content / programming-guide / event-system.h
1 /*! \page event-system Event Handling
2
3 DALi emits several signals to an application to inform it of user actions.
4
5 <h2 class="pg">Touch</h2>
6
7 An application can be notified when a user interacts with the touch screen on the device by connecting to the touch signal provided by Dali::Actor.
8 This signal will be emitted by DALi whenever the touch occurs within the connected actor's bounds.
9
10 Each point on the screen that is currently being touched or where touch has stopped is represented by a point.
11 Dali::TouchData stores information about the state of each point (down, up, motion etc.) and the co-ordinates of the touch.
12
13 When a multi-touch event occurs, each point represents the points that are currently being touched or the points where touch has stopped.
14
15 The following example shows how a connection to a touch event signal can be established:
16
17 @code
18 bool OnTouch( Dali::Actor actor, const Dali::TouchData& touch )
19 {
20   bool handled = false;
21
22   switch( touch.GetPointCount() )
23   {
24     case 1: // Single touch
25       if ( touch.GetState( 0 ) == Dali::PointState::DOWN )
26       {
27         // Do action when first touches the touch screen.
28         ...
29         handled = true;
30       }
31       ...
32       break;
33
34     case 2: // Multi-touch event
35       ...
36       break;
37     ...
38   }
39
40   return handled;  // true if we have handled the touch, false otherwise
41 }
42
43 // Elsewhere
44 Dali::Actor actor = Actor::New();
45 actor.TouchSignal().Connect( &OnTouch );
46 @endcode
47
48 The primary touch point is the first point that the user touches.
49
50 The touch signal is first emitted to the actor which is hit by the primary touch point.
51 If this hit actor does not handle (consume) the event, then the event is offered to the hit actor's parent.
52 Again, if the parent does not handle this event, it is then offered to its parent and so on until the stage is reached or the event is consumed.
53
54 If the TouchSignal of both a parent and child are connected to, then the touch event is first offered to the child's listener.
55 If it is consumed by the child's listener, then the parent will not be informed.
56
57 <h2 class="pg">Gestures</h2>
58
59 A Dali::GestureDetector analyses a stream of touch input and attempts to determine the intention of the user.
60 An actor is attached to a gesture detector and if the detector recognises a pattern, it will emit a detected signal to the application.
61
62 The following gesture detectors are currently supported in DALi:
63
64 - Dali::LongPressGestureDetector - When the user presses and holds a particular point on the screen for a specified length of time.
65 - Dali::PinchGestureDetector - When the user moves two fingers towards or away from each other.
66 - Dali::PanGestureDetector - When the user moves one or more fingers in the same direction.
67 - Dali::TapGestureDetector - When the user taps the screen.
68
69 The example below shows how an application can be notified of a pinch gesture:
70
71 @code
72 void OnPinch( Dali::Actor actor, const Dali::PinchGesture& pinch )
73 {
74   // Scale your actor according to the pinch scale
75   Vector3 newSize = actor.GetCurrentSize() * pinch.scale;
76   actor.SetSize(newSize);
77 }
78
79 // Elsewhere
80 Dali::PinchGestureDetector detector = Dali::PinchDetector::New();
81 detector.Attach( myActor );
82 detector.DetectedSignal().Connect( &OnPinch );
83 @endcode
84
85 */