Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / camera-actor-impl.h
1 #ifndef __DALI_INTERNAL_CAMERA_ACTOR_H__
2 #define __DALI_INTERNAL_CAMERA_ACTOR_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //     http://floralicense.org/license/
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19
20 // INTERNAL INCLUES
21 #include <dali/public-api/object/ref-object.h>
22 #include <dali/public-api/actors/camera-actor.h>
23 #include <dali/internal/event/actors/actor-impl.h>
24 #include <dali/internal/event/actors/actor-declarations.h>
25 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 /**
34  * An actor with a conveniently pre-attached CameraAttachment.
35  */
36 class CameraActor : public Actor
37 {
38 public:
39
40   /**
41    * Create an initialised camera actor.
42    *
43    * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
44    *
45    * @param[in] size The canvas size.
46    *
47    * @return A smart-pointer to a newly allocated camera actor.
48    */
49   static CameraActorPtr New( const Size& size );
50
51   /**
52    * @copydoc Dali::Actor::OnInitialize
53    */
54   void OnInitialize();
55
56   /**
57    * Retrieve the camera attachment.
58    * @return The attachment.
59    */
60   CameraAttachment& GetCameraAttachment()
61   {
62     return *mCameraAttachment;
63   }
64
65   /**
66    * @copydoc Dali::CameraActor::SetType
67    */
68   void SetType( Dali::Camera::Type type );
69
70   /**
71    * @copydoc Dali::CameraActor::GetType
72    */
73   Dali::Camera::Type GetType() const;
74
75   /**
76    * @copydoc Dali::CameraActor::SetProjectionMode
77    */
78   void SetProjectionMode( Dali::Camera::ProjectionMode mode );
79
80   /**
81    * @copydoc Dali::CameraActor::GetProjectionMode
82    */
83   Dali::Camera::ProjectionMode GetProjectionMode() const;
84
85   /**
86    * @copydoc Dali::CameraActor::SetFieldOfView
87    */
88   void SetFieldOfView( float fieldOfView );
89
90   /**
91    * @copydoc Dali::CameraActor::GetFieldOfView
92    */
93   float GetFieldOfView( ) const;
94
95   /**
96    * @copydoc Dali::CameraActor::SetAspectRatio
97    */
98   void SetAspectRatio( float aspectRatio );
99
100   /**
101    * @copydoc Dali::CameraActor::GetAspectRatio
102    */
103   float GetAspectRatio( ) const;
104
105   /**
106    * @copydoc Dali::CameraActor::SetNearClippingPlane
107    */
108   void SetNearClippingPlane( float nearClippingPlane );
109
110   /**
111    * @copydoc Dali::CameraActor::GetNearClippingPlane
112    */
113   float GetNearClippingPlane( ) const;
114
115   /**
116    * @copydoc Dali::CameraActor::SetFarClippingPlane
117    */
118   void SetFarClippingPlane( float farClippingPlane );
119
120   /**
121    * @copydoc Dali::CameraActor::GetFarClippingPlane
122    */
123   float GetFarClippingPlane( ) const;
124
125   /**
126    * @copydoc Dali::CameraActor::SetTargetPosition
127    */
128   void SetTargetPosition( const Vector3& targetPosition );
129
130   /**
131    * @copydoc Dali::CameraActor::GetTargetPosition
132    */
133   Vector3 GetTargetPosition() const;
134
135   /**
136    * @copydoc Dali::CameraActor::SetInvertYAxis
137    */
138   void SetInvertYAxis(bool invertYAxis);
139
140   /**
141    * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
142    */
143   bool GetInvertYAxis() const;
144
145   /**
146    * @copydoc Dali::CameraActor::SetPerspectiveProjection()
147    * @param[in] stereoBias The frustum horizontal offset for stereoscopic cameras
148    */
149   void SetPerspectiveProjection( const Size& size, float stereoBias = 0.0f );
150
151   /**
152    * @copydoc Dali::CameraActor::SetOrthographicProjection(const Vector2& size);
153    */
154   void SetOrthographicProjection( const Vector2& size );
155
156   /**
157    * @copydoc Dali::CameraActor::SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
158    */
159   void SetOrthographicProjection( float left, float right, float top, float bottom, float near, float far );
160
161   /**
162    * Build a picking ray with this camera and given screen coordinates
163    * @param [in] screenCoordinates the ray passed through
164    * @param [in] viewport to use
165    * @param [out] rayOrigin for the picking ray
166    * @param [out] rayDirection for the picking ray
167    * @return true if the building was successful, false if its not possible (camera is not valid for hit testing)
168    */
169   bool BuildPickingRay( const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection );
170
171   /**
172    * Retrieve the view-matrix; This will only be valid when the actor is on-stage.
173    * @return The view-matrix.
174    */
175   const Matrix& GetViewMatrix() const;
176
177   /**
178    * Retrieve the projection-matrix; This will only be valid when the actor is on-stage.
179    * @return The projection-matrix.
180    */
181   const Matrix& GetProjectionMatrix() const;
182
183 public: // properties
184
185   /**
186    * copydoc Dali::Internal::ProxyObject
187    */
188   virtual unsigned int GetDefaultPropertyCount() const;
189
190   /**
191    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
192    */
193   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
194
195   /**
196    * copydoc Dali::Internal::ProxyObject
197    */
198   virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
199
200   /**
201    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
202    */
203   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
204
205   /**
206    * copydoc Dali::Internal::ProxyObject
207    */
208   virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
209
210   /**
211    * copydoc Dali::Internal::ProxyObject
212    */
213   virtual const std::string& GetDefaultPropertyName( Property::Index index ) const;
214
215   /**
216    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
217    */
218   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
219
220   /**
221    * copydoc Dali::Internal::ProxyObject
222    */
223   virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
224
225   /**
226    * copydoc Dali::Internal::ProxyObject
227    */
228   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
229
230   /**
231    * copydoc Dali::Internal::ProxyObject
232    */
233   virtual bool IsDefaultPropertyWritable( Property::Index index ) const ;
234
235   /**
236    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
237    */
238   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
239
240   /**
241    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
242    */
243   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
244
245 protected:
246
247   /**
248    * Protected constructor; see also CameraActor::New()
249    */
250   CameraActor();
251
252   /**
253    * A reference counted object may only be deleted by calling Unreference()
254    */
255   virtual ~CameraActor();
256
257 private:
258   CameraAttachmentPtr mCameraAttachment;
259   static bool mFirstInstance ;
260   static DefaultPropertyLookup* mDefaultCameraActorPropertyLookup; ///< Default properties
261 };
262
263 } // namespace Internal
264
265 // Helpers for public-api forwarding methods
266
267 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
268 {
269   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
270
271   BaseObject& handle = camera.GetBaseObject();
272
273   return static_cast<Internal::CameraActor&>(handle);
274 }
275
276 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
277 {
278   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
279
280   const BaseObject& handle = camera.GetBaseObject();
281
282   return static_cast<const Internal::CameraActor&>(handle);
283 }
284
285 } // namespace Dali
286
287 #endif // __DALI_INTERNAL_CAMERA_ACTOR_H__