zkv1000 / Nasal / display.nas /
Newer Older
131 lines | 4.382kb
commit initial
Sébastien MARQUE authored on 2017-03-07
1
var displayClass = {
2
    new: func(node, role) {
3
        var m = { parents: [ displayClass ] };
4
        
5
        m.display = canvas.new({
6
                "name"      : role,
7
                "size"      : [1024, 768],
8
                "view"      : [1024, 768],
9
                "mipmapping": 1
10
        });
11
        m.display.addPlacement({
12
                "node": "Screen",
13
                "parent": role
14
        });
15
        m.display.setColorBackground(0,0,0);
16
        m.role = role;
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
17
        m.screenElements = {};
commit initial
Sébastien MARQUE authored on 2017-03-07
18

            
19
        return m;
20
    },
21

            
22
    loadsvg : func () {
23
        me.screen = me.display.createGroup();
24
        me.screen.hide();
25
        canvas.parsesvg(me.screen, "Aircraft/Instruments-3d/zkv1000/Systems/screen.svg");
26
    },
27

            
28
    _showInitProgress : func (p,t) {
29
        p.setText(t);
30
        if (zkv.getNode(me.role ~ 'init').getValue() != 0) {
31
            if (size(t) >= 10) t = '';
32
            settimer(func { me._showInitProgress(p, t ~ '.'); }, 0.1);
33
        }
34
        else {
35
            me.progress.hide();
36
            me.screen.show();
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
37
            me.loadGroup({ show : [
commit initial
Sébastien MARQUE authored on 2017-03-07
38
                    'SoftKeysTexts', 
39
                    'COMM', 
40
                    'NAV', 
41
                    'XPDR-TIME', 
AI disponible
Sébastien MARQUE authored on 2017-03-10
42
                    'FlightInstruments',
43
                    'Horizon',
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
44
            ]});
AI disponible
Sébastien MARQUE authored on 2017-03-10
45
            me.updateAi(getprop('/orientation/roll-deg'),getprop('orientation/pitch-deg'));
commit initial
Sébastien MARQUE authored on 2017-03-07
46
            me.progress.removeAllChildren();
47
            me.progress = nil;
48
            me.showInitProgress = nil;
49
            me._showInitProgress = nil;
50
            zkv.removeChild(me.role ~ 'init');
51
        }
52
    },
53

            
54
    showInitProgress : func (role) {
55
        me.progress = me.display.createGroup();
56
        me.progress.show();
57
        me.progress.createChild("text", role ~ " title")
58
            .setTranslation(512, 384)
59
            .setAlignment("center-center")
60
            .setFont("LiberationFonts/LiberationSans-Italic.ttf")
61
            .setFontSize(64, 1)
62
            .setColor(1,1,1)
63
            .setText("ZKV1000 " ~ role ~ " init");
64

            
65
        zkv.getNode(role ~ 'init',1).setIntValue(1);
66

            
67
        me._showInitProgress(me.progress.createChild("text", role ~ "progress")
68
            .setTranslation(512, 484)
69
            .setAlignment("center-center")
70
            .setFont("LiberationFonts/LiberationSans-Bold.ttf")
71
            .setFontSize(128, 1)
72
            .setColor(1,0,0), '.');
73
    },
74

            
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
75
    loadGroup : func (h) {
76
        if (typeof(h) != 'hash') {
77
            msg_dbg(sprintf("%s need a hash, but get a %s from %s",
78
                    caller(0)[0],
79
                    typeof(h),
80
                    caller(1)[0]));
81
            return;
commit initial
Sébastien MARQUE authored on 2017-03-07
82
        }
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
83
        var setMethod = func (e, t) {
84
            if (t == 'hide')
85
                me.screenElements[e].hide();
86
            elsif (t == 'show')
87
                me.screenElements[e].show();
AI disponible
Sébastien MARQUE authored on 2017-03-10
88
            elsif (t == 'rot' or t == 'trans') {
89
                if (! contains(me.screenElements[e], t))
90
                    me.screenElements[e][t] = me.screenElements[e].createTransform();
91
            }
92
            elsif (t == 'clip') {
93
                if (contains(me.clips, e))
94
                    me.screenElements[e].set("clip", me.clips[e]);
95
                else
96
                    print('no defined clip for ' ~ e);
97
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
98
            else
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
99
                print('unknown method ' ~ t);
100
        };
101
        foreach (var todo; keys(h)) {
102
            if (typeof(h[todo]) != 'vector') h[todo] = [ h[todo] ];
103
            foreach (var id; h[todo]) {
104
                if (! contains(me.screenElements, id)) {
105
                    me.screenElements[id] = me.screen.getElementById(id);
106
                    if (me.screenElements[id] != nil)
107
                        setMethod(id, todo);
108
                    else
109
                        print('SVG ID ' ~ id ~ ' not found');
110
                }
111
                else
112
                    setMethod(id, todo);
113
            }
commit initial
Sébastien MARQUE authored on 2017-03-07
114
        }
115
    },
AI disponible
Sébastien MARQUE authored on 2017-03-10
116

            
117
    clips : {
118
        PitchScale : "rect(70,664,370,256)",
119
    },
120

            
121
    updateAi: func(roll,pitch){
122
        if (pitch > 80)
123
            pitch = 80;
124
        elsif(pitch < -80)
125
            pitch = -80;
126
        me.screenElements.Horizon
127
            .setRotation(-roll * D2R)
128
            .setTranslation(0, pitch * 6.8571428);
129
        settimer(func me.updateAi(getprop('/orientation/roll-deg'),getprop('orientation/pitch-deg')), 0.1);
130
    },
commit initial
Sébastien MARQUE authored on 2017-03-07
131
};