Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / src / g_numbox.c
blobc05872bed14079cc8d967c02c1c73b30e0cd4d59
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 #ifdef ROCKBOX
8 #include "plugin.h"
9 #include "../../pdbox.h"
10 #include "m_pd.h"
11 #include "g_canvas.h"
12 #include "g_all_guis.h"
13 #else /* ROCKBOX */
14 #include <stdlib.h>
15 #include <string.h>
16 #include <stdio.h>
17 #include <ctype.h>
18 #include "m_pd.h"
19 #include "g_canvas.h"
20 #include "t_tk.h"
21 #include "g_all_guis.h"
22 #include <math.h>
24 #ifdef MSW
25 #include <io.h>
26 #else
27 #include <unistd.h>
28 #endif
29 #endif /* ROCKBOX */
31 /*------------------ global varaibles -------------------------*/
34 /*------------------ global functions -------------------------*/
36 static void my_numbox_key(void *z, t_floatarg fkey);
38 /* ------------ nmx gui-my number box ----------------------- */
40 t_widgetbehavior my_numbox_widgetbehavior;
41 static t_class *my_numbox_class;
43 /* widget helper functions */
45 static void my_numbox_tick_reset(t_my_numbox *x)
47 if(x->x_gui.x_fsf.x_change)
49 x->x_gui.x_fsf.x_change = 0;
50 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
51 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
55 static void my_numbox_tick_wait(t_my_numbox *x)
57 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
60 void my_numbox_clip(t_my_numbox *x)
62 if(x->x_val < x->x_min)
63 x->x_val = x->x_min;
64 if(x->x_val > x->x_max)
65 x->x_val = x->x_max;
68 void my_numbox_calc_fontwidth(t_my_numbox *x)
70 int w, f=31;
72 if(x->x_gui.x_fsf.x_font_style == 1)
73 f = 27;
74 else if(x->x_gui.x_fsf.x_font_style == 2)
75 f = 25;
77 w = x->x_gui.x_fontsize * f * x->x_gui.x_w;
78 w /= 36;
79 x->x_numwidth = w + (x->x_gui.x_h / 2) + 4;
82 void my_numbox_ftoa(t_my_numbox *x)
84 double f=x->x_val;
85 int bufsize, is_exp=0, i, idecimal;
87 #ifdef ROCKBOX
88 ftoan(f, x->x_buf, 10);
89 #else
90 sprintf(x->x_buf, "%g", f);
91 #endif
92 bufsize = strlen(x->x_buf);
93 if(bufsize >= 5)/* if it is in exponential mode */
95 i = bufsize - 4;
96 if((x->x_buf[i] == 'e') || (x->x_buf[i] == 'E'))
97 is_exp = 1;
99 if(bufsize > x->x_gui.x_w)/* if to reduce */
101 if(is_exp)
103 if(x->x_gui.x_w <= 5)
105 x->x_buf[0] = (f < 0.0 ? '-' : '+');
106 x->x_buf[1] = 0;
108 i = bufsize - 4;
109 for(idecimal=0; idecimal < i; idecimal++)
110 if(x->x_buf[idecimal] == '.')
111 break;
112 if(idecimal > (x->x_gui.x_w - 4))
114 x->x_buf[0] = (f < 0.0 ? '-' : '+');
115 x->x_buf[1] = 0;
117 else
119 int new_exp_index=x->x_gui.x_w-4, old_exp_index=bufsize-4;
121 for(i=0; i < 4; i++, new_exp_index++, old_exp_index++)
122 x->x_buf[new_exp_index] = x->x_buf[old_exp_index];
123 x->x_buf[x->x_gui.x_w] = 0;
127 else
129 for(idecimal=0; idecimal < bufsize; idecimal++)
130 if(x->x_buf[idecimal] == '.')
131 break;
132 if(idecimal > x->x_gui.x_w)
134 x->x_buf[0] = (f < 0.0 ? '-' : '+');
135 x->x_buf[1] = 0;
137 else
138 x->x_buf[x->x_gui.x_w] = 0;
143 static void my_numbox_draw_update(t_my_numbox *x, t_glist *glist)
145 #ifdef ROCKBOX
146 (void) x;
147 (void) glist;
148 #else /* ROCKBOX */
149 if (glist_isvisible(glist))
151 if(x->x_gui.x_fsf.x_change)
153 if(x->x_buf[0])
155 char *cp=x->x_buf;
156 int sl = strlen(x->x_buf);
158 x->x_buf[sl] = '>';
159 x->x_buf[sl+1] = 0;
160 if(sl >= x->x_gui.x_w)
161 cp += sl - x->x_gui.x_w + 1;
162 sys_vgui(
163 ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
164 glist_getcanvas(glist), x, IEM_GUI_COLOR_EDITED, cp);
165 x->x_buf[sl] = 0;
167 else
169 my_numbox_ftoa(x);
170 sys_vgui(
171 ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
172 glist_getcanvas(glist), x, IEM_GUI_COLOR_EDITED, x->x_buf);
173 x->x_buf[0] = 0;
176 else
178 my_numbox_ftoa(x);
179 sys_vgui(
180 ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
181 glist_getcanvas(glist), x,
182 x->x_gui.x_fsf.x_selected?
183 IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol,
184 x->x_buf);
185 x->x_buf[0] = 0;
188 #endif /* ROCKBOX */
191 static void my_numbox_draw_new(t_my_numbox *x, t_glist *glist)
193 #ifdef ROCKBOX
194 (void) x;
195 (void) glist;
196 #else /* ROCKBOX */
197 int half=x->x_gui.x_h/2, d=1+x->x_gui.x_h/34;
198 int xpos=text_xpix(&x->x_gui.x_obj, glist);
199 int ypos=text_ypix(&x->x_gui.x_obj, glist);
200 t_canvas *canvas=glist_getcanvas(glist);
202 sys_vgui(
203 ".x%x.c create polygon %d %d %d %d %d %d %d %d %d %d -outline #%6.6x \
204 -fill #%6.6x -tags %xBASE1\n",
205 canvas, xpos, ypos,
206 xpos + x->x_numwidth-4, ypos,
207 xpos + x->x_numwidth, ypos+4,
208 xpos + x->x_numwidth, ypos + x->x_gui.x_h,
209 xpos, ypos + x->x_gui.x_h,
210 IEM_GUI_COLOR_NORMAL, x->x_gui.x_bcol, x);
211 sys_vgui(
212 ".x%x.c create line %d %d %d %d %d %d -fill #%6.6x -tags %xBASE2\n",
213 canvas, xpos, ypos,
214 xpos + half, ypos + half,
215 xpos, ypos + x->x_gui.x_h,
216 x->x_gui.x_fcol, x);
217 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
218 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
219 canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
220 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
221 x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
222 my_numbox_ftoa(x);
223 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
224 -font {%s %d bold} -fill #%6.6x -tags %xNUMBER\n",
225 canvas, xpos+half+2, ypos+half+d,
226 x->x_buf, x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_fcol, x);
227 if(!x->x_gui.x_fsf.x_snd_able)
228 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
229 canvas,
230 xpos, ypos + x->x_gui.x_h-1,
231 xpos+IOWIDTH, ypos + x->x_gui.x_h,
232 x, 0);
233 if(!x->x_gui.x_fsf.x_rcv_able)
234 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
235 canvas,
236 xpos, ypos,
237 xpos+IOWIDTH, ypos+1,
238 x, 0);
239 #endif /* ROCKBOX */
242 static void my_numbox_draw_move(t_my_numbox *x, t_glist *glist)
244 #ifdef ROCKBOX
245 (void) x;
246 (void) glist;
247 #else /* ROCKBOX */
248 int half = x->x_gui.x_h/2, d=1+x->x_gui.x_h/34;
249 int xpos=text_xpix(&x->x_gui.x_obj, glist);
250 int ypos=text_ypix(&x->x_gui.x_obj, glist);
251 t_canvas *canvas=glist_getcanvas(glist);
253 sys_vgui(".x%x.c coords %xBASE1 %d %d %d %d %d %d %d %d %d %d\n",
254 canvas, x, xpos, ypos,
255 xpos + x->x_numwidth-4, ypos,
256 xpos + x->x_numwidth, ypos+4,
257 xpos + x->x_numwidth, ypos + x->x_gui.x_h,
258 xpos, ypos + x->x_gui.x_h);
259 sys_vgui(".x%x.c coords %xBASE2 %d %d %d %d %d %d\n",
260 canvas, x, xpos, ypos,
261 xpos + half, ypos + half,
262 xpos, ypos + x->x_gui.x_h);
263 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
264 canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
265 sys_vgui(".x%x.c coords %xNUMBER %d %d\n",
266 canvas, x, xpos+half+2, ypos+half+d);
267 if(!x->x_gui.x_fsf.x_snd_able)
268 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
269 canvas, x, 0,
270 xpos, ypos + x->x_gui.x_h-1,
271 xpos+IOWIDTH, ypos + x->x_gui.x_h);
272 if(!x->x_gui.x_fsf.x_rcv_able)
273 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
274 canvas, x, 0,
275 xpos, ypos,
276 xpos+IOWIDTH, ypos+1);
277 #endif /* ROCKBOX */
280 static void my_numbox_draw_erase(t_my_numbox* x,t_glist* glist)
282 #ifdef ROCKBOX
283 (void) x;
284 (void) glist;
285 #else /* ROCKBOX */
286 t_canvas *canvas=glist_getcanvas(glist);
288 sys_vgui(".x%x.c delete %xBASE1\n", canvas, x);
289 sys_vgui(".x%x.c delete %xBASE2\n", canvas, x);
290 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
291 sys_vgui(".x%x.c delete %xNUMBER\n", canvas, x);
292 if(!x->x_gui.x_fsf.x_snd_able)
293 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
294 if(!x->x_gui.x_fsf.x_rcv_able)
295 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
296 #endif /* ROCKBOX */
299 static void my_numbox_draw_config(t_my_numbox* x,t_glist* glist)
301 #ifdef ROCKBOX
302 (void) x;
303 (void) glist;
304 #else /* ROCKBOX */
305 t_canvas *canvas=glist_getcanvas(glist);
307 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
308 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
309 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
310 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
311 sys_vgui(".x%x.c itemconfigure %xNUMBER -font {%s %d bold} -fill #%6.6x \n",
312 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
313 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
314 sys_vgui(".x%x.c itemconfigure %xBASE1 -fill #%6.6x\n", canvas,
315 x, x->x_gui.x_bcol);
316 sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n", canvas,
317 x, x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
318 #endif /* ROCKBOX */
321 static void my_numbox_draw_io(t_my_numbox* x,t_glist* glist, int old_snd_rcv_flags)
323 #ifdef ROCKBOX
324 (void) x;
325 (void) glist;
326 (void) old_snd_rcv_flags;
327 #else /* ROCKBOX */
328 int xpos=text_xpix(&x->x_gui.x_obj, glist);
329 int ypos=text_ypix(&x->x_gui.x_obj, glist);
330 t_canvas *canvas=glist_getcanvas(glist);
332 if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
333 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
334 canvas,
335 xpos, ypos + x->x_gui.x_h-1,
336 xpos+IOWIDTH, ypos + x->x_gui.x_h,
337 x, 0);
338 if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
339 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
340 if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
341 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
342 canvas,
343 xpos, ypos,
344 xpos+IOWIDTH, ypos+1,
345 x, 0);
346 if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
347 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
348 #endif /* ROCKBOX */
351 static void my_numbox_draw_select(t_my_numbox *x, t_glist *glist)
353 #ifdef ROCKBOX
354 (void) x;
355 (void) glist;
356 #else /* ROCKBOX */
357 t_canvas *canvas=glist_getcanvas(glist);
359 if(x->x_gui.x_fsf.x_selected)
361 if(x->x_gui.x_fsf.x_change)
363 x->x_gui.x_fsf.x_change = 0;
364 clock_unset(x->x_clock_reset);
365 x->x_buf[0] = 0;
366 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
368 sys_vgui(".x%x.c itemconfigure %xBASE1 -outline #%6.6x\n",
369 canvas, x, IEM_GUI_COLOR_SELECTED);
370 sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n",
371 canvas, x, IEM_GUI_COLOR_SELECTED);
372 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n",
373 canvas, x, IEM_GUI_COLOR_SELECTED);
374 sys_vgui(".x%x.c itemconfigure %xNUMBER -fill #%6.6x\n",
375 canvas, x, IEM_GUI_COLOR_SELECTED);
377 else
379 sys_vgui(".x%x.c itemconfigure %xBASE1 -outline #%6.6x\n",
380 canvas, x, IEM_GUI_COLOR_NORMAL);
381 sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n",
382 canvas, x, x->x_gui.x_fcol);
383 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n",
384 canvas, x, x->x_gui.x_lcol);
385 sys_vgui(".x%x.c itemconfigure %xNUMBER -fill #%6.6x\n",
386 canvas, x, x->x_gui.x_fcol);
388 #endif /* ROCKBOX */
391 void my_numbox_draw(t_my_numbox *x, t_glist *glist, int mode)
393 if(mode == IEM_GUI_DRAW_MODE_UPDATE)
394 my_numbox_draw_update(x, glist);
395 else if(mode == IEM_GUI_DRAW_MODE_MOVE)
396 my_numbox_draw_move(x, glist);
397 else if(mode == IEM_GUI_DRAW_MODE_NEW)
398 my_numbox_draw_new(x, glist);
399 else if(mode == IEM_GUI_DRAW_MODE_SELECT)
400 my_numbox_draw_select(x, glist);
401 else if(mode == IEM_GUI_DRAW_MODE_ERASE)
402 my_numbox_draw_erase(x, glist);
403 else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
404 my_numbox_draw_config(x, glist);
405 else if(mode >= IEM_GUI_DRAW_MODE_IO)
406 my_numbox_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
409 /* ------------------------ nbx widgetbehaviour----------------------------- */
412 static void my_numbox_getrect(t_gobj *z, t_glist *glist,
413 int *xp1, int *yp1, int *xp2, int *yp2)
415 t_my_numbox* x = (t_my_numbox*)z;
417 *xp1 = text_xpix(&x->x_gui.x_obj, glist);
418 *yp1 = text_ypix(&x->x_gui.x_obj, glist);
419 *xp2 = *xp1 + x->x_numwidth;
420 *yp2 = *yp1 + x->x_gui.x_h;
423 static void my_numbox_save(t_gobj *z, t_binbuf *b)
425 t_my_numbox *x = (t_my_numbox *)z;
426 int bflcol[3];
427 t_symbol *srl[3];
429 iemgui_save(&x->x_gui, srl, bflcol);
430 if(x->x_gui.x_fsf.x_change)
432 x->x_gui.x_fsf.x_change = 0;
433 clock_unset(x->x_clock_reset);
434 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
435 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
438 binbuf_addv(b, "ssiisiiffiisssiiiiiiifi", gensym("#X"),gensym("obj"),
439 (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
440 gensym("nbx"), x->x_gui.x_w, x->x_gui.x_h,
441 (float)x->x_min, (float)x->x_max,
442 x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa),
443 srl[0], srl[1], srl[2],
444 x->x_gui.x_ldx, x->x_gui.x_ldy,
445 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
446 bflcol[0], bflcol[1], bflcol[2],
447 x->x_val, x->x_log_height);
448 binbuf_addv(b, ";");
451 int my_numbox_check_minmax(t_my_numbox *x, double min, double max)
453 int ret=0;
455 if(x->x_lin0_log1)
457 if((min == 0.0)&&(max == 0.0))
458 max = 1.0;
459 if(max > 0.0)
461 if(min <= 0.0)
462 min = 0.01*max;
464 else
466 if(min > 0.0)
467 max = 0.01*min;
470 x->x_min = min;
471 x->x_max = max;
472 if(x->x_val < x->x_min)
474 x->x_val = x->x_min;
475 ret = 1;
477 if(x->x_val > x->x_max)
479 x->x_val = x->x_max;
480 ret = 1;
482 if(x->x_lin0_log1)
483 x->x_k = exp(log(x->x_max/x->x_min)/(double)(x->x_log_height));
484 else
485 x->x_k = 1.0;
486 return(ret);
489 static void my_numbox_properties(t_gobj *z, t_glist *owner)
491 #ifdef ROCKBOX
492 (void) z;
493 (void) owner;
494 #else /* ROCKBOX */
495 t_my_numbox *x = (t_my_numbox *)z;
496 char buf[800];
497 t_symbol *srl[3];
499 iemgui_properties(&x->x_gui, srl);
500 if(x->x_gui.x_fsf.x_change)
502 x->x_gui.x_fsf.x_change = 0;
503 clock_unset(x->x_clock_reset);
504 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
505 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
508 sprintf(buf, "pdtk_iemgui_dialog %%s NUMBERBOX \
509 -------dimensions(digits)(pix):------- %d %d width: %d %d height: \
510 -----------output-range:----------- %g min: %g max: %d \
511 %d lin log %d %d log-height: %d \
512 %s %s \
513 %s %d %d \
514 %d %d \
515 %d %d %d\n",
516 x->x_gui.x_w, 1, x->x_gui.x_h, 8,
517 x->x_min, x->x_max, 0,/*no_schedule*/
518 x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, -1,
519 x->x_log_height, /*no multi, but iem-characteristic*/
520 srl[0]->s_name, srl[1]->s_name,
521 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
522 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
523 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol,
524 0xffffff & x->x_gui.x_lcol);
525 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
526 #endif /* ROCKBOX */
529 static void my_numbox_bang(t_my_numbox *x)
531 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_val);
532 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
533 pd_float(x->x_gui.x_snd->s_thing, x->x_val);
536 static void my_numbox_dialog(t_my_numbox *x, t_symbol *s, int argc,
537 t_atom *argv)
539 t_symbol *srl[3];
540 int w = (int)atom_getintarg(0, argc, argv);
541 int h = (int)atom_getintarg(1, argc, argv);
542 double min = (double)atom_getfloatarg(2, argc, argv);
543 double max = (double)atom_getfloatarg(3, argc, argv);
544 int lilo = (int)atom_getintarg(4, argc, argv);
545 int log_height = (int)atom_getintarg(6, argc, argv);
546 int sr_flags;
548 #ifdef ROCKBOX
549 (void) s;
550 #endif
552 if(lilo != 0) lilo = 1;
553 x->x_lin0_log1 = lilo;
554 sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
555 if(w < 1)
556 w = 1;
557 x->x_gui.x_w = w;
558 if(h < 8)
559 h = 8;
560 x->x_gui.x_h = h;
561 if(log_height < 10)
562 log_height = 10;
563 x->x_log_height = log_height;
564 my_numbox_calc_fontwidth(x);
565 /*if(my_numbox_check_minmax(x, min, max))
566 my_numbox_bang(x);*/
567 my_numbox_check_minmax(x, min, max);
568 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
569 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
570 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
571 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
572 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
575 static void my_numbox_motion(t_my_numbox *x, t_floatarg dx, t_floatarg dy)
577 double k2=1.0;
579 #ifdef ROCKBOX
580 (void) dx;
581 #endif
583 if(x->x_gui.x_fsf.x_finemoved)
584 k2 = 0.01;
585 if(x->x_lin0_log1)
586 x->x_val *= pow(x->x_k, -k2*dy);
587 else
588 x->x_val -= k2*dy;
589 my_numbox_clip(x);
590 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
591 my_numbox_bang(x);
592 clock_unset(x->x_clock_reset);
595 static void my_numbox_click(t_my_numbox *x, t_floatarg xpos, t_floatarg ypos,
596 t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
598 #ifdef ROCKBOX
599 (void) shift;
600 (void) ctrl;
601 (void) alt;
602 #endif
603 glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g,
604 (t_glistmotionfn)my_numbox_motion, my_numbox_key, xpos, ypos);
607 static int my_numbox_newclick(t_gobj *z, struct _glist *glist,
608 int xpix, int ypix, int shift, int alt, int dbl, int doit)
610 t_my_numbox* x = (t_my_numbox *)z;
612 #ifdef ROCKBOX
613 (void) glist;
614 (void) dbl;
615 #endif
617 if(doit)
619 my_numbox_click( x, (t_floatarg)xpix, (t_floatarg)ypix,
620 (t_floatarg)shift, 0, (t_floatarg)alt);
621 if(shift)
622 x->x_gui.x_fsf.x_finemoved = 1;
623 else
624 x->x_gui.x_fsf.x_finemoved = 0;
625 if(!x->x_gui.x_fsf.x_change)
627 clock_delay(x->x_clock_wait, 50);
628 x->x_gui.x_fsf.x_change = 1;
629 clock_delay(x->x_clock_reset, 3000);
630 /* glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.ob_g,
631 0, my_numbox_key, 0, 0); */
633 x->x_buf[0] = 0;
635 else
637 x->x_gui.x_fsf.x_change = 0;
638 clock_unset(x->x_clock_reset);
639 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
640 x->x_buf[0] = 0;
641 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
644 return (1);
647 static void my_numbox_set(t_my_numbox *x, t_floatarg f)
649 x->x_val = f;
650 my_numbox_clip(x);
651 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
654 static void my_numbox_log_height(t_my_numbox *x, t_floatarg lh)
656 if(lh < 10.0)
657 lh = 10.0;
658 x->x_log_height = (int)lh;
659 if(x->x_lin0_log1)
660 x->x_k = exp(log(x->x_max/x->x_min)/(double)(x->x_log_height));
661 else
662 x->x_k = 1.0;
666 static void my_numbox_float(t_my_numbox *x, t_floatarg f)
668 my_numbox_set(x, f);
669 if(x->x_gui.x_fsf.x_put_in2out)
670 my_numbox_bang(x);
673 static void my_numbox_size(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
675 int h, w;
677 #ifdef ROCKBOX
678 (void) s;
679 #endif
681 w = (int)atom_getintarg(0, ac, av);
682 if(w < 1)
683 w = 1;
684 x->x_gui.x_w = w;
685 if(ac > 1)
687 h = (int)atom_getintarg(1, ac, av);
688 if(h < 8)
689 h = 8;
690 x->x_gui.x_h = h;
692 my_numbox_calc_fontwidth(x);
693 iemgui_size((void *)x, &x->x_gui);
696 static void my_numbox_delta(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
697 {iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
699 static void my_numbox_pos(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
700 {iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
702 static void my_numbox_range(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
704 #ifdef ROCKBOX
705 (void) s;
706 #endif
707 if(my_numbox_check_minmax(x, (double)atom_getfloatarg(0, ac, av),
708 (double)atom_getfloatarg(1, ac, av)))
710 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
711 /*my_numbox_bang(x);*/
715 static void my_numbox_color(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
716 {iemgui_color((void *)x, &x->x_gui, s, ac, av);}
718 static void my_numbox_send(t_my_numbox *x, t_symbol *s)
719 {iemgui_send(x, &x->x_gui, s);}
721 static void my_numbox_receive(t_my_numbox *x, t_symbol *s)
722 {iemgui_receive(x, &x->x_gui, s);}
724 static void my_numbox_label(t_my_numbox *x, t_symbol *s)
725 {iemgui_label((void *)x, &x->x_gui, s);}
727 static void my_numbox_label_pos(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
728 {iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
730 static void my_numbox_label_font(t_my_numbox *x,
731 t_symbol *s, int ac, t_atom *av)
733 int f = (int)atom_getintarg(1, ac, av);
735 if(f < 4)
736 f = 4;
737 x->x_gui.x_fontsize = f;
738 f = (int)atom_getintarg(0, ac, av);
739 if((f < 0) || (f > 2))
740 f = 0;
741 x->x_gui.x_fsf.x_font_style = f;
742 my_numbox_calc_fontwidth(x);
743 iemgui_label_font((void *)x, &x->x_gui, s, ac, av);
746 static void my_numbox_log(t_my_numbox *x)
748 x->x_lin0_log1 = 1;
749 if(my_numbox_check_minmax(x, x->x_min, x->x_max))
751 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
752 /*my_numbox_bang(x);*/
756 static void my_numbox_lin(t_my_numbox *x)
758 x->x_lin0_log1 = 0;
761 static void my_numbox_init(t_my_numbox *x, t_floatarg f)
763 x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1;
766 static void my_numbox_loadbang(t_my_numbox *x)
768 if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
770 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
771 my_numbox_bang(x);
775 static void my_numbox_key(void *z, t_floatarg fkey)
777 t_my_numbox *x = z;
778 char c=fkey;
779 char buf[3];
780 buf[1] = 0;
782 if (c == 0)
784 x->x_gui.x_fsf.x_change = 0;
785 clock_unset(x->x_clock_reset);
786 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
787 return;
789 if(((c>='0')&&(c<='9'))||(c=='.')||(c=='-')||
790 (c=='e')||(c=='+')||(c=='E'))
792 if(strlen(x->x_buf) < (IEMGUI_MAX_NUM_LEN-2))
794 buf[0] = c;
795 strcat(x->x_buf, buf);
796 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
799 else if((c=='\b')||(c==127))
801 int sl=strlen(x->x_buf)-1;
803 if(sl < 0)
804 sl = 0;
805 x->x_buf[sl] = 0;
806 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
808 else if((c=='\n')||(c==13))
810 x->x_val = atof(x->x_buf);
811 x->x_buf[0] = 0;
812 x->x_gui.x_fsf.x_change = 0;
813 clock_unset(x->x_clock_reset);
814 my_numbox_clip(x);
815 my_numbox_bang(x);
816 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
818 clock_delay(x->x_clock_reset, 3000);
821 static void my_numbox_list(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
823 #ifdef ROCKBOX
824 (void) s;
825 #endif
826 if (IS_A_FLOAT(av,0))
828 my_numbox_set(x, atom_getfloatarg(0, ac, av));
829 my_numbox_bang(x);
833 static void *my_numbox_new(t_symbol *s, int argc, t_atom *argv)
835 t_my_numbox *x = (t_my_numbox *)pd_new(my_numbox_class);
836 int bflcol[]={-262144, -1, -1};
837 int w=5, h=14;
838 #ifdef ROCKBOX
839 int lilo=0, ldx=0, ldy=-6;
840 #else
841 int lilo=0, f=0, ldx=0, ldy=-6;
842 #endif
843 int fs=10;
844 int log_height=256;
845 double min=-1.0e+37, max=1.0e+37,v=0.0;
846 #ifndef ROCKBOX
847 char str[144];
848 #endif
850 #ifdef ROCKBOX
851 (void) s;
852 #endif
854 if((argc >= 17)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
855 &&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3)
856 &&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5)
857 &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6))
858 &&(IS_A_SYMBOL(argv,7)||IS_A_FLOAT(argv,7))
859 &&(IS_A_SYMBOL(argv,8)||IS_A_FLOAT(argv,8))
860 &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)
861 &&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)
862 &&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15)&&IS_A_FLOAT(argv,16))
864 w = (int)atom_getintarg(0, argc, argv);
865 h = (int)atom_getintarg(1, argc, argv);
866 min = (double)atom_getfloatarg(2, argc, argv);
867 max = (double)atom_getfloatarg(3, argc, argv);
868 lilo = (int)atom_getintarg(4, argc, argv);
869 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
870 iemgui_new_getnames(&x->x_gui, 6, argv);
871 ldx = (int)atom_getintarg(9, argc, argv);
872 ldy = (int)atom_getintarg(10, argc, argv);
873 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
874 fs = (int)atom_getintarg(12, argc, argv);
875 bflcol[0] = (int)atom_getintarg(13, argc, argv);
876 bflcol[1] = (int)atom_getintarg(14, argc, argv);
877 bflcol[2] = (int)atom_getintarg(15, argc, argv);
878 v = atom_getfloatarg(16, argc, argv);
880 else iemgui_new_getnames(&x->x_gui, 6, 0);
881 if((argc == 18)&&IS_A_FLOAT(argv,17))
883 log_height = (int)atom_getintarg(17, argc, argv);
885 x->x_gui.x_draw = (t_iemfunptr)my_numbox_draw;
886 x->x_gui.x_fsf.x_snd_able = 1;
887 x->x_gui.x_fsf.x_rcv_able = 1;
888 x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
889 if(x->x_gui.x_isa.x_loadinit)
890 x->x_val = v;
891 else
892 x->x_val = 0.0;
893 if(lilo != 0) lilo = 1;
894 x->x_lin0_log1 = lilo;
895 if(log_height < 10)
896 log_height = 10;
897 x->x_log_height = log_height;
898 if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
899 x->x_gui.x_fsf.x_snd_able = 0;
900 if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
901 x->x_gui.x_fsf.x_rcv_able = 0;
902 if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
903 else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
904 else { x->x_gui.x_fsf.x_font_style = 0;
905 strcpy(x->x_gui.x_font, "courier"); }
906 if (x->x_gui.x_fsf.x_rcv_able)
907 pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
908 x->x_gui.x_ldx = ldx;
909 x->x_gui.x_ldy = ldy;
910 if(fs < 4)
911 fs = 4;
912 x->x_gui.x_fontsize = fs;
913 if(w < 1)
914 w = 1;
915 x->x_gui.x_w = w;
916 if(h < 8)
917 h = 8;
918 x->x_gui.x_h = h;
919 x->x_buf[0] = 0;
920 my_numbox_calc_fontwidth(x);
921 my_numbox_check_minmax(x, min, max);
922 iemgui_all_colfromload(&x->x_gui, bflcol);
923 iemgui_verify_snd_ne_rcv(&x->x_gui);
924 x->x_clock_reset = clock_new(x, (t_method)my_numbox_tick_reset);
925 x->x_clock_wait = clock_new(x, (t_method)my_numbox_tick_wait);
926 x->x_gui.x_fsf.x_change = 0;
927 outlet_new(&x->x_gui.x_obj, &s_float);
928 return (x);
931 static void my_numbox_free(t_my_numbox *x)
933 if(x->x_gui.x_fsf.x_rcv_able)
934 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
935 clock_free(x->x_clock_reset);
936 clock_free(x->x_clock_wait);
937 #ifndef ROCKBOX
938 gfxstub_deleteforkey(x);
939 #endif
942 void g_numbox_setup(void)
944 my_numbox_class = class_new(gensym("nbx"), (t_newmethod)my_numbox_new,
945 (t_method)my_numbox_free, sizeof(t_my_numbox), 0, A_GIMME, 0);
946 class_addcreator((t_newmethod)my_numbox_new, gensym("my_numbox"),
947 A_GIMME, 0);
948 class_addbang(my_numbox_class,my_numbox_bang);
949 class_addfloat(my_numbox_class,my_numbox_float);
950 class_addlist(my_numbox_class, my_numbox_list);
951 class_addmethod(my_numbox_class, (t_method)my_numbox_click,
952 gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
953 class_addmethod(my_numbox_class, (t_method)my_numbox_motion,
954 gensym("motion"), A_FLOAT, A_FLOAT, 0);
955 class_addmethod(my_numbox_class, (t_method)my_numbox_dialog,
956 gensym("dialog"), A_GIMME, 0);
957 class_addmethod(my_numbox_class, (t_method)my_numbox_loadbang,
958 gensym("loadbang"), 0);
959 class_addmethod(my_numbox_class, (t_method)my_numbox_set,
960 gensym("set"), A_FLOAT, 0);
961 class_addmethod(my_numbox_class, (t_method)my_numbox_size,
962 gensym("size"), A_GIMME, 0);
963 class_addmethod(my_numbox_class, (t_method)my_numbox_delta,
964 gensym("delta"), A_GIMME, 0);
965 class_addmethod(my_numbox_class, (t_method)my_numbox_pos,
966 gensym("pos"), A_GIMME, 0);
967 class_addmethod(my_numbox_class, (t_method)my_numbox_range,
968 gensym("range"), A_GIMME, 0);
969 class_addmethod(my_numbox_class, (t_method)my_numbox_color,
970 gensym("color"), A_GIMME, 0);
971 class_addmethod(my_numbox_class, (t_method)my_numbox_send,
972 gensym("send"), A_DEFSYM, 0);
973 class_addmethod(my_numbox_class, (t_method)my_numbox_receive,
974 gensym("receive"), A_DEFSYM, 0);
975 class_addmethod(my_numbox_class, (t_method)my_numbox_label,
976 gensym("label"), A_DEFSYM, 0);
977 class_addmethod(my_numbox_class, (t_method)my_numbox_label_pos,
978 gensym("label_pos"), A_GIMME, 0);
979 class_addmethod(my_numbox_class, (t_method)my_numbox_label_font,
980 gensym("label_font"), A_GIMME, 0);
981 class_addmethod(my_numbox_class, (t_method)my_numbox_log,
982 gensym("log"), 0);
983 class_addmethod(my_numbox_class, (t_method)my_numbox_lin,
984 gensym("lin"), 0);
985 class_addmethod(my_numbox_class, (t_method)my_numbox_init,
986 gensym("init"), A_FLOAT, 0);
987 class_addmethod(my_numbox_class, (t_method)my_numbox_log_height,
988 gensym("log_height"), A_FLOAT, 0);
989 my_numbox_widgetbehavior.w_getrectfn = my_numbox_getrect;
990 my_numbox_widgetbehavior.w_displacefn = iemgui_displace;
991 my_numbox_widgetbehavior.w_selectfn = iemgui_select;
992 my_numbox_widgetbehavior.w_activatefn = NULL;
993 my_numbox_widgetbehavior.w_deletefn = iemgui_delete;
994 my_numbox_widgetbehavior.w_visfn = iemgui_vis;
995 my_numbox_widgetbehavior.w_clickfn = my_numbox_newclick;
996 class_setwidget(my_numbox_class, &my_numbox_widgetbehavior);
997 class_sethelpsymbol(my_numbox_class, gensym("numbox2"));
998 class_setsavefn(my_numbox_class, my_numbox_save);
999 class_setpropertiesfn(my_numbox_class, my_numbox_properties);