1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* DreemGL is a collaboration between Teeming Society & Samsung Electronics, sponsored by Samsung and others.
   Copyright 2015-2016 Teeming Society. 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.*/


/**
 * @class HeadlessLayer
 * Simulate a layer (an array of actors or layouts)
 * Modeled from DALi platform.
 */

define.class(function(require, exports){
        // internal, HeadlessApi is a static object to access the headless api
        HeadlessApi = require('./headless_api')

        // Assign a unique id to each headlessactor object
        var HeadlessLayer = exports
        HeadlessLayer.GlobalId = 0

        /**
         * @method constructor
         * Create a layout object with default parameters
         * @param {Object} parent The layer object to add this layer to. If this
         * is not defined, the layer is added to the top-level layer. If null,
         * the layer is not added. The null case is used to initialize the
         * root layer.
         * @param {Number} width The width of the layer, in pixels.
         * @param {Number} height The height of the layer, in pixels.
         */
        this.atConstructor = function(parent, width, height) {
                this.object_type = 'HeadlessLayer'

                var headless = HeadlessApi.headless;

                this.id = ++HeadlessLayer.GlobalId;
                this.onstage = false;
                if (width && height)
                        this.size = [width, height, 0];

                // The list of objects (actors or layers) belonging to this layer.
                this.actors = [];

                // Add to another layer unless parent is null (root layer)
                if (typeof parent === 'undefined')
                        parent = HeadlessApi.currentlayer;
                if (parent) {
                        HeadlessApi.rootlayer.add(this);
                }
        }


        /**
         * @method add
         * Add an actor to this layer.
         * @param {object} actor HeadlessActor or HeadlessLayer object
         */
        this.add = function(actor) {
                this.actors.push(actor);
        }


        this.name = function() {
                return 'headlesslayer' + this.id;
        }

        this.currentstate = function(verbose) {
                var states = [];
                var actors = []
                for (var i in this.actors) {
                        actors.push(this.actors[i].name());
                        states = states.concat(this.actors[i].currentstate(verbose));
                }
                
                if (!HeadlessApi.isShown(this.name())) {
                        var state = [
                                {name: this.name()}
                                ,{actors: actors}
                        ]
                        
                        HeadlessApi.shownObject(this.name());
                        states.push(state);
                }

                return states;
        }

        this.inspect = function(depth) {
                var obj = {headlesslayer:this.id, actors:this.actors};
                var util = require('util')
                return util.inspect(obj, {depth: null});
        }

});