1b8cdbd679fb0b1d9f8e59fcc2ae48f9c45b6277
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-window.cpp
1 /*
2  * Copyright (c) 2019 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.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/common/stage.h>
25 #include <dali/public-api/object/base-object.h>
26
27 // INTERNAL INCLUDES
28 #include "test-render-surface.h"
29
30 namespace Dali
31 {
32
33 class Window;
34
35 /********************************************************************************
36  * Stub for Dali::Internal::Adaptor::Window
37  ********************************************************************************/
38
39 namespace Internal
40 {
41 namespace Adaptor
42 {
43 class Window : public Dali::BaseObject
44 {
45 public:
46
47   Window( const PositionSize& positionSize )
48   : mScene( Dali::Integration::Scene::New( Size( positionSize.width, positionSize.height ) ) ),
49     mRenderSurface( new TestRenderSurface( positionSize ) )
50   {
51     mScene.SetSurface( *mRenderSurface );
52   }
53
54   virtual ~Window()
55   {
56     delete mRenderSurface;
57     mRenderSurface = nullptr;
58   }
59
60   static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent)
61   {
62     return new Window( positionSize );
63   }
64
65   Integration::Scene mScene;
66   TestRenderSurface* mRenderSurface;
67 };
68
69 } // Adaptor
70 } // Internal
71
72 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
73 {
74   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
75   BaseObject& object = window.GetBaseObject();
76   return static_cast<Internal::Adaptor::Window&>(object);
77 }
78
79 Window::Window()
80 {
81 }
82
83 Window::~Window()
84 {
85 }
86
87 Window::Window(const Window& handle)
88 : BaseHandle( handle )
89 {
90 }
91
92 Window& Window::operator=(const Window& rhs)
93 {
94   BaseHandle::operator=(rhs);
95   return *this;
96 }
97
98 Dali::Window Window::New( PositionSize windowPosition, const std::string& name, bool isTransparent )
99 {
100   Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, "", isTransparent );
101   return Window( window );
102 }
103
104 Dali::Window Window::New(PositionSize windowPosition, const std::string& name, const std::string& className, bool isTransparent )
105 {
106   Internal::Adaptor::Window* window = Internal::Adaptor::Window::New( windowPosition, name, className, isTransparent );
107   return Window( window );
108 }
109
110 Dali::Layer Window::GetRootLayer() const
111 {
112   return Dali::Stage::GetCurrent().GetRootLayer();
113 }
114
115 Window::Window( Internal::Adaptor::Window* window )
116 : BaseHandle( window )
117 {
118 }
119
120 Integration::Scene Window::GetScene()
121 {
122   return GetImplementation( *this ).mScene;
123 }
124
125 Integration::RenderSurface& Window::GetRenderSurface()
126 {
127   return *GetImplementation( *this ).mRenderSurface;
128 }
129
130 namespace DevelWindow
131 {
132
133 Window Get( Actor actor )
134 {
135   return Window();
136 }
137
138 EventProcessingFinishedSignalType& EventProcessingFinishedSignal( Window window )
139 {
140   return GetImplementation( window ).mScene.EventProcessingFinishedSignal();
141 }
142
143 KeyEventSignalType& KeyEventSignal( Window window )
144 {
145   return GetImplementation( window ).mScene.KeyEventSignal();
146 }
147
148 TouchSignalType& TouchSignal( Window window )
149 {
150   return GetImplementation( window ).mScene.TouchSignal();
151 }
152
153 WheelEventSignalType& WheelEventSignal( Window window )
154 {
155   return GetImplementation( window ).mScene.WheelEventSignal();
156 }
157
158 } // namespace DevelWindow
159
160 } // Dali