pdproperties.html 15.5 KB
Newer Older
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
<!DOCTYPE html>
<html>
  <head>
  <link rel="stylesheet" type="text/css" href="pdproperties.css">

<style>body{font-family:Verdana;}
fieldset{font-family:Georgia; background-color:#eeeeee;
		 border-radius:3px; border:2px solid black;
		 margin:5px; padding:8px; }

input[type="text"]{width:3em;}

.prop{display: none;}

</style>



  </head>
  <body>

 <form> 
     <fieldset> 
      <legend>size and behavior</legend> 

      <span class="size prop">
        <label title="size of the iemgui">
          size <input type="text" name="size"></label><br>
      </span>

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
      <span class="selection-size prop">
        <label title="size of the selection rectangle used to select and drag the object">
          selection size <input type="text" name="selection-size"></label><br>
      </span>

      <span class="width prop">
        <label title="width of the iemgui">
          width <input type="text" name="width"></label>
        <label title="height of the iemgui">
          height <input type="text" name="height"></label><br>
      </span>

      <span class="visible-width prop">
        <label title="width of the rectangle">
          width <input type="text" name="visible-width"></label>
        <label title="height of the rectangle">
          height <input type="text" name="visible-height"></label><br>
      </span>

50
51
52
53
54
      <span class="nonzero-value prop">
        <label title="value to output when the toggle shows an 'x'">
          nonzero value <input type="text" name="nonzero-value"></label><br>
      </span>

55
56
57
58
59
      <span class="number prop">
        <label title="number of buttons">
          number <input type="text" name="number"></label><br>
      </span>

60
61
62
63
64
65
66
67
68
69
      <span class="flash-interrupt prop">
        <label title="the amount of time (in milliseconds) that Pd will wait before interrupting the flashing of the button">
          interrupt <input type="text" name="flash-interrupt"></label>
      </span>

      <span class="flash-hold prop">
        <label title="the amount of time (in milliseconds) that Pd will display the flash animation">
          hold <input type="text" name="flash-hold"></label>  <br>
      </span>

70
      <span class="minimum-range prop">
71
        <label title="the lowest number to output. Anything lower will be replaced by this number">
72
          minimum <input type="text" name="minimum-range"></label>
73
        <label title="the largest number to output. Anything higher will be replaced by this number">
74
          maximum <input type="text" name="maximum-range"></label>  <br>
75
76
77
78
      </span>

      <span class="init prop">
        <label title="when checked, this will save the state of the iemgui with the patch, and output a value when the patch is loaded (as if you had an invisible [loadbang] connected to the input).">
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
          init <input type="checkbox" name="init" value="on"></label><br>
      </span>

      <span class="vu-scale prop">
        <label title="display scale (numbers) next to the meter">
          scale <input type="checkbox" name="vu-scale" value="on"></label><br>
      </span>


      <span class="log-scaling prop">
        <label title="logarithmic scale for values along the slider">
          logarithmic scaling <input type="checkbox" name="log-scaling" value="on"></label><br>
      </span>

      <span class="log-height prop">
        <label title="logarithmic scale for values along the slider">
          log height<input type="text" name="log-height"></label><br>
      </span>

      <span class="steady-on-click prop">
        <label title="don't move the slider on click, only on dragging.">
          steady on click <input type="checkbox" name="steady-on-click" value="on"></label><br>
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
      </span>
     </fieldset> 

     <fieldset> 
      <legend>messages</legend> 

      <span class="send-symbol prop">
        <label title="symbol you can use to send wireless messages to other iemguis (or a [receive] object)">
          send-symbol <input type="text" name="send-symbol" ></label> <br>
      </span>

      <span class="receive-symbol prop">
        <label title="symbol you can use to receive wireless messages from other iemguis (or from a [send] object)">
          receive-symbol <input type="text" name="receive-symbol" ></label> <br>
      </span>
     </fieldset> 

     <fieldset> 
      <legend>label</legend> 

      <span class="label prop">
        <label title="a label displayed next to this iemgui">
          label <input type="text" name="label" > <br>
      </span>

      <span class="x-offset prop">
        <label title="horizontal offset (from the top-left corner of the object) for the label">
          x offset <input type="text" name="x-offset" ></label>
        <label title="vertical offset (from the top-left corner of the object) for the label">
          y offset <input type="text" name="y-offset"></label> <br>
      </span>

      <span class="font-style prop">
        <label title="which font to use to display the label">
          font <input type="text" name="font-style"></label>
        <label title="size of the label">size <input type="text" name="font-size"><label> <br>
      </span>
     </fieldset> 

     <fieldset> 
      <legend>colors</legend> 

      <span class="background-color prop">
        <label title="background color for the object">
          background <input type="color" name="background-color"></label> <br>
      </span>

      <span class="foreground-color prop">
        <label title="foreground color for the object">
          foreground <input type="color" name="foreground-color"></label> <br>
      </span>

      <span class="label-color prop">
        <label title="color of the label text">
          label <input type="color" name="label-color"></title> <br>
      </span>
     </fieldset> 

     <span class="prop">
       <input type="hidden" name="minimum-size">
       <input type="hidden" name="range-schedule">
162
       <input type="hidden" name="hide-frame">
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
     </span>

     <div style="text-align: center">
      <button type="button" onClick="ok()" title="Apply these settings and close the window">Ok</button>
      <button type="button" onClick="apply()" title="Apply these settings without closing the window">Apply</button>
      <button type="button" onClick="cancel()" title="Close window without applying any changes">Cancel</button>
     </div>

 </form> 
        

  <script>
    'use strict';
    var nw = require('nw.gui'); 
    var pdgui = require('./pdgui.js');

    console.log("my working dire is " + pdgui.get_pwd());

    var pd_object_callback;

    function ok() {
        apply();
        cancel();
    }

188
189
190
191
//    function toggler(evt) {
//        evt.value = evt.checked ? 1 : 0; 
//    }

192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
    function substitute_space(arg) {
        var fake_space = String.fromCharCode(11);
        return arg.split(' ').join(fake_space);
    }

    function strip_problem_chars(arg) {
        var problem_chars = [';', ',', '{', '}', '\\'];
        var ret = arg;
        for(var i = 0; i < problem_chars.length; i++) {
            ret = ret.split(';').join('');
        }
        return ret;
    }

    function apply() {
        pdgui.gui_post("we're applying shits!");

        /* Not sure what these are...
            iemgui_clip_dim $id
            iemgui_clip_num $id
            iemgui_sched_rng $id
            iemgui_verify_rng $id
            iemgui_sched_rng $id
            iemgui_clip_fontsize $id
        */	

        var send_symbol = document.getElementsByName('send-symbol')[0].value;
        var receive_symbol = document.getElementsByName('receive-symbol')[0].value;
        var label =  document.getElementsByName('label')[0].value;
        if (send_symbol === null || send_symbol === '') { send_symbol = 'empty'; }
        if (receive_symbol === null || receive_symbol === '') { receive_symbol = 'empty'; }
        if (label === null || label === '') { label = 'empty'; }

        console.log("send_symbol is " + send_symbol);

        if (send_symbol.charAt(0) === '$') {
            send_symbol = '#' + send_symbol.slice(1);
        }
        if (receive_symbol.charAt(0) === '$') {
            receive_symbol = '#' + receive_symbol.slice(1);
        }
        if (label.charAt(0) === '$') {
            label = '#' + label.slice(1);
        }

        send_symbol = substitute_space(send_symbol);
        receive_symbol = substitute_space(receive_symbol);
        label = substitute_space(label);

        send_symbol = strip_problem_chars(send_symbol);
        receive_symbol = strip_problem_chars(receive_symbol);
        label = strip_problem_chars(label);

        var label_x_offset =  document.getElementsByName('x-offset')[0].value;
        var label_y_offset =  document.getElementsByName('y-offset')[0].value;

	// make sure the offset boxes have a value
        if (label_x_offset === null) { label_x_offset = 0; }
        if (label_y_offset === null) { label_y_offset = 0; }

        var height, width;
        var size = document.getElementsByName('size')[0].value;
254
255
        if (size === '') {
            var size = document.getElementsByName('selection-size')[0].value;
256
257
        }

258
259
260
261
262
263
264
        if (size !== '') {
            width = size;
            height = size;
        } else {
            width = document.getElementsByName('width')[0].value;
            height = document.getElementsByName('height')[0].value;
        }
265

266
267
        var slot3 = document.getElementsByName('minimum-range')[0].value;
        var slot4 = document.getElementsByName('maximum-range')[0].value;
268
269
270
271

        if (slot3 === '') {
            slot3 = document.getElementsByName('flash-interrupt')[0].value;
            slot4 = document.getElementsByName('flash-hold')[0].value;
272
273
274
275
276
        }

        if (slot3 === '') {
            slot3 = document.getElementsByName('visible-width')[0].value;
            slot4 = document.getElementsByName('visible-height')[0].value;
277
278
279
280
        }

        if (slot3 === '') { // toggle
            slot3 = document.getElementsByName('nonzero-value')[0].value;
281
282
283
            if (slot3 === '') {
                slot3 = 0;
            }
284
285
286
            slot4 = 0;
        }

287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
        var slot5 = +document.getElementsByName('log-scaling')[0].checked;
        // Hack to accomodate the vu-scale property, which exists in the same
        // slot as this one
        var log_scaling_spanner = document.getElementsByClassName('log-scaling')[0];
        var log_display = log_scaling_spanner.style.getPropertyValue('display');

        if (log_display === null) {
            slot5 = +document.getElementsByName('vu-scale')[0].checked;
            pdgui.gui_post('slot five is ' + slot5);
        }
        pdgui.gui_post('slot five is ' + slot5);

        var init = +document.getElementsByName('init')[0].checked;
        if (init === '') { init = 0; }

        var slot7 = document.getElementsByName('log-height')[0].value;
        if (slot7 === '') {
            slot7 = document.getElementsByName('number')[0].value;
        }
        if (slot7 === '') {
            slot7 = 0;
        }
309
310
311
312
313

        var font_style = document.getElementsByName('font-style')[0].value;
        if (font_style !== null) { font_style = 0; }

        var font_size = document.getElementsByName('font-size')[0].value;
314
        if (font_size === '') { font_size = 0; }
315
316
317
318
319

        var foreground_color = parseInt(document.getElementsByName('foreground-color')[0].value.slice(1), 16);
        var background_color = parseInt(document.getElementsByName('background-color')[0].value.slice(1), 16);
        var label_color = parseInt(document.getElementsByName('label-color')[0].value.slice(1), 16);

320
321
        var slot18 = +document.getElementsByName('steady-on-click')[0].checked;

322
323
        pdgui.pdsend([pd_object_callback, 'dialog',
            width, height,
324
325
326
327
328
329
330
331
332
333
            slot3, // bng: flash-interrupt
                   // slider: min-range
                   // toggle: nonzero-value
                   // my_canvas: visible_width
            slot4, // bng: flash-hold
                   // slider: max-range
                   // my_canvas: visible_height
            slot5, // slider: lin/log thingy
                   // nbx: lin/log
                   // vu: vu-scale
334
            init,
335
            slot7, // log-height or vradio/hradio number
336
337
338
339
340
            send_symbol, receive_symbol, label,
            label_x_offset, label_y_offset,
            font_style, font_size,
            background_color, foreground_color,
            label_color,
341
            slot18, // steady on click
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
            0].join(' '));
/*
	pd [concat $id dialog \
		$::dialog($vid:wdt) $::dialog($vid:hgt) \
		$::dialog($vid:min_rng) $::dialog($vid:max_rng) \
		$::dialog($vid:lin0_log1) $::dialog($vid:loadbang) \
		$::dialog($vid:num) \
		$hhhsnd $hhhrcv $hhhgui_nam \
		$::dialog($vid:gn_dx) $::dialog($vid:gn_dy) \
		$::dialog($vid:gn_f) $::dialog($vid:gn_fs) \
		$::dialog($vid:bcol) $::dialog($vid:fcol) \
		$::dialog($vid:lcol) \
		$::dialog($vid:steady) $::dialog($vid:hide) \;]
*/

    }

    function cancel() {
        pdgui.gui_post("closing the window at this point");
//        window.close(true);
        pdgui.pdsend(pd_object_callback + " cancel");
    }

    // This gets called from the nw_create_window function in index.html
    // It provides us with our window id from the C side.  Once we have it
    // we can create the menu and register event callbacks
    function register_canvas_id(gfxstub, attr_array) {
        pd_object_callback = gfxstub;

        console.log('attr array is ' + attr_array.toString());
        for (var i = 0; i < attr_array.length; i+=2) {
            console.log(attr_array[i] + ": " + attr_array[i+1]);
        }
        add_events(gfxstub);
        // not sure that we need this for properties windows
//        pdgui.canvas_map(gfxstub);
        populate_form(attr_array);
//        document.getElementsByClass("fumbles")[0].setAttribute('style', 'display: inline;');
    }

function populate_form(attr_array) {
    for(var i = 0; i < attr_array.length; i+=2) {
        // Unhide the span with the class with the same name as the id
        var prop_group = document.getElementsByClassName(attr_array[i])[0];
        if (prop_group !== undefined) {
            console.log("the thing here is " + attr_array[i]);
            prop_group.style.setProperty('display', 'inline');
        } else {
            pdgui.gui_post("Error: couldn't find iemgui prop group for " + attr_array[i]);
        }
        // iemguis use the string 'empty' for null because of
        // the limitations of Pd's state-saving API.  So we have
        // to filter that one out
        if(attr_array[i+1] !== 'empty') {
            var elem = document.getElementsByName(attr_array[i]);
            if (elem.length > 0) {
                if(attr_array[i].slice(-5) === 'color') {
                    var hex_string = Number(attr_array[i+1]).toString(16);
                    var color_string = "#" + (hex_string === '0' ? '000000' : hex_string);
                    pdgui.gui_post("color is " + color_string);
                    elem[0].value = color_string;
403
404
405
406
                } else if (elem[0].type === 'checkbox') {
                    // The attr here is a string, so we need to
                    // force it to number, hence the "+" below
                    elem[0].checked = +attr_array[i+1];
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
                } else {
                    elem[0].value = attr_array[i+1];
                }
            }
        }
    }
}

function add_events(name) {
    // let's handle some events for this window...

    // closing the Window
    nw.Window.get().on("close", function() {
        // this needs to do whatever the "cancel" button does
//        pdgui.pdsend(name + " menuclose 0");
//        cancel();
        pdgui.remove_dialogwin(pd_object_callback);
        this.close(true);
    });

}

  </script>
  </body>
</html>