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