summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/extra/gcanvas.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/gcanvas.c')
-rw-r--r--apps/plugins/pdbox/PDa/extra/gcanvas.c829
1 files changed, 451 insertions, 378 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/gcanvas.c b/apps/plugins/pdbox/PDa/extra/gcanvas.c
index 9e3f934299..09c120632e 100644
--- a/apps/plugins/pdbox/PDa/extra/gcanvas.c
+++ b/apps/plugins/pdbox/PDa/extra/gcanvas.c
@@ -1,379 +1,452 @@
1/* (C) Guenter Geiger <geiger@xdv.org> */ 1/* (C) Guenter Geiger <geiger@xdv.org> */
2 2
3 3
4#include "m_pd.h" 4#include "m_pd.h"
5#include "g_canvas.h" 5#include "g_canvas.h"
6 6
7/* ------------------------ gcanvas ----------------------------- */ 7/* ------------------------ gcanvas ----------------------------- */
8 8
9 9
10#define BACKGROUNDCOLOR "grey" 10#define BACKGROUNDCOLOR "grey"
11 11
12#define DEFAULTSIZE 80 12#define DEFAULTSIZE 80
13 13
14static t_class *gcanvas_class; 14static t_class *gcanvas_class;
15 15
16typedef struct _gcanvas 16typedef struct _gcanvas
17{ 17{
18 t_object x_obj; 18 t_object x_obj;
19 t_glist * x_glist; 19 t_glist * x_glist;
20 t_outlet* out2; 20 t_outlet* out2;
21 t_outlet* out3; 21 t_outlet* out3;
22 int x_width; 22 int x_width;
23 int x_height; 23 int x_height;
24 int x; 24 int x;
25 int y; 25 int y;
26 int x_xgrid; 26 int x_xgrid;
27 int x_ygrid; 27 int x_ygrid;
28} t_gcanvas; 28} t_gcanvas;
29 29
30 30
31static void rectangle(void* cv,void* o,char c,int x, int y,int w,int h,char* color) { 31static void rectangle(void* cv,void* o,char c,int x, int y,int w,int h,char* color) {
32 sys_vgui(".x%x.c create rectangle \ 32#ifdef ROCKBOX
33 %d %d %d %d -tags %x%c -fill %s\n",cv,x,y,x+w,y+h,o,c,color); 33 (void) cv;
34} 34 (void) o;
35 35 (void) c;
36static void move_object(void* cv,void* o,char c,int x, int y,int w,int h) { 36 (void) x;
37 sys_vgui(".x%x.c coords %x%c %d %d %d %d\n", 37 (void) y;
38 cv,o,c,x,y,x+w,y+h); 38 (void) w;
39 39 (void) h;
40} 40 (void) color;
41 41#else /* ROCKBOX */
42static void color_object(void* cv,void* o,char c,char* color) { 42 sys_vgui(".x%x.c create rectangle \
43 sys_vgui(".x%x.c itemconfigure %x%c -fill %s\n", cv, 43 %d %d %d %d -tags %x%c -fill %s\n",cv,x,y,x+w,y+h,o,c,color);
44 o, c,color); 44#endif /* ROCKBOX */
45} 45}
46 46
47static void delete_object(void* cv,void* o,char c) { 47static void move_object(void* cv,void* o,char c,int x, int y,int w,int h) {
48 sys_vgui(".x%x.c delete %x%c\n", 48#ifdef ROCKBOX
49 cv, o,c); 49 (void) cv;
50} 50 (void) o;
51 51 (void) c;
52static void line(void* cv,void* o,char c,int x,int y,int w,int h,char* color) { 52 (void) x;
53 sys_vgui(".x%x.c create line \ 53 (void) y;
54 %d %d %d %d -tags %x%c -fill %s\n",cv,x,y,x+w,y+h,o,c,color); 54 (void) w;
55} 55 (void) h;
56 56#else /* ROCKBOX */
57 57 sys_vgui(".x%x.c coords %x%c %d %d %d %d\n",
58/* widget helper functions */ 58 cv,o,c,x,y,x+w,y+h);
59 59#endif /* ROCKBOX */
60void gcanvas_drawme(t_gcanvas *x, t_glist *glist, int firsttime) 60}
61{ 61
62 int i; 62static void color_object(void* cv,void* o,char c,char* color) {
63 if (firsttime) { 63#ifdef ROCKBOX
64 rectangle(glist_getcanvas(glist),x,'a', 64 (void) cv;
65 x->x_obj.te_xpix, x->x_obj.te_ypix, 65 (void) o;
66 x->x_width, x->x_height,BACKGROUNDCOLOR); 66 (void) c;
67 for (i=1;i<x->x_xgrid;i++) 67 (void) color;
68 line(glist_getcanvas(glist),x,'b'+ i, 68#else /* ROCKBOX */
69 x->x_obj.te_xpix + x->x_width*i/x->x_xgrid, 69 sys_vgui(".x%x.c itemconfigure %x%c -fill %s\n", cv,
70 x->x_obj.te_ypix, 70 o, c,color);
71 0, x->x_height,"red"); 71#endif /* ROCKBOX */
72 for (i=1;i<x->x_ygrid;i++) 72}
73 line(glist_getcanvas(glist),x,'B'+ i, 73
74 x->x_obj.te_xpix, 74static void delete_object(void* cv,void* o,char c) {
75 x->x_obj.te_ypix + x->x_height*i/x->x_ygrid, 75#ifdef ROCKBOX
76 x->x_width, 0,"blue"); 76 (void) cv;
77 } 77 (void) o;
78 else { 78 (void) c;
79 move_object( 79#else /* ROCKBOX */
80 glist_getcanvas(glist),x,'a', 80 sys_vgui(".x%x.c delete %x%c\n",
81 x->x_obj.te_xpix, x->x_obj.te_ypix, 81 cv, o,c);
82 x->x_width, x->x_height); 82#endif /* ROCKBOX */
83 for (i=1;i<x->x_xgrid;i++) 83}
84 move_object(glist_getcanvas(glist),x,'b'+ i, 84
85 x->x_obj.te_xpix + x->x_width*i/x->x_xgrid, 85static void line(void* cv,void* o,char c,int x,int y,int w,int h,char* color) {
86 x->x_obj.te_ypix, 86#ifdef ROCKBOX
87 0, x->x_height); 87 (void) cv;
88 for (i=1;i<x->x_ygrid;i++) 88 (void) o;
89 move_object(glist_getcanvas(glist),x,'B'+ i, 89 (void) c;
90 x->x_obj.te_xpix, 90 (void) x;
91 x->x_obj.te_ypix + x->x_height*i/x->x_ygrid, 91 (void) y;
92 x->x_width, 0); 92 (void) w;
93 } 93 (void) h;
94 94 (void) color;
95 { 95#else /* ROCKBOX */
96 /* outlets */ 96 sys_vgui(".x%x.c create line \
97 int n = 3; 97 %d %d %d %d -tags %x%c -fill %s\n",cv,x,y,x+w,y+h,o,c,color);
98 int nplus, i; 98#endif /* ROCKBOX */
99 nplus = (n == 1 ? 1 : n-1); 99}
100 for (i = 0; i < n; i++) 100
101 { 101
102 int onset = x->x_obj.te_xpix + (x->x_width - IOWIDTH) * i / nplus; 102/* widget helper functions */
103 if (firsttime) 103
104 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n", 104void gcanvas_drawme(t_gcanvas *x, t_glist *glist, int firsttime)
105 glist_getcanvas(glist), 105{
106 onset, x->x_obj.te_ypix + x->x_height - 1, 106 int i;
107 onset + IOWIDTH, x->x_obj.te_ypix + x->x_height, 107 if (firsttime) {
108 x, i); 108 rectangle(glist_getcanvas(glist),x,'a',
109 else 109 x->x_obj.te_xpix, x->x_obj.te_ypix,
110 sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n", 110 x->x_width, x->x_height,BACKGROUNDCOLOR);
111 glist_getcanvas(glist), x, i, 111 for (i=1;i<x->x_xgrid;i++)
112 onset, x->x_obj.te_ypix + x->x_height - 1, 112 line(glist_getcanvas(glist),x,'b'+ i,
113 onset + IOWIDTH, x->x_obj.te_ypix + x->x_height); 113 x->x_obj.te_xpix + x->x_width*i/x->x_xgrid,
114 } 114 x->x_obj.te_ypix,
115 /* inlets */ 115 0, x->x_height,"red");
116 n = 0; 116 for (i=1;i<x->x_ygrid;i++)
117 nplus = (n == 1 ? 1 : n-1); 117 line(glist_getcanvas(glist),x,'B'+ i,
118 for (i = 0; i < n; i++) 118 x->x_obj.te_xpix,
119 { 119 x->x_obj.te_ypix + x->x_height*i/x->x_ygrid,
120 int onset = x->x_obj.te_xpix + (x->x_width - IOWIDTH) * i / nplus; 120 x->x_width, 0,"blue");
121 if (firsttime) 121 }
122 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n", 122 else {
123 glist_getcanvas(glist), 123 move_object(
124 onset, x->x_obj.te_ypix, 124 glist_getcanvas(glist),x,'a',
125 onset + IOWIDTH, x->x_obj.te_ypix + 1, 125 x->x_obj.te_xpix, x->x_obj.te_ypix,
126 x, i); 126 x->x_width, x->x_height);
127 else 127 for (i=1;i<x->x_xgrid;i++)
128 sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n", 128 move_object(glist_getcanvas(glist),x,'b'+ i,
129 glist_getcanvas(glist), x, i, 129 x->x_obj.te_xpix + x->x_width*i/x->x_xgrid,
130 onset, x->x_obj.te_ypix, 130 x->x_obj.te_ypix,
131 onset + IOWIDTH, x->x_obj.te_ypix + 1); 131 0, x->x_height);
132 132 for (i=1;i<x->x_ygrid;i++)
133 } 133 move_object(glist_getcanvas(glist),x,'B'+ i,
134 } 134 x->x_obj.te_xpix,
135 135 x->x_obj.te_ypix + x->x_height*i/x->x_ygrid,
136} 136 x->x_width, 0);
137 137 }
138 138
139 139 {
140 140 /* outlets */
141void gcanvas_erase(t_gcanvas* x,t_glist* glist) 141 int n = 3;
142{ 142 int nplus, i;
143 int n,i; 143 nplus = (n == 1 ? 1 : n-1);
144 delete_object(glist_getcanvas(glist),x,'a'); 144 for (i = 0; i < n; i++)
145 for (i=1;i<x->x_xgrid;i++) 145 {
146 delete_object(glist_getcanvas(glist),x,'b'+ i); 146#ifndef ROCKBOX
147 for (i=1;i<x->x_ygrid;i++) 147 int onset = x->x_obj.te_xpix + (x->x_width - IOWIDTH) * i / nplus;
148 delete_object(glist_getcanvas(glist),x,'B'+ i); 148 if (firsttime)
149 149 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n",
150 n = 2; 150 glist_getcanvas(glist),
151 while (n--) { 151 onset, x->x_obj.te_ypix + x->x_height - 1,
152 sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist),x,n); 152 onset + IOWIDTH, x->x_obj.te_ypix + x->x_height,
153 } 153 x, i);
154} 154 else
155 155 sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n",
156 156 glist_getcanvas(glist), x, i,
157 157 onset, x->x_obj.te_ypix + x->x_height - 1,
158/* ------------------------ gcanvas widgetbehaviour----------------------------- */ 158 onset + IOWIDTH, x->x_obj.te_ypix + x->x_height);
159 159#endif /* ROCKBOX */
160 160 }
161static void gcanvas_getrect(t_gobj *z, t_glist *owner, 161 /* inlets */
162 int *xp1, int *yp1, int *xp2, int *yp2) 162 n = 0;
163{ 163 nplus = (n == 1 ? 1 : n-1);
164 int width, height; 164 for (i = 0; i < n; i++)
165 t_gcanvas* s = (t_gcanvas*)z; 165 {
166 166#ifndef ROCKBOX
167 167 int onset = x->x_obj.te_xpix + (x->x_width - IOWIDTH) * i / nplus;
168 width = s->x_width; 168 if (firsttime)
169 height = s->x_height; 169 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n",
170 *xp1 = s->x_obj.te_xpix; 170 glist_getcanvas(glist),
171 *yp1 = s->x_obj.te_ypix; 171 onset, x->x_obj.te_ypix,
172 *xp2 = s->x_obj.te_xpix + width; 172 onset + IOWIDTH, x->x_obj.te_ypix + 1,
173 *yp2 = s->x_obj.te_ypix + height; 173 x, i);
174} 174 else
175 175 sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n",
176static void gcanvas_displace(t_gobj *z, t_glist *glist, 176 glist_getcanvas(glist), x, i,
177 int dx, int dy) 177 onset, x->x_obj.te_ypix,
178{ 178 onset + IOWIDTH, x->x_obj.te_ypix + 1);
179 t_gcanvas *x = (t_gcanvas *)z; 179#endif /* ROCKBOX */
180 x->x_obj.te_xpix += dx; 180 }
181 x->x_obj.te_ypix += dy; 181 }
182 gcanvas_drawme(x, glist, 0); 182
183 canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x); 183}
184} 184
185 185
186static void gcanvas_select(t_gobj *z, t_glist *glist, int state) 186
187{ 187
188 t_gcanvas *x = (t_gcanvas *)z; 188void gcanvas_erase(t_gcanvas* x,t_glist* glist)
189 color_object(glist,x,'a',state ? "blue" : BACKGROUNDCOLOR); 189{
190} 190 int n,i;
191 191 delete_object(glist_getcanvas(glist),x,'a');
192 192 for (i=1;i<x->x_xgrid;i++)
193static void gcanvas_activate(t_gobj *z, t_glist *glist, int state) 193 delete_object(glist_getcanvas(glist),x,'b'+ i);
194{ 194 for (i=1;i<x->x_ygrid;i++)
195/* t_text *x = (t_text *)z; 195 delete_object(glist_getcanvas(glist),x,'B'+ i);
196 t_rtext *y = glist_findrtext(glist, x); 196
197 if (z->g_pd != gatom_class) rtext_activate(y, state);*/ 197 n = 2;
198} 198 while (n--) {
199 199#ifndef ROCKBOX
200static void gcanvas_delete(t_gobj *z, t_glist *glist) 200 sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist),x,n);
201{ 201#endif
202 t_text *x = (t_text *)z; 202 }
203 canvas_deletelinesfor(glist_getcanvas(glist), x); 203}
204} 204
205 205
206 206
207static void gcanvas_vis(t_gobj *z, t_glist *glist, int vis) 207/* ------------------------ gcanvas widgetbehaviour----------------------------- */
208{ 208
209 t_gcanvas* s = (t_gcanvas*)z; 209
210 if (vis) 210static void gcanvas_getrect(t_gobj *z, t_glist *owner,
211 gcanvas_drawme(s, glist, 1); 211 int *xp1, int *yp1, int *xp2, int *yp2)
212 else 212{
213 gcanvas_erase(s,glist); 213#ifdef ROCKBOX
214} 214 (void) owner;
215 215#endif
216/* can we use the normal text save function ?? */ 216 int width, height;
217 217 t_gcanvas* s = (t_gcanvas*)z;
218static void gcanvas_save(t_gobj *z, t_binbuf *b) 218
219{ 219
220 t_gcanvas *x = (t_gcanvas *)z; 220 width = s->x_width;
221 binbuf_addv(b, "ssiisiiii", gensym("#X"),gensym("obj"), 221 height = s->x_height;
222 (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix, 222 *xp1 = s->x_obj.te_xpix;
223 gensym("gcanvas"),x->x_width,x->x_height, 223 *yp1 = s->x_obj.te_ypix;
224 x->x_xgrid, 224 *xp2 = s->x_obj.te_xpix + width;
225 x->x_ygrid); 225 *yp2 = s->x_obj.te_ypix + height;
226 binbuf_addv(b, ";"); 226}
227} 227
228 228static void gcanvas_displace(t_gobj *z, t_glist *glist,
229 229 int dx, int dy)
230t_widgetbehavior gcanvas_widgetbehavior; 230{
231 231 t_gcanvas *x = (t_gcanvas *)z;
232static void gcanvas_motion(t_gcanvas *x, t_floatarg dx, t_floatarg dy) 232 x->x_obj.te_xpix += dx;
233{ 233 x->x_obj.te_ypix += dy;
234 x->x += dx; 234 gcanvas_drawme(x, glist, 0);
235 x->y += dy; 235 canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
236 outlet_float(x->out2,x->y); 236}
237 outlet_float(x->x_obj.ob_outlet,x->x); 237
238} 238static void gcanvas_select(t_gobj *z, t_glist *glist, int state)
239 239{
240void gcanvas_key(t_gcanvas *x, t_floatarg f) 240 t_gcanvas *x = (t_gcanvas *)z;
241{ 241 color_object(glist,x,'a',state ? "blue" : BACKGROUNDCOLOR);
242 post("key"); 242}
243} 243
244 244
245 245static void gcanvas_activate(t_gobj *z, t_glist *glist, int state)
246static void gcanvas_click(t_gcanvas *x, 246{
247 t_floatarg xpos, t_floatarg ypos, t_floatarg shift, t_floatarg ctrl, 247#ifdef ROCKBOX
248 t_floatarg doit,int up) 248 (void) z;
249{ 249 (void) glist;
250 glist_grab(x->x_glist, &x->x_obj.te_g, (t_glistmotionfn) gcanvas_motion, 250 (void) state;
251 (t_glistkeyfn) NULL, xpos, ypos); 251#endif
252 252/* t_text *x = (t_text *)z;
253 x->x = xpos - x->x_obj.te_xpix; 253 t_rtext *y = glist_findrtext(glist, x);
254 x->y = ypos - x->x_obj.te_ypix; 254 if (z->g_pd != gatom_class) rtext_activate(y, state);*/
255 outlet_float(x->out2,x->y); 255}
256 outlet_float(x->x_obj.ob_outlet,x->x); 256
257 outlet_float(x->out3,0); 257static void gcanvas_delete(t_gobj *z, t_glist *glist)
258} 258{
259 259 t_text *x = (t_text *)z;
260static int gcanvas_newclick(t_gobj *z, struct _glist *glist, 260 canvas_deletelinesfor(glist_getcanvas(glist), x);
261 int xpix, int ypix, int shift, int alt, int dbl, int doit) 261}
262{ 262
263 if (doit) 263
264 gcanvas_click((t_gcanvas *)z, (t_floatarg)xpix, (t_floatarg)ypix, 264static void gcanvas_vis(t_gobj *z, t_glist *glist, int vis)
265 (t_floatarg)shift, 0, (t_floatarg)alt,dbl); 265{
266 266 t_gcanvas* s = (t_gcanvas*)z;
267 if (dbl) outlet_float(((t_gcanvas*)z)->out3,1); 267 if (vis)
268 return (1); 268 gcanvas_drawme(s, glist, 1);
269} 269 else
270 270 gcanvas_erase(s,glist);
271void gcanvas_size(t_gcanvas* x,t_floatarg w,t_floatarg h) { 271}
272 x->x_width = w; 272
273 x->x_height = h; 273/* can we use the normal text save function ?? */
274 gcanvas_drawme(x, x->x_glist, 0); 274
275} 275static void gcanvas_save(t_gobj *z, t_binbuf *b)
276 276{
277static void gcanvas_setwidget(void) 277 t_gcanvas *x = (t_gcanvas *)z;
278{ 278 binbuf_addv(b, "ssiisiiii", gensym("#X"),gensym("obj"),
279 gcanvas_widgetbehavior.w_getrectfn = gcanvas_getrect; 279 (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
280 gcanvas_widgetbehavior.w_displacefn = gcanvas_displace; 280 gensym("gcanvas"),x->x_width,x->x_height,
281 gcanvas_widgetbehavior.w_selectfn = gcanvas_select; 281 x->x_xgrid,
282 gcanvas_widgetbehavior.w_activatefn = gcanvas_activate; 282 x->x_ygrid);
283 gcanvas_widgetbehavior.w_deletefn = gcanvas_delete; 283 binbuf_addv(b, ";");
284 gcanvas_widgetbehavior.w_visfn = gcanvas_vis; 284}
285 gcanvas_widgetbehavior.w_clickfn = gcanvas_newclick; 285
286 class_setsavefn(gcanvas_class,gcanvas_save); 286
287} 287t_widgetbehavior gcanvas_widgetbehavior;
288 288
289 289static void gcanvas_motion(t_gcanvas *x, t_floatarg dx, t_floatarg dy)
290static void *gcanvas_new(t_symbol* s,t_int ac,t_atom* at) 290{
291{ 291 x->x += dx;
292 t_gcanvas *x = (t_gcanvas *)pd_new(gcanvas_class); 292 x->y += dy;
293 293 outlet_float(x->out2,x->y);
294 x->x_glist = (t_glist*) canvas_getcurrent(); 294 outlet_float(x->x_obj.ob_outlet,x->x);
295 295}
296 296
297 /* Fetch the width */ 297void gcanvas_key(t_gcanvas *x, t_floatarg f)
298 298{
299 x->x_width = DEFAULTSIZE; 299#ifdef ROCKBOX
300 if (ac-- > 0) { 300 (void) x;
301 if (at->a_type != A_FLOAT) 301 (void) f;
302 error("gcanvas: wrong argument type"); 302#endif
303 else 303 post("key");
304 x->x_width = atom_getfloat(at++); 304}
305 305
306 if (x->x_width < 0 || x->x_width > 2000) { 306
307 error("gcanvas: unallowed width %f",x->x_width); 307static void gcanvas_click(t_gcanvas *x,
308 x->x_width = DEFAULTSIZE; 308 t_floatarg xpos, t_floatarg ypos, t_floatarg shift, t_floatarg ctrl,
309 } 309 t_floatarg doit,int up)
310 } 310{
311 311#ifdef ROCKBOX
312 /* Fetch the height */ 312 (void) shift;
313 313 (void) ctrl;
314 x->x_height = DEFAULTSIZE; 314 (void) doit;
315 if (ac-- > 0) { 315 (void) up;
316 if (at->a_type != A_FLOAT) 316#endif
317 error("gcanvas: wrong argument type"); 317 glist_grab(x->x_glist, &x->x_obj.te_g, (t_glistmotionfn) gcanvas_motion,
318 else 318 (t_glistkeyfn) NULL, xpos, ypos);
319 x->x_height = atom_getfloat(at++); 319
320 320 x->x = xpos - x->x_obj.te_xpix;
321 if (x->x_height < 0 || x->x_height > 2000) { 321 x->y = ypos - x->x_obj.te_ypix;
322 error("gcanvas: unallowed height %f",x->x_height); 322 outlet_float(x->out2,x->y);
323 x->x_width = DEFAULTSIZE; 323 outlet_float(x->x_obj.ob_outlet,x->x);
324 } 324 outlet_float(x->out3,0);
325 } 325}
326 326
327 /* Fetch the xgrid */ 327static int gcanvas_newclick(t_gobj *z, struct _glist *glist,
328 328 int xpix, int ypix, int shift, int alt, int dbl, int doit)
329 x->x_xgrid = 0; 329{
330 if (ac-- > 0) { 330#ifdef ROCKBOX
331 if (at->a_type != A_FLOAT) 331 (void) glist;
332 error("gcanvas: wrong argument type"); 332#endif
333 else 333 if (doit)
334 x->x_xgrid = atom_getfloat(at++); 334 gcanvas_click((t_gcanvas *)z, (t_floatarg)xpix, (t_floatarg)ypix,
335 335 (t_floatarg)shift, 0, (t_floatarg)alt,dbl);
336 if (x->x_xgrid < 0 || x->x_xgrid > x->x_width/2) { 336
337 error("gcanvas: unallowed xgrid %f",x->x_xgrid); 337 if (dbl) outlet_float(((t_gcanvas*)z)->out3,1);
338 x->x_xgrid = 0; 338 return (1);
339 } 339}
340 } 340
341 341void gcanvas_size(t_gcanvas* x,t_floatarg w,t_floatarg h) {
342 /* Fetch the ygrid */ 342 x->x_width = w;
343 343 x->x_height = h;
344 x->x_ygrid = 0; 344 gcanvas_drawme(x, x->x_glist, 0);
345 if (ac-- > 0) { 345}
346 if (at->a_type != A_FLOAT) 346
347 error("gcanvas: wrong argument type"); 347static void gcanvas_setwidget(void)
348 else 348{
349 x->x_ygrid = atom_getfloat(at++); 349 gcanvas_widgetbehavior.w_getrectfn = gcanvas_getrect;
350 350 gcanvas_widgetbehavior.w_displacefn = gcanvas_displace;
351 if (x->x_ygrid < 0 || x->x_ygrid > x->x_height/2) { 351 gcanvas_widgetbehavior.w_selectfn = gcanvas_select;
352 error("gcanvas: unallowed xgrid %f",x->x_ygrid); 352 gcanvas_widgetbehavior.w_activatefn = gcanvas_activate;
353 x->x_ygrid = 0; 353 gcanvas_widgetbehavior.w_deletefn = gcanvas_delete;
354 } 354 gcanvas_widgetbehavior.w_visfn = gcanvas_vis;
355 } 355 gcanvas_widgetbehavior.w_clickfn = gcanvas_newclick;
356 356 class_setsavefn(gcanvas_class,gcanvas_save);
357 outlet_new(&x->x_obj, &s_float); 357}
358 x->out2 = outlet_new(&x->x_obj, &s_float); 358
359 x->out3 = outlet_new(&x->x_obj, &s_float); 359
360 return (x); 360static void *gcanvas_new(t_symbol* s,t_int ac,t_atom* at)
361} 361{
362 362#ifdef ROCKBOX
363 363 (void) s;
364 364#endif
365void gcanvas_setup(void) 365 t_gcanvas *x = (t_gcanvas *)pd_new(gcanvas_class);
366{ 366
367 gcanvas_class = class_new(gensym("gcanvas"), (t_newmethod)gcanvas_new, 0, 367 x->x_glist = (t_glist*) canvas_getcurrent();
368 sizeof(t_gcanvas),0, A_GIMME,0); 368
369 369
370 class_addmethod(gcanvas_class, (t_method)gcanvas_click, gensym("click"), 370 /* Fetch the width */
371 A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); 371
372 class_addmethod(gcanvas_class, (t_method)gcanvas_size, gensym("size"), 372 x->x_width = DEFAULTSIZE;
373 A_FLOAT, A_FLOAT, 0); 373 if (ac-- > 0) {
374 374 if (at->a_type != A_FLOAT)
375 gcanvas_setwidget(); 375 error("gcanvas: wrong argument type");
376 class_setwidget(gcanvas_class,&gcanvas_widgetbehavior); 376 else
377} 377 x->x_width = atom_getfloat(at++);
378 378
379 if (x->x_width < 0 || x->x_width > 2000) {
380 error("gcanvas: unallowed width %f",x->x_width);
381 x->x_width = DEFAULTSIZE;
382 }
383 }
384
385 /* Fetch the height */
386
387 x->x_height = DEFAULTSIZE;
388 if (ac-- > 0) {
389 if (at->a_type != A_FLOAT)
390 error("gcanvas: wrong argument type");
391 else
392 x->x_height = atom_getfloat(at++);
393
394 if (x->x_height < 0 || x->x_height > 2000) {
395 error("gcanvas: unallowed height %f",x->x_height);
396 x->x_width = DEFAULTSIZE;
397 }
398 }
399
400 /* Fetch the xgrid */
401
402 x->x_xgrid = 0;
403 if (ac-- > 0) {
404 if (at->a_type != A_FLOAT)
405 error("gcanvas: wrong argument type");
406 else
407 x->x_xgrid = atom_getfloat(at++);
408
409 if (x->x_xgrid < 0 || x->x_xgrid > x->x_width/2) {
410 error("gcanvas: unallowed xgrid %f",x->x_xgrid);
411 x->x_xgrid = 0;
412 }
413 }
414
415 /* Fetch the ygrid */
416
417 x->x_ygrid = 0;
418 if (ac-- > 0) {
419 if (at->a_type != A_FLOAT)
420 error("gcanvas: wrong argument type");
421 else
422 x->x_ygrid = atom_getfloat(at++);
423
424 if (x->x_ygrid < 0 || x->x_ygrid > x->x_height/2) {
425 error("gcanvas: unallowed xgrid %f",x->x_ygrid);
426 x->x_ygrid = 0;
427 }
428 }
429
430 outlet_new(&x->x_obj, &s_float);
431 x->out2 = outlet_new(&x->x_obj, &s_float);
432 x->out3 = outlet_new(&x->x_obj, &s_float);
433 return (x);
434}
435
436
437
438void gcanvas_setup(void)
439{
440 gcanvas_class = class_new(gensym("gcanvas"), (t_newmethod)gcanvas_new, 0,
441 sizeof(t_gcanvas),0, A_GIMME,0);
442
443 class_addmethod(gcanvas_class, (t_method)gcanvas_click, gensym("click"),
444 A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
445 class_addmethod(gcanvas_class, (t_method)gcanvas_size, gensym("size"),
446 A_FLOAT, A_FLOAT, 0);
447
448 gcanvas_setwidget();
449 class_setwidget(gcanvas_class,&gcanvas_widgetbehavior);
450}
451
379 452