Use RegisterUniqueProperty for some more renderers
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-window.cpp
1 /*
2  * Copyright (c) 2020 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 "toolkit-window-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/public-api/object/base-object.h>
25
26 #define DALI_WINDOW_H
27 #include <dali/integration-api/adaptor-framework/adaptor.h>
28 #include <toolkit-adaptor-impl.h>
29
30 using AdaptorImpl = Dali::Internal::Adaptor::Adaptor;
31
32 namespace Dali
33 {
34
35 class Window;
36
37 /********************************************************************************
38  * Stub for Dali::Internal::Adaptor::Window
39  ********************************************************************************/
40
41 namespace Internal
42 {
43 namespace Adaptor
44 {
45
46 Window::Window( const PositionSize& positionSize )
47 : SceneHolder( positionSize ),
48   mFocusChangeSignal(),
49   mResizeSignal(),
50   mRotationAngle(90), // dummy angle for test coverage
51   mVisible(true),
52   mVisibilityChangedSignal()
53 {
54 }
55
56 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
57 {
58   return new Window( positionSize );
59 }
60
61 WindowPosition Window::GetPosition() const
62 {
63   PositionSize positionSize = mRenderSurface.GetPositionSize();
64
65   return WindowPosition(positionSize.x, positionSize.y);
66 }
67
68 PositionSize Window::GetPositionSize() const
69 {
70   return mRenderSurface.GetPositionSize();
71 }
72
73 Dali::Window::WindowSize Window::GetSize() const
74 {
75   PositionSize positionSize = mRenderSurface.GetPositionSize();
76
77   return Dali::Window::WindowSize(positionSize.width, positionSize.height);
78 }
79
80 void Window::SetPositionSize(PositionSize positionSize)
81 {
82   mRenderSurface.MoveResize(positionSize);
83
84   Uint16Pair newSize(positionSize.width, positionSize.height);
85   Dali::Window handle(this);
86   mResizeSignal.Emit(handle, newSize);
87 }
88
89 } // Adaptor
90 } // Internal
91
92 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
93 {
94   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
95   BaseObject& object = window.GetBaseObject();
96   return static_cast<Internal::Adaptor::Window&>(object);
97 }
98
99 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
100 {
101   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
102   const BaseObject& object = window.GetBaseObject();
103   return static_cast<const Internal::Adaptor::Window&>(object);
104 }
105
106 Window::Window()
107 {
108 }
109
110 Window::~Window()
111 {
112 }
113
114 Window::Window( const Window& copy ) = default;
115
116 Window& Window::operator=( const Window& rhs ) = default;
117
118 Window::Window( Window&& rhs ) = default;
119
120 Window& Window::operator=( Window&& rhs ) = default;
121
122 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
123 {
124   return New( windowPosition, name, "", isTransparent );
125 }
126
127 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
128 {
129   Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
130
131   Dali::Window result( window );
132
133   // This will also emit the window created signals
134   AdaptorImpl::GetImpl( AdaptorImpl::Get() ).AddWindow( window );
135
136   return result;
137 }
138
139 Window::Window( Internal::Adaptor::Window* window )
140 : BaseHandle( window )
141 {
142 }
143
144 Integration::Scene Window::GetScene()
145 {
146   return GetImplementation( *this ).GetScene();
147 }
148
149 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
150 {
151   return GetImplementation( *this ).GetRenderSurface();
152 }
153
154 void Window::Add( Actor actor )
155 {
156   GetImplementation( *this ).Add( actor );
157 }
158
159 void Window::Remove( Actor actor )
160 {
161   GetImplementation( *this ).Remove( actor );
162 }
163
164 Dali::Layer Window::GetRootLayer() const
165 {
166   return GetImplementation( *this ).GetRootLayer();
167 }
168
169 void Window::SetBackgroundColor( const Vector4& color )
170 {
171   GetImplementation( *this ).SetBackgroundColor( color );
172 }
173
174 Vector4 Window::GetBackgroundColor() const
175 {
176   return GetImplementation( *this ).GetBackgroundColor();
177 }
178
179 void Window::Raise()
180 {
181   GetImplementation( *this ).mFocusChangeSignal.Emit(*this, true);
182 }
183
184 void Window::Hide()
185 {
186   GetImplementation( *this ).mVisibilityChangedSignal.Emit( *this, false );
187   GetImplementation( *this ).mVisible = false;
188 }
189
190 bool Window::IsVisible() const
191 {
192   return GetImplementation( *this ).mVisible;
193 }
194
195 FocusChangeSignalType& Window::FocusChangeSignal()
196 {
197   return GetImplementation( *this ).mFocusChangeSignal;
198 }
199
200 ResizeSignalType& Window::ResizeSignal()
201 {
202   return GetImplementation( *this ).mResizeSignal;
203 }
204
205 Window::KeyEventSignalType& Window::KeyEventSignal()
206 {
207   return GetImplementation( *this ).KeyEventSignal();
208 }
209
210 Window::TouchEventSignalType& Window::TouchedSignal()
211 {
212   return GetImplementation( *this ).TouchedSignal();
213 }
214
215 namespace DevelWindow
216 {
217
218 Window Get( Actor actor )
219 {
220   Internal::Adaptor::Window* windowImpl = nullptr;
221
222   if ( Dali::Adaptor::IsAvailable() )
223   {
224     windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
225   }
226
227   return Dali::Window( windowImpl );
228 }
229
230 Window DownCast( BaseHandle handle )
231 {
232   Internal::Adaptor::Window* windowImpl = nullptr;
233   if ( Dali::Adaptor::IsAvailable() )
234   {
235     windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>( handle.GetObjectPtr());
236   }
237   return Dali::Window( windowImpl );
238 }
239
240 void SetPositionSize(Window window, PositionSize positionSize)
241 {
242   GetImplementation( window ).SetPositionSize(positionSize);
243 }
244
245 int GetPhysicalOrientation(Window window)
246 {
247   return GetImplementation( window ).mRotationAngle;
248 }
249
250 void AddFrameRenderedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
251 {
252   CallbackBase::Execute( *callback, frameId );
253 }
254
255 void AddFramePresentedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
256 {
257   CallbackBase::Execute( *callback, frameId );
258 }
259
260 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
261 {
262   return GetImplementation( window ).GetScene().EventProcessingFinishedSignal();
263 }
264
265 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
266 {
267   return GetImplementation( window ).KeyEventGeneratedSignal();
268 }
269
270 WheelEventSignalType& WheelEventSignal( Window window )
271 {
272   return GetImplementation( window ).WheelEventSignal();
273 }
274
275 VisibilityChangedSignalType& VisibilityChangedSignal( Window window )
276 {
277   return GetImplementation( window ).mVisibilityChangedSignal;
278 }
279
280 } // namespace DevelWindow
281
282 } // Dali