2 * Copyright (c) 2020 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 <dali/internal/event/events/actor-gesture-data.h>
27 ActorGestureData::ActorGestureData()
28 : gesturesRequired( GestureType::Value( 0 ) ),
29 panDetectors( nullptr ),
30 pinchDetectors( nullptr ),
31 longPressDetectors( nullptr ),
32 tapDetectors( nullptr ),
33 rotationDetectors( nullptr )
37 ActorGestureData::~ActorGestureData()
40 delete pinchDetectors;
41 delete longPressDetectors;
43 delete rotationDetectors;
46 void ActorGestureData::AddGestureDetector( GestureDetector& detector )
48 const GestureType::Value type( detector.GetType() );
50 GestureDetectorContainer*& containerPtr( GetContainerPtr( type ) );
51 if ( nullptr == containerPtr )
53 containerPtr = new GestureDetectorContainer;
55 containerPtr->push_back( &detector );
57 gesturesRequired = GestureType::Value( gesturesRequired | type );
60 void ActorGestureData::RemoveGestureDetector( GestureDetector& detector )
62 const GestureType::Value type( detector.GetType() );
64 GestureDetectorContainer*& containerPtr( GetContainerPtr( type ) );
65 DALI_ASSERT_DEBUG( containerPtr && "Container had not been created" );
67 GestureDetectorContainer& container( *containerPtr );
68 GestureDetectorContainer::iterator match( std::remove( container.begin(), container.end(), &detector ) );
69 DALI_ASSERT_DEBUG( match != container.end() && "Actor does not have the detector" );
70 container.erase( match, container.end() );
72 if ( container.empty() )
74 gesturesRequired = GestureType::Value( gesturesRequired & ~type );
76 containerPtr = nullptr;
80 GestureDetectorContainer& ActorGestureData::GetGestureDetectorContainer( GestureType::Value type )
82 return *GetContainerPtr( type );
85 GestureDetectorContainer*& ActorGestureData::GetContainerPtr( GestureType::Value type )
89 case GestureType::PAN:
94 case GestureType::PINCH:
96 return pinchDetectors;
99 case GestureType::LONG_PRESS:
101 return longPressDetectors;
104 case GestureType::TAP:
109 case GestureType::ROTATION:
111 return rotationDetectors;
115 DALI_ASSERT_DEBUG( ! "Invalid Type" );
116 static GestureDetectorContainer* invalidType( nullptr );
120 } // namespace Internal