b1b566067642f3f138cc73a9fd45887c2f115c24
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-orientation.cpp
1 /*
2  * Copyright (c) 2014 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 #include <dali/devel-api/adaptor-framework/orientation.h>
19
20 #include <dali/public-api/common/dali-common.h>
21 #include <dali/public-api/object/base-object.h>
22 #include <dali/public-api/signals/dali-signal.h>
23
24 using namespace Dali;
25
26 namespace Dali
27 {
28 class Adaptor;
29
30 namespace Internal
31 {
32 namespace Adaptor
33 {
34 class Window;
35
36
37 struct RotationEvent
38 {
39   int angle;     ///< one of 0, 90, 180, 270
40   int winResize; ///< true if the window should be resized
41   int width;     ///< new window width
42   int height;    ///< new window height
43 };
44
45 /**
46  * The RotationObserver can be overridden in order to listen to rotation events.
47  */
48 class RotationObserver
49 {
50 public:
51   virtual void OnRotationPrepare( const RotationEvent& rotation ) = 0;
52   virtual void OnRotationRequest( ) = 0;
53
54 protected:
55   RotationObserver(){}
56   virtual ~RotationObserver(){}
57 };
58
59 class Orientation : public BaseObject, public RotationObserver
60 {
61 public:
62   typedef Dali::Orientation::OrientationSignalType OrientationSignalType;
63
64   static Orientation* New(Window* window)
65   {
66     Orientation* orientation = new Orientation(window);
67     return orientation;
68   }
69   Orientation(Window* window)
70   {
71   }
72
73 protected:
74   virtual ~Orientation()
75   {
76   }
77 public:
78   void SetAdaptor(Dali::Adaptor& adaptor)
79   {
80   }
81   int GetDegrees() const
82   {
83     return 0;
84   }
85   float GetRadians() const
86   {
87     return 0.0f;
88   }
89   OrientationSignalType& ChangedSignal()
90   {
91     return mChangedSignal;
92   }
93   virtual void OnRotationPrepare( const RotationEvent& rotation )
94   {
95   };
96   virtual void OnRotationRequest( )
97   {
98   };
99
100 private:
101   Orientation(const Orientation&);
102   Orientation& operator=(Orientation&);
103   OrientationSignalType mChangedSignal;
104 };
105
106 } // Adaptor namespace
107 } // Internal namespace
108
109 inline Internal::Adaptor::Orientation& GetImplementation (Dali::Orientation& orientation)
110 {
111   DALI_ASSERT_ALWAYS(orientation && "Orientation handle is empty");
112   BaseObject& handle = orientation.GetBaseObject();
113   return static_cast<Internal::Adaptor::Orientation&>(handle);
114 }
115 inline const Internal::Adaptor::Orientation& GetImplementation(const Dali::Orientation& orientation)
116 {
117   DALI_ASSERT_ALWAYS(orientation && "Orientation handle is empty");
118   const BaseObject& handle = orientation.GetBaseObject();
119   return static_cast<const Internal::Adaptor::Orientation&>(handle);
120 }
121
122 Orientation::Orientation()
123 {
124 }
125 Orientation::~Orientation()
126 {
127 }
128 Orientation::Orientation(const Orientation& handle)
129 : BaseHandle(handle)
130 {
131 }
132
133 Orientation& Orientation::operator=(const Orientation& rhs)
134 {
135   BaseHandle::operator=(rhs);
136   return *this;
137 }
138
139 int Orientation::GetDegrees() const
140 {
141   return GetImplementation(*this).GetDegrees();
142 }
143
144 float Orientation::GetRadians() const
145 {
146   return GetImplementation(*this).GetRadians();
147 }
148
149 Orientation::OrientationSignalType& Orientation::ChangedSignal()
150 {
151   return GetImplementation(*this).ChangedSignal();
152 }
153
154 Orientation::Orientation( Internal::Adaptor::Orientation* orientation )
155 : BaseHandle(orientation)
156 {
157 }
158
159 } // Dali