summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/g_vslider.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/g_vslider.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/g_vslider.c1254
1 files changed, 1254 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/g_vslider.c b/apps/plugins/pdbox/PDa/src/g_vslider.c
new file mode 100644
index 0000000000..8e2e326f30
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/src/g_vslider.c
@@ -0,0 +1,1254 @@
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/* g_7_guis.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
6/* thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja */
7
8
9#include <stdlib.h>
10#include <string.h>
11#include <stdio.h>
12#include <ctype.h>
13#include "m_pd.h"
14#include "g_canvas.h"
15#include "t_tk.h"
16#include "g_all_guis.h"
17#include <math.h>
18
19#ifdef MSW
20#include <io.h>
21#else
22#include <unistd.h>
23#endif
24
25
26/* ------------ vsl gui-vertical slider ----------------------- */
27
28t_widgetbehavior vslider_widgetbehavior;
29static t_class *vslider_class;
30
31/* widget helper functions */
32
33static void vslider_draw_update(t_vslider *x, t_glist *glist)
34{
35 if (glist_isvisible(glist))
36 {
37 int r = text_ypix(&x->x_gui.x_obj, glist) + x->x_gui.x_h - (x->x_val + 50)/100;
38 int xpos=text_xpix(&x->x_gui.x_obj, glist);
39
40 sys_vgui(".x%x.c coords %xKNOB %d %d %d %d\n",
41 glist_getcanvas(glist), x, xpos+1, r,
42 xpos + x->x_gui.x_w, r);
43 }
44}
45
46static void vslider_draw_new(t_vslider *x, t_glist *glist)
47{
48 int xpos=text_xpix(&x->x_gui.x_obj, glist);
49 int ypos=text_ypix(&x->x_gui.x_obj, glist);
50 int r = ypos + x->x_gui.x_h - (x->x_val + 50)/100;
51 t_canvas *canvas=glist_getcanvas(glist);
52
53 sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n",
54 canvas, xpos, ypos-2,
55 xpos + x->x_gui.x_w, ypos + x->x_gui.x_h+3,
56 x->x_gui.x_bcol, x);
57 sys_vgui(".x%x.c create line %d %d %d %d -width 3 -fill #%6.6x -tags %xKNOB\n",
58 canvas, xpos+1, r,
59 xpos + x->x_gui.x_w, r, x->x_gui.x_fcol, x);
60 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
61 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
62 canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
63 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
64 x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
65 if(!x->x_gui.x_fsf.x_snd_able)
66 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
67 canvas,
68 xpos, ypos + x->x_gui.x_h+2,
69 xpos+7, ypos + x->x_gui.x_h+3,
70 x, 0);
71 if(!x->x_gui.x_fsf.x_rcv_able)
72 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
73 canvas,
74 xpos, ypos-2,
75 xpos+7, ypos-1,
76 x, 0);
77}
78
79static void vslider_draw_move(t_vslider *x, t_glist *glist)
80{
81 int xpos=text_xpix(&x->x_gui.x_obj, glist);
82 int ypos=text_ypix(&x->x_gui.x_obj, glist);
83 int r = ypos + x->x_gui.x_h - (x->x_val + 50)/100;
84 t_canvas *canvas=glist_getcanvas(glist);
85
86 sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
87 canvas, x,
88 xpos, ypos-2,
89 xpos + x->x_gui.x_w, ypos + x->x_gui.x_h+3);
90 sys_vgui(".x%x.c coords %xKNOB %d %d %d %d\n",
91 canvas, x, xpos+1, r,
92 xpos + x->x_gui.x_w, r);
93 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
94 canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
95 if(!x->x_gui.x_fsf.x_snd_able)
96 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
97 canvas, x, 0,
98 xpos, ypos + x->x_gui.x_h+2,
99 xpos+7, ypos + x->x_gui.x_h+3);
100 if(!x->x_gui.x_fsf.x_rcv_able)
101 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
102 canvas, x, 0,
103 xpos, ypos-2,
104 xpos+7, ypos-1);
105}
106
107static void vslider_draw_erase(t_vslider* x,t_glist* glist)
108{
109 t_canvas *canvas=glist_getcanvas(glist);
110
111 sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
112 sys_vgui(".x%x.c delete %xKNOB\n", canvas, x);
113 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
114 if(!x->x_gui.x_fsf.x_snd_able)
115 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
116 if(!x->x_gui.x_fsf.x_rcv_able)
117 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
118}
119
120static void vslider_draw_config(t_vslider* x,t_glist* glist)
121{
122 t_canvas *canvas=glist_getcanvas(glist);
123
124 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
125 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
126 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
127 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
128 sys_vgui(".x%x.c itemconfigure %xKNOB -fill #%6.6x\n", canvas,
129 x, x->x_gui.x_fcol);
130 sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas,
131 x, x->x_gui.x_bcol);
132}
133
134static void vslider_draw_io(t_vslider* x,t_glist* glist, int old_snd_rcv_flags)
135{
136 int xpos=text_xpix(&x->x_gui.x_obj, glist);
137 int ypos=text_ypix(&x->x_gui.x_obj, glist);
138 t_canvas *canvas=glist_getcanvas(glist);
139
140 if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
141 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
142 canvas,
143 xpos, ypos + x->x_gui.x_h+2,
144 xpos+7, ypos + x->x_gui.x_h+3,
145 x, 0);
146 if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
147 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
148 if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
149 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
150 canvas,
151 xpos, ypos-2,
152 xpos+7, ypos-1,
153 x, 0);
154 if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
155 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
156}
157
158static void vslider_draw_select(t_vslider *x, t_glist *glist)
159{
160 t_canvas *canvas=glist_getcanvas(glist);
161
162 if(x->x_gui.x_fsf.x_selected)
163 {
164 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
165 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
166 }
167 else
168 {
169 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
170 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
171 }
172}
173
174void vslider_draw(t_vslider *x, t_glist *glist, int mode)
175{
176 if(mode == IEM_GUI_DRAW_MODE_UPDATE)
177 vslider_draw_update(x, glist);
178 else if(mode == IEM_GUI_DRAW_MODE_MOVE)
179 vslider_draw_move(x, glist);
180 else if(mode == IEM_GUI_DRAW_MODE_NEW)
181 vslider_draw_new(x, glist);
182 else if(mode == IEM_GUI_DRAW_MODE_SELECT)
183 vslider_draw_select(x, glist);
184 else if(mode == IEM_GUI_DRAW_MODE_ERASE)
185 vslider_draw_erase(x, glist);
186 else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
187 vslider_draw_config(x, glist);
188 else if(mode >= IEM_GUI_DRAW_MODE_IO)
189 vslider_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
190}
191
192/* ------------------------ vsl widgetbehaviour----------------------------- */
193
194
195static void vslider_getrect(t_gobj *z, t_glist *glist,
196 int *xp1, int *yp1, int *xp2, int *yp2)
197{
198 t_vslider* x = (t_vslider*)z;
199
200 *xp1 = text_xpix(&x->x_gui.x_obj, glist);
201 *yp1 = text_ypix(&x->x_gui.x_obj, glist) - 2;
202 *xp2 = *xp1 + x->x_gui.x_w;
203 *yp2 = *yp1 + x->x_gui.x_h + 5;
204}
205
206static void vslider_save(t_gobj *z, t_binbuf *b)
207{
208 t_vslider *x = (t_vslider *)z;
209 int bflcol[3];
210 t_symbol *srl[3];
211
212 iemgui_save(&x->x_gui, srl, bflcol);
213 binbuf_addv(b, "ssiisiiffiisssiiiiiiiii", gensym("#X"),gensym("obj"),
214 (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
215 gensym("vsl"), x->x_gui.x_w, x->x_gui.x_h,
216 (float)x->x_min, (float)x->x_max,
217 x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa),
218 srl[0], srl[1], srl[2],
219 x->x_gui.x_ldx, x->x_gui.x_ldy,
220 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
221 bflcol[0], bflcol[1], bflcol[2],
222 x->x_val, x->x_steady);
223 binbuf_addv(b, ";");
224}
225
226void vslider_check_height(t_vslider *x, int h)
227{
228 if(h < IEM_SL_MINSIZE)
229 h = IEM_SL_MINSIZE;
230 x->x_gui.x_h = h;
231 if(x->x_val > (x->x_gui.x_h*100 - 100))
232 {
233 x->x_pos = x->x_gui.x_h*100 - 100;
234 x->x_val = x->x_pos;
235 }
236 if(x->x_lin0_log1)
237 x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_h - 1);
238 else
239 x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
240}
241
242void vslider_check_minmax(t_vslider *x, double min, double max)
243{
244 if(x->x_lin0_log1)
245 {
246 if((min == 0.0)&&(max == 0.0))
247 max = 1.0;
248 if(max > 0.0)
249 {
250 if(min <= 0.0)
251 min = 0.01*max;
252 }
253 else
254 {
255 if(min > 0.0)
256 max = 0.01*min;
257 }
258 }
259 x->x_min = min;
260 x->x_max = max;
261 if(x->x_min > x->x_max) /* bugfix */
262 x->x_gui.x_isa.x_reverse = 1;
263 else
264 x->x_gui.x_isa.x_reverse = 0;
265 if(x->x_lin0_log1)
266 x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_h - 1);
267 else
268 x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
269}
270
271static void vslider_properties(t_gobj *z, t_glist *owner)
272{
273 t_vslider *x = (t_vslider *)z;
274 char buf[800];
275 t_symbol *srl[3];
276
277 iemgui_properties(&x->x_gui, srl);
278
279 sprintf(buf, "pdtk_iemgui_dialog %%s VSLIDER \
280 --------dimensions(pix)(pix):-------- %d %d width: %d %d height: \
281 -----------output-range:----------- %g bottom: %g top: %d \
282 %d lin log %d %d empty %d \
283 %s %s \
284 %s %d %d \
285 %d %d \
286 %d %d %d\n",
287 x->x_gui.x_w, IEM_GUI_MINSIZE, x->x_gui.x_h, IEM_SL_MINSIZE,
288 x->x_min, x->x_max, 0,/*no_schedule*/
289 x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, x->x_steady, -1,/*no multi, but iem-characteristic*/
290 srl[0]->s_name, srl[1]->s_name,
291 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
292 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
293 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
294 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
295}
296
297static void vslider_bang(t_vslider *x)
298{
299 double out;
300
301 if(x->x_lin0_log1)
302 out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01);
303 else
304 out = (double)(x->x_val)*0.01*x->x_k + x->x_min;
305 if((out < 1.0e-10)&&(out > -1.0e-10))
306 out = 0.0;
307
308 outlet_float(x->x_gui.x_obj.ob_outlet, out);
309 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
310 pd_float(x->x_gui.x_snd->s_thing, out);
311}
312
313static void vslider_dialog(t_vslider *x, t_symbol *s, int argc, t_atom *argv)
314{
315 t_symbol *srl[3];
316 int w = (int)atom_getintarg(0, argc, argv);
317 int h = (int)atom_getintarg(1, argc, argv);
318 double min = (double)atom_getfloatarg(2, argc, argv);
319 double max = (double)atom_getfloatarg(3, argc, argv);
320 int lilo = (int)atom_getintarg(4, argc, argv);
321 int steady = (int)atom_getintarg(17, argc, argv);
322 int sr_flags;
323
324 if(lilo != 0) lilo = 1;
325 x->x_lin0_log1 = lilo;
326 if(steady)
327 x->x_steady = 1;
328 else
329 x->x_steady = 0;
330 sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
331 x->x_gui.x_w = iemgui_clip_size(w);
332 vslider_check_height(x, h);
333 vslider_check_minmax(x, min, max);
334 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
335 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
336 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
337 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
338}
339
340static void vslider_motion(t_vslider *x, t_floatarg dx, t_floatarg dy)
341{
342 int old = x->x_val;
343
344 if(x->x_gui.x_fsf.x_finemoved)
345 x->x_pos -= (int)dy;
346 else
347 x->x_pos -= 100*(int)dy;
348 x->x_val = x->x_pos;
349 if(x->x_val > (100*x->x_gui.x_h - 100))
350 {
351 x->x_val = 100*x->x_gui.x_h - 100;
352 x->x_pos += 50;
353 x->x_pos -= x->x_pos%100;
354 }
355 if(x->x_val < 0)
356 {
357 x->x_val = 0;
358 x->x_pos -= 50;
359 x->x_pos -= x->x_pos%100;
360 }
361 if(old != x->x_val)
362 {
363 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
364 vslider_bang(x);
365 }
366}
367
368static void vslider_click(t_vslider *x, t_floatarg xpos, t_floatarg ypos,
369 t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
370{
371 if(!x->x_steady)
372 x->x_val = (int)(100.0 * (x->x_gui.x_h + text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist) - ypos));
373 if(x->x_val > (100*x->x_gui.x_h - 100))
374 x->x_val = 100*x->x_gui.x_h - 100;
375 if(x->x_val < 0)
376 x->x_val = 0;
377 x->x_pos = x->x_val;
378 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
379 vslider_bang(x);
380 glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g,
381 (t_glistmotionfn)vslider_motion, 0, xpos, ypos);
382}
383
384static int vslider_newclick(t_gobj *z, struct _glist *glist,
385 int xpix, int ypix, int shift, int alt, int dbl, int doit)
386{
387 t_vslider* x = (t_vslider *)z;
388
389 if(doit)
390 {
391 vslider_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift,
392 0, (t_floatarg)alt);
393 if(shift)
394 x->x_gui.x_fsf.x_finemoved = 1;
395 else
396 x->x_gui.x_fsf.x_finemoved = 0;
397 }
398 return (1);
399}
400
401static void vslider_set(t_vslider *x, t_floatarg f)
402{
403 double g;
404
405 if(x->x_gui.x_isa.x_reverse) /* bugfix */
406 {
407 if(f > x->x_min)
408 f = x->x_min;
409 if(f < x->x_max)
410 f = x->x_max;
411 }
412 else
413 {
414 if(f > x->x_max)
415 f = x->x_max;
416 if(f < x->x_min)
417 f = x->x_min;
418 }
419 if(x->x_lin0_log1)
420 g = log(f/x->x_min)/x->x_k;
421 else
422 g = (f - x->x_min) / x->x_k;
423 x->x_val = (int)(100.0*g + 0.49999);
424 x->x_pos = x->x_val;
425 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
426}
427
428static void vslider_float(t_vslider *x, t_floatarg f)
429{
430 vslider_set(x, f);
431 if(x->x_gui.x_fsf.x_put_in2out)
432 vslider_bang(x);
433}
434
435static void vslider_size(t_vslider *x, t_symbol *s, int ac, t_atom *av)
436{
437 x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av));
438 if(ac > 1)
439 vslider_check_height(x, (int)atom_getintarg(1, ac, av));
440 iemgui_size((void *)x, &x->x_gui);
441}
442
443static void vslider_delta(t_vslider *x, t_symbol *s, int ac, t_atom *av)
444{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
445
446static void vslider_pos(t_vslider *x, t_symbol *s, int ac, t_atom *av)
447{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
448
449static void vslider_range(t_vslider *x, t_symbol *s, int ac, t_atom *av)
450{
451 vslider_check_minmax(x, (double)atom_getfloatarg(0, ac, av),
452 (double)atom_getfloatarg(1, ac, av));
453}
454
455static void vslider_color(t_vslider *x, t_symbol *s, int ac, t_atom *av)
456{iemgui_color((void *)x, &x->x_gui, s, ac, av);}
457
458static void vslider_send(t_vslider *x, t_symbol *s)
459{iemgui_send(x, &x->x_gui, s);}
460
461static void vslider_receive(t_vslider *x, t_symbol *s)
462{iemgui_receive(x, &x->x_gui, s);}
463
464static void vslider_label(t_vslider *x, t_symbol *s)
465{iemgui_label((void *)x, &x->x_gui, s);}
466
467static void vslider_label_pos(t_vslider *x, t_symbol *s, int ac, t_atom *av)
468{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
469
470static void vslider_label_font(t_vslider *x, t_symbol *s, int ac, t_atom *av)
471{iemgui_label_font((void *)x, &x->x_gui, s, ac, av);}
472
473static void vslider_log(t_vslider *x)
474{
475 x->x_lin0_log1 = 1;
476 vslider_check_minmax(x, x->x_min, x->x_max);
477}
478
479static void vslider_lin(t_vslider *x)
480{
481 x->x_lin0_log1 = 0;
482 x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
483}
484
485static void vslider_init(t_vslider *x, t_floatarg f)
486{
487 x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1;
488}
489
490static void vslider_steady(t_vslider *x, t_floatarg f)
491{
492 x->x_steady = (f==0.0)?0:1;
493}
494
495static void vslider_loadbang(t_vslider *x)
496{
497 if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
498 {
499 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
500 vslider_bang(x);
501 }
502}
503
504static void *vslider_new(t_symbol *s, int argc, t_atom *argv)
505{
506 t_vslider *x = (t_vslider *)pd_new(vslider_class);
507 int bflcol[]={-262144, -1, -1};
508 int w=IEM_GUI_DEFAULTSIZE, h=IEM_SL_DEFAULTSIZE;
509 int lilo=0, f=0, ldx=0, ldy=-8;
510 int fs=8, v=0, steady=1;
511 double min=0.0, max=(double)(IEM_SL_DEFAULTSIZE-1);
512 char str[144];
513
514 iem_inttosymargs(&x->x_gui.x_isa, 0);
515 iem_inttofstyle(&x->x_gui.x_fsf, 0);
516
517 if(((argc == 17)||(argc == 18))&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
518 &&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3)
519 &&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5)
520 &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6))
521 &&(IS_A_SYMBOL(argv,7)||IS_A_FLOAT(argv,7))
522 &&(IS_A_SYMBOL(argv,8)||IS_A_FLOAT(argv,8))
523 &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)
524 &&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)
525 &&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15)&&IS_A_FLOAT(argv,16))
526 {
527 w = (int)atom_getintarg(0, argc, argv);
528 h = (int)atom_getintarg(1, argc, argv);
529 min = (double)atom_getfloatarg(2, argc, argv);
530 max = (double)atom_getfloatarg(3, argc, argv);
531 lilo = (int)atom_getintarg(4, argc, argv);
532 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
533 iemgui_new_getnames(&x->x_gui, 6, argv);
534 ldx = (int)atom_getintarg(9, argc, argv);
535 ldy = (int)atom_getintarg(10, argc, argv);
536 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
537 fs = (int)atom_getintarg(12, argc, argv);
538 bflcol[0] = (int)atom_getintarg(13, argc, argv);
539 bflcol[1] = (int)atom_getintarg(14, argc, argv);
540 bflcol[2] = (int)atom_getintarg(15, argc, argv);
541 v = (int)atom_getintarg(16, argc, argv);
542 }
543 else iemgui_new_getnames(&x->x_gui, 6, 0);
544 if((argc == 18)&&IS_A_FLOAT(argv,17))
545 steady = (int)atom_getintarg(17, argc, argv);
546 x->x_gui.x_draw = (t_iemfunptr)vslider_draw;
547 x->x_gui.x_fsf.x_snd_able = 1;
548 x->x_gui.x_fsf.x_rcv_able = 1;
549 x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
550 if(x->x_gui.x_isa.x_loadinit)
551 x->x_val = v;
552 else
553 x->x_val = 0;
554 x->x_pos = x->x_val;
555 if(lilo != 0) lilo = 1;
556 x->x_lin0_log1 = lilo;
557 if(steady != 0) steady = 1;
558 x->x_steady = steady;
559 if(!strcmp(x->x_gui.x_snd->s_name, "empty")) x->x_gui.x_fsf.x_snd_able = 0;
560 if(!strcmp(x->x_gui.x_rcv->s_name, "empty")) x->x_gui.x_fsf.x_rcv_able = 0;
561 if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
562 else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
563 else { x->x_gui.x_fsf.x_font_style = 0;
564 strcpy(x->x_gui.x_font, "courier"); }
565 if(x->x_gui.x_fsf.x_rcv_able) pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
566 x->x_gui.x_ldx = ldx;
567 x->x_gui.x_ldy = ldy;
568 if(fs < 4)
569 fs = 4;
570 x->x_gui.x_fontsize = fs;
571 x->x_gui.x_w = iemgui_clip_size(w);
572 vslider_check_height(x, h);
573 vslider_check_minmax(x, min, max);
574 iemgui_all_colfromload(&x->x_gui, bflcol);
575 iemgui_verify_snd_ne_rcv(&x->x_gui);
576 outlet_new(&x->x_gui.x_obj, &s_float);
577 return (x);
578}
579
580static void vslider_free(t_vslider *x)
581{
582 if(x->x_gui.x_fsf.x_rcv_able)
583 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
584 gfxstub_deleteforkey(x);
585}
586
587void g_vslider_setup(void)
588{
589 vslider_class = class_new(gensym("vsl"), (t_newmethod)vslider_new,
590 (t_method)vslider_free, sizeof(t_vslider), 0, A_GIMME, 0);
591 class_addcreator((t_newmethod)vslider_new, gensym("vslider"), A_GIMME, 0);
592 class_addbang(vslider_class,vslider_bang);
593 class_addfloat(vslider_class,vslider_float);
594 class_addmethod(vslider_class, (t_method)vslider_click, gensym("click"),
595 A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
596 class_addmethod(vslider_class, (t_method)vslider_motion, gensym("motion"),
597 A_FLOAT, A_FLOAT, 0);
598 class_addmethod(vslider_class, (t_method)vslider_dialog, gensym("dialog"),
599 A_GIMME, 0);
600 class_addmethod(vslider_class, (t_method)vslider_loadbang, gensym("loadbang"), 0);
601 class_addmethod(vslider_class, (t_method)vslider_set, gensym("set"), A_FLOAT, 0);
602 class_addmethod(vslider_class, (t_method)vslider_size, gensym("size"), A_GIMME, 0);
603 class_addmethod(vslider_class, (t_method)vslider_delta, gensym("delta"), A_GIMME, 0);
604 class_addmethod(vslider_class, (t_method)vslider_pos, gensym("pos"), A_GIMME, 0);
605 class_addmethod(vslider_class, (t_method)vslider_range, gensym("range"), A_GIMME, 0);
606 class_addmethod(vslider_class, (t_method)vslider_color, gensym("color"), A_GIMME, 0);
607 class_addmethod(vslider_class, (t_method)vslider_send, gensym("send"), A_DEFSYM, 0);
608 class_addmethod(vslider_class, (t_method)vslider_receive, gensym("receive"), A_DEFSYM, 0);
609 class_addmethod(vslider_class, (t_method)vslider_label, gensym("label"), A_DEFSYM, 0);
610 class_addmethod(vslider_class, (t_method)vslider_label_pos, gensym("label_pos"), A_GIMME, 0);
611 class_addmethod(vslider_class, (t_method)vslider_label_font, gensym("label_font"), A_GIMME, 0);
612 class_addmethod(vslider_class, (t_method)vslider_log, gensym("log"), 0);
613 class_addmethod(vslider_class, (t_method)vslider_lin, gensym("lin"), 0);
614 class_addmethod(vslider_class, (t_method)vslider_init, gensym("init"), A_FLOAT, 0);
615 class_addmethod(vslider_class, (t_method)vslider_steady, gensym("steady"), A_FLOAT, 0);
616 vslider_widgetbehavior.w_getrectfn = vslider_getrect;
617 vslider_widgetbehavior.w_displacefn = iemgui_displace;
618 vslider_widgetbehavior.w_selectfn = iemgui_select;
619 vslider_widgetbehavior.w_activatefn = NULL;
620 vslider_widgetbehavior.w_deletefn = iemgui_delete;
621 vslider_widgetbehavior.w_visfn = iemgui_vis;
622 vslider_widgetbehavior.w_clickfn = vslider_newclick;
623 class_setwidget(vslider_class, &vslider_widgetbehavior);
624 class_sethelpsymbol(vslider_class, gensym("vslider"));
625 class_setsavefn(vslider_class, vslider_save);
626 class_setpropertiesfn(vslider_class, vslider_properties);
627}
628/* Copyright (c) 1997-1999 Miller Puckette.
629 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
630 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
631
632/* g_7_guis.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
633/* thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja */
634
635
636#include <stdlib.h>
637#include <string.h>
638#include <stdio.h>
639#include <ctype.h>
640#include "m_pd.h"
641#include "g_canvas.h"
642#include "t_tk.h"
643#include "g_all_guis.h"
644#include <math.h>
645
646#ifdef MSW
647#include <io.h>
648#else
649#include <unistd.h>
650#endif
651
652
653/* ------------ vsl gui-vertical slider ----------------------- */
654
655t_widgetbehavior vslider_widgetbehavior;
656static t_class *vslider_class;
657
658/* widget helper functions */
659
660static void vslider_draw_update(t_vslider *x, t_glist *glist)
661{
662 if (glist_isvisible(glist))
663 {
664 int r = text_ypix(&x->x_gui.x_obj, glist) + x->x_gui.x_h - (x->x_val + 50)/100;
665 int xpos=text_xpix(&x->x_gui.x_obj, glist);
666
667 sys_vgui(".x%x.c coords %xKNOB %d %d %d %d\n",
668 glist_getcanvas(glist), x, xpos+1, r,
669 xpos + x->x_gui.x_w, r);
670 }
671}
672
673static void vslider_draw_new(t_vslider *x, t_glist *glist)
674{
675 int xpos=text_xpix(&x->x_gui.x_obj, glist);
676 int ypos=text_ypix(&x->x_gui.x_obj, glist);
677 int r = ypos + x->x_gui.x_h - (x->x_val + 50)/100;
678 t_canvas *canvas=glist_getcanvas(glist);
679
680 sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n",
681 canvas, xpos, ypos-2,
682 xpos + x->x_gui.x_w, ypos + x->x_gui.x_h+3,
683 x->x_gui.x_bcol, x);
684 sys_vgui(".x%x.c create line %d %d %d %d -width 3 -fill #%6.6x -tags %xKNOB\n",
685 canvas, xpos+1, r,
686 xpos + x->x_gui.x_w, r, x->x_gui.x_fcol, x);
687 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
688 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
689 canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
690 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
691 x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
692 if(!x->x_gui.x_fsf.x_snd_able)
693 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
694 canvas,
695 xpos, ypos + x->x_gui.x_h+2,
696 xpos+7, ypos + x->x_gui.x_h+3,
697 x, 0);
698 if(!x->x_gui.x_fsf.x_rcv_able)
699 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
700 canvas,
701 xpos, ypos-2,
702 xpos+7, ypos-1,
703 x, 0);
704}
705
706static void vslider_draw_move(t_vslider *x, t_glist *glist)
707{
708 int xpos=text_xpix(&x->x_gui.x_obj, glist);
709 int ypos=text_ypix(&x->x_gui.x_obj, glist);
710 int r = ypos + x->x_gui.x_h - (x->x_val + 50)/100;
711 t_canvas *canvas=glist_getcanvas(glist);
712
713 sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
714 canvas, x,
715 xpos, ypos-2,
716 xpos + x->x_gui.x_w, ypos + x->x_gui.x_h+3);
717 sys_vgui(".x%x.c coords %xKNOB %d %d %d %d\n",
718 canvas, x, xpos+1, r,
719 xpos + x->x_gui.x_w, r);
720 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
721 canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
722 if(!x->x_gui.x_fsf.x_snd_able)
723 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
724 canvas, x, 0,
725 xpos, ypos + x->x_gui.x_h+2,
726 xpos+7, ypos + x->x_gui.x_h+3);
727 if(!x->x_gui.x_fsf.x_rcv_able)
728 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
729 canvas, x, 0,
730 xpos, ypos-2,
731 xpos+7, ypos-1);
732}
733
734static void vslider_draw_erase(t_vslider* x,t_glist* glist)
735{
736 t_canvas *canvas=glist_getcanvas(glist);
737
738 sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
739 sys_vgui(".x%x.c delete %xKNOB\n", canvas, x);
740 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
741 if(!x->x_gui.x_fsf.x_snd_able)
742 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
743 if(!x->x_gui.x_fsf.x_rcv_able)
744 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
745}
746
747static void vslider_draw_config(t_vslider* x,t_glist* glist)
748{
749 t_canvas *canvas=glist_getcanvas(glist);
750
751 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
752 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
753 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
754 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
755 sys_vgui(".x%x.c itemconfigure %xKNOB -fill #%6.6x\n", canvas,
756 x, x->x_gui.x_fcol);
757 sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas,
758 x, x->x_gui.x_bcol);
759}
760
761static void vslider_draw_io(t_vslider* x,t_glist* glist, int old_snd_rcv_flags)
762{
763 int xpos=text_xpix(&x->x_gui.x_obj, glist);
764 int ypos=text_ypix(&x->x_gui.x_obj, glist);
765 t_canvas *canvas=glist_getcanvas(glist);
766
767 if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
768 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
769 canvas,
770 xpos, ypos + x->x_gui.x_h+2,
771 xpos+7, ypos + x->x_gui.x_h+3,
772 x, 0);
773 if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
774 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
775 if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
776 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
777 canvas,
778 xpos, ypos-2,
779 xpos+7, ypos-1,
780 x, 0);
781 if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
782 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
783}
784
785static void vslider_draw_select(t_vslider *x, t_glist *glist)
786{
787 t_canvas *canvas=glist_getcanvas(glist);
788
789 if(x->x_gui.x_fsf.x_selected)
790 {
791 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
792 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
793 }
794 else
795 {
796 sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
797 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
798 }
799}
800
801void vslider_draw(t_vslider *x, t_glist *glist, int mode)
802{
803 if(mode == IEM_GUI_DRAW_MODE_UPDATE)
804 vslider_draw_update(x, glist);
805 else if(mode == IEM_GUI_DRAW_MODE_MOVE)
806 vslider_draw_move(x, glist);
807 else if(mode == IEM_GUI_DRAW_MODE_NEW)
808 vslider_draw_new(x, glist);
809 else if(mode == IEM_GUI_DRAW_MODE_SELECT)
810 vslider_draw_select(x, glist);
811 else if(mode == IEM_GUI_DRAW_MODE_ERASE)
812 vslider_draw_erase(x, glist);
813 else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
814 vslider_draw_config(x, glist);
815 else if(mode >= IEM_GUI_DRAW_MODE_IO)
816 vslider_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
817}
818
819/* ------------------------ vsl widgetbehaviour----------------------------- */
820
821
822static void vslider_getrect(t_gobj *z, t_glist *glist,
823 int *xp1, int *yp1, int *xp2, int *yp2)
824{
825 t_vslider* x = (t_vslider*)z;
826
827 *xp1 = text_xpix(&x->x_gui.x_obj, glist);
828 *yp1 = text_ypix(&x->x_gui.x_obj, glist) - 2;
829 *xp2 = *xp1 + x->x_gui.x_w;
830 *yp2 = *yp1 + x->x_gui.x_h + 5;
831}
832
833static void vslider_save(t_gobj *z, t_binbuf *b)
834{
835 t_vslider *x = (t_vslider *)z;
836 int bflcol[3];
837 t_symbol *srl[3];
838
839 iemgui_save(&x->x_gui, srl, bflcol);
840 binbuf_addv(b, "ssiisiiffiisssiiiiiiiii", gensym("#X"),gensym("obj"),
841 (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
842 gensym("vsl"), x->x_gui.x_w, x->x_gui.x_h,
843 (float)x->x_min, (float)x->x_max,
844 x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa),
845 srl[0], srl[1], srl[2],
846 x->x_gui.x_ldx, x->x_gui.x_ldy,
847 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
848 bflcol[0], bflcol[1], bflcol[2],
849 x->x_val, x->x_steady);
850 binbuf_addv(b, ";");
851}
852
853void vslider_check_height(t_vslider *x, int h)
854{
855 if(h < IEM_SL_MINSIZE)
856 h = IEM_SL_MINSIZE;
857 x->x_gui.x_h = h;
858 if(x->x_val > (x->x_gui.x_h*100 - 100))
859 {
860 x->x_pos = x->x_gui.x_h*100 - 100;
861 x->x_val = x->x_pos;
862 }
863 if(x->x_lin0_log1)
864 x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_h - 1);
865 else
866 x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
867}
868
869void vslider_check_minmax(t_vslider *x, double min, double max)
870{
871 if(x->x_lin0_log1)
872 {
873 if((min == 0.0)&&(max == 0.0))
874 max = 1.0;
875 if(max > 0.0)
876 {
877 if(min <= 0.0)
878 min = 0.01*max;
879 }
880 else
881 {
882 if(min > 0.0)
883 max = 0.01*min;
884 }
885 }
886 x->x_min = min;
887 x->x_max = max;
888 if(x->x_min > x->x_max) /* bugfix */
889 x->x_gui.x_isa.x_reverse = 1;
890 else
891 x->x_gui.x_isa.x_reverse = 0;
892 if(x->x_lin0_log1)
893 x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_h - 1);
894 else
895 x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
896}
897
898static void vslider_properties(t_gobj *z, t_glist *owner)
899{
900 t_vslider *x = (t_vslider *)z;
901 char buf[800];
902 t_symbol *srl[3];
903
904 iemgui_properties(&x->x_gui, srl);
905
906 sprintf(buf, "pdtk_iemgui_dialog %%s VSLIDER \
907 --------dimensions(pix)(pix):-------- %d %d width: %d %d height: \
908 -----------output-range:----------- %g bottom: %g top: %d \
909 %d lin log %d %d empty %d \
910 %s %s \
911 %s %d %d \
912 %d %d \
913 %d %d %d\n",
914 x->x_gui.x_w, IEM_GUI_MINSIZE, x->x_gui.x_h, IEM_SL_MINSIZE,
915 x->x_min, x->x_max, 0,/*no_schedule*/
916 x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, x->x_steady, -1,/*no multi, but iem-characteristic*/
917 srl[0]->s_name, srl[1]->s_name,
918 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
919 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
920 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
921 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
922}
923
924static void vslider_bang(t_vslider *x)
925{
926 double out;
927
928 if(x->x_lin0_log1)
929 out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01);
930 else
931 out = (double)(x->x_val)*0.01*x->x_k + x->x_min;
932 if((out < 1.0e-10)&&(out > -1.0e-10))
933 out = 0.0;
934
935 outlet_float(x->x_gui.x_obj.ob_outlet, out);
936 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
937 pd_float(x->x_gui.x_snd->s_thing, out);
938}
939
940static void vslider_dialog(t_vslider *x, t_symbol *s, int argc, t_atom *argv)
941{
942 t_symbol *srl[3];
943 int w = (int)atom_getintarg(0, argc, argv);
944 int h = (int)atom_getintarg(1, argc, argv);
945 double min = (double)atom_getfloatarg(2, argc, argv);
946 double max = (double)atom_getfloatarg(3, argc, argv);
947 int lilo = (int)atom_getintarg(4, argc, argv);
948 int steady = (int)atom_getintarg(17, argc, argv);
949 int sr_flags;
950
951 if(lilo != 0) lilo = 1;
952 x->x_lin0_log1 = lilo;
953 if(steady)
954 x->x_steady = 1;
955 else
956 x->x_steady = 0;
957 sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
958 x->x_gui.x_w = iemgui_clip_size(w);
959 vslider_check_height(x, h);
960 vslider_check_minmax(x, min, max);
961 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
962 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
963 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
964 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
965}
966
967static void vslider_motion(t_vslider *x, t_floatarg dx, t_floatarg dy)
968{
969 int old = x->x_val;
970
971 if(x->x_gui.x_fsf.x_finemoved)
972 x->x_pos -= (int)dy;
973 else
974 x->x_pos -= 100*(int)dy;
975 x->x_val = x->x_pos;
976 if(x->x_val > (100*x->x_gui.x_h - 100))
977 {
978 x->x_val = 100*x->x_gui.x_h - 100;
979 x->x_pos += 50;
980 x->x_pos -= x->x_pos%100;
981 }
982 if(x->x_val < 0)
983 {
984 x->x_val = 0;
985 x->x_pos -= 50;
986 x->x_pos -= x->x_pos%100;
987 }
988 if(old != x->x_val)
989 {
990 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
991 vslider_bang(x);
992 }
993}
994
995static void vslider_click(t_vslider *x, t_floatarg xpos, t_floatarg ypos,
996 t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
997{
998 if(!x->x_steady)
999 x->x_val = (int)(100.0 * (x->x_gui.x_h + text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist) - ypos));
1000 if(x->x_val > (100*x->x_gui.x_h - 100))
1001 x->x_val = 100*x->x_gui.x_h - 100;
1002 if(x->x_val < 0)
1003 x->x_val = 0;
1004 x->x_pos = x->x_val;
1005 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1006 vslider_bang(x);
1007 glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g,
1008 (t_glistmotionfn)vslider_motion, 0, xpos, ypos);
1009}
1010
1011static int vslider_newclick(t_gobj *z, struct _glist *glist,
1012 int xpix, int ypix, int shift, int alt, int dbl, int doit)
1013{
1014 t_vslider* x = (t_vslider *)z;
1015
1016 if(doit)
1017 {
1018 vslider_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift,
1019 0, (t_floatarg)alt);
1020 if(shift)
1021 x->x_gui.x_fsf.x_finemoved = 1;
1022 else
1023 x->x_gui.x_fsf.x_finemoved = 0;
1024 }
1025 return (1);
1026}
1027
1028static void vslider_set(t_vslider *x, t_floatarg f)
1029{
1030 double g;
1031
1032 if(x->x_gui.x_isa.x_reverse) /* bugfix */
1033 {
1034 if(f > x->x_min)
1035 f = x->x_min;
1036 if(f < x->x_max)
1037 f = x->x_max;
1038 }
1039 else
1040 {
1041 if(f > x->x_max)
1042 f = x->x_max;
1043 if(f < x->x_min)
1044 f = x->x_min;
1045 }
1046 if(x->x_lin0_log1)
1047 g = log(f/x->x_min)/x->x_k;
1048 else
1049 g = (f - x->x_min) / x->x_k;
1050 x->x_val = (int)(100.0*g + 0.49999);
1051 x->x_pos = x->x_val;
1052 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1053}
1054
1055static void vslider_float(t_vslider *x, t_floatarg f)
1056{
1057 vslider_set(x, f);
1058 if(x->x_gui.x_fsf.x_put_in2out)
1059 vslider_bang(x);
1060}
1061
1062static void vslider_size(t_vslider *x, t_symbol *s, int ac, t_atom *av)
1063{
1064 x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av));
1065 if(ac > 1)
1066 vslider_check_height(x, (int)atom_getintarg(1, ac, av));
1067 iemgui_size((void *)x, &x->x_gui);
1068}
1069
1070static void vslider_delta(t_vslider *x, t_symbol *s, int ac, t_atom *av)
1071{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
1072
1073static void vslider_pos(t_vslider *x, t_symbol *s, int ac, t_atom *av)
1074{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
1075
1076static void vslider_range(t_vslider *x, t_symbol *s, int ac, t_atom *av)
1077{
1078 vslider_check_minmax(x, (double)atom_getfloatarg(0, ac, av),
1079 (double)atom_getfloatarg(1, ac, av));
1080}
1081
1082static void vslider_color(t_vslider *x, t_symbol *s, int ac, t_atom *av)
1083{iemgui_color((void *)x, &x->x_gui, s, ac, av);}
1084
1085static void vslider_send(t_vslider *x, t_symbol *s)
1086{iemgui_send(x, &x->x_gui, s);}
1087
1088static void vslider_receive(t_vslider *x, t_symbol *s)
1089{iemgui_receive(x, &x->x_gui, s);}
1090
1091static void vslider_label(t_vslider *x, t_symbol *s)
1092{iemgui_label((void *)x, &x->x_gui, s);}
1093
1094static void vslider_label_pos(t_vslider *x, t_symbol *s, int ac, t_atom *av)
1095{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
1096
1097static void vslider_label_font(t_vslider *x, t_symbol *s, int ac, t_atom *av)
1098{iemgui_label_font((void *)x, &x->x_gui, s, ac, av);}
1099
1100static void vslider_log(t_vslider *x)
1101{
1102 x->x_lin0_log1 = 1;
1103 vslider_check_minmax(x, x->x_min, x->x_max);
1104}
1105
1106static void vslider_lin(t_vslider *x)
1107{
1108 x->x_lin0_log1 = 0;
1109 x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
1110}
1111
1112static void vslider_init(t_vslider *x, t_floatarg f)
1113{
1114 x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1;
1115}
1116
1117static void vslider_steady(t_vslider *x, t_floatarg f)
1118{
1119 x->x_steady = (f==0.0)?0:1;
1120}
1121
1122static void vslider_loadbang(t_vslider *x)
1123{
1124 if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
1125 {
1126 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1127 vslider_bang(x);
1128 }
1129}
1130
1131static void *vslider_new(t_symbol *s, int argc, t_atom *argv)
1132{
1133 t_vslider *x = (t_vslider *)pd_new(vslider_class);
1134 int bflcol[]={-262144, -1, -1};
1135 int w=IEM_GUI_DEFAULTSIZE, h=IEM_SL_DEFAULTSIZE;
1136 int lilo=0, f=0, ldx=0, ldy=-8;
1137 int fs=8, v=0, steady=1;
1138 double min=0.0, max=(double)(IEM_SL_DEFAULTSIZE-1);
1139 char str[144];
1140
1141 iem_inttosymargs(&x->x_gui.x_isa, 0);
1142 iem_inttofstyle(&x->x_gui.x_fsf, 0);
1143
1144 if(((argc == 17)||(argc == 18))&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
1145 &&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3)
1146 &&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5)
1147 &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6))
1148 &&(IS_A_SYMBOL(argv,7)||IS_A_FLOAT(argv,7))
1149 &&(IS_A_SYMBOL(argv,8)||IS_A_FLOAT(argv,8))
1150 &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)
1151 &&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)
1152 &&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15)&&IS_A_FLOAT(argv,16))
1153 {
1154 w = (int)atom_getintarg(0, argc, argv);
1155 h = (int)atom_getintarg(1, argc, argv);
1156 min = (double)atom_getfloatarg(2, argc, argv);
1157 max = (double)atom_getfloatarg(3, argc, argv);
1158 lilo = (int)atom_getintarg(4, argc, argv);
1159 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
1160 iemgui_new_getnames(&x->x_gui, 6, argv);
1161 ldx = (int)atom_getintarg(9, argc, argv);
1162 ldy = (int)atom_getintarg(10, argc, argv);
1163 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
1164 fs = (int)atom_getintarg(12, argc, argv);
1165 bflcol[0] = (int)atom_getintarg(13, argc, argv);
1166 bflcol[1] = (int)atom_getintarg(14, argc, argv);
1167 bflcol[2] = (int)atom_getintarg(15, argc, argv);
1168 v = (int)atom_getintarg(16, argc, argv);
1169 }
1170 else iemgui_new_getnames(&x->x_gui, 6, 0);
1171 if((argc == 18)&&IS_A_FLOAT(argv,17))
1172 steady = (int)atom_getintarg(17, argc, argv);
1173 x->x_gui.x_draw = (t_iemfunptr)vslider_draw;
1174 x->x_gui.x_fsf.x_snd_able = 1;
1175 x->x_gui.x_fsf.x_rcv_able = 1;
1176 x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
1177 if(x->x_gui.x_isa.x_loadinit)
1178 x->x_val = v;
1179 else
1180 x->x_val = 0;
1181 x->x_pos = x->x_val;
1182 if(lilo != 0) lilo = 1;
1183 x->x_lin0_log1 = lilo;
1184 if(steady != 0) steady = 1;
1185 x->x_steady = steady;
1186 if(!strcmp(x->x_gui.x_snd->s_name, "empty")) x->x_gui.x_fsf.x_snd_able = 0;
1187 if(!strcmp(x->x_gui.x_rcv->s_name, "empty")) x->x_gui.x_fsf.x_rcv_able = 0;
1188 if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
1189 else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
1190 else { x->x_gui.x_fsf.x_font_style = 0;
1191 strcpy(x->x_gui.x_font, "courier"); }
1192 if(x->x_gui.x_fsf.x_rcv_able) pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
1193 x->x_gui.x_ldx = ldx;
1194 x->x_gui.x_ldy = ldy;
1195 if(fs < 4)
1196 fs = 4;
1197 x->x_gui.x_fontsize = fs;
1198 x->x_gui.x_w = iemgui_clip_size(w);
1199 vslider_check_height(x, h);
1200 vslider_check_minmax(x, min, max);
1201 iemgui_all_colfromload(&x->x_gui, bflcol);
1202 iemgui_verify_snd_ne_rcv(&x->x_gui);
1203 outlet_new(&x->x_gui.x_obj, &s_float);
1204 return (x);
1205}
1206
1207static void vslider_free(t_vslider *x)
1208{
1209 if(x->x_gui.x_fsf.x_rcv_able)
1210 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
1211 gfxstub_deleteforkey(x);
1212}
1213
1214void g_vslider_setup(void)
1215{
1216 vslider_class = class_new(gensym("vsl"), (t_newmethod)vslider_new,
1217 (t_method)vslider_free, sizeof(t_vslider), 0, A_GIMME, 0);
1218 class_addcreator((t_newmethod)vslider_new, gensym("vslider"), A_GIMME, 0);
1219 class_addbang(vslider_class,vslider_bang);
1220 class_addfloat(vslider_class,vslider_float);
1221 class_addmethod(vslider_class, (t_method)vslider_click, gensym("click"),
1222 A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
1223 class_addmethod(vslider_class, (t_method)vslider_motion, gensym("motion"),
1224 A_FLOAT, A_FLOAT, 0);
1225 class_addmethod(vslider_class, (t_method)vslider_dialog, gensym("dialog"),
1226 A_GIMME, 0);
1227 class_addmethod(vslider_class, (t_method)vslider_loadbang, gensym("loadbang"), 0);
1228 class_addmethod(vslider_class, (t_method)vslider_set, gensym("set"), A_FLOAT, 0);
1229 class_addmethod(vslider_class, (t_method)vslider_size, gensym("size"), A_GIMME, 0);
1230 class_addmethod(vslider_class, (t_method)vslider_delta, gensym("delta"), A_GIMME, 0);
1231 class_addmethod(vslider_class, (t_method)vslider_pos, gensym("pos"), A_GIMME, 0);
1232 class_addmethod(vslider_class, (t_method)vslider_range, gensym("range"), A_GIMME, 0);
1233 class_addmethod(vslider_class, (t_method)vslider_color, gensym("color"), A_GIMME, 0);
1234 class_addmethod(vslider_class, (t_method)vslider_send, gensym("send"), A_DEFSYM, 0);
1235 class_addmethod(vslider_class, (t_method)vslider_receive, gensym("receive"), A_DEFSYM, 0);
1236 class_addmethod(vslider_class, (t_method)vslider_label, gensym("label"), A_DEFSYM, 0);
1237 class_addmethod(vslider_class, (t_method)vslider_label_pos, gensym("label_pos"), A_GIMME, 0);
1238 class_addmethod(vslider_class, (t_method)vslider_label_font, gensym("label_font"), A_GIMME, 0);
1239 class_addmethod(vslider_class, (t_method)vslider_log, gensym("log"), 0);
1240 class_addmethod(vslider_class, (t_method)vslider_lin, gensym("lin"), 0);
1241 class_addmethod(vslider_class, (t_method)vslider_init, gensym("init"), A_FLOAT, 0);
1242 class_addmethod(vslider_class, (t_method)vslider_steady, gensym("steady"), A_FLOAT, 0);
1243 vslider_widgetbehavior.w_getrectfn = vslider_getrect;
1244 vslider_widgetbehavior.w_displacefn = iemgui_displace;
1245 vslider_widgetbehavior.w_selectfn = iemgui_select;
1246 vslider_widgetbehavior.w_activatefn = NULL;
1247 vslider_widgetbehavior.w_deletefn = iemgui_delete;
1248 vslider_widgetbehavior.w_visfn = iemgui_vis;
1249 vslider_widgetbehavior.w_clickfn = vslider_newclick;
1250 class_setwidget(vslider_class, &vslider_widgetbehavior);
1251 class_sethelpsymbol(vslider_class, gensym("vslider"));
1252 class_setsavefn(vslider_class, vslider_save);
1253 class_setpropertiesfn(vslider_class, vslider_properties);
1254}