zkv1000 / Nasal / display.nas /
Newer Older
167 lines | 5.672kb
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();
animation VSI
Sébastien MARQUE authored on 2017-03-10
37
            me.loadGroup({
38
                show : [
commit initial
Sébastien MARQUE authored on 2017-03-07
39
                    'SoftKeysTexts', 
40
                    'COMM', 
41
                    'NAV', 
42
                    'XPDR-TIME', 
AI disponible
Sébastien MARQUE authored on 2017-03-10
43
                    'FlightInstruments',
44
                    'Horizon',
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
45
                    'bankPointer',
animation VSI
Sébastien MARQUE authored on 2017-03-10
46
                    'VSI',
47
                ],
48
                text: 'VSIText',
49
            });
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
50
            me.updateAI(getprop('/orientation/roll-deg'),getprop('orientation/pitch-deg'));
animation VSI
Sébastien MARQUE authored on 2017-03-10
51
            me.updateVSI(getprop('/instrumentation/vertical-speed-indicator/indicated-speed-fpm'));
commit initial
Sébastien MARQUE authored on 2017-03-07
52
            me.progress.removeAllChildren();
53
            me.progress = nil;
54
            me.showInitProgress = nil;
55
            me._showInitProgress = nil;
56
            zkv.removeChild(me.role ~ 'init');
57
        }
58
    },
59

            
60
    showInitProgress : func (role) {
61
        me.progress = me.display.createGroup();
62
        me.progress.show();
63
        me.progress.createChild("text", role ~ " title")
64
            .setTranslation(512, 384)
65
            .setAlignment("center-center")
66
            .setFont("LiberationFonts/LiberationSans-Italic.ttf")
67
            .setFontSize(64, 1)
68
            .setColor(1,1,1)
69
            .setText("ZKV1000 " ~ role ~ " init");
70

            
71
        zkv.getNode(role ~ 'init',1).setIntValue(1);
72

            
73
        me._showInitProgress(me.progress.createChild("text", role ~ "progress")
74
            .setTranslation(512, 484)
75
            .setAlignment("center-center")
76
            .setFont("LiberationFonts/LiberationSans-Bold.ttf")
77
            .setFontSize(128, 1)
78
            .setColor(1,0,0), '.');
79
    },
80

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

            
133
    clips : {
134
        PitchScale : "rect(70,664,370,256)",
135
    },
136

            
animation VSI
Sébastien MARQUE authored on 2017-03-10
137
    texts : {
138
        VSIText : {
139
            alignment: "right-bottom", default : num('0'),
140
        },
141
    },
142

            
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
143
    updateAI: func(roll,pitch){
AI disponible
Sébastien MARQUE authored on 2017-03-10
144
        if (pitch > 80)
145
            pitch = 80;
146
        elsif(pitch < -80)
147
            pitch = -80;
148
        me.screenElements.Horizon
149
            .setRotation(-roll * D2R)
150
            .setTranslation(0, pitch * 6.8571428);
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
151
        me.screenElements.bankPointer
152
            .setRotation(-roll * D2R);
153
        settimer(func me.updateAI(getprop('/orientation/roll-deg'),getprop('orientation/pitch-deg')), 0.1);
AI disponible
Sébastien MARQUE authored on 2017-03-10
154
    },
animation VSI
Sébastien MARQUE authored on 2017-03-10
155

            
156
    updateVSI: func (vsi) {
157
        me.screenElements.VSIText
158
            .setText(num(math.round(vsi, 10)));
159
        if (vsi > 4500)
160
            vsi = 4500;
161
        elsif (vsi < -4500)
162
            vsi = -4500;
163
        me.screenElements.VSI
164
            .setTranslation(0, vsi * -0.03465);
165
        settimer(func me.updateVSI(getprop('/instrumentation/vertical-speed-indicator/indicated-speed-fpm')), 0.1);
166
    },
commit initial
Sébastien MARQUE authored on 2017-03-07
167
};