25bbd484034e9d232e3c03cfba86069dd3469f92
[platform/core/uifw/dali-toolkit.git] / node-addon / test.js
1  var window= {
2         x:800,
3          y:500,
4        width:880,
5        height: 1020,
6        transparent: false,
7        name:'my-first-dali-app'
8  };
9 var viewMode={
10        'stereoscopic-mode':'mono', // stereo-horizontal, stereo-vertical, stereo-interlaced,
11        'stereo-base': 65 // Distance in millimeters between left/right cameras typically between (50-70mm)
12  };
13  var options= {
14     'window': window,
15     'view-mode': viewMode,
16  }
17
18 var dali = require('./build/Release/dali')( options );
19 var netflixRoulette = require('netflix-roulette');
20
21
22 var NUMBER_OF_IMAGES = 40; // for now use 16 ( demo files go up to 30)
23 var DEMO_IMAGES = []; // array to store Dali Images
24 var VIDEO_WALL_ACTORS = []; // array to store Image actors
25 var VIDEO_WALL_ROWS = 5; // use 3 rows for the video wall
26 var VIDEO_WALL_COLUMNS = 6; // use 12 columns for the video wall
27 var VIDEO_WALL_TOTAL_ITEMS = VIDEO_WALL_COLUMNS * VIDEO_WALL_ROWS; // total items
28 var VIDEO_WALL_ITEM_SIZE = 128; // width / height of a item in the video wall
29 var BORDER_SIZE = 5;
30 var VIDEO_WALL_ITEM_SIZE_NO_BORDER = VIDEO_WALL_ITEM_SIZE - BORDER_SIZE;
31 var VIDEO_WALL_WIDTH = VIDEO_WALL_COLUMNS * VIDEO_WALL_ITEM_SIZE;
32 var VIDEO_WALL_HEIGHT = VIDEO_WALL_ROWS * VIDEO_WALL_ITEM_SIZE;
33 var daliApp = {};
34 var posters = [];
35
36 var wallRootActor; // the root actor of the video wall
37
38
39 daliApp.loadNetflixImages = function() {
40
41   if( NUMBER_OF_IMAGES >= VIDEO_WALL_TOTAL_ITEMS)
42   {
43     NUMBER_OF_IMAGES = VIDEO_WALL_TOTAL_ITEMS-1;
44   }
45
46   for (index = 0; index < NUMBER_OF_IMAGES; ++index) {
47
48     fileName = posters[ index % (posters.length-1)  ];
49     if ( fileName )
50     {
51       DEMO_IMAGES[index] = new dali.ResourceImage( { url:fileName } );
52     }
53   }
54 }
55
56
57 daliApp.createRootActor = function() {
58     wallRootActor = new dali.Actor();
59     wallRootActor.parentOrigin = dali.CENTER;
60     wallRootActor.anchorPoint = dali.CENTER;
61     dali.stage.add(wallRootActor);
62
63     var field = new dali.Control("TextField");
64     field.parentOrigin = dali.CENTER;
65     field.anchorPoint = dali.CENTER;
66
67     field.placeholderText = "DALi netflix netflix-roulette demo";
68     dali.stage.add( field );
69 }
70
71
72
73 daliApp.getWallActorIndex = function(x, y) {
74     return x + y * VIDEO_WALL_COLUMNS;
75 }
76
77 daliApp.createActors = function() {
78     daliApp.createRootActor();
79
80     var anim = new dali.Animation(1);
81     var animOptions = {
82       alpha: "linear",
83       delay: 0.0,     // used to delay the start of the animation
84       duration: 1,    // duration of the animation
85      };
86
87     for (y = 0; y < VIDEO_WALL_ROWS; ++y) {
88         for (x = 0; x < VIDEO_WALL_COLUMNS; ++x) {
89
90             var actorIndex = daliApp.getWallActorIndex(x, y);
91             var imageView = new dali.Control("ImageView");
92
93             // wrap image index between 0 and NUMBER_OF_IMAGES
94             var imageIndex = actorIndex % NUMBER_OF_IMAGES;
95
96             imageView.image = DEMO_IMAGES[imageIndex];
97
98             imageView.parentOrigin = dali.CENTER;
99             imageView.anchorPoint = dali.CENTER;
100             imageView.size = [VIDEO_WALL_ITEM_SIZE_NO_BORDER, VIDEO_WALL_ITEM_SIZE_NO_BORDER, 1.0]; // start with zero size so it zooms up
101
102             var xPosition = x * VIDEO_WALL_ITEM_SIZE;
103             //  as the middle the wall is at zero (relative to wallRootActor), we need to subtract half the wall width.
104             // + add half item size because the item anchor point is the center of the wallRootActor.
105             xPosition = xPosition - (VIDEO_WALL_WIDTH / 2) + (VIDEO_WALL_ITEM_SIZE / 2);
106
107             var yPosition = y * VIDEO_WALL_ITEM_SIZE;
108             yPosition = yPosition - (VIDEO_WALL_HEIGHT / 2) + (VIDEO_WALL_ITEM_SIZE / 2);
109
110             imageView.position = [0,0,0];
111
112             animOptions.delay+=0.25;
113             anim.animateTo( imageView,"position",[xPosition, yPosition, 0.0],animOptions);
114             // store the actor
115             VIDEO_WALL_ACTORS[actorIndex] = imageView;
116
117             // Add to the video wall root actor.
118             wallRootActor.add(imageView);
119         }
120     }
121     anim.play();
122 }
123
124 function Initialise() {
125
126     daliApp.loadNetflixImages();
127
128     daliApp.createActors();
129 }
130
131 function actorLoaded( error, data )
132 {
133   for( i = 0; i < data.length; ++i )
134   {
135     var entry = data[i];
136
137    if( entry.poster )
138     {
139       posters.push(entry.poster);
140       //console.log(" entry = " + entry.poster );
141     }
142   }
143   Initialise();
144
145 }
146
147
148 netflixRoulette.actor('nicolas', actorLoaded );
149