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.
18 #include "toolkit-adaptor.h"
20 #include <dali/public-api/common/dali-common.h>
21 #include <dali/public-api/common/map-wrapper.h>
22 #include <dali/public-api/signals/dali-signal-v2.h>
27 ////////////////////////////////////////////////////////////////////////////////////////////////////
30 * Stub for RenderSurface
36 typedef Dali::Rect<int> PositionSize;
39 * Stub for the Adaptor
45 typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2;
47 typedef std::pair<std::string, Dali::BaseHandle> SingletonPair;
48 typedef std::map<std::string, Dali::BaseHandle> SingletonContainer;
49 typedef SingletonContainer::const_iterator SingletonConstIter;
53 Adaptor(ToolkitAdaptor& toolkitAdaptor);
62 bool AddIdle(boost::function<void(void)> callBack);
63 void FeedEvent(TouchPoint& point, int timeStamp);
64 bool MoveResize(const PositionSize& positionSize);
65 void SurfaceResized(const PositionSize& positionSize);
66 void ReplaceSurface(RenderSurface& surface);
68 RenderSurface& GetSurface();
70 void RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton);
71 Dali::BaseHandle GetSingleton(const std::type_info& info) const;
73 public: // static methods
74 static Adaptor& Get();
75 static bool IsAvailable();
79 AdaptorSignalV2& SignalResize();
81 void EmitSignalResize()
83 mResizeSignal.Emit( *this );
89 Adaptor(const Adaptor&);
90 Adaptor& operator=(Adaptor&);
92 AdaptorSignalV2 mResizeSignal;
93 RenderSurface mRenderSurface;
94 ToolkitAdaptor& mToolkitAdaptor;
96 SingletonContainer mSingletonContainer;
101 Adaptor* gAdaptor = NULL;
105 Adaptor::Adaptor(ToolkitAdaptor& toolkitAdaptor)
106 : mToolkitAdaptor(toolkitAdaptor)
115 void Adaptor::Start()
117 mToolkitAdaptor.mFunctionsCalled.Start = true;
120 void Adaptor::Pause()
122 mToolkitAdaptor.mFunctionsCalled.Pause = true;
125 void Adaptor::Resume()
127 mToolkitAdaptor.mFunctionsCalled.Resume = true;
132 mToolkitAdaptor.mFunctionsCalled.Stop = true;
135 bool Adaptor::AddIdle(boost::function<void(void)> callBack)
137 mToolkitAdaptor.mFunctionsCalled.AddIdle = true;
138 mToolkitAdaptor.mLastIdleAdded = callBack;
142 void Adaptor::FeedEvent(TouchPoint& point, int timeStamp)
144 mToolkitAdaptor.mFunctionsCalled.FeedEvent = true;
145 mToolkitAdaptor.mLastTouchPointFed = point;
146 mToolkitAdaptor.mLastTimeStampFed = timeStamp;
149 bool Adaptor::MoveResize(const PositionSize& positionSize)
151 mToolkitAdaptor.mFunctionsCalled.MoveResize = true;
152 mToolkitAdaptor.mLastSizeSet = positionSize;
156 void Adaptor::SurfaceResized(const PositionSize& positionSize)
158 mToolkitAdaptor.mFunctionsCalled.SurfaceResized = true;
159 mToolkitAdaptor.mLastSizeSet = positionSize;
162 void Adaptor::ReplaceSurface(RenderSurface& surface)
164 mToolkitAdaptor.mFunctionsCalled.ReplaceSurface = true;
167 void Adaptor::RenderSync()
169 mToolkitAdaptor.mFunctionsCalled.RenderSync = true;
172 RenderSurface& Adaptor::GetSurface()
174 mToolkitAdaptor.mFunctionsCalled.GetSurface = true;
175 return mRenderSurface;
178 Adaptor& Adaptor::Get()
180 DALI_ASSERT_ALWAYS(gAdaptor);
181 gAdaptor->mToolkitAdaptor.mFunctionsCalled.Get = true;
185 bool Adaptor::IsAvailable()
187 bool available(false);
191 gAdaptor->mToolkitAdaptor.mFunctionsCalled.IsAvailable = true;
198 void Adaptor::RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton)
200 mToolkitAdaptor.mFunctionsCalled.RegisterSingleton = true;
204 mSingletonContainer.insert(SingletonPair(info.name(), singleton));
208 Dali::BaseHandle Adaptor::GetSingleton(const std::type_info& info) const
210 mToolkitAdaptor.mFunctionsCalled.GetSingleton = true;
212 Dali::BaseHandle object = Dali::BaseHandle();
214 SingletonConstIter iter = mSingletonContainer.find(info.name());
215 if(iter != mSingletonContainer.end())
217 object = (*iter).second;
223 Adaptor::AdaptorSignalV2& Adaptor::SignalResize()
225 mToolkitAdaptor.mFunctionsCalled.SignalResize = true;
226 return mResizeSignal;
229 ////////////////////////////////////////////////////////////////////////////////////////////////////
231 ToolkitAdaptor::ToolkitAdaptor()
232 : mLastTouchPointFed(0, TouchPoint::Down, 0.0f, 0.0f),
233 mLastTimeStampFed(0),
234 mAdaptorStub(new Adaptor(*this))
236 gAdaptor = mAdaptorStub;
239 ToolkitAdaptor::~ToolkitAdaptor()
245 void ToolkitAdaptor::EmitSignalResize()
247 mAdaptorStub->EmitSignalResize();