Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin...
[kugel-rb.git] / apps / plugins / pdbox / PDa / src / g_numbox.c
blobe7421204d337850f07f26fda4fa361f2e10e5d84
1 /* Copyright (c) 1997-1999 Miller Puckette.
2 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
3 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
5 /* my_numbox.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <stdio.h>
10 #include <ctype.h>
11 #include "m_pd.h"
12 #include "g_canvas.h"
13 #include "t_tk.h"
14 #include "g_all_guis.h"
15 #include <math.h>
17 #ifdef MSW
18 #include <io.h>
19 #else
20 #include <unistd.h>
21 #endif
23 /*------------------ global varaibles -------------------------*/
26 /*------------------ global functions -------------------------*/
28 static void my_numbox_key(void *z, t_floatarg fkey);
30 /* ------------ nmx gui-my number box ----------------------- */
32 t_widgetbehavior my_numbox_widgetbehavior;
33 static t_class *my_numbox_class;
35 /* widget helper functions */
37 static void my_numbox_tick_reset(t_my_numbox *x)
39 if(x->x_gui.x_fsf.x_change)
41 x->x_gui.x_fsf.x_change = 0;
42 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
43 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
47 static void my_numbox_tick_wait(t_my_numbox *x)
49 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
52 void my_numbox_clip(t_my_numbox *x)
54 if(x->x_val < x->x_min)
55 x->x_val = x->x_min;
56 if(x->x_val > x->x_max)
57 x->x_val = x->x_max;
60 void my_numbox_calc_fontwidth(t_my_numbox *x)
62 int w, f=31;
64 if(x->x_gui.x_fsf.x_font_style == 1)
65 f = 27;
66 else if(x->x_gui.x_fsf.x_font_style == 2)
67 f = 25;
69 w = x->x_gui.x_fontsize * f * x->x_gui.x_w;
70 w /= 36;
71 x->x_numwidth = w + (x->x_gui.x_h / 2) + 4;
74 void my_numbox_ftoa(t_my_numbox *x)
76 double f=x->x_val;
77 int bufsize, is_exp=0, i, idecimal;
79 sprintf(x->x_buf, "%g", f);
80 bufsize = strlen(x->x_buf);
81 if(bufsize >= 5)/* if it is in exponential mode */
83 i = bufsize - 4;
84 if((x->x_buf[i] == 'e') || (x->x_buf[i] == 'E'))
85 is_exp = 1;
87 if(bufsize > x->x_gui.x_w)/* if to reduce */
89 if(is_exp)
91 if(x->x_gui.x_w <= 5)
93 x->x_buf[0] = (f < 0.0 ? '-' : '+');
94 x->x_buf[1] = 0;
96 i = bufsize - 4;
97 for(idecimal=0; idecimal < i; idecimal++)
98 if(x->x_buf[idecimal] == '.')
99 break;
100 if(idecimal > (x->x_gui.x_w - 4))
102 x->x_buf[0] = (f < 0.0 ? '-' : '+');
103 x->x_buf[1] = 0;
105 else
107 int new_exp_index=x->x_gui.x_w-4, old_exp_index=bufsize-4;
109 for(i=0; i < 4; i++, new_exp_index++, old_exp_index++)
110 x->x_buf[new_exp_index] = x->x_buf[old_exp_index];
111 x->x_buf[x->x_gui.x_w] = 0;
115 else
117 for(idecimal=0; idecimal < bufsize; idecimal++)
118 if(x->x_buf[idecimal] == '.')
119 break;
120 if(idecimal > x->x_gui.x_w)
122 x->x_buf[0] = (f < 0.0 ? '-' : '+');
123 x->x_buf[1] = 0;
125 else
126 x->x_buf[x->x_gui.x_w] = 0;
131 static void my_numbox_draw_update(t_my_numbox *x, t_glist *glist)
133 if (glist_isvisible(glist))
135 if(x->x_gui.x_fsf.x_change)
137 if(x->x_buf[0])
139 char *cp=x->x_buf;
140 int sl = strlen(x->x_buf);
142 x->x_buf[sl] = '>';
143 x->x_buf[sl+1] = 0;
144 if(sl >= x->x_gui.x_w)
145 cp += sl - x->x_gui.x_w + 1;
146 sys_vgui(
147 ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
148 glist_getcanvas(glist), x, IEM_GUI_COLOR_EDITED, cp);
149 x->x_buf[sl] = 0;
151 else
153 my_numbox_ftoa(x);
154 sys_vgui(
155 ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
156 glist_getcanvas(glist), x, IEM_GUI_COLOR_EDITED, x->x_buf);
157 x->x_buf[0] = 0;
160 else
162 my_numbox_ftoa(x);
163 sys_vgui(
164 ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
165 glist_getcanvas(glist), x,
166 x->x_gui.x_fsf.x_selected?
167 IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol,
168 x->x_buf);
169 x->x_buf[0] = 0;
174 static void my_numbox_draw_new(t_my_numbox *x, t_glist *glist)
176 int half=x->x_gui.x_h/2, d=1+x->x_gui.x_h/34;
177 int xpos=text_xpix(&x->x_gui.x_obj, glist);
178 int ypos=text_ypix(&x->x_gui.x_obj, glist);
179 t_canvas *canvas=glist_getcanvas(glist);
181 sys_vgui(
182 ".x%x.c create polygon %d %d %d %d %d %d %d %d %d %d -outline #%6.6x \
183 -fill #%6.6x -tags %xBASE1\n",
184 canvas, xpos, ypos,
185 xpos + x->x_numwidth-4, ypos,
186 xpos + x->x_numwidth, ypos+4,
187 xpos + x->x_numwidth, ypos + x->x_gui.x_h,
188 xpos, ypos + x->x_gui.x_h,
189 IEM_GUI_COLOR_NORMAL, x->x_gui.x_bcol, x);
190 sys_vgui(
191 ".x%x.c create line %d %d %d %d %d %d -fill #%6.6x -tags %xBASE2\n",
192 canvas, xpos, ypos,
193 xpos + half, ypos + half,
194 xpos, ypos + x->x_gui.x_h,
195 x->x_gui.x_fcol, x);
196 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
197 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
198 canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
199 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
200 x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
201 my_numbox_ftoa(x);
202 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
203 -font {%s %d bold} -fill #%6.6x -tags %xNUMBER\n",
204 canvas, xpos+half+2, ypos+half+d,
205 x->x_buf, x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_fcol, x);
206 if(!x->x_gui.x_fsf.x_snd_able)
207 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
208 canvas,
209 xpos, ypos + x->x_gui.x_h-1,
210 xpos+IOWIDTH, ypos + x->x_gui.x_h,
211 x, 0);
212 if(!x->x_gui.x_fsf.x_rcv_able)
213 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
214 canvas,
215 xpos, ypos,
216 xpos+IOWIDTH, ypos+1,
217 x, 0);
220 static void my_numbox_draw_move(t_my_numbox *x, t_glist *glist)
222 int half = x->x_gui.x_h/2, d=1+x->x_gui.x_h/34;
223 int xpos=text_xpix(&x->x_gui.x_obj, glist);
224 int ypos=text_ypix(&x->x_gui.x_obj, glist);
225 t_canvas *canvas=glist_getcanvas(glist);
227 sys_vgui(".x%x.c coords %xBASE1 %d %d %d %d %d %d %d %d %d %d\n",
228 canvas, x, xpos, ypos,
229 xpos + x->x_numwidth-4, ypos,
230 xpos + x->x_numwidth, ypos+4,
231 xpos + x->x_numwidth, ypos + x->x_gui.x_h,
232 xpos, ypos + x->x_gui.x_h);
233 sys_vgui(".x%x.c coords %xBASE2 %d %d %d %d %d %d\n",
234 canvas, x, xpos, ypos,
235 xpos + half, ypos + half,
236 xpos, ypos + x->x_gui.x_h);
237 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
238 canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
239 sys_vgui(".x%x.c coords %xNUMBER %d %d\n",
240 canvas, x, xpos+half+2, ypos+half+d);
241 if(!x->x_gui.x_fsf.x_snd_able)
242 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
243 canvas, x, 0,
244 xpos, ypos + x->x_gui.x_h-1,
245 xpos+IOWIDTH, ypos + x->x_gui.x_h);
246 if(!x->x_gui.x_fsf.x_rcv_able)
247 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
248 canvas, x, 0,
249 xpos, ypos,
250 xpos+IOWIDTH, ypos+1);
253 static void my_numbox_draw_erase(t_my_numbox* x,t_glist* glist)
255 t_canvas *canvas=glist_getcanvas(glist);
257 sys_vgui(".x%x.c delete %xBASE1\n", canvas, x);
258 sys_vgui(".x%x.c delete %xBASE2\n", canvas, x);
259 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
260 sys_vgui(".x%x.c delete %xNUMBER\n", canvas, x);
261 if(!x->x_gui.x_fsf.x_snd_able)
262 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
263 if(!x->x_gui.x_fsf.x_rcv_able)
264 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
267 static void my_numbox_draw_config(t_my_numbox* x,t_glist* glist)
269 t_canvas *canvas=glist_getcanvas(glist);
271 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
272 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
273 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
274 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
275 sys_vgui(".x%x.c itemconfigure %xNUMBER -font {%s %d bold} -fill #%6.6x \n",
276 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
277 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
278 sys_vgui(".x%x.c itemconfigure %xBASE1 -fill #%6.6x\n", canvas,
279 x, x->x_gui.x_bcol);
280 sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n", canvas,
281 x, x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
284 static void my_numbox_draw_io(t_my_numbox* x,t_glist* glist, int old_snd_rcv_flags)
286 int xpos=text_xpix(&x->x_gui.x_obj, glist);
287 int ypos=text_ypix(&x->x_gui.x_obj, glist);
288 t_canvas *canvas=glist_getcanvas(glist);
290 if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
291 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
292 canvas,
293 xpos, ypos + x->x_gui.x_h-1,
294 xpos+IOWIDTH, ypos + x->x_gui.x_h,
295 x, 0);
296 if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
297 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
298 if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
299 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
300 canvas,
301 xpos, ypos,
302 xpos+IOWIDTH, ypos+1,
303 x, 0);
304 if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
305 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
308 static void my_numbox_draw_select(t_my_numbox *x, t_glist *glist)
310 t_canvas *canvas=glist_getcanvas(glist);
312 if(x->x_gui.x_fsf.x_selected)
314 if(x->x_gui.x_fsf.x_change)
316 x->x_gui.x_fsf.x_change = 0;
317 clock_unset(x->x_clock_reset);
318 x->x_buf[0] = 0;
319 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
321 sys_vgui(".x%x.c itemconfigure %xBASE1 -outline #%6.6x\n",
322 canvas, x, IEM_GUI_COLOR_SELECTED);
323 sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n",
324 canvas, x, IEM_GUI_COLOR_SELECTED);
325 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n",
326 canvas, x, IEM_GUI_COLOR_SELECTED);
327 sys_vgui(".x%x.c itemconfigure %xNUMBER -fill #%6.6x\n",
328 canvas, x, IEM_GUI_COLOR_SELECTED);
330 else
332 sys_vgui(".x%x.c itemconfigure %xBASE1 -outline #%6.6x\n",
333 canvas, x, IEM_GUI_COLOR_NORMAL);
334 sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n",
335 canvas, x, x->x_gui.x_fcol);
336 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n",
337 canvas, x, x->x_gui.x_lcol);
338 sys_vgui(".x%x.c itemconfigure %xNUMBER -fill #%6.6x\n",
339 canvas, x, x->x_gui.x_fcol);
343 void my_numbox_draw(t_my_numbox *x, t_glist *glist, int mode)
345 if(mode == IEM_GUI_DRAW_MODE_UPDATE)
346 my_numbox_draw_update(x, glist);
347 else if(mode == IEM_GUI_DRAW_MODE_MOVE)
348 my_numbox_draw_move(x, glist);
349 else if(mode == IEM_GUI_DRAW_MODE_NEW)
350 my_numbox_draw_new(x, glist);
351 else if(mode == IEM_GUI_DRAW_MODE_SELECT)
352 my_numbox_draw_select(x, glist);
353 else if(mode == IEM_GUI_DRAW_MODE_ERASE)
354 my_numbox_draw_erase(x, glist);
355 else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
356 my_numbox_draw_config(x, glist);
357 else if(mode >= IEM_GUI_DRAW_MODE_IO)
358 my_numbox_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
361 /* ------------------------ nbx widgetbehaviour----------------------------- */
364 static void my_numbox_getrect(t_gobj *z, t_glist *glist,
365 int *xp1, int *yp1, int *xp2, int *yp2)
367 t_my_numbox* x = (t_my_numbox*)z;
369 *xp1 = text_xpix(&x->x_gui.x_obj, glist);
370 *yp1 = text_ypix(&x->x_gui.x_obj, glist);
371 *xp2 = *xp1 + x->x_numwidth;
372 *yp2 = *yp1 + x->x_gui.x_h;
375 static void my_numbox_save(t_gobj *z, t_binbuf *b)
377 t_my_numbox *x = (t_my_numbox *)z;
378 int bflcol[3];
379 t_symbol *srl[3];
381 iemgui_save(&x->x_gui, srl, bflcol);
382 if(x->x_gui.x_fsf.x_change)
384 x->x_gui.x_fsf.x_change = 0;
385 clock_unset(x->x_clock_reset);
386 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
387 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
390 binbuf_addv(b, "ssiisiiffiisssiiiiiiifi", gensym("#X"),gensym("obj"),
391 (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
392 gensym("nbx"), x->x_gui.x_w, x->x_gui.x_h,
393 (float)x->x_min, (float)x->x_max,
394 x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa),
395 srl[0], srl[1], srl[2],
396 x->x_gui.x_ldx, x->x_gui.x_ldy,
397 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
398 bflcol[0], bflcol[1], bflcol[2],
399 x->x_val, x->x_log_height);
400 binbuf_addv(b, ";");
403 int my_numbox_check_minmax(t_my_numbox *x, double min, double max)
405 int ret=0;
407 if(x->x_lin0_log1)
409 if((min == 0.0)&&(max == 0.0))
410 max = 1.0;
411 if(max > 0.0)
413 if(min <= 0.0)
414 min = 0.01*max;
416 else
418 if(min > 0.0)
419 max = 0.01*min;
422 x->x_min = min;
423 x->x_max = max;
424 if(x->x_val < x->x_min)
426 x->x_val = x->x_min;
427 ret = 1;
429 if(x->x_val > x->x_max)
431 x->x_val = x->x_max;
432 ret = 1;
434 if(x->x_lin0_log1)
435 x->x_k = exp(log(x->x_max/x->x_min)/(double)(x->x_log_height));
436 else
437 x->x_k = 1.0;
438 return(ret);
441 static void my_numbox_properties(t_gobj *z, t_glist *owner)
443 t_my_numbox *x = (t_my_numbox *)z;
444 char buf[800];
445 t_symbol *srl[3];
447 iemgui_properties(&x->x_gui, srl);
448 if(x->x_gui.x_fsf.x_change)
450 x->x_gui.x_fsf.x_change = 0;
451 clock_unset(x->x_clock_reset);
452 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
453 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
456 sprintf(buf, "pdtk_iemgui_dialog %%s NUMBERBOX \
457 -------dimensions(digits)(pix):------- %d %d width: %d %d height: \
458 -----------output-range:----------- %g min: %g max: %d \
459 %d lin log %d %d log-height: %d \
460 %s %s \
461 %s %d %d \
462 %d %d \
463 %d %d %d\n",
464 x->x_gui.x_w, 1, x->x_gui.x_h, 8,
465 x->x_min, x->x_max, 0,/*no_schedule*/
466 x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, -1,
467 x->x_log_height, /*no multi, but iem-characteristic*/
468 srl[0]->s_name, srl[1]->s_name,
469 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
470 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
471 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol,
472 0xffffff & x->x_gui.x_lcol);
473 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
476 static void my_numbox_bang(t_my_numbox *x)
478 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_val);
479 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
480 pd_float(x->x_gui.x_snd->s_thing, x->x_val);
483 static void my_numbox_dialog(t_my_numbox *x, t_symbol *s, int argc,
484 t_atom *argv)
486 t_symbol *srl[3];
487 int w = (int)atom_getintarg(0, argc, argv);
488 int h = (int)atom_getintarg(1, argc, argv);
489 double min = (double)atom_getfloatarg(2, argc, argv);
490 double max = (double)atom_getfloatarg(3, argc, argv);
491 int lilo = (int)atom_getintarg(4, argc, argv);
492 int log_height = (int)atom_getintarg(6, argc, argv);
493 int sr_flags;
495 if(lilo != 0) lilo = 1;
496 x->x_lin0_log1 = lilo;
497 sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
498 if(w < 1)
499 w = 1;
500 x->x_gui.x_w = w;
501 if(h < 8)
502 h = 8;
503 x->x_gui.x_h = h;
504 if(log_height < 10)
505 log_height = 10;
506 x->x_log_height = log_height;
507 my_numbox_calc_fontwidth(x);
508 /*if(my_numbox_check_minmax(x, min, max))
509 my_numbox_bang(x);*/
510 my_numbox_check_minmax(x, min, max);
511 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
512 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
513 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
514 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
515 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
518 static void my_numbox_motion(t_my_numbox *x, t_floatarg dx, t_floatarg dy)
520 double k2=1.0;
522 if(x->x_gui.x_fsf.x_finemoved)
523 k2 = 0.01;
524 if(x->x_lin0_log1)
525 x->x_val *= pow(x->x_k, -k2*dy);
526 else
527 x->x_val -= k2*dy;
528 my_numbox_clip(x);
529 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
530 my_numbox_bang(x);
531 clock_unset(x->x_clock_reset);
534 static void my_numbox_click(t_my_numbox *x, t_floatarg xpos, t_floatarg ypos,
535 t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
537 glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g,
538 (t_glistmotionfn)my_numbox_motion, my_numbox_key, xpos, ypos);
541 static int my_numbox_newclick(t_gobj *z, struct _glist *glist,
542 int xpix, int ypix, int shift, int alt, int dbl, int doit)
544 t_my_numbox* x = (t_my_numbox *)z;
546 if(doit)
548 my_numbox_click( x, (t_floatarg)xpix, (t_floatarg)ypix,
549 (t_floatarg)shift, 0, (t_floatarg)alt);
550 if(shift)
551 x->x_gui.x_fsf.x_finemoved = 1;
552 else
553 x->x_gui.x_fsf.x_finemoved = 0;
554 if(!x->x_gui.x_fsf.x_change)
556 clock_delay(x->x_clock_wait, 50);
557 x->x_gui.x_fsf.x_change = 1;
558 clock_delay(x->x_clock_reset, 3000);
559 /* glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.ob_g,
560 0, my_numbox_key, 0, 0); */
562 x->x_buf[0] = 0;
564 else
566 x->x_gui.x_fsf.x_change = 0;
567 clock_unset(x->x_clock_reset);
568 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
569 x->x_buf[0] = 0;
570 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
573 return (1);
576 static void my_numbox_set(t_my_numbox *x, t_floatarg f)
578 x->x_val = f;
579 my_numbox_clip(x);
580 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
583 static void my_numbox_log_height(t_my_numbox *x, t_floatarg lh)
585 if(lh < 10.0)
586 lh = 10.0;
587 x->x_log_height = (int)lh;
588 if(x->x_lin0_log1)
589 x->x_k = exp(log(x->x_max/x->x_min)/(double)(x->x_log_height));
590 else
591 x->x_k = 1.0;
595 static void my_numbox_float(t_my_numbox *x, t_floatarg f)
597 my_numbox_set(x, f);
598 if(x->x_gui.x_fsf.x_put_in2out)
599 my_numbox_bang(x);
602 static void my_numbox_size(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
604 int h, w;
606 w = (int)atom_getintarg(0, ac, av);
607 if(w < 1)
608 w = 1;
609 x->x_gui.x_w = w;
610 if(ac > 1)
612 h = (int)atom_getintarg(1, ac, av);
613 if(h < 8)
614 h = 8;
615 x->x_gui.x_h = h;
617 my_numbox_calc_fontwidth(x);
618 iemgui_size((void *)x, &x->x_gui);
621 static void my_numbox_delta(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
622 {iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
624 static void my_numbox_pos(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
625 {iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
627 static void my_numbox_range(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
629 if(my_numbox_check_minmax(x, (double)atom_getfloatarg(0, ac, av),
630 (double)atom_getfloatarg(1, ac, av)))
632 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
633 /*my_numbox_bang(x);*/
637 static void my_numbox_color(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
638 {iemgui_color((void *)x, &x->x_gui, s, ac, av);}
640 static void my_numbox_send(t_my_numbox *x, t_symbol *s)
641 {iemgui_send(x, &x->x_gui, s);}
643 static void my_numbox_receive(t_my_numbox *x, t_symbol *s)
644 {iemgui_receive(x, &x->x_gui, s);}
646 static void my_numbox_label(t_my_numbox *x, t_symbol *s)
647 {iemgui_label((void *)x, &x->x_gui, s);}
649 static void my_numbox_label_pos(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
650 {iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
652 static void my_numbox_label_font(t_my_numbox *x,
653 t_symbol *s, int ac, t_atom *av)
655 int f = (int)atom_getintarg(1, ac, av);
657 if(f < 4)
658 f = 4;
659 x->x_gui.x_fontsize = f;
660 f = (int)atom_getintarg(0, ac, av);
661 if((f < 0) || (f > 2))
662 f = 0;
663 x->x_gui.x_fsf.x_font_style = f;
664 my_numbox_calc_fontwidth(x);
665 iemgui_label_font((void *)x, &x->x_gui, s, ac, av);
668 static void my_numbox_log(t_my_numbox *x)
670 x->x_lin0_log1 = 1;
671 if(my_numbox_check_minmax(x, x->x_min, x->x_max))
673 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
674 /*my_numbox_bang(x);*/
678 static void my_numbox_lin(t_my_numbox *x)
680 x->x_lin0_log1 = 0;
683 static void my_numbox_init(t_my_numbox *x, t_floatarg f)
685 x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1;
688 static void my_numbox_loadbang(t_my_numbox *x)
690 if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
692 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
693 my_numbox_bang(x);
697 static void my_numbox_key(void *z, t_floatarg fkey)
699 t_my_numbox *x = z;
700 char c=fkey;
701 char buf[3];
702 buf[1] = 0;
704 if (c == 0)
706 x->x_gui.x_fsf.x_change = 0;
707 clock_unset(x->x_clock_reset);
708 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
709 return;
711 if(((c>='0')&&(c<='9'))||(c=='.')||(c=='-')||
712 (c=='e')||(c=='+')||(c=='E'))
714 if(strlen(x->x_buf) < (IEMGUI_MAX_NUM_LEN-2))
716 buf[0] = c;
717 strcat(x->x_buf, buf);
718 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
721 else if((c=='\b')||(c==127))
723 int sl=strlen(x->x_buf)-1;
725 if(sl < 0)
726 sl = 0;
727 x->x_buf[sl] = 0;
728 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
730 else if((c=='\n')||(c==13))
732 x->x_val = atof(x->x_buf);
733 x->x_buf[0] = 0;
734 x->x_gui.x_fsf.x_change = 0;
735 clock_unset(x->x_clock_reset);
736 my_numbox_clip(x);
737 my_numbox_bang(x);
738 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
740 clock_delay(x->x_clock_reset, 3000);
743 static void my_numbox_list(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
745 if (IS_A_FLOAT(av,0))
747 my_numbox_set(x, atom_getfloatarg(0, ac, av));
748 my_numbox_bang(x);
752 static void *my_numbox_new(t_symbol *s, int argc, t_atom *argv)
754 t_my_numbox *x = (t_my_numbox *)pd_new(my_numbox_class);
755 int bflcol[]={-262144, -1, -1};
756 int w=5, h=14;
757 int lilo=0, f=0, ldx=0, ldy=-6;
758 int fs=10;
759 int log_height=256;
760 double min=-1.0e+37, max=1.0e+37,v=0.0;
761 char str[144];
763 if((argc >= 17)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
764 &&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3)
765 &&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5)
766 &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6))
767 &&(IS_A_SYMBOL(argv,7)||IS_A_FLOAT(argv,7))
768 &&(IS_A_SYMBOL(argv,8)||IS_A_FLOAT(argv,8))
769 &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)
770 &&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)
771 &&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15)&&IS_A_FLOAT(argv,16))
773 w = (int)atom_getintarg(0, argc, argv);
774 h = (int)atom_getintarg(1, argc, argv);
775 min = (double)atom_getfloatarg(2, argc, argv);
776 max = (double)atom_getfloatarg(3, argc, argv);
777 lilo = (int)atom_getintarg(4, argc, argv);
778 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
779 iemgui_new_getnames(&x->x_gui, 6, argv);
780 ldx = (int)atom_getintarg(9, argc, argv);
781 ldy = (int)atom_getintarg(10, argc, argv);
782 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
783 fs = (int)atom_getintarg(12, argc, argv);
784 bflcol[0] = (int)atom_getintarg(13, argc, argv);
785 bflcol[1] = (int)atom_getintarg(14, argc, argv);
786 bflcol[2] = (int)atom_getintarg(15, argc, argv);
787 v = atom_getfloatarg(16, argc, argv);
789 else iemgui_new_getnames(&x->x_gui, 6, 0);
790 if((argc == 18)&&IS_A_FLOAT(argv,17))
792 log_height = (int)atom_getintarg(17, argc, argv);
794 x->x_gui.x_draw = (t_iemfunptr)my_numbox_draw;
795 x->x_gui.x_fsf.x_snd_able = 1;
796 x->x_gui.x_fsf.x_rcv_able = 1;
797 x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
798 if(x->x_gui.x_isa.x_loadinit)
799 x->x_val = v;
800 else
801 x->x_val = 0.0;
802 if(lilo != 0) lilo = 1;
803 x->x_lin0_log1 = lilo;
804 if(log_height < 10)
805 log_height = 10;
806 x->x_log_height = log_height;
807 if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
808 x->x_gui.x_fsf.x_snd_able = 0;
809 if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
810 x->x_gui.x_fsf.x_rcv_able = 0;
811 if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
812 else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
813 else { x->x_gui.x_fsf.x_font_style = 0;
814 strcpy(x->x_gui.x_font, "courier"); }
815 if (x->x_gui.x_fsf.x_rcv_able)
816 pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
817 x->x_gui.x_ldx = ldx;
818 x->x_gui.x_ldy = ldy;
819 if(fs < 4)
820 fs = 4;
821 x->x_gui.x_fontsize = fs;
822 if(w < 1)
823 w = 1;
824 x->x_gui.x_w = w;
825 if(h < 8)
826 h = 8;
827 x->x_gui.x_h = h;
828 x->x_buf[0] = 0;
829 my_numbox_calc_fontwidth(x);
830 my_numbox_check_minmax(x, min, max);
831 iemgui_all_colfromload(&x->x_gui, bflcol);
832 iemgui_verify_snd_ne_rcv(&x->x_gui);
833 x->x_clock_reset = clock_new(x, (t_method)my_numbox_tick_reset);
834 x->x_clock_wait = clock_new(x, (t_method)my_numbox_tick_wait);
835 x->x_gui.x_fsf.x_change = 0;
836 outlet_new(&x->x_gui.x_obj, &s_float);
837 return (x);
840 static void my_numbox_free(t_my_numbox *x)
842 if(x->x_gui.x_fsf.x_rcv_able)
843 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
844 clock_free(x->x_clock_reset);
845 clock_free(x->x_clock_wait);
846 gfxstub_deleteforkey(x);
849 void g_numbox_setup(void)
851 my_numbox_class = class_new(gensym("nbx"), (t_newmethod)my_numbox_new,
852 (t_method)my_numbox_free, sizeof(t_my_numbox), 0, A_GIMME, 0);
853 class_addcreator((t_newmethod)my_numbox_new, gensym("my_numbox"),
854 A_GIMME, 0);
855 class_addbang(my_numbox_class,my_numbox_bang);
856 class_addfloat(my_numbox_class,my_numbox_float);
857 class_addlist(my_numbox_class, my_numbox_list);
858 class_addmethod(my_numbox_class, (t_method)my_numbox_click,
859 gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
860 class_addmethod(my_numbox_class, (t_method)my_numbox_motion,
861 gensym("motion"), A_FLOAT, A_FLOAT, 0);
862 class_addmethod(my_numbox_class, (t_method)my_numbox_dialog,
863 gensym("dialog"), A_GIMME, 0);
864 class_addmethod(my_numbox_class, (t_method)my_numbox_loadbang,
865 gensym("loadbang"), 0);
866 class_addmethod(my_numbox_class, (t_method)my_numbox_set,
867 gensym("set"), A_FLOAT, 0);
868 class_addmethod(my_numbox_class, (t_method)my_numbox_size,
869 gensym("size"), A_GIMME, 0);
870 class_addmethod(my_numbox_class, (t_method)my_numbox_delta,
871 gensym("delta"), A_GIMME, 0);
872 class_addmethod(my_numbox_class, (t_method)my_numbox_pos,
873 gensym("pos"), A_GIMME, 0);
874 class_addmethod(my_numbox_class, (t_method)my_numbox_range,
875 gensym("range"), A_GIMME, 0);
876 class_addmethod(my_numbox_class, (t_method)my_numbox_color,
877 gensym("color"), A_GIMME, 0);
878 class_addmethod(my_numbox_class, (t_method)my_numbox_send,
879 gensym("send"), A_DEFSYM, 0);
880 class_addmethod(my_numbox_class, (t_method)my_numbox_receive,
881 gensym("receive"), A_DEFSYM, 0);
882 class_addmethod(my_numbox_class, (t_method)my_numbox_label,
883 gensym("label"), A_DEFSYM, 0);
884 class_addmethod(my_numbox_class, (t_method)my_numbox_label_pos,
885 gensym("label_pos"), A_GIMME, 0);
886 class_addmethod(my_numbox_class, (t_method)my_numbox_label_font,
887 gensym("label_font"), A_GIMME, 0);
888 class_addmethod(my_numbox_class, (t_method)my_numbox_log,
889 gensym("log"), 0);
890 class_addmethod(my_numbox_class, (t_method)my_numbox_lin,
891 gensym("lin"), 0);
892 class_addmethod(my_numbox_class, (t_method)my_numbox_init,
893 gensym("init"), A_FLOAT, 0);
894 class_addmethod(my_numbox_class, (t_method)my_numbox_log_height,
895 gensym("log_height"), A_FLOAT, 0);
896 my_numbox_widgetbehavior.w_getrectfn = my_numbox_getrect;
897 my_numbox_widgetbehavior.w_displacefn = iemgui_displace;
898 my_numbox_widgetbehavior.w_selectfn = iemgui_select;
899 my_numbox_widgetbehavior.w_activatefn = NULL;
900 my_numbox_widgetbehavior.w_deletefn = iemgui_delete;
901 my_numbox_widgetbehavior.w_visfn = iemgui_vis;
902 my_numbox_widgetbehavior.w_clickfn = my_numbox_newclick;
903 class_setwidget(my_numbox_class, &my_numbox_widgetbehavior);
904 class_sethelpsymbol(my_numbox_class, gensym("numbox2"));
905 class_setsavefn(my_numbox_class, my_numbox_save);
906 class_setpropertiesfn(my_numbox_class, my_numbox_properties);
908 /* Copyright (c) 1997-1999 Miller Puckette.
909 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
910 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
912 /* my_numbox.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
914 #include <stdlib.h>
915 #include <string.h>
916 #include <stdio.h>
917 #include <ctype.h>
918 #include "m_pd.h"
919 #include "g_canvas.h"
920 #include "t_tk.h"
921 #include "g_all_guis.h"
922 #include <math.h>
924 #ifdef MSW
925 #include <io.h>
926 #else
927 #include <unistd.h>
928 #endif
930 /*------------------ global varaibles -------------------------*/
933 /*------------------ global functions -------------------------*/
935 static void my_numbox_key(void *z, t_floatarg fkey);
937 /* ------------ nmx gui-my number box ----------------------- */
939 t_widgetbehavior my_numbox_widgetbehavior;
940 static t_class *my_numbox_class;
942 /* widget helper functions */
944 static void my_numbox_tick_reset(t_my_numbox *x)
946 if(x->x_gui.x_fsf.x_change)
948 x->x_gui.x_fsf.x_change = 0;
949 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
950 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
954 static void my_numbox_tick_wait(t_my_numbox *x)
956 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
959 void my_numbox_clip(t_my_numbox *x)
961 if(x->x_val < x->x_min)
962 x->x_val = x->x_min;
963 if(x->x_val > x->x_max)
964 x->x_val = x->x_max;
967 void my_numbox_calc_fontwidth(t_my_numbox *x)
969 int w, f=31;
971 if(x->x_gui.x_fsf.x_font_style == 1)
972 f = 27;
973 else if(x->x_gui.x_fsf.x_font_style == 2)
974 f = 25;
976 w = x->x_gui.x_fontsize * f * x->x_gui.x_w;
977 w /= 36;
978 x->x_numwidth = w + (x->x_gui.x_h / 2) + 4;
981 void my_numbox_ftoa(t_my_numbox *x)
983 double f=x->x_val;
984 int bufsize, is_exp=0, i, idecimal;
986 sprintf(x->x_buf, "%g", f);
987 bufsize = strlen(x->x_buf);
988 if(bufsize >= 5)/* if it is in exponential mode */
990 i = bufsize - 4;
991 if((x->x_buf[i] == 'e') || (x->x_buf[i] == 'E'))
992 is_exp = 1;
994 if(bufsize > x->x_gui.x_w)/* if to reduce */
996 if(is_exp)
998 if(x->x_gui.x_w <= 5)
1000 x->x_buf[0] = (f < 0.0 ? '-' : '+');
1001 x->x_buf[1] = 0;
1003 i = bufsize - 4;
1004 for(idecimal=0; idecimal < i; idecimal++)
1005 if(x->x_buf[idecimal] == '.')
1006 break;
1007 if(idecimal > (x->x_gui.x_w - 4))
1009 x->x_buf[0] = (f < 0.0 ? '-' : '+');
1010 x->x_buf[1] = 0;
1012 else
1014 int new_exp_index=x->x_gui.x_w-4, old_exp_index=bufsize-4;
1016 for(i=0; i < 4; i++, new_exp_index++, old_exp_index++)
1017 x->x_buf[new_exp_index] = x->x_buf[old_exp_index];
1018 x->x_buf[x->x_gui.x_w] = 0;
1022 else
1024 for(idecimal=0; idecimal < bufsize; idecimal++)
1025 if(x->x_buf[idecimal] == '.')
1026 break;
1027 if(idecimal > x->x_gui.x_w)
1029 x->x_buf[0] = (f < 0.0 ? '-' : '+');
1030 x->x_buf[1] = 0;
1032 else
1033 x->x_buf[x->x_gui.x_w] = 0;
1038 static void my_numbox_draw_update(t_my_numbox *x, t_glist *glist)
1040 if (glist_isvisible(glist))
1042 if(x->x_gui.x_fsf.x_change)
1044 if(x->x_buf[0])
1046 char *cp=x->x_buf;
1047 int sl = strlen(x->x_buf);
1049 x->x_buf[sl] = '>';
1050 x->x_buf[sl+1] = 0;
1051 if(sl >= x->x_gui.x_w)
1052 cp += sl - x->x_gui.x_w + 1;
1053 sys_vgui(
1054 ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
1055 glist_getcanvas(glist), x, IEM_GUI_COLOR_EDITED, cp);
1056 x->x_buf[sl] = 0;
1058 else
1060 my_numbox_ftoa(x);
1061 sys_vgui(
1062 ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
1063 glist_getcanvas(glist), x, IEM_GUI_COLOR_EDITED, x->x_buf);
1064 x->x_buf[0] = 0;
1067 else
1069 my_numbox_ftoa(x);
1070 sys_vgui(
1071 ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
1072 glist_getcanvas(glist), x,
1073 x->x_gui.x_fsf.x_selected?
1074 IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol,
1075 x->x_buf);
1076 x->x_buf[0] = 0;
1081 static void my_numbox_draw_new(t_my_numbox *x, t_glist *glist)
1083 int half=x->x_gui.x_h/2, d=1+x->x_gui.x_h/34;
1084 int xpos=text_xpix(&x->x_gui.x_obj, glist);
1085 int ypos=text_ypix(&x->x_gui.x_obj, glist);
1086 t_canvas *canvas=glist_getcanvas(glist);
1088 sys_vgui(
1089 ".x%x.c create polygon %d %d %d %d %d %d %d %d %d %d -outline #%6.6x \
1090 -fill #%6.6x -tags %xBASE1\n",
1091 canvas, xpos, ypos,
1092 xpos + x->x_numwidth-4, ypos,
1093 xpos + x->x_numwidth, ypos+4,
1094 xpos + x->x_numwidth, ypos + x->x_gui.x_h,
1095 xpos, ypos + x->x_gui.x_h,
1096 IEM_GUI_COLOR_NORMAL, x->x_gui.x_bcol, x);
1097 sys_vgui(
1098 ".x%x.c create line %d %d %d %d %d %d -fill #%6.6x -tags %xBASE2\n",
1099 canvas, xpos, ypos,
1100 xpos + half, ypos + half,
1101 xpos, ypos + x->x_gui.x_h,
1102 x->x_gui.x_fcol, x);
1103 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
1104 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
1105 canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
1106 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
1107 x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
1108 my_numbox_ftoa(x);
1109 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
1110 -font {%s %d bold} -fill #%6.6x -tags %xNUMBER\n",
1111 canvas, xpos+half+2, ypos+half+d,
1112 x->x_buf, x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_fcol, x);
1113 if(!x->x_gui.x_fsf.x_snd_able)
1114 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
1115 canvas,
1116 xpos, ypos + x->x_gui.x_h-1,
1117 xpos+IOWIDTH, ypos + x->x_gui.x_h,
1118 x, 0);
1119 if(!x->x_gui.x_fsf.x_rcv_able)
1120 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
1121 canvas,
1122 xpos, ypos,
1123 xpos+IOWIDTH, ypos+1,
1124 x, 0);
1127 static void my_numbox_draw_move(t_my_numbox *x, t_glist *glist)
1129 int half = x->x_gui.x_h/2, d=1+x->x_gui.x_h/34;
1130 int xpos=text_xpix(&x->x_gui.x_obj, glist);
1131 int ypos=text_ypix(&x->x_gui.x_obj, glist);
1132 t_canvas *canvas=glist_getcanvas(glist);
1134 sys_vgui(".x%x.c coords %xBASE1 %d %d %d %d %d %d %d %d %d %d\n",
1135 canvas, x, xpos, ypos,
1136 xpos + x->x_numwidth-4, ypos,
1137 xpos + x->x_numwidth, ypos+4,
1138 xpos + x->x_numwidth, ypos + x->x_gui.x_h,
1139 xpos, ypos + x->x_gui.x_h);
1140 sys_vgui(".x%x.c coords %xBASE2 %d %d %d %d %d %d\n",
1141 canvas, x, xpos, ypos,
1142 xpos + half, ypos + half,
1143 xpos, ypos + x->x_gui.x_h);
1144 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
1145 canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
1146 sys_vgui(".x%x.c coords %xNUMBER %d %d\n",
1147 canvas, x, xpos+half+2, ypos+half+d);
1148 if(!x->x_gui.x_fsf.x_snd_able)
1149 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
1150 canvas, x, 0,
1151 xpos, ypos + x->x_gui.x_h-1,
1152 xpos+IOWIDTH, ypos + x->x_gui.x_h);
1153 if(!x->x_gui.x_fsf.x_rcv_able)
1154 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
1155 canvas, x, 0,
1156 xpos, ypos,
1157 xpos+IOWIDTH, ypos+1);
1160 static void my_numbox_draw_erase(t_my_numbox* x,t_glist* glist)
1162 t_canvas *canvas=glist_getcanvas(glist);
1164 sys_vgui(".x%x.c delete %xBASE1\n", canvas, x);
1165 sys_vgui(".x%x.c delete %xBASE2\n", canvas, x);
1166 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
1167 sys_vgui(".x%x.c delete %xNUMBER\n", canvas, x);
1168 if(!x->x_gui.x_fsf.x_snd_able)
1169 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
1170 if(!x->x_gui.x_fsf.x_rcv_able)
1171 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
1174 static void my_numbox_draw_config(t_my_numbox* x,t_glist* glist)
1176 t_canvas *canvas=glist_getcanvas(glist);
1178 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
1179 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
1180 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
1181 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
1182 sys_vgui(".x%x.c itemconfigure %xNUMBER -font {%s %d bold} -fill #%6.6x \n",
1183 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
1184 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
1185 sys_vgui(".x%x.c itemconfigure %xBASE1 -fill #%6.6x\n", canvas,
1186 x, x->x_gui.x_bcol);
1187 sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n", canvas,
1188 x, x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
1191 static void my_numbox_draw_io(t_my_numbox* x,t_glist* glist, int old_snd_rcv_flags)
1193 int xpos=text_xpix(&x->x_gui.x_obj, glist);
1194 int ypos=text_ypix(&x->x_gui.x_obj, glist);
1195 t_canvas *canvas=glist_getcanvas(glist);
1197 if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
1198 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
1199 canvas,
1200 xpos, ypos + x->x_gui.x_h-1,
1201 xpos+IOWIDTH, ypos + x->x_gui.x_h,
1202 x, 0);
1203 if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
1204 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
1205 if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
1206 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
1207 canvas,
1208 xpos, ypos,
1209 xpos+IOWIDTH, ypos+1,
1210 x, 0);
1211 if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
1212 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
1215 static void my_numbox_draw_select(t_my_numbox *x, t_glist *glist)
1217 t_canvas *canvas=glist_getcanvas(glist);
1219 if(x->x_gui.x_fsf.x_selected)
1221 if(x->x_gui.x_fsf.x_change)
1223 x->x_gui.x_fsf.x_change = 0;
1224 clock_unset(x->x_clock_reset);
1225 x->x_buf[0] = 0;
1226 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1228 sys_vgui(".x%x.c itemconfigure %xBASE1 -outline #%6.6x\n",
1229 canvas, x, IEM_GUI_COLOR_SELECTED);
1230 sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n",
1231 canvas, x, IEM_GUI_COLOR_SELECTED);
1232 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n",
1233 canvas, x, IEM_GUI_COLOR_SELECTED);
1234 sys_vgui(".x%x.c itemconfigure %xNUMBER -fill #%6.6x\n",
1235 canvas, x, IEM_GUI_COLOR_SELECTED);
1237 else
1239 sys_vgui(".x%x.c itemconfigure %xBASE1 -outline #%6.6x\n",
1240 canvas, x, IEM_GUI_COLOR_NORMAL);
1241 sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n",
1242 canvas, x, x->x_gui.x_fcol);
1243 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n",
1244 canvas, x, x->x_gui.x_lcol);
1245 sys_vgui(".x%x.c itemconfigure %xNUMBER -fill #%6.6x\n",
1246 canvas, x, x->x_gui.x_fcol);
1250 void my_numbox_draw(t_my_numbox *x, t_glist *glist, int mode)
1252 if(mode == IEM_GUI_DRAW_MODE_UPDATE)
1253 my_numbox_draw_update(x, glist);
1254 else if(mode == IEM_GUI_DRAW_MODE_MOVE)
1255 my_numbox_draw_move(x, glist);
1256 else if(mode == IEM_GUI_DRAW_MODE_NEW)
1257 my_numbox_draw_new(x, glist);
1258 else if(mode == IEM_GUI_DRAW_MODE_SELECT)
1259 my_numbox_draw_select(x, glist);
1260 else if(mode == IEM_GUI_DRAW_MODE_ERASE)
1261 my_numbox_draw_erase(x, glist);
1262 else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
1263 my_numbox_draw_config(x, glist);
1264 else if(mode >= IEM_GUI_DRAW_MODE_IO)
1265 my_numbox_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
1268 /* ------------------------ nbx widgetbehaviour----------------------------- */
1271 static void my_numbox_getrect(t_gobj *z, t_glist *glist,
1272 int *xp1, int *yp1, int *xp2, int *yp2)
1274 t_my_numbox* x = (t_my_numbox*)z;
1276 *xp1 = text_xpix(&x->x_gui.x_obj, glist);
1277 *yp1 = text_ypix(&x->x_gui.x_obj, glist);
1278 *xp2 = *xp1 + x->x_numwidth;
1279 *yp2 = *yp1 + x->x_gui.x_h;
1282 static void my_numbox_save(t_gobj *z, t_binbuf *b)
1284 t_my_numbox *x = (t_my_numbox *)z;
1285 int bflcol[3];
1286 t_symbol *srl[3];
1288 iemgui_save(&x->x_gui, srl, bflcol);
1289 if(x->x_gui.x_fsf.x_change)
1291 x->x_gui.x_fsf.x_change = 0;
1292 clock_unset(x->x_clock_reset);
1293 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
1294 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1297 binbuf_addv(b, "ssiisiiffiisssiiiiiiifi", gensym("#X"),gensym("obj"),
1298 (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
1299 gensym("nbx"), x->x_gui.x_w, x->x_gui.x_h,
1300 (float)x->x_min, (float)x->x_max,
1301 x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa),
1302 srl[0], srl[1], srl[2],
1303 x->x_gui.x_ldx, x->x_gui.x_ldy,
1304 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
1305 bflcol[0], bflcol[1], bflcol[2],
1306 x->x_val, x->x_log_height);
1307 binbuf_addv(b, ";");
1310 int my_numbox_check_minmax(t_my_numbox *x, double min, double max)
1312 int ret=0;
1314 if(x->x_lin0_log1)
1316 if((min == 0.0)&&(max == 0.0))
1317 max = 1.0;
1318 if(max > 0.0)
1320 if(min <= 0.0)
1321 min = 0.01*max;
1323 else
1325 if(min > 0.0)
1326 max = 0.01*min;
1329 x->x_min = min;
1330 x->x_max = max;
1331 if(x->x_val < x->x_min)
1333 x->x_val = x->x_min;
1334 ret = 1;
1336 if(x->x_val > x->x_max)
1338 x->x_val = x->x_max;
1339 ret = 1;
1341 if(x->x_lin0_log1)
1342 x->x_k = exp(log(x->x_max/x->x_min)/(double)(x->x_log_height));
1343 else
1344 x->x_k = 1.0;
1345 return(ret);
1348 static void my_numbox_properties(t_gobj *z, t_glist *owner)
1350 t_my_numbox *x = (t_my_numbox *)z;
1351 char buf[800];
1352 t_symbol *srl[3];
1354 iemgui_properties(&x->x_gui, srl);
1355 if(x->x_gui.x_fsf.x_change)
1357 x->x_gui.x_fsf.x_change = 0;
1358 clock_unset(x->x_clock_reset);
1359 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
1360 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1363 sprintf(buf, "pdtk_iemgui_dialog %%s NUMBERBOX \
1364 -------dimensions(digits)(pix):------- %d %d width: %d %d height: \
1365 -----------output-range:----------- %g min: %g max: %d \
1366 %d lin log %d %d log-height: %d \
1367 %s %s \
1368 %s %d %d \
1369 %d %d \
1370 %d %d %d\n",
1371 x->x_gui.x_w, 1, x->x_gui.x_h, 8,
1372 x->x_min, x->x_max, 0,/*no_schedule*/
1373 x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, -1,
1374 x->x_log_height, /*no multi, but iem-characteristic*/
1375 srl[0]->s_name, srl[1]->s_name,
1376 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
1377 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
1378 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol,
1379 0xffffff & x->x_gui.x_lcol);
1380 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
1383 static void my_numbox_bang(t_my_numbox *x)
1385 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_val);
1386 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
1387 pd_float(x->x_gui.x_snd->s_thing, x->x_val);
1390 static void my_numbox_dialog(t_my_numbox *x, t_symbol *s, int argc,
1391 t_atom *argv)
1393 t_symbol *srl[3];
1394 int w = (int)atom_getintarg(0, argc, argv);
1395 int h = (int)atom_getintarg(1, argc, argv);
1396 double min = (double)atom_getfloatarg(2, argc, argv);
1397 double max = (double)atom_getfloatarg(3, argc, argv);
1398 int lilo = (int)atom_getintarg(4, argc, argv);
1399 int log_height = (int)atom_getintarg(6, argc, argv);
1400 int sr_flags;
1402 if(lilo != 0) lilo = 1;
1403 x->x_lin0_log1 = lilo;
1404 sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
1405 if(w < 1)
1406 w = 1;
1407 x->x_gui.x_w = w;
1408 if(h < 8)
1409 h = 8;
1410 x->x_gui.x_h = h;
1411 if(log_height < 10)
1412 log_height = 10;
1413 x->x_log_height = log_height;
1414 my_numbox_calc_fontwidth(x);
1415 /*if(my_numbox_check_minmax(x, min, max))
1416 my_numbox_bang(x);*/
1417 my_numbox_check_minmax(x, min, max);
1418 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1419 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
1420 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
1421 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
1422 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
1425 static void my_numbox_motion(t_my_numbox *x, t_floatarg dx, t_floatarg dy)
1427 double k2=1.0;
1429 if(x->x_gui.x_fsf.x_finemoved)
1430 k2 = 0.01;
1431 if(x->x_lin0_log1)
1432 x->x_val *= pow(x->x_k, -k2*dy);
1433 else
1434 x->x_val -= k2*dy;
1435 my_numbox_clip(x);
1436 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1437 my_numbox_bang(x);
1438 clock_unset(x->x_clock_reset);
1441 static void my_numbox_click(t_my_numbox *x, t_floatarg xpos, t_floatarg ypos,
1442 t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
1444 glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g,
1445 (t_glistmotionfn)my_numbox_motion, my_numbox_key, xpos, ypos);
1448 static int my_numbox_newclick(t_gobj *z, struct _glist *glist,
1449 int xpix, int ypix, int shift, int alt, int dbl, int doit)
1451 t_my_numbox* x = (t_my_numbox *)z;
1453 if(doit)
1455 my_numbox_click( x, (t_floatarg)xpix, (t_floatarg)ypix,
1456 (t_floatarg)shift, 0, (t_floatarg)alt);
1457 if(shift)
1458 x->x_gui.x_fsf.x_finemoved = 1;
1459 else
1460 x->x_gui.x_fsf.x_finemoved = 0;
1461 if(!x->x_gui.x_fsf.x_change)
1463 clock_delay(x->x_clock_wait, 50);
1464 x->x_gui.x_fsf.x_change = 1;
1465 clock_delay(x->x_clock_reset, 3000);
1466 /* glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.ob_g,
1467 0, my_numbox_key, 0, 0); */
1469 x->x_buf[0] = 0;
1471 else
1473 x->x_gui.x_fsf.x_change = 0;
1474 clock_unset(x->x_clock_reset);
1475 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
1476 x->x_buf[0] = 0;
1477 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1480 return (1);
1483 static void my_numbox_set(t_my_numbox *x, t_floatarg f)
1485 x->x_val = f;
1486 my_numbox_clip(x);
1487 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1490 static void my_numbox_log_height(t_my_numbox *x, t_floatarg lh)
1492 if(lh < 10.0)
1493 lh = 10.0;
1494 x->x_log_height = (int)lh;
1495 if(x->x_lin0_log1)
1496 x->x_k = exp(log(x->x_max/x->x_min)/(double)(x->x_log_height));
1497 else
1498 x->x_k = 1.0;
1502 static void my_numbox_float(t_my_numbox *x, t_floatarg f)
1504 my_numbox_set(x, f);
1505 if(x->x_gui.x_fsf.x_put_in2out)
1506 my_numbox_bang(x);
1509 static void my_numbox_size(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1511 int h, w;
1513 w = (int)atom_getintarg(0, ac, av);
1514 if(w < 1)
1515 w = 1;
1516 x->x_gui.x_w = w;
1517 if(ac > 1)
1519 h = (int)atom_getintarg(1, ac, av);
1520 if(h < 8)
1521 h = 8;
1522 x->x_gui.x_h = h;
1524 my_numbox_calc_fontwidth(x);
1525 iemgui_size((void *)x, &x->x_gui);
1528 static void my_numbox_delta(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1529 {iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
1531 static void my_numbox_pos(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1532 {iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
1534 static void my_numbox_range(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1536 if(my_numbox_check_minmax(x, (double)atom_getfloatarg(0, ac, av),
1537 (double)atom_getfloatarg(1, ac, av)))
1539 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1540 /*my_numbox_bang(x);*/
1544 static void my_numbox_color(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1545 {iemgui_color((void *)x, &x->x_gui, s, ac, av);}
1547 static void my_numbox_send(t_my_numbox *x, t_symbol *s)
1548 {iemgui_send(x, &x->x_gui, s);}
1550 static void my_numbox_receive(t_my_numbox *x, t_symbol *s)
1551 {iemgui_receive(x, &x->x_gui, s);}
1553 static void my_numbox_label(t_my_numbox *x, t_symbol *s)
1554 {iemgui_label((void *)x, &x->x_gui, s);}
1556 static void my_numbox_label_pos(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1557 {iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
1559 static void my_numbox_label_font(t_my_numbox *x,
1560 t_symbol *s, int ac, t_atom *av)
1562 int f = (int)atom_getintarg(1, ac, av);
1564 if(f < 4)
1565 f = 4;
1566 x->x_gui.x_fontsize = f;
1567 f = (int)atom_getintarg(0, ac, av);
1568 if((f < 0) || (f > 2))
1569 f = 0;
1570 x->x_gui.x_fsf.x_font_style = f;
1571 my_numbox_calc_fontwidth(x);
1572 iemgui_label_font((void *)x, &x->x_gui, s, ac, av);
1575 static void my_numbox_log(t_my_numbox *x)
1577 x->x_lin0_log1 = 1;
1578 if(my_numbox_check_minmax(x, x->x_min, x->x_max))
1580 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1581 /*my_numbox_bang(x);*/
1585 static void my_numbox_lin(t_my_numbox *x)
1587 x->x_lin0_log1 = 0;
1590 static void my_numbox_init(t_my_numbox *x, t_floatarg f)
1592 x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1;
1595 static void my_numbox_loadbang(t_my_numbox *x)
1597 if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
1599 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1600 my_numbox_bang(x);
1604 static void my_numbox_key(void *z, t_floatarg fkey)
1606 t_my_numbox *x = z;
1607 char c=fkey;
1608 char buf[3];
1609 buf[1] = 0;
1611 if (c == 0)
1613 x->x_gui.x_fsf.x_change = 0;
1614 clock_unset(x->x_clock_reset);
1615 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1616 return;
1618 if(((c>='0')&&(c<='9'))||(c=='.')||(c=='-')||
1619 (c=='e')||(c=='+')||(c=='E'))
1621 if(strlen(x->x_buf) < (IEMGUI_MAX_NUM_LEN-2))
1623 buf[0] = c;
1624 strcat(x->x_buf, buf);
1625 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1628 else if((c=='\b')||(c==127))
1630 int sl=strlen(x->x_buf)-1;
1632 if(sl < 0)
1633 sl = 0;
1634 x->x_buf[sl] = 0;
1635 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1637 else if((c=='\n')||(c==13))
1639 x->x_val = atof(x->x_buf);
1640 x->x_buf[0] = 0;
1641 x->x_gui.x_fsf.x_change = 0;
1642 clock_unset(x->x_clock_reset);
1643 my_numbox_clip(x);
1644 my_numbox_bang(x);
1645 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1647 clock_delay(x->x_clock_reset, 3000);
1650 static void my_numbox_list(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1652 if (IS_A_FLOAT(av,0))
1654 my_numbox_set(x, atom_getfloatarg(0, ac, av));
1655 my_numbox_bang(x);
1659 static void *my_numbox_new(t_symbol *s, int argc, t_atom *argv)
1661 t_my_numbox *x = (t_my_numbox *)pd_new(my_numbox_class);
1662 int bflcol[]={-262144, -1, -1};
1663 int w=5, h=14;
1664 int lilo=0, f=0, ldx=0, ldy=-6;
1665 int fs=10;
1666 int log_height=256;
1667 double min=-1.0e+37, max=1.0e+37,v=0.0;
1668 char str[144];
1670 if((argc >= 17)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
1671 &&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3)
1672 &&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5)
1673 &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6))
1674 &&(IS_A_SYMBOL(argv,7)||IS_A_FLOAT(argv,7))
1675 &&(IS_A_SYMBOL(argv,8)||IS_A_FLOAT(argv,8))
1676 &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)
1677 &&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)
1678 &&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15)&&IS_A_FLOAT(argv,16))
1680 w = (int)atom_getintarg(0, argc, argv);
1681 h = (int)atom_getintarg(1, argc, argv);
1682 min = (double)atom_getfloatarg(2, argc, argv);
1683 max = (double)atom_getfloatarg(3, argc, argv);
1684 lilo = (int)atom_getintarg(4, argc, argv);
1685 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
1686 iemgui_new_getnames(&x->x_gui, 6, argv);
1687 ldx = (int)atom_getintarg(9, argc, argv);
1688 ldy = (int)atom_getintarg(10, argc, argv);
1689 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
1690 fs = (int)atom_getintarg(12, argc, argv);
1691 bflcol[0] = (int)atom_getintarg(13, argc, argv);
1692 bflcol[1] = (int)atom_getintarg(14, argc, argv);
1693 bflcol[2] = (int)atom_getintarg(15, argc, argv);
1694 v = atom_getfloatarg(16, argc, argv);
1696 else iemgui_new_getnames(&x->x_gui, 6, 0);
1697 if((argc == 18)&&IS_A_FLOAT(argv,17))
1699 log_height = (int)atom_getintarg(17, argc, argv);
1701 x->x_gui.x_draw = (t_iemfunptr)my_numbox_draw;
1702 x->x_gui.x_fsf.x_snd_able = 1;
1703 x->x_gui.x_fsf.x_rcv_able = 1;
1704 x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
1705 if(x->x_gui.x_isa.x_loadinit)
1706 x->x_val = v;
1707 else
1708 x->x_val = 0.0;
1709 if(lilo != 0) lilo = 1;
1710 x->x_lin0_log1 = lilo;
1711 if(log_height < 10)
1712 log_height = 10;
1713 x->x_log_height = log_height;
1714 if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
1715 x->x_gui.x_fsf.x_snd_able = 0;
1716 if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
1717 x->x_gui.x_fsf.x_rcv_able = 0;
1718 if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
1719 else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
1720 else { x->x_gui.x_fsf.x_font_style = 0;
1721 strcpy(x->x_gui.x_font, "courier"); }
1722 if (x->x_gui.x_fsf.x_rcv_able)
1723 pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
1724 x->x_gui.x_ldx = ldx;
1725 x->x_gui.x_ldy = ldy;
1726 if(fs < 4)
1727 fs = 4;
1728 x->x_gui.x_fontsize = fs;
1729 if(w < 1)
1730 w = 1;
1731 x->x_gui.x_w = w;
1732 if(h < 8)
1733 h = 8;
1734 x->x_gui.x_h = h;
1735 x->x_buf[0] = 0;
1736 my_numbox_calc_fontwidth(x);
1737 my_numbox_check_minmax(x, min, max);
1738 iemgui_all_colfromload(&x->x_gui, bflcol);
1739 iemgui_verify_snd_ne_rcv(&x->x_gui);
1740 x->x_clock_reset = clock_new(x, (t_method)my_numbox_tick_reset);
1741 x->x_clock_wait = clock_new(x, (t_method)my_numbox_tick_wait);
1742 x->x_gui.x_fsf.x_change = 0;
1743 outlet_new(&x->x_gui.x_obj, &s_float);
1744 return (x);
1747 static void my_numbox_free(t_my_numbox *x)
1749 if(x->x_gui.x_fsf.x_rcv_able)
1750 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
1751 clock_free(x->x_clock_reset);
1752 clock_free(x->x_clock_wait);
1753 gfxstub_deleteforkey(x);
1756 void g_numbox_setup(void)
1758 my_numbox_class = class_new(gensym("nbx"), (t_newmethod)my_numbox_new,
1759 (t_method)my_numbox_free, sizeof(t_my_numbox), 0, A_GIMME, 0);
1760 class_addcreator((t_newmethod)my_numbox_new, gensym("my_numbox"),
1761 A_GIMME, 0);
1762 class_addbang(my_numbox_class,my_numbox_bang);
1763 class_addfloat(my_numbox_class,my_numbox_float);
1764 class_addlist(my_numbox_class, my_numbox_list);
1765 class_addmethod(my_numbox_class, (t_method)my_numbox_click,
1766 gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
1767 class_addmethod(my_numbox_class, (t_method)my_numbox_motion,
1768 gensym("motion"), A_FLOAT, A_FLOAT, 0);
1769 class_addmethod(my_numbox_class, (t_method)my_numbox_dialog,
1770 gensym("dialog"), A_GIMME, 0);
1771 class_addmethod(my_numbox_class, (t_method)my_numbox_loadbang,
1772 gensym("loadbang"), 0);
1773 class_addmethod(my_numbox_class, (t_method)my_numbox_set,
1774 gensym("set"), A_FLOAT, 0);
1775 class_addmethod(my_numbox_class, (t_method)my_numbox_size,
1776 gensym("size"), A_GIMME, 0);
1777 class_addmethod(my_numbox_class, (t_method)my_numbox_delta,
1778 gensym("delta"), A_GIMME, 0);
1779 class_addmethod(my_numbox_class, (t_method)my_numbox_pos,
1780 gensym("pos"), A_GIMME, 0);
1781 class_addmethod(my_numbox_class, (t_method)my_numbox_range,
1782 gensym("range"), A_GIMME, 0);
1783 class_addmethod(my_numbox_class, (t_method)my_numbox_color,
1784 gensym("color"), A_GIMME, 0);
1785 class_addmethod(my_numbox_class, (t_method)my_numbox_send,
1786 gensym("send"), A_DEFSYM, 0);
1787 class_addmethod(my_numbox_class, (t_method)my_numbox_receive,
1788 gensym("receive"), A_DEFSYM, 0);
1789 class_addmethod(my_numbox_class, (t_method)my_numbox_label,
1790 gensym("label"), A_DEFSYM, 0);
1791 class_addmethod(my_numbox_class, (t_method)my_numbox_label_pos,
1792 gensym("label_pos"), A_GIMME, 0);
1793 class_addmethod(my_numbox_class, (t_method)my_numbox_label_font,
1794 gensym("label_font"), A_GIMME, 0);
1795 class_addmethod(my_numbox_class, (t_method)my_numbox_log,
1796 gensym("log"), 0);
1797 class_addmethod(my_numbox_class, (t_method)my_numbox_lin,
1798 gensym("lin"), 0);
1799 class_addmethod(my_numbox_class, (t_method)my_numbox_init,
1800 gensym("init"), A_FLOAT, 0);
1801 class_addmethod(my_numbox_class, (t_method)my_numbox_log_height,
1802 gensym("log_height"), A_FLOAT, 0);
1803 my_numbox_widgetbehavior.w_getrectfn = my_numbox_getrect;
1804 my_numbox_widgetbehavior.w_displacefn = iemgui_displace;
1805 my_numbox_widgetbehavior.w_selectfn = iemgui_select;
1806 my_numbox_widgetbehavior.w_activatefn = NULL;
1807 my_numbox_widgetbehavior.w_deletefn = iemgui_delete;
1808 my_numbox_widgetbehavior.w_visfn = iemgui_vis;
1809 my_numbox_widgetbehavior.w_clickfn = my_numbox_newclick;
1810 class_setwidget(my_numbox_class, &my_numbox_widgetbehavior);
1811 class_sethelpsymbol(my_numbox_class, gensym("numbox2"));
1812 class_setsavefn(my_numbox_class, my_numbox_save);
1813 class_setpropertiesfn(my_numbox_class, my_numbox_properties);