diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
commit | 513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch) | |
tree | 10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/src/g_numbox.c | |
parent | 95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff) | |
download | rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip |
Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin project of Wincent Balin. Stripped some non-sourcefiles and added a rockbox readme that needs a bit more info from Wincent. Is added to CATEGORIES and viewers, but not yet to SUBDIRS (ie doesn't build yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/g_numbox.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/g_numbox.c | 1814 |
1 files changed, 1814 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/g_numbox.c b/apps/plugins/pdbox/PDa/src/g_numbox.c new file mode 100644 index 0000000000..e7421204d3 --- /dev/null +++ b/apps/plugins/pdbox/PDa/src/g_numbox.c | |||
@@ -0,0 +1,1814 @@ | |||
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. */ | ||
4 | |||
5 | /* my_numbox.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */ | ||
6 | |||
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> | ||
16 | |||
17 | #ifdef MSW | ||
18 | #include <io.h> | ||
19 | #else | ||
20 | #include <unistd.h> | ||
21 | #endif | ||
22 | |||
23 | /*------------------ global varaibles -------------------------*/ | ||
24 | |||
25 | |||
26 | /*------------------ global functions -------------------------*/ | ||
27 | |||
28 | static void my_numbox_key(void *z, t_floatarg fkey); | ||
29 | |||
30 | /* ------------ nmx gui-my number box ----------------------- */ | ||
31 | |||
32 | t_widgetbehavior my_numbox_widgetbehavior; | ||
33 | static t_class *my_numbox_class; | ||
34 | |||
35 | /* widget helper functions */ | ||
36 | |||
37 | static void my_numbox_tick_reset(t_my_numbox *x) | ||
38 | { | ||
39 | if(x->x_gui.x_fsf.x_change) | ||
40 | { | ||
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); | ||
44 | } | ||
45 | } | ||
46 | |||
47 | static void my_numbox_tick_wait(t_my_numbox *x) | ||
48 | { | ||
49 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
50 | } | ||
51 | |||
52 | void my_numbox_clip(t_my_numbox *x) | ||
53 | { | ||
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; | ||
58 | } | ||
59 | |||
60 | void my_numbox_calc_fontwidth(t_my_numbox *x) | ||
61 | { | ||
62 | int w, f=31; | ||
63 | |||
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; | ||
68 | |||
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; | ||
72 | } | ||
73 | |||
74 | void my_numbox_ftoa(t_my_numbox *x) | ||
75 | { | ||
76 | double f=x->x_val; | ||
77 | int bufsize, is_exp=0, i, idecimal; | ||
78 | |||
79 | sprintf(x->x_buf, "%g", f); | ||
80 | bufsize = strlen(x->x_buf); | ||
81 | if(bufsize >= 5)/* if it is in exponential mode */ | ||
82 | { | ||
83 | i = bufsize - 4; | ||
84 | if((x->x_buf[i] == 'e') || (x->x_buf[i] == 'E')) | ||
85 | is_exp = 1; | ||
86 | } | ||
87 | if(bufsize > x->x_gui.x_w)/* if to reduce */ | ||
88 | { | ||
89 | if(is_exp) | ||
90 | { | ||
91 | if(x->x_gui.x_w <= 5) | ||
92 | { | ||
93 | x->x_buf[0] = (f < 0.0 ? '-' : '+'); | ||
94 | x->x_buf[1] = 0; | ||
95 | } | ||
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)) | ||
101 | { | ||
102 | x->x_buf[0] = (f < 0.0 ? '-' : '+'); | ||
103 | x->x_buf[1] = 0; | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | int new_exp_index=x->x_gui.x_w-4, old_exp_index=bufsize-4; | ||
108 | |||
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; | ||
112 | } | ||
113 | |||
114 | } | ||
115 | else | ||
116 | { | ||
117 | for(idecimal=0; idecimal < bufsize; idecimal++) | ||
118 | if(x->x_buf[idecimal] == '.') | ||
119 | break; | ||
120 | if(idecimal > x->x_gui.x_w) | ||
121 | { | ||
122 | x->x_buf[0] = (f < 0.0 ? '-' : '+'); | ||
123 | x->x_buf[1] = 0; | ||
124 | } | ||
125 | else | ||
126 | x->x_buf[x->x_gui.x_w] = 0; | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | |||
131 | static void my_numbox_draw_update(t_my_numbox *x, t_glist *glist) | ||
132 | { | ||
133 | if (glist_isvisible(glist)) | ||
134 | { | ||
135 | if(x->x_gui.x_fsf.x_change) | ||
136 | { | ||
137 | if(x->x_buf[0]) | ||
138 | { | ||
139 | char *cp=x->x_buf; | ||
140 | int sl = strlen(x->x_buf); | ||
141 | |||
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; | ||
150 | } | ||
151 | else | ||
152 | { | ||
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; | ||
158 | } | ||
159 | } | ||
160 | else | ||
161 | { | ||
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; | ||
170 | } | ||
171 | } | ||
172 | } | ||
173 | |||
174 | static void my_numbox_draw_new(t_my_numbox *x, t_glist *glist) | ||
175 | { | ||
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); | ||
180 | |||
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); | ||
218 | } | ||
219 | |||
220 | static void my_numbox_draw_move(t_my_numbox *x, t_glist *glist) | ||
221 | { | ||
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); | ||
226 | |||
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); | ||
251 | } | ||
252 | |||
253 | static void my_numbox_draw_erase(t_my_numbox* x,t_glist* glist) | ||
254 | { | ||
255 | t_canvas *canvas=glist_getcanvas(glist); | ||
256 | |||
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); | ||
265 | } | ||
266 | |||
267 | static void my_numbox_draw_config(t_my_numbox* x,t_glist* glist) | ||
268 | { | ||
269 | t_canvas *canvas=glist_getcanvas(glist); | ||
270 | |||
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); | ||
282 | } | ||
283 | |||
284 | static void my_numbox_draw_io(t_my_numbox* x,t_glist* glist, int old_snd_rcv_flags) | ||
285 | { | ||
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); | ||
289 | |||
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); | ||
306 | } | ||
307 | |||
308 | static void my_numbox_draw_select(t_my_numbox *x, t_glist *glist) | ||
309 | { | ||
310 | t_canvas *canvas=glist_getcanvas(glist); | ||
311 | |||
312 | if(x->x_gui.x_fsf.x_selected) | ||
313 | { | ||
314 | if(x->x_gui.x_fsf.x_change) | ||
315 | { | ||
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); | ||
320 | } | ||
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); | ||
329 | } | ||
330 | else | ||
331 | { | ||
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); | ||
340 | } | ||
341 | } | ||
342 | |||
343 | void my_numbox_draw(t_my_numbox *x, t_glist *glist, int mode) | ||
344 | { | ||
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); | ||
359 | } | ||
360 | |||
361 | /* ------------------------ nbx widgetbehaviour----------------------------- */ | ||
362 | |||
363 | |||
364 | static void my_numbox_getrect(t_gobj *z, t_glist *glist, | ||
365 | int *xp1, int *yp1, int *xp2, int *yp2) | ||
366 | { | ||
367 | t_my_numbox* x = (t_my_numbox*)z; | ||
368 | |||
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; | ||
373 | } | ||
374 | |||
375 | static void my_numbox_save(t_gobj *z, t_binbuf *b) | ||
376 | { | ||
377 | t_my_numbox *x = (t_my_numbox *)z; | ||
378 | int bflcol[3]; | ||
379 | t_symbol *srl[3]; | ||
380 | |||
381 | iemgui_save(&x->x_gui, srl, bflcol); | ||
382 | if(x->x_gui.x_fsf.x_change) | ||
383 | { | ||
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); | ||
388 | |||
389 | } | ||
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, ";"); | ||
401 | } | ||
402 | |||
403 | int my_numbox_check_minmax(t_my_numbox *x, double min, double max) | ||
404 | { | ||
405 | int ret=0; | ||
406 | |||
407 | if(x->x_lin0_log1) | ||
408 | { | ||
409 | if((min == 0.0)&&(max == 0.0)) | ||
410 | max = 1.0; | ||
411 | if(max > 0.0) | ||
412 | { | ||
413 | if(min <= 0.0) | ||
414 | min = 0.01*max; | ||
415 | } | ||
416 | else | ||
417 | { | ||
418 | if(min > 0.0) | ||
419 | max = 0.01*min; | ||
420 | } | ||
421 | } | ||
422 | x->x_min = min; | ||
423 | x->x_max = max; | ||
424 | if(x->x_val < x->x_min) | ||
425 | { | ||
426 | x->x_val = x->x_min; | ||
427 | ret = 1; | ||
428 | } | ||
429 | if(x->x_val > x->x_max) | ||
430 | { | ||
431 | x->x_val = x->x_max; | ||
432 | ret = 1; | ||
433 | } | ||
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); | ||
439 | } | ||
440 | |||
441 | static void my_numbox_properties(t_gobj *z, t_glist *owner) | ||
442 | { | ||
443 | t_my_numbox *x = (t_my_numbox *)z; | ||
444 | char buf[800]; | ||
445 | t_symbol *srl[3]; | ||
446 | |||
447 | iemgui_properties(&x->x_gui, srl); | ||
448 | if(x->x_gui.x_fsf.x_change) | ||
449 | { | ||
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); | ||
454 | |||
455 | } | ||
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); | ||
474 | } | ||
475 | |||
476 | static void my_numbox_bang(t_my_numbox *x) | ||
477 | { | ||
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); | ||
481 | } | ||
482 | |||
483 | static void my_numbox_dialog(t_my_numbox *x, t_symbol *s, int argc, | ||
484 | t_atom *argv) | ||
485 | { | ||
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; | ||
494 | |||
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); | ||
516 | } | ||
517 | |||
518 | static void my_numbox_motion(t_my_numbox *x, t_floatarg dx, t_floatarg dy) | ||
519 | { | ||
520 | double k2=1.0; | ||
521 | |||
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); | ||
532 | } | ||
533 | |||
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) | ||
536 | { | ||
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); | ||
539 | } | ||
540 | |||
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) | ||
543 | { | ||
544 | t_my_numbox* x = (t_my_numbox *)z; | ||
545 | |||
546 | if(doit) | ||
547 | { | ||
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) | ||
555 | { | ||
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); */ | ||
561 | |||
562 | x->x_buf[0] = 0; | ||
563 | } | ||
564 | else | ||
565 | { | ||
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); | ||
571 | } | ||
572 | } | ||
573 | return (1); | ||
574 | } | ||
575 | |||
576 | static void my_numbox_set(t_my_numbox *x, t_floatarg f) | ||
577 | { | ||
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); | ||
581 | } | ||
582 | |||
583 | static void my_numbox_log_height(t_my_numbox *x, t_floatarg lh) | ||
584 | { | ||
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; | ||
592 | |||
593 | } | ||
594 | |||
595 | static void my_numbox_float(t_my_numbox *x, t_floatarg f) | ||
596 | { | ||
597 | my_numbox_set(x, f); | ||
598 | if(x->x_gui.x_fsf.x_put_in2out) | ||
599 | my_numbox_bang(x); | ||
600 | } | ||
601 | |||
602 | static void my_numbox_size(t_my_numbox *x, t_symbol *s, int ac, t_atom *av) | ||
603 | { | ||
604 | int h, w; | ||
605 | |||
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) | ||
611 | { | ||
612 | h = (int)atom_getintarg(1, ac, av); | ||
613 | if(h < 8) | ||
614 | h = 8; | ||
615 | x->x_gui.x_h = h; | ||
616 | } | ||
617 | my_numbox_calc_fontwidth(x); | ||
618 | iemgui_size((void *)x, &x->x_gui); | ||
619 | } | ||
620 | |||
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);} | ||
623 | |||
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);} | ||
626 | |||
627 | static void my_numbox_range(t_my_numbox *x, t_symbol *s, int ac, t_atom *av) | ||
628 | { | ||
629 | if(my_numbox_check_minmax(x, (double)atom_getfloatarg(0, ac, av), | ||
630 | (double)atom_getfloatarg(1, ac, av))) | ||
631 | { | ||
632 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
633 | /*my_numbox_bang(x);*/ | ||
634 | } | ||
635 | } | ||
636 | |||
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);} | ||
639 | |||
640 | static void my_numbox_send(t_my_numbox *x, t_symbol *s) | ||
641 | {iemgui_send(x, &x->x_gui, s);} | ||
642 | |||
643 | static void my_numbox_receive(t_my_numbox *x, t_symbol *s) | ||
644 | {iemgui_receive(x, &x->x_gui, s);} | ||
645 | |||
646 | static void my_numbox_label(t_my_numbox *x, t_symbol *s) | ||
647 | {iemgui_label((void *)x, &x->x_gui, s);} | ||
648 | |||
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);} | ||
651 | |||
652 | static void my_numbox_label_font(t_my_numbox *x, | ||
653 | t_symbol *s, int ac, t_atom *av) | ||
654 | { | ||
655 | int f = (int)atom_getintarg(1, ac, av); | ||
656 | |||
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); | ||
666 | } | ||
667 | |||
668 | static void my_numbox_log(t_my_numbox *x) | ||
669 | { | ||
670 | x->x_lin0_log1 = 1; | ||
671 | if(my_numbox_check_minmax(x, x->x_min, x->x_max)) | ||
672 | { | ||
673 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
674 | /*my_numbox_bang(x);*/ | ||
675 | } | ||
676 | } | ||
677 | |||
678 | static void my_numbox_lin(t_my_numbox *x) | ||
679 | { | ||
680 | x->x_lin0_log1 = 0; | ||
681 | } | ||
682 | |||
683 | static void my_numbox_init(t_my_numbox *x, t_floatarg f) | ||
684 | { | ||
685 | x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1; | ||
686 | } | ||
687 | |||
688 | static void my_numbox_loadbang(t_my_numbox *x) | ||
689 | { | ||
690 | if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit) | ||
691 | { | ||
692 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
693 | my_numbox_bang(x); | ||
694 | } | ||
695 | } | ||
696 | |||
697 | static void my_numbox_key(void *z, t_floatarg fkey) | ||
698 | { | ||
699 | t_my_numbox *x = z; | ||
700 | char c=fkey; | ||
701 | char buf[3]; | ||
702 | buf[1] = 0; | ||
703 | |||
704 | if (c == 0) | ||
705 | { | ||
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; | ||
710 | } | ||
711 | if(((c>='0')&&(c<='9'))||(c=='.')||(c=='-')|| | ||
712 | (c=='e')||(c=='+')||(c=='E')) | ||
713 | { | ||
714 | if(strlen(x->x_buf) < (IEMGUI_MAX_NUM_LEN-2)) | ||
715 | { | ||
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); | ||
719 | } | ||
720 | } | ||
721 | else if((c=='\b')||(c==127)) | ||
722 | { | ||
723 | int sl=strlen(x->x_buf)-1; | ||
724 | |||
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); | ||
729 | } | ||
730 | else if((c=='\n')||(c==13)) | ||
731 | { | ||
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); | ||
739 | } | ||
740 | clock_delay(x->x_clock_reset, 3000); | ||
741 | } | ||
742 | |||
743 | static void my_numbox_list(t_my_numbox *x, t_symbol *s, int ac, t_atom *av) | ||
744 | { | ||
745 | if (IS_A_FLOAT(av,0)) | ||
746 | { | ||
747 | my_numbox_set(x, atom_getfloatarg(0, ac, av)); | ||
748 | my_numbox_bang(x); | ||
749 | } | ||
750 | } | ||
751 | |||
752 | static void *my_numbox_new(t_symbol *s, int argc, t_atom *argv) | ||
753 | { | ||
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]; | ||
762 | |||
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)) | ||
772 | { | ||
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); | ||
788 | } | ||
789 | else iemgui_new_getnames(&x->x_gui, 6, 0); | ||
790 | if((argc == 18)&&IS_A_FLOAT(argv,17)) | ||
791 | { | ||
792 | log_height = (int)atom_getintarg(17, argc, argv); | ||
793 | } | ||
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); | ||
838 | } | ||
839 | |||
840 | static void my_numbox_free(t_my_numbox *x) | ||
841 | { | ||
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); | ||
847 | } | ||
848 | |||
849 | void g_numbox_setup(void) | ||
850 | { | ||
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); | ||
907 | } | ||
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. */ | ||
911 | |||
912 | /* my_numbox.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */ | ||
913 | |||
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> | ||
923 | |||
924 | #ifdef MSW | ||
925 | #include <io.h> | ||
926 | #else | ||
927 | #include <unistd.h> | ||
928 | #endif | ||
929 | |||
930 | /*------------------ global varaibles -------------------------*/ | ||
931 | |||
932 | |||
933 | /*------------------ global functions -------------------------*/ | ||
934 | |||
935 | static void my_numbox_key(void *z, t_floatarg fkey); | ||
936 | |||
937 | /* ------------ nmx gui-my number box ----------------------- */ | ||
938 | |||
939 | t_widgetbehavior my_numbox_widgetbehavior; | ||
940 | static t_class *my_numbox_class; | ||
941 | |||
942 | /* widget helper functions */ | ||
943 | |||
944 | static void my_numbox_tick_reset(t_my_numbox *x) | ||
945 | { | ||
946 | if(x->x_gui.x_fsf.x_change) | ||
947 | { | ||
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); | ||
951 | } | ||
952 | } | ||
953 | |||
954 | static void my_numbox_tick_wait(t_my_numbox *x) | ||
955 | { | ||
956 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
957 | } | ||
958 | |||
959 | void my_numbox_clip(t_my_numbox *x) | ||
960 | { | ||
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; | ||
965 | } | ||
966 | |||
967 | void my_numbox_calc_fontwidth(t_my_numbox *x) | ||
968 | { | ||
969 | int w, f=31; | ||
970 | |||
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; | ||
975 | |||
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; | ||
979 | } | ||
980 | |||
981 | void my_numbox_ftoa(t_my_numbox *x) | ||
982 | { | ||
983 | double f=x->x_val; | ||
984 | int bufsize, is_exp=0, i, idecimal; | ||
985 | |||
986 | sprintf(x->x_buf, "%g", f); | ||
987 | bufsize = strlen(x->x_buf); | ||
988 | if(bufsize >= 5)/* if it is in exponential mode */ | ||
989 | { | ||
990 | i = bufsize - 4; | ||
991 | if((x->x_buf[i] == 'e') || (x->x_buf[i] == 'E')) | ||
992 | is_exp = 1; | ||
993 | } | ||
994 | if(bufsize > x->x_gui.x_w)/* if to reduce */ | ||
995 | { | ||
996 | if(is_exp) | ||
997 | { | ||
998 | if(x->x_gui.x_w <= 5) | ||
999 | { | ||
1000 | x->x_buf[0] = (f < 0.0 ? '-' : '+'); | ||
1001 | x->x_buf[1] = 0; | ||
1002 | } | ||
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)) | ||
1008 | { | ||
1009 | x->x_buf[0] = (f < 0.0 ? '-' : '+'); | ||
1010 | x->x_buf[1] = 0; | ||
1011 | } | ||
1012 | else | ||
1013 | { | ||
1014 | int new_exp_index=x->x_gui.x_w-4, old_exp_index=bufsize-4; | ||
1015 | |||
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; | ||
1019 | } | ||
1020 | |||
1021 | } | ||
1022 | else | ||
1023 | { | ||
1024 | for(idecimal=0; idecimal < bufsize; idecimal++) | ||
1025 | if(x->x_buf[idecimal] == '.') | ||
1026 | break; | ||
1027 | if(idecimal > x->x_gui.x_w) | ||
1028 | { | ||
1029 | x->x_buf[0] = (f < 0.0 ? '-' : '+'); | ||
1030 | x->x_buf[1] = 0; | ||
1031 | } | ||
1032 | else | ||
1033 | x->x_buf[x->x_gui.x_w] = 0; | ||
1034 | } | ||
1035 | } | ||
1036 | } | ||
1037 | |||
1038 | static void my_numbox_draw_update(t_my_numbox *x, t_glist *glist) | ||
1039 | { | ||
1040 | if (glist_isvisible(glist)) | ||
1041 | { | ||
1042 | if(x->x_gui.x_fsf.x_change) | ||
1043 | { | ||
1044 | if(x->x_buf[0]) | ||
1045 | { | ||
1046 | char *cp=x->x_buf; | ||
1047 | int sl = strlen(x->x_buf); | ||
1048 | |||
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; | ||
1057 | } | ||
1058 | else | ||
1059 | { | ||
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; | ||
1065 | } | ||
1066 | } | ||
1067 | else | ||
1068 | { | ||
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; | ||
1077 | } | ||
1078 | } | ||
1079 | } | ||
1080 | |||
1081 | static void my_numbox_draw_new(t_my_numbox *x, t_glist *glist) | ||
1082 | { | ||
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); | ||
1087 | |||
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); | ||
1125 | } | ||
1126 | |||
1127 | static void my_numbox_draw_move(t_my_numbox *x, t_glist *glist) | ||
1128 | { | ||
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); | ||
1133 | |||
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); | ||
1158 | } | ||
1159 | |||
1160 | static void my_numbox_draw_erase(t_my_numbox* x,t_glist* glist) | ||
1161 | { | ||
1162 | t_canvas *canvas=glist_getcanvas(glist); | ||
1163 | |||
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); | ||
1172 | } | ||
1173 | |||
1174 | static void my_numbox_draw_config(t_my_numbox* x,t_glist* glist) | ||
1175 | { | ||
1176 | t_canvas *canvas=glist_getcanvas(glist); | ||
1177 | |||
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); | ||
1189 | } | ||
1190 | |||
1191 | static void my_numbox_draw_io(t_my_numbox* x,t_glist* glist, int old_snd_rcv_flags) | ||
1192 | { | ||
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); | ||
1196 | |||
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); | ||
1213 | } | ||
1214 | |||
1215 | static void my_numbox_draw_select(t_my_numbox *x, t_glist *glist) | ||
1216 | { | ||
1217 | t_canvas *canvas=glist_getcanvas(glist); | ||
1218 | |||
1219 | if(x->x_gui.x_fsf.x_selected) | ||
1220 | { | ||
1221 | if(x->x_gui.x_fsf.x_change) | ||
1222 | { | ||
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); | ||
1227 | } | ||
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); | ||
1236 | } | ||
1237 | else | ||
1238 | { | ||
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); | ||
1247 | } | ||
1248 | } | ||
1249 | |||
1250 | void my_numbox_draw(t_my_numbox *x, t_glist *glist, int mode) | ||
1251 | { | ||
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); | ||
1266 | } | ||
1267 | |||
1268 | /* ------------------------ nbx widgetbehaviour----------------------------- */ | ||
1269 | |||
1270 | |||
1271 | static void my_numbox_getrect(t_gobj *z, t_glist *glist, | ||
1272 | int *xp1, int *yp1, int *xp2, int *yp2) | ||
1273 | { | ||
1274 | t_my_numbox* x = (t_my_numbox*)z; | ||
1275 | |||
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; | ||
1280 | } | ||
1281 | |||
1282 | static void my_numbox_save(t_gobj *z, t_binbuf *b) | ||
1283 | { | ||
1284 | t_my_numbox *x = (t_my_numbox *)z; | ||
1285 | int bflcol[3]; | ||
1286 | t_symbol *srl[3]; | ||
1287 | |||
1288 | iemgui_save(&x->x_gui, srl, bflcol); | ||
1289 | if(x->x_gui.x_fsf.x_change) | ||
1290 | { | ||
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); | ||
1295 | |||
1296 | } | ||
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, ";"); | ||
1308 | } | ||
1309 | |||
1310 | int my_numbox_check_minmax(t_my_numbox *x, double min, double max) | ||
1311 | { | ||
1312 | int ret=0; | ||
1313 | |||
1314 | if(x->x_lin0_log1) | ||
1315 | { | ||
1316 | if((min == 0.0)&&(max == 0.0)) | ||
1317 | max = 1.0; | ||
1318 | if(max > 0.0) | ||
1319 | { | ||
1320 | if(min <= 0.0) | ||
1321 | min = 0.01*max; | ||
1322 | } | ||
1323 | else | ||
1324 | { | ||
1325 | if(min > 0.0) | ||
1326 | max = 0.01*min; | ||
1327 | } | ||
1328 | } | ||
1329 | x->x_min = min; | ||
1330 | x->x_max = max; | ||
1331 | if(x->x_val < x->x_min) | ||
1332 | { | ||
1333 | x->x_val = x->x_min; | ||
1334 | ret = 1; | ||
1335 | } | ||
1336 | if(x->x_val > x->x_max) | ||
1337 | { | ||
1338 | x->x_val = x->x_max; | ||
1339 | ret = 1; | ||
1340 | } | ||
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); | ||
1346 | } | ||
1347 | |||
1348 | static void my_numbox_properties(t_gobj *z, t_glist *owner) | ||
1349 | { | ||
1350 | t_my_numbox *x = (t_my_numbox *)z; | ||
1351 | char buf[800]; | ||
1352 | t_symbol *srl[3]; | ||
1353 | |||
1354 | iemgui_properties(&x->x_gui, srl); | ||
1355 | if(x->x_gui.x_fsf.x_change) | ||
1356 | { | ||
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); | ||
1361 | |||
1362 | } | ||
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); | ||
1381 | } | ||
1382 | |||
1383 | static void my_numbox_bang(t_my_numbox *x) | ||
1384 | { | ||
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); | ||
1388 | } | ||
1389 | |||
1390 | static void my_numbox_dialog(t_my_numbox *x, t_symbol *s, int argc, | ||
1391 | t_atom *argv) | ||
1392 | { | ||
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; | ||
1401 | |||
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); | ||
1423 | } | ||
1424 | |||
1425 | static void my_numbox_motion(t_my_numbox *x, t_floatarg dx, t_floatarg dy) | ||
1426 | { | ||
1427 | double k2=1.0; | ||
1428 | |||
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); | ||
1439 | } | ||
1440 | |||
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) | ||
1443 | { | ||
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); | ||
1446 | } | ||
1447 | |||
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) | ||
1450 | { | ||
1451 | t_my_numbox* x = (t_my_numbox *)z; | ||
1452 | |||
1453 | if(doit) | ||
1454 | { | ||
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) | ||
1462 | { | ||
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); */ | ||
1468 | |||
1469 | x->x_buf[0] = 0; | ||
1470 | } | ||
1471 | else | ||
1472 | { | ||
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); | ||
1478 | } | ||
1479 | } | ||
1480 | return (1); | ||
1481 | } | ||
1482 | |||
1483 | static void my_numbox_set(t_my_numbox *x, t_floatarg f) | ||
1484 | { | ||
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); | ||
1488 | } | ||
1489 | |||
1490 | static void my_numbox_log_height(t_my_numbox *x, t_floatarg lh) | ||
1491 | { | ||
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; | ||
1499 | |||
1500 | } | ||
1501 | |||
1502 | static void my_numbox_float(t_my_numbox *x, t_floatarg f) | ||
1503 | { | ||
1504 | my_numbox_set(x, f); | ||
1505 | if(x->x_gui.x_fsf.x_put_in2out) | ||
1506 | my_numbox_bang(x); | ||
1507 | } | ||
1508 | |||
1509 | static void my_numbox_size(t_my_numbox *x, t_symbol *s, int ac, t_atom *av) | ||
1510 | { | ||
1511 | int h, w; | ||
1512 | |||
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) | ||
1518 | { | ||
1519 | h = (int)atom_getintarg(1, ac, av); | ||
1520 | if(h < 8) | ||
1521 | h = 8; | ||
1522 | x->x_gui.x_h = h; | ||
1523 | } | ||
1524 | my_numbox_calc_fontwidth(x); | ||
1525 | iemgui_size((void *)x, &x->x_gui); | ||
1526 | } | ||
1527 | |||
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);} | ||
1530 | |||
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);} | ||
1533 | |||
1534 | static void my_numbox_range(t_my_numbox *x, t_symbol *s, int ac, t_atom *av) | ||
1535 | { | ||
1536 | if(my_numbox_check_minmax(x, (double)atom_getfloatarg(0, ac, av), | ||
1537 | (double)atom_getfloatarg(1, ac, av))) | ||
1538 | { | ||
1539 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
1540 | /*my_numbox_bang(x);*/ | ||
1541 | } | ||
1542 | } | ||
1543 | |||
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);} | ||
1546 | |||
1547 | static void my_numbox_send(t_my_numbox *x, t_symbol *s) | ||
1548 | {iemgui_send(x, &x->x_gui, s);} | ||
1549 | |||
1550 | static void my_numbox_receive(t_my_numbox *x, t_symbol *s) | ||
1551 | {iemgui_receive(x, &x->x_gui, s);} | ||
1552 | |||
1553 | static void my_numbox_label(t_my_numbox *x, t_symbol *s) | ||
1554 | {iemgui_label((void *)x, &x->x_gui, s);} | ||
1555 | |||
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);} | ||
1558 | |||
1559 | static void my_numbox_label_font(t_my_numbox *x, | ||
1560 | t_symbol *s, int ac, t_atom *av) | ||
1561 | { | ||
1562 | int f = (int)atom_getintarg(1, ac, av); | ||
1563 | |||
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); | ||
1573 | } | ||
1574 | |||
1575 | static void my_numbox_log(t_my_numbox *x) | ||
1576 | { | ||
1577 | x->x_lin0_log1 = 1; | ||
1578 | if(my_numbox_check_minmax(x, x->x_min, x->x_max)) | ||
1579 | { | ||
1580 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
1581 | /*my_numbox_bang(x);*/ | ||
1582 | } | ||
1583 | } | ||
1584 | |||
1585 | static void my_numbox_lin(t_my_numbox *x) | ||
1586 | { | ||
1587 | x->x_lin0_log1 = 0; | ||
1588 | } | ||
1589 | |||
1590 | static void my_numbox_init(t_my_numbox *x, t_floatarg f) | ||
1591 | { | ||
1592 | x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1; | ||
1593 | } | ||
1594 | |||
1595 | static void my_numbox_loadbang(t_my_numbox *x) | ||
1596 | { | ||
1597 | if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit) | ||
1598 | { | ||
1599 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); | ||
1600 | my_numbox_bang(x); | ||
1601 | } | ||
1602 | } | ||
1603 | |||
1604 | static void my_numbox_key(void *z, t_floatarg fkey) | ||
1605 | { | ||
1606 | t_my_numbox *x = z; | ||
1607 | char c=fkey; | ||
1608 | char buf[3]; | ||
1609 | buf[1] = 0; | ||
1610 | |||
1611 | if (c == 0) | ||
1612 | { | ||
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; | ||
1617 | } | ||
1618 | if(((c>='0')&&(c<='9'))||(c=='.')||(c=='-')|| | ||
1619 | (c=='e')||(c=='+')||(c=='E')) | ||
1620 | { | ||
1621 | if(strlen(x->x_buf) < (IEMGUI_MAX_NUM_LEN-2)) | ||
1622 | { | ||
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); | ||
1626 | } | ||
1627 | } | ||
1628 | else if((c=='\b')||(c==127)) | ||
1629 | { | ||
1630 | int sl=strlen(x->x_buf)-1; | ||
1631 | |||
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); | ||
1636 | } | ||
1637 | else if((c=='\n')||(c==13)) | ||
1638 | { | ||
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); | ||
1646 | } | ||
1647 | clock_delay(x->x_clock_reset, 3000); | ||
1648 | } | ||
1649 | |||
1650 | static void my_numbox_list(t_my_numbox *x, t_symbol *s, int ac, t_atom *av) | ||
1651 | { | ||
1652 | if (IS_A_FLOAT(av,0)) | ||
1653 | { | ||
1654 | my_numbox_set(x, atom_getfloatarg(0, ac, av)); | ||
1655 | my_numbox_bang(x); | ||
1656 | } | ||
1657 | } | ||
1658 | |||
1659 | static void *my_numbox_new(t_symbol *s, int argc, t_atom *argv) | ||
1660 | { | ||
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]; | ||
1669 | |||
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)) | ||
1679 | { | ||
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); | ||
1695 | } | ||
1696 | else iemgui_new_getnames(&x->x_gui, 6, 0); | ||
1697 | if((argc == 18)&&IS_A_FLOAT(argv,17)) | ||
1698 | { | ||
1699 | log_height = (int)atom_getintarg(17, argc, argv); | ||
1700 | } | ||
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); | ||
1745 | } | ||
1746 | |||
1747 | static void my_numbox_free(t_my_numbox *x) | ||
1748 | { | ||
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); | ||
1754 | } | ||
1755 | |||
1756 | void g_numbox_setup(void) | ||
1757 | { | ||
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); | ||
1814 | } | ||