2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "javascript-application-options.h"
27 namespace DaliNodeAddon
35 const char* const name;
38 StereoInfo StereoModeTable[] = {
39 { "mono", Dali::MONO},
40 { "stereoHorizontal", Dali::STEREO_HORIZONTAL },
41 { "stereoVertical", Dali::STEREO_VERTICAL },
42 { "stereoInterlaced", Dali::STEREO_INTERLACED },
45 const unsigned int numberViewModes = sizeof( StereoModeTable ) / sizeof( StereoModeTable[0] );
47 bool GetViewMode( const std::string& modeString, Dali::ViewMode& mode )
49 for( unsigned int i = 0; i < numberViewModes; ++i )
51 const StereoInfo& info (StereoModeTable[i]);
53 if( strcmp ( modeString.c_str() , info.name ) == 0 )
65 // Note we can't parse the enviroment options for window width / height because
66 // adaptor which holds the environment option class has not been created
67 // and we can't create it, until we have a window
68 bool ParseWindowOptions( v8::Isolate* isolate, const v8::Local<v8::Object>& obj, WindowOptions& window )
70 v8::HandleScope scope(isolate);
72 v8::Local<v8::Value> xValue = obj->Get( v8::String::NewFromUtf8( isolate, "x" ) );
73 v8::Local<v8::Value> yValue = obj->Get( v8::String::NewFromUtf8( isolate, "y" ) );
74 v8::Local<v8::Value> widthValue = obj->Get( v8::String::NewFromUtf8( isolate, "width" ) );
75 v8::Local<v8::Value> heightValue = obj->Get( v8::String::NewFromUtf8( isolate, "height" ) );
76 v8::Local<v8::Value> nameValue = obj->Get( v8::String::NewFromUtf8( isolate, "name" ) );
77 v8::Local<v8::Value> transparencyValue = obj->Get( v8::String::NewFromUtf8( isolate, "transparent" ) );
79 // if x,y are optional
80 if( xValue->IsUint32() )
82 window.positionSize.x = xValue->ToUint32()->Value();
84 if( yValue->IsUint32() )
86 window.positionSize.y = yValue->ToUint32()->Value();
89 // width and height are optional but will only accept them if they are both set
90 if( widthValue->IsUint32() && heightValue->IsUint32() )
92 window.positionSize.width = widthValue->ToUint32()->Value();
93 window.positionSize.height = heightValue->ToUint32()->Value();
96 // get the window name
97 if( nameValue->IsString() )
99 window.name = Dali::V8Plugin::V8Utils::v8StringToStdString( nameValue );
103 window.name ="DALi application";
106 if( transparencyValue->IsBoolean() )
108 window.transparent = transparencyValue->ToBoolean()->Value();
113 bool ParseStereoScopicOptions( v8::Isolate* isolate, const v8::Local<v8::Object>& stereoObject, StereoScopicOptions& options )
115 v8::HandleScope scope(isolate);
117 v8::Local<v8::Value> modeValue = stereoObject->Get( v8::String::NewFromUtf8( isolate, "stereoscopicMode" ) );
118 v8::Local<v8::Value> stereoBaseValue = stereoObject->Get( v8::String::NewFromUtf8( isolate, "stereoBase" ) );
120 if( !modeValue->IsString() )
125 std::string mode = Dali::V8Plugin::V8Utils::v8StringToStdString( modeValue );
126 bool ok = GetViewMode( mode, options.viewMode);
131 if( stereoBaseValue->IsNumber() )
133 options.stereoBase = stereoBaseValue->ToNumber()->Value();
139 } // unnamed namespace
141 bool GetApplicationOptions(const v8::FunctionCallbackInfo<v8::Value>& args, ApplicationOptions& options )
143 v8::Isolate* isolate = args.GetIsolate();
144 v8::HandleScope scope(isolate);
147 if( !args[ 0 ]->IsObject() )
152 v8::Local<v8::Object> object = args[ 0 ]->ToObject();
154 // get the window settings
155 v8::Local<v8::Value> windowValue= object->Get( v8::String::NewFromUtf8( isolate, "window" ) );
156 if( windowValue->IsObject() )
158 ok = ParseWindowOptions( isolate, windowValue->ToObject(), options.window );
161 return false; // missing window size
165 // get the stereoscopic settings
166 v8::Local<v8::Value> stereoValue= object->Get( v8::String::NewFromUtf8( isolate, "viewMode" ) );
167 if( stereoValue->IsObject() )
169 ok = ParseStereoScopicOptions( isolate, stereoValue->ToObject(), options.stereo );
172 return false; // incorrect stereoscopic mode
176 // get the style sheet
177 v8::Local<v8::Value> stylesheetValue= object->Get( v8::String::NewFromUtf8( isolate, "styleSheet" ) );
178 if( stylesheetValue->IsString() )
180 options.stylesheet = Dali::V8Plugin::V8Utils::v8StringToStdString( stylesheetValue );
186 } // namespace DaliNodeAddon