[dali_1.4.26] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / actors / camera-actor-api.cpp
1 /*
2  * Copyright (c) 2015 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 "camera-actor-api.h"
20
21 // INTERNAL INCLUDES
22 #include <object/handle-wrapper.h>
23 #include <v8-utils.h>
24 #include <shared/base-wrapped-object.h>
25 #include <object/property-value-wrapper.h>
26
27 namespace Dali
28 {
29
30 namespace V8Plugin
31 {
32
33 namespace // un-named namespace
34 {
35
36 CameraActor GetCameraActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
37 {
38   HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
39   return CameraActor::DownCast( handleWrapper->mHandle );
40 }
41
42 } // un-named name space
43
44 /***************************************
45  * CAMERA ACTOR FUNCTIONS
46  ****************************************/
47 /**
48  * Constructor
49  *
50  * @constructor
51  * @method CameraActor
52  * @for CameraActor
53  * @return {Object} CameraActor
54  */
55 Actor CameraActorApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
56 {
57   return CameraActor::New();
58 }
59
60 /**
61  *
62  * Sets the default camera perspective projection for the given canvas size.
63  *
64  * Sets the near and far clipping planes, the field of view, the aspect ratio
65  * and the Z position of the actor based on the canvas size so that 1 unit in
66  * XY (z=0) plane is 1 pixel on screen.
67  *
68  * If the canvas size is ZERO, it sets the default camera perspective
69  * projection for the stage's size.
70  *
71  * If size is non ZERO, \e width and \e height must be greater than zero.
72  *
73  *
74  * @example
75  *     var camera = dali.stage.getRenderTaskList().getTask(0).getCameraActor();
76  *
77  *     camera.setPerspectiveProjection( [100, 150] );
78  *
79  *
80  * @for CameraActor
81  * @method setPerspectiveProjection
82  * @param {Object}  The canvas size, array of 2 numbers
83  */
84 void CameraActorApi::SetPerspectiveProjection( const v8::FunctionCallbackInfo< v8::Value >& args )
85 {
86   v8::Isolate* isolate = args.GetIsolate();
87   v8::HandleScope handleScope( isolate );
88   CameraActor cameraActor = GetCameraActor( isolate, args );
89
90   bool found;
91   Vector2 size = V8Utils::GetVector2Parameter( PARAMETER_0, found, isolate, args );
92   if( !found )
93   {
94     DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
95     return;
96   }
97   cameraActor.SetPerspectiveProjection( size );
98 }
99
100 /**
101  *
102  * Sets the camera projection to use orthographic projection.
103  *
104  * The XY plane is centered on the camera axis. The units in the X/Y
105  * plane directly equate to pixels on an equivalently sized
106  * framebuffer.
107  *
108  * The Z position of the actor, and the near and far clip planes of the
109  * bounding box match those that would be created by using
110  * SetPerspectiveProjection with the same size.
111  *
112  *
113  * @example
114  *     var camera = dali.stage.getRenderTaskList().getTask(0).getCameraActor();
115  *     camera.setOrthographicProjection( [1920, 1080] );
116  *
117  * @for CameraActor
118  * @method setOrthographicProjection
119  * @param {Object}  Size Size of XY plane (normal to camera axis)
120  */
121 void CameraActorApi::SetOrthographicProjection( const v8::FunctionCallbackInfo< v8::Value >& args )
122 {
123   v8::Isolate* isolate = args.GetIsolate();
124   v8::HandleScope handleScope( isolate );
125   CameraActor cameraActor = GetCameraActor( isolate, args );
126
127   bool found;
128   Vector2 size = V8Utils::GetVector2Parameter( PARAMETER_0, found, isolate, args );
129   if( !found )
130   {
131     DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
132     return;
133   }
134   cameraActor.SetOrthographicProjection( size );
135 }
136
137 } // namespace V8Plugin
138
139 } // namespace Dali