zkv1000 / Nasal / menu.nas /
Newer Older
196 lines | 7.589kb
add window management
Sébastien MARQUE authored on 2017-03-28
1
var pageClass = {
2
    new : func (d) {
3
        var m = { parents : [pageClass] };
fix issue #2
Sébastien MARQUE authored on 2017-04-23
4
        m.page = d.display.display.createGroup().set('z-index', 100);
add window management
Sébastien MARQUE authored on 2017-03-28
5
        m.window = {};
6
        m.state = {};
7
        m.selected = '';
8
        return m;
9
    },
10

            
11
    del : func (id = nil) {
fixes some bugs in windows
Sébastien MARQUE authored on 2017-04-12
12
        if (id != nil and typeof(id) == 'scalar') {
add window management
Sébastien MARQUE authored on 2017-03-28
13
            delete(me.state, id);
fix deletion of specific win...
Sébastien MARQUE authored on 2017-04-24
14
            var _id = id ~ '-';
15
            id = [];
16
            foreach (var w; keys(me.window))
17
                if (find(_id, w) == 0)
18
                    append(id, w);
add window management
Sébastien MARQUE authored on 2017-03-28
19
        }
20
        else {
21
            foreach (var s; keys(me.state))
22
                delete(me.state, s);
23
            id = keys(me.window);
24
        }
25
        foreach (var w; id) {
26
            me.window[w]
27
                .hide()
28
                .del();
29
            delete(me.window, w);
30
        }
31
    },
32

            
33
    _selected_text : func (id, text, x, y) {
34
        me.selected = id;
35
        me.window[id]
36
            .setFontSize(16)
37
            .setFont('LiberationFonts/LiberationMono-Regular.ttf')
38
            .setTranslation(x, y)
39
            .setDrawMode(0x01 + 0x04)
40
            .setText(text)
41
            .setColorFill(0,1,1)
42
            .setColor(0,0,0);
43
    },
44

            
45
    _editable_text : func (id, text, x, y) {
46
        me.window[id]
47
            .setFontSize(16)
48
            .setFont('LiberationFonts/LiberationMono-Regular.ttf')
49
            .setTranslation(x, y)
50
            .setText(text)
51
            .setColorFill(0,0,0)
52
            .setColor(0,1,1);
53
    },
54

            
55
    _normal_text : func (id, text, x, y) {
56
        me.window[id]
57
            .setFontSize(16)
58
            .setFont('LiberationFonts/LiberationMono-Regular.ttf')
59
            .setTranslation(x, y)
60
            .setText(text)
61
            .setColorFill(0,0,0)
62
            .setColor(1,1,1);
63
    },
64

            
65
    _title_text : func (id, text, x, y) {
66
        me.window[id]
67
            .setFontSize(16)
68
            .setFont('LiberationFonts/LiberationMono-Regular.ttf')
69
            .setTranslation(x, y)
70
            .setAlignment('center-center')
71
            .setText(text)
72
            .setColorFill(0,0,0)
73
            .setColor(0,1,1);
74
    },
75

            
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
76
    fill : func (id, scroll = nil) {
add window management
Sébastien MARQUE authored on 2017-03-28
77
        var state = me.state[id];
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
78
        state.scroll = {
79
            offset : 0,           # offset between canvas element and state element
80
            last : 9999,          # last scrollgroup
81
            begin: -9999,         # first canvas element of the scrolling area
82
            end: 9999,            # last canvas element of the scrolling area
83
            upper: -9999,         # group printed on the top of the scrolling area
84
            lower: 9999,          # group printed at the bottom of the scrolling area
fixes some bugs in windows
Sébastien MARQUE authored on 2017-04-12
85
            lines : scroll != nil ? scroll.lines : 0, # number of lines for the scrolling area
86
            columns : scroll != nil ? scroll.columns : 0, # number of objects on each scrolling lines
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
87
        };
88
        var scrollgroup = {};
89
        forindex (var line; state.objects) {
90
            if (find('separator', state.objects[line].type) > -1) {
91
                me.window[id ~ '-' ~ (line - state.scroll.offset)] = me.page.createChild('path')
add window management
Sébastien MARQUE authored on 2017-03-28
92
                    .setStrokeLineWidth(1)
93
                    .moveTo(state.x_base, state.geometry.y - 12)
94
                    .horiz(state.geometry.w - 20)
95
                    .setColor(1,1,1);
96
                state.geometry.x = state.x_base;
97
                state.geometry.y += 8;
98
            }
99
            else {
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
100
                if (contains(state.objects[line], 'scrollgroup')) {
101
                    state.scroll.last = state.objects[line].scrollgroup;
102
                    scrollgroup[state.objects[line].scrollgroup] = 1;
103
                    if (state.scroll.begin == -9999) {
104
                        state.scroll.begin = line;
105
                        state.scroll.upper = state.objects[line].scrollgroup;
106
                    }
107
                    if (size(keys(scrollgroup)) > state.scroll.lines) {
108
                        if (state.scroll.end == 9999) {
109
                            state.scroll.end = line - 1;
110
                            state.scroll.lower = state.objects[line - 1].scrollgroup;
111
                        }
112
                        else
113
                            state.scroll.last = state.objects[line].scrollgroup;
114
                        state.scroll.offset += 1;
115
                        continue;
116
                    }
117
                }
118
                me.window[id ~ '-' ~ (line - state.scroll.offset)] = me.page.createChild('text');
type normal for text is defa...
Sébastien MARQUE authored on 2017-04-12
119
                if (find('selected', state.objects[line].type) > -1)
add window management
Sébastien MARQUE authored on 2017-03-28
120
                    me._selected_text(
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
121
                            id ~ '-' ~ (line - state.scroll.offset),
122
                            state.objects[line].text,
add window management
Sébastien MARQUE authored on 2017-03-28
123
                            state.geometry.x,
124
                            state.geometry.y,
125
                            );
126

            
adds type highlighted
Sébastien MARQUE authored on 2017-04-12
127
                elsif (find('editable', state.objects[line].type) > -1
128
                   or  find('highlighted', state.objects[line].type) > -1)
add window management
Sébastien MARQUE authored on 2017-03-28
129
                    me._editable_text(
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
130
                            id ~ '-' ~ (line - state.scroll.offset),
131
                            state.objects[line].text,
add window management
Sébastien MARQUE authored on 2017-03-28
132
                            state.geometry.x,
133
                            state.geometry.y,
134
                            );
135

            
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
136
                elsif (find('title', state.objects[line].type) > -1)
add window management
Sébastien MARQUE authored on 2017-03-28
137
                    me._title_text(
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
138
                            id ~ '-' ~ (line - state.scroll.offset),
139
                            state.objects[line].text,
add window management
Sébastien MARQUE authored on 2017-03-28
140
                            state.x_base - 10 + state.geometry.w / 2,
141
                            state.geometry.y
142
                        );
143

            
type normal for text is defa...
Sébastien MARQUE authored on 2017-04-12
144
                else
145
                    me._normal_text(
146
                            id ~ '-' ~ (line - state.scroll.offset),
147
                            state.objects[line].text,
148
                            state.geometry.x,
149
                            state.geometry.y,
150
                            );
151

            
152

            
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
153
                if (find('end-of-line', state.objects[line].type) > -1
154
                or  find('title', state.objects[line].type) > -1) {
add window management
Sébastien MARQUE authored on 2017-03-28
155
                    state.geometry.x = state.x_base;
156
                    state.geometry.y += 24;
157
                }
158
                else
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
159
                    state.geometry.x += size(state.objects[line].text) * 10 + 8;
add window management
Sébastien MARQUE authored on 2017-03-28
160
            }
161
        }
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
162
        # reset the scrolling offset before the first move
163
        state.scroll.offset = 0;
add window management
Sébastien MARQUE authored on 2017-03-28
164
    },
165
    
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
166
    draw : func (id, geometry, objects, scroll = nil) {
add window management
Sébastien MARQUE authored on 2017-03-28
167
        if (contains(me.window, id ~ '-bg')) {
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
168
            logprint(LOG_DEBUG, 'objet ' ~ id ~ ' already exists');
add window management
Sébastien MARQUE authored on 2017-03-28
169
            return;
170
        }
171
        if (!contains(geometry, 'h') and !contains(geometry, 'l')) {
printlog deprecated + consta...
Sébastien MARQUE authored on 2020-04-24
172
            logprint(LOG_DEBUG, 'missing parameter l or h');
add window management
Sébastien MARQUE authored on 2017-03-28
173
            return;
174
        }
fixes some bugs in windows
Sébastien MARQUE authored on 2017-04-12
175
        var save_x = geometry.x;
176
        var save_y = geometry.y;
add window management
Sébastien MARQUE authored on 2017-03-28
177
        me.state[id] = {
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
178
            objects: objects,
add window management
Sébastien MARQUE authored on 2017-03-28
179
            geometry: geometry,
180
            x_base : geometry.x + 10,
181
            h_max : contains(geometry, 'h') ? h : geometry.l * 24 + 8 + geometry.sep * 16,
182
        };
183
        me.state[id].y_max = me.state[id].h_max + me.state[id].geometry.y;
184
        me.window[id ~ '-bg'] = me.page.createChild('path');
185
        me.window[id ~ '-bg']
186
            .rect(geometry.x, geometry.y,
187
                  geometry.w, me.state[id].h_max)
188
            .setColor(1,1,1)
189
            .setColorFill(0,0,0);
190
        me.state[id].geometry.x += 10;
191
        me.state[id].geometry.y += 16;
changes about how to fill wi...
Sébastien MARQUE authored on 2017-04-02
192
        me.fill(id, scroll);
fixes some bugs in windows
Sébastien MARQUE authored on 2017-04-12
193
        geometry.x = save_x;
194
        geometry.y = save_y;
add window management
Sébastien MARQUE authored on 2017-03-28
195
    },
196
};