PositionSize API at dali-toolkit-test-utils/toolkit-window.cpp
[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   mVisibilityChangedSignal()
52 {
53 }
54
55 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
56 {
57   return new Window( positionSize );
58 }
59
60 WindowPosition Window::GetPosition() const
61 {
62   PositionSize positionSize = mRenderSurface.GetPositionSize();
63
64   return WindowPosition(positionSize.x, positionSize.y);
65 }
66
67 PositionSize Window::GetPositionSize() const
68 {
69   return mRenderSurface.GetPositionSize();
70 }
71
72 void Window::SetPositionSize(PositionSize positionSize)
73 {
74   mRenderSurface.MoveResize(positionSize);
75
76   Uint16Pair newSize(positionSize.width, positionSize.height);
77   Dali::Window handle(this);
78   mResizeSignal.Emit(handle, newSize);
79 }
80
81 } // Adaptor
82 } // Internal
83
84 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
85 {
86   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
87   BaseObject& object = window.GetBaseObject();
88   return static_cast<Internal::Adaptor::Window&>(object);
89 }
90
91 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
92 {
93   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
94   const BaseObject& object = window.GetBaseObject();
95   return static_cast<const Internal::Adaptor::Window&>(object);
96 }
97
98 Window::Window()
99 {
100 }
101
102 Window::~Window()
103 {
104 }
105
106 Window::Window( const Window& copy ) = default;
107
108 Window& Window::operator=( const Window& rhs ) = default;
109
110 Window::Window( Window&& rhs ) = default;
111
112 Window& Window::operator=( Window&& rhs ) = default;
113
114 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
115 {
116   return New( windowPosition, name, "", isTransparent );
117 }
118
119 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
120 {
121   Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
122
123   Dali::Window result( window );
124
125   // This will also emit the window created signals
126   AdaptorImpl::GetImpl( AdaptorImpl::Get() ).AddWindow( window );
127
128   return result;
129 }
130
131 Window::Window( Internal::Adaptor::Window* window )
132 : BaseHandle( window )
133 {
134 }
135
136 Integration::Scene Window::GetScene()
137 {
138   return GetImplementation( *this ).GetScene();
139 }
140
141 Dali::RenderSurfaceInterface& Window::GetRenderSurface()
142 {
143   return GetImplementation( *this ).GetRenderSurface();
144 }
145
146 void Window::Add( Actor actor )
147 {
148   GetImplementation( *this ).Add( actor );
149 }
150
151 void Window::Remove( Actor actor )
152 {
153   GetImplementation( *this ).Remove( actor );
154 }
155
156 Dali::Layer Window::GetRootLayer() const
157 {
158   return GetImplementation( *this ).GetRootLayer();
159 }
160
161 void Window::SetBackgroundColor( const Vector4& color )
162 {
163   GetImplementation( *this ).SetBackgroundColor( color );
164 }
165
166 Vector4 Window::GetBackgroundColor() const
167 {
168   return GetImplementation( *this ).GetBackgroundColor();
169 }
170
171 void Window::Raise()
172 {
173   GetImplementation( *this ).mFocusChangeSignal.Emit(*this, true);
174 }
175
176 void Window::Hide()
177 {
178   GetImplementation( *this ).mVisibilityChangedSignal.Emit( *this, false );
179 }
180
181 FocusChangeSignalType& Window::FocusChangeSignal()
182 {
183   return GetImplementation( *this ).mFocusChangeSignal;
184 }
185
186 ResizeSignalType& Window::ResizeSignal()
187 {
188   return GetImplementation( *this ).mResizeSignal;
189 }
190
191 Window::KeyEventSignalType& Window::KeyEventSignal()
192 {
193   return GetImplementation( *this ).KeyEventSignal();
194 }
195
196 Window::TouchEventSignalType& Window::TouchedSignal()
197 {
198   return GetImplementation( *this ).TouchedSignal();
199 }
200
201 namespace DevelWindow
202 {
203
204 Window Get( Actor actor )
205 {
206   Internal::Adaptor::Window* windowImpl = nullptr;
207
208   if ( Dali::Adaptor::IsAvailable() )
209   {
210     windowImpl = static_cast<Internal::Adaptor::Window*>( AdaptorImpl::GetImpl( AdaptorImpl::Get() ).GetWindow( actor ) );
211   }
212
213   return Dali::Window( windowImpl );
214 }
215
216 Window DownCast( BaseHandle handle )
217 {
218   Internal::Adaptor::Window* windowImpl = nullptr;
219   if ( Dali::Adaptor::IsAvailable() )
220   {
221     windowImpl = dynamic_cast<Dali::Internal::Adaptor::Window*>( handle.GetObjectPtr());
222   }
223   return Dali::Window( windowImpl );
224 }
225
226 void SetPositionSize(Window window, PositionSize positionSize)
227 {
228   GetImplementation( window ).SetPositionSize(positionSize);
229 }
230
231 int GetPhysicalOrientation(Window window)
232 {
233   return GetImplementation( window ).mRotationAngle;
234 }
235
236 void AddFrameRenderedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
237 {
238   CallbackBase::Execute( *callback, frameId );
239 }
240
241 void AddFramePresentedCallback( Window window, std::unique_ptr< CallbackBase > callback, int32_t frameId )
242 {
243   CallbackBase::Execute( *callback, frameId );
244 }
245
246 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
247 {
248   return GetImplementation( window ).GetScene().EventProcessingFinishedSignal();
249 }
250
251 KeyEventGeneratedSignalType& KeyEventGeneratedSignal( Window window )
252 {
253   return GetImplementation( window ).KeyEventGeneratedSignal();
254 }
255
256 WheelEventSignalType& WheelEventSignal( Window window )
257 {
258   return GetImplementation( window ).WheelEventSignal();
259 }
260
261 VisibilityChangedSignalType& VisibilityChangedSignal( Window window )
262 {
263   return GetImplementation( window ).mVisibilityChangedSignal;
264 }
265
266 } // namespace DevelWindow
267
268 } // Dali