2 * Copyright (c) 2021 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>
25 ActorGestureData::ActorGestureData()
26 : gesturesRequired(GestureType::Value(0)),
27 panDetectors(nullptr),
28 pinchDetectors(nullptr),
29 longPressDetectors(nullptr),
30 tapDetectors(nullptr),
31 rotationDetectors(nullptr)
35 ActorGestureData::~ActorGestureData()
38 delete pinchDetectors;
39 delete longPressDetectors;
41 delete rotationDetectors;
44 void ActorGestureData::AddGestureDetector(GestureDetector& detector)
46 const GestureType::Value type(detector.GetType());
48 GestureDetectorContainer*& containerPtr(GetContainerPtr(type));
49 if(nullptr == containerPtr)
51 containerPtr = new GestureDetectorContainer;
53 containerPtr->push_back(&detector);
55 gesturesRequired = GestureType::Value(gesturesRequired | type);
58 void ActorGestureData::RemoveGestureDetector(GestureDetector& detector)
60 const GestureType::Value type(detector.GetType());
62 GestureDetectorContainer*& containerPtr(GetContainerPtr(type));
63 DALI_ASSERT_DEBUG(containerPtr && "Container had not been created");
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());
72 gesturesRequired = GestureType::Value(gesturesRequired & ~type);
74 containerPtr = nullptr;
78 GestureDetectorContainer& ActorGestureData::GetGestureDetectorContainer(GestureType::Value type)
80 return *GetContainerPtr(type);
83 GestureDetectorContainer*& ActorGestureData::GetContainerPtr(GestureType::Value type)
87 case GestureType::PAN:
92 case GestureType::PINCH:
94 return pinchDetectors;
97 case GestureType::LONG_PRESS:
99 return longPressDetectors;
102 case GestureType::TAP:
107 case GestureType::ROTATION:
109 return rotationDetectors;
113 DALI_ASSERT_DEBUG(!"Invalid Type");
114 static GestureDetectorContainer* invalidType(nullptr);
118 } // namespace Internal