zkv1000 / Nasal / display.nas /
Newer Older
134 lines | 4.494kb
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',
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
44
                    'bankPointer',
écriture du wrapper pour le ...
Sébastien MARQUE authored on 2017-03-10
45
            ]});
AI disponible, avec bankPoin...
Sébastien MARQUE authored on 2017-03-10
46
            me.updateAI(getprop('/orientation/roll-deg'),getprop('orientation/pitch-deg'));
commit initial
Sébastien MARQUE authored on 2017-03-07
47
            me.progress.removeAllChildren();
48
            me.progress = nil;
49
            me.showInitProgress = nil;
50
            me._showInitProgress = nil;
51
            zkv.removeChild(me.role ~ 'init');
52
        }
53
    },
54

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

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

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

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

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

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