/* * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ /*global */ /* eslint-env browser */ /* eslint "brace-style": [2, "1tbs"] */ /* eslint "no-console": 0 */ /* eslint "no-underscore-dangle": 0 */ // // Dali browser application for testing the javascript API. // // browser variables defined for eslint var $; var ace; var dali; // var canvas; var app; var eventHandler; var assert; // // Global state // var test; var database; var uiApp; var uiJavascriptTab; var uiImageTab; var uiShaderTab; var actorIdToShaderSet = {}; // actor id to shader var compiledShaders = {}; // compiled shaders by name var animationList = []; // list of animations that have been added [ { animation: new dali.Animation(), properties: [] } ] var animationSelectionIndex; // selected animation // // // Demo Shaders // // var shaderSourceSelection = 0; var shaderSources = [ { name: "pass through texture", hints: "", vertex: "\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "uniform mediump mat4 uMvpMatrix;\n" + "\n" + "void main(void)\n" + "{\n" + " mediump vec4 vertexPosition = vec4(aPosition, 1.0);\n" + " vertexPosition.xyz *= uSize;\n" + " gl_Position = uMvpMatrix * vertexPosition;\n" + " vTexCoord = aTexCoord;\n" + "}\n", fragment: "precision mediump float;\n" + "\n" + "uniform sampler2D sTexture;\n" + "uniform mediump vec4 uColor;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "void main()\n" + "{\n" + " gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n" + "}\n" }, { name: "pass through color", hints: "", vertex: "\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "\n" + "void main(void)\n" + "{\n" + " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n" + " vertexPosition.xyz *= uSize;\n" + " vTexCoord = aTexCoord;\n" + "}\n", fragment: "precision mediump float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "void main()\n" + "{\n" + " gl_FragColor = vColor * uColor;\n" + "}\n" }, { name: "sRGB Correction", hints: "", vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "uniform mediump mat4 uModelMatrix;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "\n" + "void main(void)\n" + "{\n" + " mediump vec3 vertexPosition = aPosition * uSize;\n" + " gl_Position = uProjection * uModelView * vec4(vertexPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n", fragment: "precision mediump float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "void main()\n" + "{\n" + "vec4 col = texture2D( sTexture, vTexCoord ) * uColor;\n" + "vec3 mask = vec3(greaterThan(col.rgb, vec3(0.0031308)));\n" + "vec3 o = mix(col.rgb * 12.92, \n" + " pow(col.rgb, vec3(1.0/2.4)) * 1.055 - 0.055, \n" + " mask);\n" + "gl_FragColor = vec4(o.r, o.g, o.b, col.a);\n" + "}\n" }, { name: "adjust brightness", hints: "", animateTo: [ ["uGain", 1.0, "Linear", 0, 3], ["uOffset", 0.2, "Linear", 0, 3] ], vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "\n" + "void main(void)\n" + "{\n" + " mediump vec3 vertexPosition = aPosition * uSize;\n" + " gl_Position = uProjection * uModelView * vec4(vertexPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n" + "\n" + "", fragment: "precision mediump float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "uniform float uGain; // {default:1.0} \n" + "uniform float uOffset; // {default:0.0} \n" + "void main()\n" + "{\n" + " vec4 t = texture2D( sTexture, vTexCoord );\n" + " \n" + " float y = 0.0 + (0.299 *t.r) + 0.587*t.g + 0.114*t.b;\n" + " float cb= 128.0-(0.168736*t.r)-0.331264*t.g+0.5*t.b;\n" + " float cr= 128.0+(0.5*t.r)-(0.418688*t.g)-0.081312*t.b;\n" + " \n" + " y = (y*uGain) + uOffset;\n" + " \n" + " vec4 col = vec4(t.a);\n" + " \n" + " col.r = y + 1.402*(cr-128.0);\n" + " col.g = y - 0.34414*(cb-128.0)-0.71414*(cr-128.0);\n" + " col.b = y + 1.722*(cb-128.0);\n" + " \n" + " \n" + " gl_FragColor = col * uColor;\n" + "}\n" + "\n" + "" }, { name: "wavey", hints: "", animateTo: [ ["uAmplitude", 0.2, "Linear", 0, 3], ["uFrequency", 4, "Linear", 0, 3] ], vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "\n" + "void main(void)\n" + "{\n" + " mediump vec3 vertexPosition = aPosition * uSize;\n" + " gl_Position = uProjection * uModelView * vec4(vertexPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n", fragment: "precision mediump float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "uniform float uAmplitude; // {default:0.4, description:\"amplitude in x\"} \n" + "uniform float uFrequency; // {default: 4, description:\"frequence in y\"} \n" + "void main()\n" + "{\n" + " vec2 uv = vTexCoord.xy;\n" + "\n" + " uv.x += sin(uv.y * 3.14 * uFrequency) * uAmplitude;\n" + " \n" + " vec4 color = texture2D(sTexture, uv);\n" + " \n" + " gl_FragColor = color;\n" + "}\n" }, { name: "melt", hints: "", animateTo: [ ["uFactor", -4.0, "Linear", 0, 3] ], vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "\n" + "void main(void)\n" + "{\n" + " mediump vec3 vertexPosition = aPosition * uSize;\n" + " gl_Position = uProjection * uModelView * vec4(vertexPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n" + "\n" + "", fragment: "precision mediump float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "uniform float uFactor; // {default:0.2, description:\"drip factor\"} \n" + "\n" + " \n" + "float random( vec2 p )\n" + "{\n" + " float q = p.x * 269.5 + p.y * 183.3;\n" + " return fract( sin( q ) * 43758.5453 );\n" + "}\n" + "\n" + "void main()\n" + "{\n" + " vec2 uv = vTexCoord.xy;\n" + " \n" + " float kindaRandom = (texture2D(sTexture, vec2(uv.x,0.5)).r + texture2D(sTexture, vec2(0.5,uv.x)).r) / 2.0;\n" + " \n" + " //kindaRandom = random( vec2(texture2D(sTexture, vec2(uv.x,0.5)).r, texture2D(sTexture, vec2(0.5,uv.y)).g) );\n" + " \n" + " uv.y += uFactor * kindaRandom;\n" + " \n" + "\n" + " gl_FragColor = texture2D( sTexture, uv ) * uColor;\n" + "}\n" + "\n" + "\n" + "" }, { name: "round window", hints: "", animateTo: [ ["uRadius", 0.8, "Linear", 0, 3] ], vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "void main(void)\n" + "{\n" + " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n", fragment: "precision lowp float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "\n" + "uniform lowp float uRadius; // {default: 0.2} \n" + "varying mediump vec2 vTexCoord;\n" + "void main()\n" + "{\n" + " precision lowp float;\n" + " lowp vec2 pos= vec2(vTexCoord.x-0.5,vTexCoord.y-0.5);\n" + " lowp float radius = dot(pos, pos ) ;\n" + " if( radius > (uRadius*uRadius) )\n" + " discard;\n" + " gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor ;\n" + "}\n" }, { name: "mosaic", hints: "", animateTo: [ ["uPixelFactor", 0.3, "Linear", 0, 3] ], vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "\n" + "void main(void)\n" + "{\n" + " mediump vec3 vertexPosition = aPosition * uSize;\n" + " gl_Position = uProjection * uModelView * vec4(vertexPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n", fragment: "precision mediump float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + " \n" + "uniform float uPixelFactor; // {default:0.1, min:0.0, max:0.3} \n" + "\n" + "\n" + "float smooth(float f) {\n" + " return 32.0*f*f*(0.25*f*f-0.5*f+0.25)+0.5;\n" + "}\n" + "\n" + "void main()\n" + "{\n" + " vec2 resolution = vec2(1,1); // uniform vec2 resolution;\n" + " //uPixelFactor = 8.0 + 8.0 * (0.5 + 0.5 * sin(globaltime * 0.25));\n" + " vec2 chunkCoord = floor(vTexCoord.xy / uPixelFactor) * uPixelFactor;\n" + " vec2 locCoord = (vTexCoord.xy - chunkCoord) / uPixelFactor;\n" + " vec4 color = vec4(floor(5.0 * texture2D(sTexture, chunkCoord / resolution.xy).xyz) / 5.0, 1.0);\n" + " float grey = (color.x + color.y + color.z) / 3.0;\n" + " gl_FragColor = color * smooth(locCoord.x) * smooth(locCoord.y);\n" + "}\n" }, { name: "burn", hints: "", animateTo: [ ["uThresh", 0.8, "Linear", 0, 3] ], vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "\n" + "void main(void)\n" + "{\n" + " mediump vec3 vertexPosition = aPosition * uSize;\n" + " gl_Position = uProjection * uModelView * vec4(vertexPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n" + "\n" + "\n" + "\n" + "", fragment: "precision mediump float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "\n" + "float uScale = 2.0; // {default:10.0, description:\"noise texture scaling\"} \n" + "uniform float uThresh; // {default:1.1, description:\"threshold of noise for burn\"} \n" + "\n" + "float random( vec2 p )\n" + "{\n" + " float q = p.x * 269.5 + p.y * 183.3;\n" + " return fract( sin( q ) * 43758.5453 );\n" + "}\n" + "\n" + "float noise( vec2 point )\n" + "{\n" + " vec2 p = floor( point );\n" + " vec2 f = fract( point );\n" + " return mix(\n" + " mix( random( p + vec2( 0.0, 0.0 ) ), random( p + vec2( 1.0, 0.0 ) ), f.x ),\n" + " mix( random( p + vec2( 0.0, 1.0 ) ), random( p + vec2( 1.0, 1.0 ) ), f.x ),\n" + " f.y\n" + " );\n" + "}\n" + "\n" + "float fractal( vec2 point )\n" + "{\n" + " float sum = 0.0;\n" + " float scale = 0.5;\n" + " for ( int i = 0; i < 5; i++ )\n" + " {\n" + " sum += noise( point ) * scale;\n" + " point *= 2.0;\n" + " scale /= 2.0;\n" + " }\n" + " \n" + " return sum;\n" + "}\n" + "\n" + "\n" + "void main( )\n" + "{\n" + " vec2 point = vTexCoord.xy / uScale;\n" + " //point.x += iGlobalTime * 0.1;\n" + " float noise = fractal( point * 20.0 );\n" + " \n" + " vec2 uv = vTexCoord.xy; // iResolution.xy;\n" + " //uv.y = 1.0-uv.y;\n" + " gl_FragColor = texture2D(sTexture, uv);\n" + " \n" + " if(noise < uThresh)\n" + " {\n" + " gl_FragColor = vec4(1.0, 0.5, 0.0, 1.0);\n" + " }\n" + " if(noise < uThresh - 0.05)\n" + " {\n" + " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" + " }\n" + " if(noise < uThresh - 0.1)\n" + " {\n" + " \n" + " gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); // use discard?\n" + " }\n" + "}\n" + "\n" + "\n" + "" }, { name: "ripple 2D", hints: "", animateTo: [ ["uAmplitude", 0.1, "Linear", 0, 3], ["uTime", 6, "Linear", 0, 3] ], vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "void main(void)\n" + "{\n" + " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n" + "\n" + "", fragment: "precision mediump float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "uniform float uAmplitude; // {default:0.02, min:0.0, max:1.0}\n" + "uniform float uTime;\n" + "uniform mediump vec4 sTextureRect;\n" + "void main()\n" + "{\n" + " highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\n" + " highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\n" + " highp float len = length(pos);\n" + " highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \n" + " gl_FragColor = texture2D(sTexture, texCoord) * uColor;\n" + "}\n" + "\n" + "\n" + "" }, { name: "emboss combine", hints: "", animateTo: [ ["uWeight", [10.0, 10.0, 10.0, 10.0], "Linear", 0, 3] ], vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "\n" + "void main(void)\n" + "{\n" + " mediump vec3 vertexPosition = aPosition * uSize;\n" + " gl_Position = uProjection * uModelView * vec4(vertexPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n" + "\n" + "", fragment: "precision mediump float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "const int KERNEL_SIZE = 9;\n" + "\n" + "uniform vec4 uWeight; // {default: [10,10,10,10] }\n" + "\n" + "// Gaussian kernel\n" + "float kernel[KERNEL_SIZE];\n" + "\n" + "float width = 512.0;\n" + "float height = 512.0;\n" + "\n" + "float step_w = 1.0/width;\n" + "float step_h = 1.0/height;\n" + "\n" + "vec2 offset[KERNEL_SIZE];\n" + "\n" + "void main(void)\n" + "{\n" + " precision mediump float;\n" + "\n" + " vec4 sum = vec4(0.0);\n" + "\n" + " offset[0] = vec2(-step_w, -step_h);\n" + " offset[1] = vec2(0.0, -step_h);\n" + " offset[2] = vec2(step_w, -step_h);\n" + "\n" + " offset[3] = vec2(-step_w, 0.0);\n" + " offset[4] = vec2(0.0, 0.0);\n" + " offset[5] = vec2(step_w, 0.0);\n" + "\n" + " offset[6] = vec2(-step_w, step_h);\n" + " offset[7] = vec2(0.0, step_h);\n" + " offset[8] = vec2(step_w, step_h);\n" + "\n" + " // guassian blur\n" + " // kernel[0] = 1.0/16.0; kernel[1] = 2.0/16.0; kernel[2] = 1.0/16.0;\n" + " // kernel[3] = 2.0/16.0; kernel[4] = 4.0/16.0; kernel[5] = 2.0/16.0;\n" + " // kernel[6] = 1.0/16.0; kernel[7] = 2.0/16.0; kernel[8] = 1.0/16.0;\n" + "\n" + " // laplace\n" + " // kernel[0] = 0.0; kernel[1] = 1.0; kernel[2] = 0.0;\n" + " // kernel[3] = 1.0; kernel[4] = -4.0; kernel[5] = 1.0;\n" + " // kernel[6] = 0.0; kernel[7] = 1.0; kernel[8] = 0.0;\n" + "\n" + " // edge\n" + " // kernel[0] = -1.0; kernel[1] = -1.0; kernel[2] = -1.0;\n" + " // kernel[3] = -1.0; kernel[4] = +9.0; kernel[5] = -1.0;\n" + " // kernel[6] = -1.0; kernel[7] = -1.0; kernel[8] = -1.0;\n" + "\n" + " // Embossing\n" + " // 2 0 0\n" + " // 0 -1 0\n" + " // 0 0 -1\n" + " kernel[0] = 2.0; kernel[1] = 0.0; kernel[2] = 0.0;\n" + " kernel[3] = 0.0; kernel[4] = -1.0; kernel[5] = 0.0;\n" + " kernel[6] = 0.0; kernel[7] = 0.0; kernel[8] =-1.0;\n" + "\n" + " vec4 tmp = texture2D(sTexture, vTexCoord.st + offset[0]);\n" + " sum += tmp * kernel[0];\n" + "\n" + " tmp = texture2D(sTexture, vTexCoord.st + offset[1]);\n" + " sum += tmp * kernel[1];\n" + "\n" + " tmp = texture2D(sTexture, vTexCoord.st + offset[2]);\n" + " sum += tmp * kernel[2];\n" + "\n" + " tmp = texture2D(sTexture, vTexCoord.st + offset[3]);\n" + " sum += tmp * kernel[3];\n" + "\n" + " tmp = texture2D(sTexture, vTexCoord.st + offset[4]);\n" + " sum += tmp * kernel[4];\n" + "\n" + " tmp = texture2D(sTexture, vTexCoord.st + offset[5]);\n" + " sum += tmp * kernel[5];\n" + "\n" + " tmp = texture2D(sTexture, vTexCoord.st + offset[6]);\n" + " sum += tmp * kernel[6];\n" + "\n" + " tmp = texture2D(sTexture, vTexCoord.st + offset[7]);\n" + " sum += tmp * kernel[7];\n" + "\n" + " tmp = texture2D(sTexture, vTexCoord.st + offset[8]);\n" + " sum += tmp * kernel[8];\n" + "\n" + " sum = texture2D(sTexture, vTexCoord.xy) + (sum * uWeight);\n" + "\n" + " gl_FragColor = sum;\n" + "}\n" }, { name: "blur", hints: "", vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "uniform mediump vec3 uSize;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "void main(void)\n" + "{\n" + " mediump vec3 vertexPosition = aPosition * uSize;\n" + " gl_Position = uProjection * uModelView * vec4(vertexPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n" + "\n" + "", fragment: "\n" + "precision mediump float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "\n" + "#define PI2 6.283184\n" + "\n" + "#define CV 0.1\n" + "#define ST 0.05\n" + "\n" + "uniform float uFactor; // {default: 0.5, min:0.0, max:1.0}\n" + "\n" + "vec4 colorat(vec2 uv) {\n" + " return texture2D(sTexture, uv);\n" + "}\n" + "vec4 blur(vec2 uv) { // convolve\n" + " vec4 col = vec4(0.0);\n" + " for(float r0 = 0.0; r0 < 1.0; r0 += ST) {\n" + " float r = r0 * CV;\n" + " for(float a0 = 0.0; a0 < 1.0; a0 += ST) {\n" + " float a = a0 * PI2;\n" + " col += colorat(uv + vec2(cos(a), sin(a)) * r);\n" + " }\n" + " }\n" + " col *= ST * ST;\n" + " return col;\n" + "}\n" + "\n" + "\n" + "\n" + "void main() {\n" + " vec2 uv = vTexCoord.xy;\n" + " gl_FragColor = blur(uv) * uFactor + ((1.0-uFactor) * texture2D(sTexture, uv));\n" + "}\n" + "\n" }, {name: "image-click", hints: "", animateTo: [ ["uRadius", 0.3, "Linear", 0, 0.3] ], vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "\n" + "void main(void)\n" + "{\n" + " mediump vec3 vertexPosition = aPosition * uSize;\n" + " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n" + "\n" + "", fragment: "precision lowp float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform sampler2D sTexture;\n" + "\n" + "uniform lowp float uRadius; // {default 0.2, min:0, max:0.3, description:\"touch radius and brightness mix\"\n" + "vec2 offset = vec2(0.3,-0.2); // offset from center; for touch point (todo - make uniform)\n" + "\n" + "void main()\n" + "{\n" + " precision lowp float;\n" + " lowp vec2 pos= vec2(vTexCoord.x-0.5-offset.x,vTexCoord.y-0.5-offset.y);\n" + " lowp float radius = dot(pos, pos ) ;\n" + "\n" + " // use sRGB correction to brighten image\n" + " vec4 col = texture2D( sTexture, vTexCoord ) * uColor;\n" + " vec3 mask = vec3(greaterThan(col.rgb, vec3(0.0031308)));\n" + " vec3 o = mix(col.rgb * 12.92, \n" + " pow(col.rgb, vec3(1.0/2.4)) * 1.055 - 0.055, \n" + " mask);\n" + " \n" + " vec3 diff = o - col.rgb;\n" + " diff *= uRadius * 3.0;\n" + " o = col.rgb + diff;\n" + " \n" + " gl_FragColor = vec4(o.r, o.g, o.b, col.a);\n" + "\n" + " if( radius <= (uRadius*uRadius) )\n" + " {\n" + " gl_FragColor += vec4(0.1);\n" + " }\n" + " \n" + "}\n" + "\n" + "" }, {name: "iris effect", hints: "", animateTo: [ ["uRadius", 1.0, "Linear", 0, 0.3], ["uCenter", [0.2, 0.2], "Linear", 0, 0.0], ["uBlendFactor", 1.0, "Linear", 0, 0.0] ], vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "\n" + "uniform mediump vec2 uCenter; // { default: [0.7, 0.7] } \n" + "varying mediump vec2 vRelativePosition;\n" + "\n" + "void main()\n" + "{\n" + " mediump vec3 vertexPosition = aPosition * uSize;\n" + " mediump vec4 world = uModelView * vec4(vertexPosition,1.0);\n" + " gl_Position = uProjection * world;\n" + "\n" + " vTexCoord = aTexCoord;\n" + " vRelativePosition = aTexCoord - uCenter;\n" + "}\n" + "\n" + "\n" + "", fragment: "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "uniform mediump float uRadius; // {default:0.5} \n" + "uniform mediump float uBlendFactor; // {default:2} \n" + "varying mediump vec2 vRelativePosition;\n" + "void main()\n" + "{\n" + " mediump float delta = (length(vRelativePosition) - uRadius);\n" + " delta = clamp(0.0 - delta * uBlendFactor, 0.0, 1.0);\n" + " gl_FragColor = texture2D(sTexture, vTexCoord) * uColor;\n" + " gl_FragColor.a *= delta;\n" + "}\n" + "\n" + "" }, {name: "mirror effect", hints: "", animateTo: [ ["uDepth", 0.5, "Linear", 0, 0.0], ["uAlpha", 1.0, "Linear", 0, 0.0] ], vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "\n" + "void main()\n" + "{\n" + " mediump vec3 pos = aPosition * uSize;\n" + " pos.y = pos.y * 3.0;\n" + " mediump vec4 world = uModelView * vec4(pos,1.0);\n" + " gl_Position = uProjection * world;\n" + " vTexCoord = aTexCoord;\n" + "}\n" + "\n" + "", fragment: "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "uniform mediump float uDepth; // {default: 0.3 }\n" + "uniform mediump float uAlpha; // {default: 10.0 }\n" + "void main()\n" + "{\n" + " if(vTexCoord.y < 1.0 / 3.0)\n" + " {\n" + " gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n" + " }\n" + " else if(vTexCoord.y < 2.0 / 3.0)\n" + " {\n" + " gl_FragColor = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y * 3.0 - 1.0)) * uColor;\n" + " gl_FragColor.a *= uAlpha;\n" + " }\n" + " else\n" + " {\n" + " highp float darkness = 3.0 - vTexCoord.y * 3.0;\n" + " darkness = (1.0 - 1.0 / uDepth + darkness * 1.0/ uDepth) * 0.65;\n" + " highp vec4 color = texture2D(sTexture, vec2(vTexCoord.x, -vTexCoord.y *3.0 + 3.0)) * uColor;\n" + " color.a *= uAlpha;\n" + " gl_FragColor = color * vec4(darkness, darkness, darkness, darkness);\n" + " }\n" + "}\n" + "" }, {name: "square dissolve", animateTo: [ ["uRows", 0.4, "Linear", 0, 0.0], ["uColumns", 0.4, "Linear", 0, 0.0], ["texSize", [100, 100], "Linear", 0, 0.0], ["uStep", 1, "Linear", 0, 3.0] ], hints: " grid blending", vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "void main(void)\n" + "{\n" + " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n" + "\n" + "", fragment: "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "uniform mediump vec2 texSize;\n" + "uniform mediump float uStep;\n" + "uniform mediump float uRows;\n" + "uniform mediump float uColumns;\n" + "uniform sampler2D sTexture;\n" + "void main()\n" + "{\n" + " mediump vec2 mosaicSize = vec2(1.0 / uRows, 1.0 / uColumns);\n" + " mediump vec2 intXY = vec2(vTexCoord.x * texSize.x, vTexCoord.y * texSize.y);\n" + " mediump vec2 XYMosaic = vec2(floor(intXY.x / mosaicSize.x) * mosaicSize.x, floor(intXY.y / mosaicSize.y) * mosaicSize.y);\n" + " mediump vec2 UVMosaic = vec2(XYMosaic.x /texSize.x, XYMosaic.y / texSize.y);\n" + " mediump vec4 noiseVec = texture2D(sEffect, UVMosaic);\n" + " mediump float intensity = (noiseVec[0] + noiseVec[1] + noiseVec[2] + noiseVec[3]) / 4.0;\n" + " if(intensity < uStep)\n" + " gl_FragColor = vec4(0.1, 0.1, 0.1, 1.0);\n" + " else\n" + " gl_FragColor = texture2D(sTexture, vTexCoord);\n" + " gl_FragColor *= uColor;\n" + "}\n" + "\n" + "" }, {name: "swirl", hints: " grid blending", animateTo: [ ["uCenter", [0.5, 0.5], "Linear", 0, 0.0], ["uTextureSize", [100, 100], "Linear", 0, 0.0], ["uRadius", 1.0, "Linear", 0, 3.0], ["uAngle", 3.0, "Linear", 0, 3.0] ], vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "\n" + "void main(void)\n" + "{\n" + " mediump vec3 vertexPosition = aPosition * uSize;\n" + " gl_Position = uProjection * uModelView * vec4(vertexPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n" + "\n" + "", fragment: "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "uniform mediump vec4 sTextureRect;\n" + "\n" + "uniform mediump vec2 uTextureSize;\n" + "uniform highp float uRadius;\n" + "uniform highp float uAngle;\n" + "uniform mediump vec2 uCenter;\n" + "varying mediump vec2 vTexCoord;\n" + "void main()\n" + "{\n" + " highp vec2 textureCenter = (sTextureRect.xy + sTextureRect.zw) * 0.5;\n" + " textureCenter = vTexCoord.st - textureCenter;\n" + " highp float distance = length(textureCenter);\n" + " if (distance >= uRadius)\n" + " discard;\n" + " highp float percent = (uRadius - distance) / uRadius;\n" + " highp float theta = percent * percent * uAngle * 4.0;\n" + " highp float sinTheta = sin(theta);\n" + " highp float cosTheta = cos(theta);\n" + "// if warp, loose the sign from sin\n" + " bool warp = true;\n" + " if( warp )\n" + " {\n" + " textureCenter = vec2( dot( textureCenter, vec2(cosTheta, sinTheta) ),\n" + " dot( textureCenter, vec2(sinTheta, cosTheta) ) );\n" + " }\n" + " else\n" + " {\n" + " textureCenter = vec2( dot( textureCenter, vec2(cosTheta, -sinTheta) ),\n" + " dot( textureCenter, vec2(sinTheta, cosTheta) ) );\n" + " }\n" + " textureCenter += uCenter;\n" + " gl_FragColor = texture2D( sTexture, textureCenter ) * uColor;\n" + "}\n" + "\n" + "\n" + "" }, {name: "drop shadow", vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize;\n" + "\n" + "void main()\n" + "{\n" + " mediump vec3 pos = aPosition * uSize;\n" + " pos.y = pos.y * 1.1; \n" + " pos.x = pos.x * 1.1;\n" + " \n" + " mediump vec4 world = uModelView * vec4(pos,1.0);\n" + " gl_Position = uProjection * world;\n" + " vTexCoord = aTexCoord;\n" + "}\n" + "\n" + "\n" + "", fragment: "\n" + "uniform mediump vec4 uColor;\n" + "uniform sampler2D sTexture;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "void main()\n" + "{\n" + " if(vTexCoord.y < 0.05)\n" + " {\n" + " discard;\n" + " gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);\n" + " }\n" + " else if(vTexCoord.x < 0.05)\n" + " {\n" + " discard;\n" + " gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);\n" + " }\n" + " else if(vTexCoord.y < 0.95 && vTexCoord.x < 0.95)\n" + " {\n" + " gl_FragColor = texture2D(sTexture, vec2(vTexCoord.x/ (1.0/1.1) - 0.05, vTexCoord.y / (1.0/1.0) - 0.05 )) * uColor;\n" + " }\n" + " else\n" + " {\n" + " if(vTexCoord.y < 0.1 || vTexCoord.x < 0.1)\n" + " {\n" + " discard;\n" + " }\n" + " else\n" + " {\n" + " gl_FragColor = vec4(0.2, 0.2, 0.2, 1.0);\n" + " }\n" + " }\n" + "}\n" + "\n" + "\n" + "", hints: "" }, { name: "noise", hints: "", vertex: "\n" + "uniform mediump mat4 uModelView;\n" + "uniform mediump mat4 uProjection;\n" + "attribute mediump vec3 aPosition;\n" + "attribute mediump vec2 aTexCoord;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform mediump vec3 uSize; \n" + "\n" + "void main(void)\n" + "{\n" + " mediump vec3 vertexPosition = aPosition * uSize;\n" + "\n" + " gl_Position = uProjection * uModelView * vec4(vertexPosition, 1.0);\n" + " vTexCoord = aTexCoord;\n" + "}\n" + "\n" + "", fragment: "\n" + "precision mediump float;\n" + "\n" + "uniform mediump vec4 uColor;\n" + "varying mediump vec2 vTexCoord;\n" + "\n" + "// noise\n" + "float noise(vec2 pos)\n" + "{\n" + " return fract( sin( dot(pos*0.001 ,vec2(24.12357, 36.789) ) ) * 12345.123);\n" + "}\n" + "\n" + "\n" + "// blur noise\n" + "float smooth_noise(vec2 pos)\n" + "{\n" + " return ( noise(pos + vec2(1,1)) + noise(pos + vec2(1,1)) + noise(pos + vec2(1,1)) + noise(pos + vec2(1,1)) ) / 16.0\n" + " + ( noise(pos + vec2(1,0)) + noise(pos + vec2(-1,0)) + noise(pos + vec2(0,1)) + noise(pos + vec2(0,-1)) ) / 8.0\n" + " + noise(pos) / 4.0;\n" + "}\n" + "\n" + "\n" + "// linear interpolation\n" + "float interpolate_noise(vec2 pos)\n" + "{\n" + "float a, b, c, d;\n" + " \n" + " a = smooth_noise(floor(pos));\n" + " b = smooth_noise(vec2(floor(pos.x+1.0), floor(pos.y)));\n" + " c = smooth_noise(vec2(floor(pos.x), floor(pos.y+1.0)));\n" + " d = smooth_noise(vec2(floor(pos.x+1.0), floor(pos.y+1.0)));\n" + "\n" + " a = mix(a, b, fract(pos.x));\n" + " b = mix(c, d, fract(pos.x));\n" + " a = mix(a, b, fract(pos.y));\n" + " \n" + " return a;\n" + "}\n" + "\n" + "\n" + "float perlin_noise(vec2 pos)\n" + "{\n" + " float n;\n" + " \n" + " n = interpolate_noise(pos*0.0625)*0.5;\n" + " n += interpolate_noise(pos*0.125)*0.25;\n" + " n += interpolate_noise(pos*0.025)*0.225;\n" + " n += interpolate_noise(pos*0.05)*0.0625;\n" + " n += interpolate_noise(pos)*0.03125;\n" + " return n;\n" + "}\n" + "\n" + "\n" + "\n" + "void main()\n" + "{\n" + " vec2 pos = vTexCoord.xy;\n" + " float c, n;\n" + "\n" + "\n" + " n = perlin_noise(pos);\n" + "\n" + "\n" + " vec2 p = pos; // / iResolution.xy;\n" + "\n" + " if(p.y < 0.333) // last row\n" + "{\n" + " \n" + " if(p.x < 0.333)\n" + " c = abs(cos(n*10.0));\n" + " else if(p.x < 0.666)\n" + " c = cos(pos.x*0.02 + n*10.0);//*0.5+0.5;\n" + " else\n" + " {\n" + " pos *= 0.05;\n" + " c = abs(sin(pos.x+n*5.0)*cos(pos.y+n*5.0));\n" + " }\n" + " }\n" + " else if(p.y < 0.666) // middle row\n" + " {\n" + " \n" + " if(p.x < 0.333)\n" + " {\n" + " pos *= 0.05;\n" + " pos += vec2(10.0, 10.0);\n" + " c = sqrt(pos.x * pos.x + pos.y * pos.y);\n" + " c = fract(c+n);\n" + " }\n" + " else if(p.x < 0.666)\n" + " {\n" + " c = max(1.0 - mod(pos.x*0.5, 80.3+n*4.0)*0.5, 1.0 - mod(pos.y*0.5, 80.3+n*4.0)*0.5);\n" + " c = max(c, 0.5*max(1.0 - mod(pos.x*0.5+40.0, 80.3+n*4.0)*0.5, 1.0 - mod(pos.y*0.5+40.0, 80.3+n*4.0)*0.5));\n" + " }\n" + " else\n" + " c = abs(cos(pos.x*0.1 + n*20.0));// mod(pos.x*0.1, cos(pos.x));\n" + " }\n" + " else // first row\n" + " {\n" + " if(p.x < 0.333)\n" + " c = noise(pos);\n" + " else if(p.x < 0.666)\n" + " c = n;\n" + " else\n" + " c =max(fract(n*20.0), max(fract(n*5.0), fract(n*10.0)));\n" + " }\n" + "\n" + " gl_FragColor = vec4(c, c, c, 1.0);\n" + "}\n" + "\n" + "" } ]; // // Demo Javascript snippets // // var javascriptSources = [ { name: "XX. Regression tests", source: "\n" + "clear();\n" + "var test = new Test();\n" + "test.regression(); // results in developer console (F12)\n" + "\n" }, { name: "10. ImageView", source:"\n" + "var a = new dali.ImageView();\n" + "\n" + "var img = imageFromUiBuffer(\"field\");\n" + "\n" + "a.setImage(img);\n" + "\n" + "a.size = [100,100,1];\n" + "\n" + "dali.stage.add(a)\n" + "" }, { name: "01. Colored Quad", source: "var halfQuadSize = 0.5;\n" + "\n" + "// using helper function to create property buffer\n" + "var verts = dali.createPropertyBuffer( {format: [ [\"aPosition\", dali.PropertyType.VECTOR3],\n" + " [\"aCol\", dali.PropertyType.VECTOR4] ],\n" + " data: { \"aPosition\": [ [-halfQuadSize, -halfQuadSize, 0.0],\n" + " [+halfQuadSize, -halfQuadSize, 0.0],\n" + " [-halfQuadSize, +halfQuadSize, 0.0],\n" + " [+halfQuadSize, +halfQuadSize, 0.0]\n" + " ],\n" + " \"aCol\": [ [0, 0, 0, 1],\n" + " [1, 0, 1, 1],\n" + " [0, 1, 0, 1],\n" + " [1, 1, 1, 1]\n" + " ]\n" + " }\n" + " }\n" + " );\n" + "\n" + "var indices = dali.createPropertyBuffer( { format: [ [\"indices\", dali.PropertyType.INTEGER]],\n" + " data: { \"indices\": [0, 3, 1, 0, 2, 3] } } ) ;\n" + "\n" + "var geometry = new dali.Geometry();\n" + "\n" + "geometry.addVertexBuffer(verts);\n" + "geometry.setIndexBuffer(indices);\n" + "\n" + "var vertex = \"\" +\n" + " \"attribute mediump vec3 aPosition;\" +\n" + " \"attribute mediump vec4 aCol;\" +\n" + " \"uniform mediump mat4 uMvpMatrix;\" +\n" + " \"uniform mediump vec3 uSize;\" +\n" + " \"uniform lowp vec4 uColor;\" +\n" + " \"varying lowp vec4 vColor;\" +\n" + " \"\" +\n" + " \"void main()\" +\n" + " \"{\" +\n" + " \" vColor = aCol * uColor;\" +\n" + " \" mediump vec4 vertexPosition = vec4(aPosition,1.0);\" +\n" + " \" vertexPosition.xyz *= uSize;\" +\n" + " \" gl_Position = uMvpMatrix * vertexPosition;\" +\n" + " \"}\";\n" + "\n" + "var fragment = \"\" +\n" + " \"varying lowp vec4 vColor;\" +\n" + " \"uniform lowp vec4 uColor;\" +\n" + " \"\" +\n" + " \"void main()\" +\n" + " \"{\" +\n" + " \" gl_FragColor = vColor * uColor;\" +\n" + " \"}\";\n" + "\n" + "var shader = new dali.Shader(vertex, fragment, dali.ShaderHints.HINT_NONE);\n" + "\n" + "var material = new dali.Material(shader);\n" + "\n" + "var renderer = new dali.Renderer(geometry, material);\n" + "\n" + "var actor = new dali.Actor();\n" + "\n" + "actor.addRenderer(renderer);\n" + "\n" + "dali.stage.add(actor);\n" + "\n" + "actor.parentOrigin = [0.5, 0.5, 0.0];\n" + "actor.size = [100,100,1];\n" + "\n" + "" }, { name: "02. Textured Quad", source: "var halfQuadSize = 0.5;\n" + "\n" + "// using helper function to create property buffer\n" + "var verts = dali.createPropertyBuffer( {format: [ [\"aPosition\", dali.PropertyType.VECTOR3],\n" + " [\"aTexCoord\", dali.PropertyType.VECTOR2] ],\n" + " data: { \"aPosition\": [ [-halfQuadSize, -halfQuadSize, 0.0],\n" + " [+halfQuadSize, -halfQuadSize, 0.0],\n" + " [-halfQuadSize, +halfQuadSize, 0.0],\n" + " [+halfQuadSize, +halfQuadSize, 0.0]\n" + " ],\n" + " \"aTexCoord\": [ [0, 0],\n" + " [1, 0],\n" + " [0, 1],\n" + " [1, 1]\n" + " ]\n" + " }\n" + " });\n" + "\n" + "var indices = dali.createPropertyBuffer( { format: [ [\"indices\", dali.PropertyType.INTEGER]],\n" + " data: { \"indices\": [0, 3, 1, 0, 2, 3] } } ) ;\n" + "\n" + "var geometry = new dali.Geometry();\n" + "\n" + "geometry.addVertexBuffer(verts);\n" + "geometry.setIndexBuffer(indices);\n" + "\n" + "var shader = shaderFromUiBuffer(\"pass through texture\");\n" + "\n" + "var material = new dali.Material(shader);\n" + "\n" + "var image = imageFromUiBuffer(\"ducks\");\n" + "var sampler = new dali.Sampler();\n" + "material.addTexture(image, \"sTexture\", sampler);\n" + "\n" + "var renderer = new dali.Renderer(geometry, material);\n" + "\n" + "var actor = new dali.Actor();\n" + "\n" + "actor.addRenderer(renderer);\n" + "\n" + "dali.stage.add(actor);\n" + "\n" + "actor.parentOrigin = [0.5, 0.5, 0.0];\n" + "actor.size = [100,100,1];\n" + "\n" + "\n" + "" }, { name: "03. Shaded Quads", source: "var halfQuadSize = 0.5;\n" + "\n" + "// using helper function to create property buffer\n" + "var verts = dali.createPropertyBuffer( {format: [ [\"aPosition\", dali.PropertyType.VECTOR3],\n" + " [\"aTexCoord\", dali.PropertyType.VECTOR2] ],\n" + " data: { \"aPosition\": [ [-halfQuadSize, -halfQuadSize, 0.0],\n" + " [+halfQuadSize, -halfQuadSize, 0.0],\n" + " [-halfQuadSize, +halfQuadSize, 0.0],\n" + " [+halfQuadSize, +halfQuadSize, 0.0]\n" + " ],\n" + " \"aTexCoord\": [ [0, 0],\n" + " [1, 0],\n" + " [0, 1],\n" + " [1, 1]\n" + " ]\n" + " }\n" + " });\n" + "\n" + "\n" + "var indices = dali.createPropertyBuffer( { format: [ [\"indices\", dali.PropertyType.INTEGER]],\n" + " data: { \"indices\": [0, 3, 1, 0, 2, 3] } } ) ;\n" + "\n" + "var geometry = new dali.Geometry();\n" + "\n" + "geometry.addVertexBuffer(verts);\n" + "geometry.setIndexBuffer(indices);\n" + "\n" + "\n" + "// some shader buffers for textured quad\n" + "var names = [\"adjust brightness\", \"blur\", \"burn\", \"drop shadow\", \"emboss combine\",\n" + " \"image-click\", \"melt\", \"ripple 2D\", \"mirror effect\", \"iris effect\",\n" + " \"mosaic\", \"round window\", \"swirl\", \"noise\"];\n" + "\n" + "var n = Math.floor(Math.sqrt(names.length));\n" + "var c = 0;\n" + "var x = -(0.5*n*100);\n" + "var y = -(0.5*n*100);\n" + "\n" + "for(var i = 0; i < names.length; i++) {\n" + " var shader = shaderFromUiBuffer(names[i]);\n" + "\n" + " var material = new dali.Material(shader);\n" + "\n" + " var image = imageFromUiBuffer(\"ducks\");\n" + " var sampler = new dali.Sampler();\n" + " material.addTexture(image, \"sTexture\", sampler);\n" + "\n" + " var renderer = new dali.Renderer(geometry, material);\n" + "\n" + " var actor = new dali.Actor();\n" + "\n" + " actor.name = \"actor for shader:\" + names[i];\n" + "\n" + " actor.addRenderer(renderer);\n" + "\n" + " dali.stage.add(actor);\n" + "\n" + " actor.parentOrigin = [0.5, 0.5, 0.0];\n" + " actor.size = [100,100,1];\n" + "\n" + " actor.position = [x,\n" + " y + (c*110), \n" + " 0];\n" + "\n" + " if(c>n) {\n" + " c = 0;\n" + " x += 110;\n" + " } else {\n" + " c += 1;\n" + " }\n" + "\n" + "}\n" + "\n" + "" }, { name: "04. Animation", source: "var halfQuadSize = 0.5;\n" + "\n" + "// use helper function to create property buffer\n" + "var verts = dali.createPropertyBuffer( {format: [ [\"aPosition\", dali.PropertyType.VECTOR3],\n" + " [\"aTexCoord\", dali.PropertyType.VECTOR2] ],\n" + " data: { \"aPosition\": [ [-halfQuadSize, -halfQuadSize, 0.0],\n" + " [+halfQuadSize, -halfQuadSize, 0.0],\n" + " [-halfQuadSize, +halfQuadSize, 0.0],\n" + " [+halfQuadSize, +halfQuadSize, 0.0]\n" + " ],\n" + " \"aTexCoord\": [ [0, 0],\n" + " [1, 0],\n" + " [0, 1],\n" + " [1, 1]\n" + " ]\n" + " }\n" + " });\n" + "\n" + "var indices = dali.createPropertyBuffer( { format: [ [\"indices\", dali.PropertyType.INTEGER]],\n" + " data: { \"indices\": [0, 3, 1, 0, 2, 3] } } ) ;\n" + "\n" + "var geometry = new dali.Geometry();\n" + "\n" + "geometry.addVertexBuffer(verts);\n" + "geometry.setIndexBuffer(indices);\n" + "\n" + "var vertex = \"\" + \n" + " \"// atributes\\n\" + \n" + " \"attribute mediump vec3 aPosition;\\n\" + \n" + " \"attribute mediump vec2 aTexCoord;\\n\" + \n" + " \"// inbuilt\\n\" + \n" + " \"uniform mediump mat4 uMvpMatrix;\\n\" + \n" + " \"uniform mediump vec3 uSize;\\n\" + \n" + " \"uniform lowp vec4 uColor;\\n\" + \n" + " \"// varying\\n\" + \n" + " \"varying mediump vec2 vTexCoord;\\n\" + \n" + " \"\\n\" + \n" + " \"void main()\\n\" + \n" + " \"{\\n\" + \n" + " \" mediump vec4 vertexPosition = vec4(aPosition, 1.0);\\n\" + \n" + " \" vertexPosition.xyz *= uSize;\\n\" + \n" + " \" gl_Position = uMvpMatrix * vertexPosition;\\n\" + \n" + " \" vTexCoord = aTexCoord;\\n\" + \n" + " \"}\";\n" + "\n" + "var fragment = \"\" + \n" + " \"uniform lowp vec4 uColor;\\n\" + \n" + " \"uniform sampler2D sTexture;\\n\" + \n" + " \"varying mediump vec2 vTexCoord;\\n\" + \n" + " \"\\n\" + \n" + " \"void main()\\n\" + \n" + " \"{\\n\" + \n" + " \" gl_FragColor = texture2D(sTexture, vTexCoord) * uColor;\\n\" + \n" + " \"}\";\n" + "\n" + "var shader = new dali.Shader(vertex, fragment, dali.ShaderHints.HINT_NONE);\n" + "\n" + "var material = new dali.Material(shader);\n" + "\n" + "var image = imageFromUiBuffer(\"ducks\");\n" + "var sampler = new dali.Sampler();\n" + "material.addTexture(image, \"sTexture\",sampler);\n" + "\n" + "var renderer = new dali.Renderer(geometry, material);\n" + "\n" + "var actor = new dali.Actor();\n" + "\n" + "actor.addRenderer(renderer);\n" + "\n" + "dali.stage.add(actor);\n" + "\n" + "actor.parentOrigin = [0.5, 0.5, 0.0];\n" + "actor.size = [100,100,1];\n" + "\n" + "\n" + "var animation = new dali.Animation(9);\n" + "\n" + "animation.animateTo(actor, \"orientation\", [0,90,0], \"linear\", 0, 3);\n" + "animation.animateTo(actor, \"orientation\", [0,0,0], \"linear\", 6, 3);\n" + "\n" + "var p = new dali.Path();\n" + "\n" + "p.addPoint( [0,0,0] );\n" + "p.addPoint( [200,200,200] );\n" + "p.addPoint( [0,0,-200] );\n" + "p.addPoint( [0,-200,-900] );\n" + "p.addPoint( [0,0,0] );\n" + "\n" + "p.generateControlPoints(0.43);\n" + "\n" + "animation.animatePath( actor, p, [1,0,0], \"linear\", 0, 6);\n" + "\n" + "//animation.setEndAction(dali.EndAction.Discard);\n" + "\n" + "animation.play();\n" + "\n" + "\n" + "" }, { name: "05. Event driven Animation", source: "var halfQuadSize = 0.5;\n" + "\n" + "// use helper function to create property buffer\n" + "var verts = dali.createPropertyBuffer( {format: [ [\"aPosition\", dali.PropertyType.VECTOR3],\n" + " [\"aTexCoord\", dali.PropertyType.VECTOR2] ],\n" + " data: { \"aPosition\": [ [-halfQuadSize, -halfQuadSize, 0.0],\n" + " [+halfQuadSize, -halfQuadSize, 0.0],\n" + " [-halfQuadSize, +halfQuadSize, 0.0],\n" + " [+halfQuadSize, +halfQuadSize, 0.0]\n" + " ],\n" + " \"aTexCoord\": [ [0, 0],\n" + " [1, 0],\n" + " [0, 1],\n" + " [1, 1]\n" + " ]\n" + " }\n" + " });\n" + "\n" + "var indices = dali.createPropertyBuffer( { format: [ [\"indices\", dali.PropertyType.INTEGER]],\n" + " data: { \"indices\": [0, 3, 1, 0, 2, 3] } } ) ;\n" + "\n" + "var geometry = new dali.Geometry();\n" + "\n" + "geometry.addVertexBuffer(verts);\n" + "geometry.setIndexBuffer(indices);\n" + "\n" + "var vertex = \"\" +\n" + " \"// atributes\\n\" + \n" + " \"attribute mediump vec3 aPosition;\\n\" + \n" + " \"attribute mediump vec2 aTexCoord;\\n\" + \n" + " \"// inbuilt\\n\" + \n" + " \"uniform mediump mat4 uMvpMatrix;\\n\" + \n" + " \"uniform mediump vec3 uSize;\\n\" + \n" + " \"uniform lowp vec4 uColor;\\n\" + \n" + " \"// varying\\n\" + \n" + " \"varying mediump vec2 vTexCoord;\\n\" + \n" + " \"\\n\" + \n" + " \"void main()\\n\" + \n" + " \"{\\n\" + \n" + " \" mediump vec4 vertexPosition = vec4(aPosition, 1.0);\\n\" + \n" + " \" vertexPosition.xyz *= uSize;\\n\" + \n" + " \" gl_Position = uMvpMatrix * vertexPosition;\\n\" + \n" + " \" vTexCoord = aTexCoord;\\n\" + \n" + " \"}\";\n" + "\n" + "var fragment = \"\" +\n" + " \"uniform lowp vec4 uColor;\\n\" + \n" + " \"uniform sampler2D sTexture;\\n\" + \n" + " \"varying mediump vec2 vTexCoord;\\n\" + \n" + " \"\\n\" + \n" + " \"void main()\\n\" + \n" + " \"{\\n\" + \n" + " \" gl_FragColor = texture2D(sTexture, vTexCoord) * uColor;\\n\" + \n" + " \"}\";\n" + "\n" + "var shader = new dali.Shader(vertex, fragment, dali.ShaderHints.HINT_NONE);\n" + "\n" + "var material = new dali.Material(shader);\n" + "\n" + "var image = imageFromUiBuffer(\"ducks\");\n" + "var sampler = new dali.Sampler();\n" + "material.addTexture(image, \"sTexture\", sampler);\n" + "\n" + "var renderer = new dali.Renderer(geometry, material);\n" + "\n" + "var actor = new dali.Actor();\n" + "\n" + "actor.addRenderer(renderer);\n" + "\n" + "dali.stage.add(actor);\n" + "\n" + "actor.parentOrigin = [0.5, 0.5, 0.0];\n" + "actor.size = [100,100,1];\n" + "\n" + "var actor2 = new dali.Actor();\n" + "\n" + "// @todo?? why can I no reuse the same renderer?\n" + "//actor2.addRenderer(renderer);\n" + "var renderer2 = new dali.Renderer(geometry, material);\n" + "actor2.addRenderer(renderer2);\n" + "\n" + "dali.stage.add(actor2);\n" + "\n" + "actor2.position = [-200,0,0];\n" + "actor2.parentOrigin = [0.5, 0.5, 0.0];\n" + "actor2.size = [100,100,1];\n" + "\n" + "var animation = new dali.Animation(9);\n" + "\n" + "animation.animateTo(actor, \"orientation\", [0,90,0], \"linear\", 0, 3);\n" + "animation.animateTo(actor, \"orientation\", [0,0,0], \"linear\", 6, 3);\n" + "\n" + "var p = new dali.Path();\n" + "\n" + "p.addPoint( [0,0,0] );\n" + "p.addPoint( [200,200,200] );\n" + "p.addPoint( [0,0,-200] );\n" + "p.addPoint( [0,-200,-900] );\n" + "p.addPoint( [0,0,0] );\n" + "\n" + "p.generateControlPoints(0.43);\n" + "\n" + "animation.animatePath( actor, p, [1,0,0], \"linear\", 0, 6);\n" + "\n" + "function onTouched(actor, e) {\n" + " for(var i = 0; i < e.points.length; i++) {\n" + " if(e.points[i].state === \"DOWN\") {\n" + " console.log(e);\n" + " animation.play();\n" + " return;\n" + " }\n" + " }\n" + "}\n" + "\n" + "actor2.connect(\"touch\", onTouched);\n" + "\n" + "\n" + "" }, { name: "06. Offscreen", source: "\n" + "// todo" }, { name: "07. DALi toy pseudo dsl", source: "\n" + "//\n" + "// @todo\n" + "//\n" + "addTo(\"stage\",\n" + " image({\n" + " name:\"img\",\n" + " image:\"ducks\",\n" + " size:[100,100,1]\n" + " }),\n" + " image({\n" + " name:\"img2\",\n" + " tag:\"listitem\",\n" + " image:\"field\",\n" + " position:[100,0,0],\n" + " size:[100,100,1]\n" + " }),\n" + " image({\n" + " name:\"img3\",\n" + " tag:\"listitem\",\n" + " image:\"funnyface\",\n" + " position:[100,0,0],\n" + " size:[100,100,1]\n" + " }),\n" + " image({\n" + " name:\"img4\",\n" + " tag:\"listitem\",\n" + " image:\"girl1\",\n" + " position:[100,0,0],\n" + " size:[100,100,1]\n" + " })\n" + ");\n" + "\n" + "\n" + "when(\"img\", \"touchedDown\",\n" + " set(\"sensitive\", true),\n" + " set(\"size\", to([200,200,200])),\n" + " set(\"img2\", \"size\", to([200,200,200], 0,3, \"ease_in\")),\n" + " set(excludeFrom(tagged(\"scrollitem\"), \"myimage\"), path(0,3, \"ease_in\", \"path0\")),\n" + " endAction(\"Discard\")\n" + " then(set(\"img4\", \"hide\"),\n" + " play(\"anAnim\")) );\n" + " \n" + "\n" + "\n" } ]; function log(errorLog) { console.log(errorLog); } function consoleAssert( test, message ) { // using this rather than inbuild assert // it lets dali carry on for some reason if(!test) { throw message; } } function consoleLogErrorEvent(event) { "use strict"; console.log("Error"); console.dir(event); if(event.target) { if(event.target.result) { event.target.result.close(); } } } function consoleLogSuccess(message) { "use strict"; return function() { console.log("Success:" + message); }; } /** * Gets embedded base64 images embedded in the HTML file */ function getStockImageData(index) { "use strict"; var name = "testImage" + index; // need to draw it off screen first? @todo var c = document.createElement("canvas"); var img = document.getElementById(name); c.width = img.naturalWidth; c.height = img.naturalHeight; var context = c.getContext("2d"); context.drawImage(img, 0, 0 ); var imageData = context.getImageData(0, 0, img.naturalWidth, img.naturalHeight); // <-ImageData return imageData; } function formatValue(value) { if(typeof(value) === "number") { if(value === 3.4028234663852886e+38) { return "MAX_FLOAT"; } else if(value === Number.MAX_VALUE) { return "MAX_DBL"; } else if(value === 2147483647) { return "MAX_INT"; } else if(value === 9223372036854775807) { return "MAX_INT64"; } else { return value.toFixed(3); } } else { return value; } } /** * Add bootstrap column for single value (not array) */ function add1ColElement(elem, value) { var e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = formatValue(value); elem.appendChild(e); e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = ""; elem.appendChild(e); e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = ""; elem.appendChild(e); e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = ""; elem.appendChild(e); return e; } /* * Add bootstrap column for array of 2 value */ function add2ColElement(elem, value) { var e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = formatValue(value[0]); elem.appendChild(e); e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = formatValue(value[1]); elem.appendChild(e); e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = ""; elem.appendChild(e); e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = ""; elem.appendChild(e); return e; } /* * Add bootstrap table cell for array of 3 value */ function add3ColElement(elem, value) { var e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = formatValue(value[0]); elem.appendChild(e); e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = formatValue(value[1]); elem.appendChild(e); e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = formatValue(value[2]); elem.appendChild(e); e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = ""; elem.appendChild(e); return e; } /* * Add bootstrap table cell for array of 4 value */ function add4ColElement(elem, value) { var e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = formatValue(value[0]); elem.appendChild(e); e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = formatValue(value[1]); elem.appendChild(e); e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = formatValue(value[2]); elem.appendChild(e); e = document.createElement("div"); e.className = "col-md-3"; e.innerHTML = formatValue(value[3]); elem.appendChild(e); return e; } /* * Add a bootstrap table cell for property 'name' for an actor */ function createElementForActorProperty(actor, name) { "use strict"; var elem = document.createElement("div"); var value = actor[name]; var type = typeof value; if(name === "maximumSize") { value = value; } if(type === "string" || type === "number" || type === "boolean") { elem.className = "row"; add1ColElement(elem, value); } else if(value === undefined) { elem.className = "row"; add1ColElement(elem, "???undefined???"); } else { var r; var length = value.length; if(length === 2) { elem.className = "row"; add2ColElement(elem, value); } else if(length === 3) { elem.className = "row"; add3ColElement(elem, value); } else if(length === 4) { elem.className = "row"; add4ColElement(elem, value); } else if(length === 9) { r = document.createElement("div"); r.className = "row"; add3ColElement(r, value.slice(0, 3)); elem.appendChild(r); r = document.createElement("div"); r.className = "row"; add3ColElement(r, value.slice(3, 6)); elem.appendChild(r); r = document.createElement("div"); r.className = "row"; add3ColElement(r, value.slice(6, 9)); elem.appendChild(r); } else if(length === 16) { r = document.createElement("div"); r.className = "row"; add4ColElement(r, value.slice(0, 4)); elem.appendChild(r); r = document.createElement("div"); r.className = "row"; add4ColElement(r, value.slice(4, 8)); elem.appendChild(r); r = document.createElement("div"); r.className = "row"; add4ColElement(r, value.slice(8, 12)); elem.appendChild(r); r = document.createElement("div"); r.className = "row"; add4ColElement(r, value.slice(12, 16)); elem.appendChild(r); } } return elem; } /** * Adds a bootstrap table to show the actor properties */ function onActorSelected(actor) { "use strict"; var i; var name; var gridBlock; var nameBlock; var valueBlock; var actorId; // // recreate property tab // var elem = document.getElementById("selected"); removeAllChildren(elem); // // setup property view // if (actor) { actorId = actor.getId(); var p = document.createElement("div"); p.innerHTML = "

" + actor.name + " [" + actorId + "] (" + actor.position + ")

"; elem.appendChild(p); var parent = actor.getParent(); if(parent) { p = document.createElement("div"); p.innerHTML = "

" + "(Parent: " + parent.name + " [" + parent.getId() + "] (" + parent.position + ")" + " Anchored: " + actor.anchorPoint + "" + " ParentOrigin: " + actor.parentOrigin + " )" + "

"; elem.appendChild(p); } if( actorId in actorIdToShaderSet && "shaderEffect" in actorIdToShaderSet[actorId]) { // if has compiled var shaderOptions = actorIdToShaderSet[actorId]; var uniforms = dali.sourceUniformMetaData(shaderOptions.vertex); uniforms = uniforms.concat(dali.sourceUniformMetaData(shaderOptions.fragment)); var shader = getShader(actor); if(uniforms.length) { gridBlock = document.createElement("div"); gridBlock.className = "row"; nameBlock = document.createElement("div"); nameBlock.className = "col-md-5"; nameBlock.innerHTML = "Shader Uniforms:"; gridBlock.appendChild(nameBlock); valueBlock = document.createElement("div"); valueBlock.className = "col-md-7"; valueBlock.innerHTML = ""; gridBlock.appendChild(valueBlock); elem.appendChild(gridBlock); for(i = 0; i < uniforms.length; i++) { var type = uniforms[i].type; name = uniforms[i].name; gridBlock = document.createElement("div"); gridBlock.className = "row"; nameBlock = document.createElement("div"); nameBlock.className = "col-md-5"; nameBlock.innerHTML = type + " " + name + " (Animatable) "; gridBlock.appendChild(nameBlock); valueBlock = document.createElement("div"); valueBlock.className = "col-md-7"; valueBlock.innerHTML = shader[ name ]; gridBlock.appendChild(valueBlock); elem.appendChild(gridBlock); } } } // getproperties returns std::vector var props = actor.getProperties(); gridBlock = document.createElement("div"); gridBlock.className = "row"; nameBlock = document.createElement("div"); nameBlock.className = "col-md-5"; nameBlock.innerHTML = "Properties:"; gridBlock.appendChild(nameBlock); valueBlock = document.createElement("div"); valueBlock.className = "col-md-7"; valueBlock.innerHTML = ""; gridBlock.appendChild(valueBlock); elem.appendChild(gridBlock); for (i = 0; i < props.size(); i++) { name = props.get(i); gridBlock = document.createElement("div"); gridBlock.className = "row"; var animatable = actor.isPropertyAnimatable(actor.getPropertyIndex(name)); nameBlock = document.createElement("div"); nameBlock.className = "col-md-5"; if(animatable) { nameBlock.innerHTML = "'" + name + "'" + " (animatable)"; } else { nameBlock.innerHTML = "'" + name + "'"; } gridBlock.appendChild(nameBlock); valueBlock = document.createElement("div"); valueBlock.className = "col-md-7"; valueBlock.appendChild( createElementForActorProperty(actor, name) ); gridBlock.appendChild(valueBlock); elem.appendChild(gridBlock); } props.delete(); } } /** * creates page element and set namesValues array */ function createElement(elementName, namesValues) { "use strict"; var e = document.createElement(elementName); for(var name in namesValues) { e[name] = namesValues[name]; } return e; } /** * create element with innerHTML */ function createElementInnerHTML(elementName, innerHTML) { "use strict"; return createElement(elementName, {"innerHTML": innerHTML}); } /** * remove all the children from the element */ function removeAllChildren(elem) { "use strict"; var count = elem.children.length; for (var i = 0; i < count; i++) { elem.removeChild(elem.children[0]); } } /** * */ function onChangeSetDataChanged(e) { e.currentTarget["data-changed"] = true; } /** * creates a document input element [ ] */ function inputElem(type, propObject, property, val, arrayIndex) { "use strict"; var e = document.createElement("input"); e.type = type; // for number then step of any means it can be a real number not just integer e.step = "any"; e.value = val; e.className = "form-control"; e["data-value"] = val; e["data-arrayIndex"] = arrayIndex; e["data-changed"] = false; e.addEventListener("changed", onChangeSetDataChanged); return e; } /** * creates an input 2 element [ , ] */ function inputElem2(type, propObject, property, val, startIndex) { "use strict"; var d = document.createElement("div"); var a = inputElem("number", propObject, property, val[startIndex], startIndex); a.className = "col-md-3"; d.appendChild(a); a = inputElem("number", propObject, property, val[startIndex + 1], startIndex + 1); a.className = "col-md-3"; d.appendChild(a); a.className = "col-md-3"; d.appendChild(a); a = createElement("div"); a.className = "col-md-3"; d.appendChild(a); return d; } /** * creates an input 3 element [ , , ] */ function inputElem3(type, propObject, property, val, startIndex) { "use strict"; var d = document.createElement("div"); var a = inputElem("number", propObject, property, val[startIndex], startIndex); a.className = "col-md-3"; d.appendChild(a); a = inputElem("number", propObject, property, val[startIndex + 1], startIndex + 1); a.className = "col-md-3"; d.appendChild(a); a = inputElem("number", propObject, property, val[startIndex + 2], startIndex + 2); a.className = "col-md-3"; d.appendChild(a); a = createElement("div"); a.className = "col-md-3"; d.appendChild(a); return d; } /** * creates an input 4 element [ , , , ] */ function inputElem4(type, propObject, property, val, startIndex) { "use strict"; var d = document.createElement("div"); var a = inputElem("number", propObject, property, val[startIndex], startIndex); a.className = "col-md-3"; d.appendChild(a); a = inputElem("number", propObject, property, val[startIndex + 1], startIndex + 1); a.className = "col-md-3"; d.appendChild(a); a = inputElem("number", propObject, property, val[startIndex + 2], startIndex + 2); a.className = "col-md-3"; d.appendChild(a); a = inputElem("number", propObject, property, val[startIndex + 3], startIndex + 3); a.className = "col-md-3"; d.appendChild(a); return d; } /** * creates a document input element for an actor/shader's property */ function createInputElement(actorShader, propertyName, value) { // always4 ja columns "use strict"; var type = typeof value; var e; if(type === "string") { e = inputElem("string", actorShader, propertyName, value); } else if(type === "number") { e = inputElem("number", actorShader, propertyName, value); } else if(type === "boolean") { e = inputElem("checkbox", actorShader, propertyName, value); } else { var length = value.length; if(length === 2) { e = inputElem2("number", actorShader, propertyName, value, 0); } else if(length === 3) { e = inputElem3("number", actorShader, propertyName, value, 0); } else if(length === 4) { e = inputElem4("number", actorShader, propertyName, value, 0); } else if(length === 9) { e = createElement("div"); e.appendChild( inputElem3("number", actorShader, propertyName, value, 0) ); e.appendChild( inputElem3("number", actorShader, propertyName, value, 3) ); e.appendChild( inputElem3("number", actorShader, propertyName, value, 6) ); } else if(length === 16) { e = createElement("div"); e.appendChild( inputElem4("number", actorShader, propertyName, value, 0) ); e.appendChild( inputElem4("number", actorShader, propertyName, value, 4) ); e.appendChild( inputElem4("number", actorShader, propertyName, value, 8) ); e.appendChild( inputElem4("number", actorShader, propertyName, value, 12) ); } else { throw "should not happen"; } } return e; } /** * Selects an actor by id */ function selectActor(id) { // from html tree "use strict"; if(id === null) { eventHandler.selectActor(null); } else { var root = dali.stage.getRootLayer(); var actor = root.findChildById(id); if (actor) { eventHandler.selectActor(actor); } root.delete(); // wrapper } } /** * Rebuild the document actor property display */ function rebuildTree() { "use strict"; // remove childred var e = document.getElementById("tree"); var count = e.children.length; for (var i = 0; i < count; i++) { e.removeChild(e.children[0]); } //