Revert "[Tizen] Restore Uploaded signal for BufferImage and ResourceImage"
[platform/core/uifw/dali-core.git] / dali / internal / event / events / actor-gesture-data.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/events/actor-gesture-data.h>
20
21 namespace Dali
22 {
23
24 namespace Internal
25 {
26
27 ActorGestureData::ActorGestureData()
28 : gesturesRequired( Gesture::Type( 0 ) ),
29   panDetectors( NULL ),
30   pinchDetectors( NULL ),
31   longPressDetectors( NULL ),
32   tapDetectors( NULL )
33 {
34 }
35
36 ActorGestureData::~ActorGestureData()
37 {
38   delete panDetectors;
39   delete pinchDetectors;
40   delete longPressDetectors;
41   delete tapDetectors;
42 }
43
44 void ActorGestureData::AddGestureDetector( GestureDetector& detector )
45 {
46   const Gesture::Type type( detector.GetType() );
47
48   GestureDetectorContainer*& containerPtr( GetContainerPtr( type ) );
49   if ( NULL == containerPtr )
50   {
51     containerPtr = new GestureDetectorContainer;
52   }
53   containerPtr->push_back( &detector );
54
55   gesturesRequired = Gesture::Type( gesturesRequired | type );
56 }
57
58 void ActorGestureData::RemoveGestureDetector( GestureDetector& detector )
59 {
60   const Gesture::Type type( detector.GetType() );
61
62   GestureDetectorContainer*& containerPtr( GetContainerPtr( type ) );
63   DALI_ASSERT_DEBUG( containerPtr && "Container had not been created" );
64
65   GestureDetectorContainer& container( *containerPtr );
66   GestureDetectorContainer::iterator match( std::remove( container.begin(), container.end(), &detector ) );
67   DALI_ASSERT_DEBUG( match != container.end() && "Actor does not have the detector" );
68   container.erase( match, container.end() );
69
70   if ( container.empty() )
71   {
72     gesturesRequired = Gesture::Type( gesturesRequired & ~type );
73     delete containerPtr;
74     containerPtr = NULL;
75   }
76 }
77
78 GestureDetectorContainer& ActorGestureData::GetGestureDetectorContainer( Gesture::Type type )
79 {
80   return *GetContainerPtr( type );
81 }
82
83 GestureDetectorContainer*& ActorGestureData::GetContainerPtr( Gesture::Type type )
84 {
85   switch ( type )
86   {
87     case Gesture::Pan:
88     {
89       return panDetectors;
90     }
91
92     case Gesture::Pinch:
93     {
94       return pinchDetectors;
95     }
96
97     case Gesture::LongPress:
98     {
99       return longPressDetectors;
100     }
101
102     case Gesture::Tap:
103     {
104       return tapDetectors;
105     }
106   }
107
108   DALI_ASSERT_DEBUG( ! "Invalid Type" );
109   static GestureDetectorContainer* invalidType( NULL );
110   return invalidType;
111 }
112
113 } // namespace Internal
114
115 } // namespace Dali
116