2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
17 #include "toolkit-adaptor.h"
19 #include <dali/public-api/common/dali-common.h>
20 #include <dali/public-api/common/map-wrapper.h>
21 #include <dali/public-api/signals/dali-signal-v2.h>
26 ////////////////////////////////////////////////////////////////////////////////////////////////////
29 * Stub for RenderSurface
35 typedef Dali::Rect<int> PositionSize;
38 * Stub for the Adaptor
44 typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2;
46 typedef std::pair<std::string, Dali::BaseHandle> SingletonPair;
47 typedef std::map<std::string, Dali::BaseHandle> SingletonContainer;
48 typedef SingletonContainer::const_iterator SingletonConstIter;
52 Adaptor(ToolkitAdaptor& toolkitAdaptor);
61 bool AddIdle(boost::function<void(void)> callBack);
62 void FeedEvent(TouchPoint& point, int timeStamp);
63 bool MoveResize(const PositionSize& positionSize);
64 void SurfaceResized(const PositionSize& positionSize);
65 void ReplaceSurface(RenderSurface& surface);
67 RenderSurface& GetSurface();
69 void RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton);
70 Dali::BaseHandle GetSingleton(const std::type_info& info) const;
72 public: // static methods
73 static Adaptor& Get();
74 static bool IsAvailable();
78 AdaptorSignalV2& SignalResize();
80 void EmitSignalResize()
82 mResizeSignal.Emit( *this );
88 Adaptor(const Adaptor&);
89 Adaptor& operator=(Adaptor&);
91 AdaptorSignalV2 mResizeSignal;
92 RenderSurface mRenderSurface;
93 ToolkitAdaptor& mToolkitAdaptor;
95 SingletonContainer mSingletonContainer;
100 Adaptor* gAdaptor = NULL;
104 Adaptor::Adaptor(ToolkitAdaptor& toolkitAdaptor)
105 : mToolkitAdaptor(toolkitAdaptor)
114 void Adaptor::Start()
116 mToolkitAdaptor.mFunctionsCalled.Start = true;
119 void Adaptor::Pause()
121 mToolkitAdaptor.mFunctionsCalled.Pause = true;
124 void Adaptor::Resume()
126 mToolkitAdaptor.mFunctionsCalled.Resume = true;
131 mToolkitAdaptor.mFunctionsCalled.Stop = true;
134 bool Adaptor::AddIdle(boost::function<void(void)> callBack)
136 mToolkitAdaptor.mFunctionsCalled.AddIdle = true;
137 mToolkitAdaptor.mLastIdleAdded = callBack;
141 void Adaptor::FeedEvent(TouchPoint& point, int timeStamp)
143 mToolkitAdaptor.mFunctionsCalled.FeedEvent = true;
144 mToolkitAdaptor.mLastTouchPointFed = point;
145 mToolkitAdaptor.mLastTimeStampFed = timeStamp;
148 bool Adaptor::MoveResize(const PositionSize& positionSize)
150 mToolkitAdaptor.mFunctionsCalled.MoveResize = true;
151 mToolkitAdaptor.mLastSizeSet = positionSize;
155 void Adaptor::SurfaceResized(const PositionSize& positionSize)
157 mToolkitAdaptor.mFunctionsCalled.SurfaceResized = true;
158 mToolkitAdaptor.mLastSizeSet = positionSize;
161 void Adaptor::ReplaceSurface(RenderSurface& surface)
163 mToolkitAdaptor.mFunctionsCalled.ReplaceSurface = true;
166 void Adaptor::RenderSync()
168 mToolkitAdaptor.mFunctionsCalled.RenderSync = true;
171 RenderSurface& Adaptor::GetSurface()
173 mToolkitAdaptor.mFunctionsCalled.GetSurface = true;
174 return mRenderSurface;
177 Adaptor& Adaptor::Get()
179 DALI_ASSERT_ALWAYS(gAdaptor);
180 gAdaptor->mToolkitAdaptor.mFunctionsCalled.Get = true;
184 bool Adaptor::IsAvailable()
186 bool available(false);
190 gAdaptor->mToolkitAdaptor.mFunctionsCalled.IsAvailable = true;
197 void Adaptor::RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton)
199 mToolkitAdaptor.mFunctionsCalled.RegisterSingleton = true;
203 mSingletonContainer.insert(SingletonPair(info.name(), singleton));
207 Dali::BaseHandle Adaptor::GetSingleton(const std::type_info& info) const
209 mToolkitAdaptor.mFunctionsCalled.GetSingleton = true;
211 Dali::BaseHandle object = Dali::BaseHandle();
213 SingletonConstIter iter = mSingletonContainer.find(info.name());
214 if(iter != mSingletonContainer.end())
216 object = (*iter).second;
222 Adaptor::AdaptorSignalV2& Adaptor::SignalResize()
224 mToolkitAdaptor.mFunctionsCalled.SignalResize = true;
225 return mResizeSignal;
228 ////////////////////////////////////////////////////////////////////////////////////////////////////
230 ToolkitAdaptor::ToolkitAdaptor()
231 : mLastTouchPointFed(0, TouchPoint::Down, 0.0f, 0.0f),
232 mLastTimeStampFed(0),
233 mAdaptorStub(new Adaptor(*this))
235 gAdaptor = mAdaptorStub;
238 ToolkitAdaptor::~ToolkitAdaptor()
244 void ToolkitAdaptor::EmitSignalResize()
246 mAdaptorStub->EmitSignalResize();