summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/extra/image.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/image.c')
-rw-r--r--apps/plugins/pdbox/PDa/extra/image.c434
1 files changed, 434 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/image.c b/apps/plugins/pdbox/PDa/extra/image.c
new file mode 100644
index 0000000000..6de48ef8fb
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/image.c
@@ -0,0 +1,434 @@
1#include "m_pd.h"
2#include "g_canvas.h"
3
4#ifdef NT
5#pragma warning( disable : 4244 )
6#pragma warning( disable : 4305 )
7#endif
8
9/* ------------------------ image ----------------------------- */
10
11static t_class *image_class;
12
13typedef struct _image
14{
15 t_object x_obj;
16 t_glist * x_glist;
17 int x_width;
18 int x_height;
19 t_symbol* x_fname;
20} t_image;
21
22/* widget helper functions */
23
24void image_drawme(t_image *x, t_glist *glist, int firsttime)
25{
26 if (firsttime) {
27 char fname[MAXPDSTRING];
28 canvas_makefilename(glist_getcanvas(x->x_glist), x->x_fname->s_name,
29 fname, MAXPDSTRING);
30
31 sys_vgui("image create photo img%x -file %s\n",x,fname);
32 sys_vgui(".x%x.c create image %d %d -image img%x -tags %xS\n",
33 glist_getcanvas(glist),text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x,x);
34
35 /* TODO callback from gui
36 sys_vgui("image_size logo");
37 */
38 }
39 else {
40 sys_vgui(".x%x.c coords %xS \
41%d %d\n",
42 glist_getcanvas(glist), x,
43 text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
44 }
45
46}
47
48
49void image_erase(t_image* x,t_glist* glist)
50{
51 int n;
52 sys_vgui(".x%x.c delete %xS\n",
53 glist_getcanvas(glist), x);
54
55}
56
57
58
59/* ------------------------ image widgetbehaviour----------------------------- */
60
61
62static void image_getrect(t_gobj *z, t_glist *glist,
63 int *xp1, int *yp1, int *xp2, int *yp2)
64{
65 int width, height;
66 t_image* x = (t_image*)z;
67
68
69 width = x->x_width;
70 height = x->x_height;
71 *xp1 = text_xpix(&x->x_obj, glist);
72 *yp1 = text_ypix(&x->x_obj, glist);
73 *xp2 = text_xpix(&x->x_obj, glist) + width;
74 *yp2 = text_ypix(&x->x_obj, glist) + height;
75}
76
77static void image_displace(t_gobj *z, t_glist *glist,
78 int dx, int dy)
79{
80 t_image *x = (t_image *)z;
81 x->x_obj.te_xpix += dx;
82 x->x_obj.te_ypix += dy;
83 sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n",
84 glist_getcanvas(glist), x,
85 text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
86 text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height);
87
88 image_drawme(x, glist, 0);
89 canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
90}
91
92static void image_select(t_gobj *z, t_glist *glist, int state)
93{
94 t_image *x = (t_image *)z;
95 if (state) {
96 sys_vgui(".x%x.c create rectangle \
97%d %d %d %d -tags %xSEL -outline blue\n",
98 glist_getcanvas(glist),
99 text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
100 text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
101 x);
102 }
103 else {
104 sys_vgui(".x%x.c delete %xSEL\n",
105 glist_getcanvas(glist), x);
106 }
107
108
109
110}
111
112
113static void image_activate(t_gobj *z, t_glist *glist, int state)
114{
115/* t_text *x = (t_text *)z;
116 t_rtext *y = glist_findrtext(glist, x);
117 if (z->g_pd != gatom_class) rtext_activate(y, state);*/
118}
119
120static void image_delete(t_gobj *z, t_glist *glist)
121{
122 t_text *x = (t_text *)z;
123 canvas_deletelinesfor(glist_getcanvas(glist), x);
124}
125
126
127static void image_vis(t_gobj *z, t_glist *glist, int vis)
128{
129 t_image* s = (t_image*)z;
130 if (vis)
131 image_drawme(s, glist, 1);
132 else
133 image_erase(s,glist);
134}
135
136/* can we use the normal text save function ?? */
137
138static void image_save(t_gobj *z, t_binbuf *b)
139{
140 t_image *x = (t_image *)z;
141 binbuf_addv(b, "ssiiss", gensym("#X"),gensym("obj"),
142 x->x_obj.te_xpix, x->x_obj.te_ypix,
143 gensym("image"),x->x_fname);
144 binbuf_addv(b, ";");
145}
146
147
148t_widgetbehavior image_widgetbehavior;
149
150void image_size(t_image* x,t_floatarg w,t_floatarg h) {
151 x->x_width = w;
152 x->x_height = h;
153}
154
155void image_color(t_image* x,t_symbol* col)
156{
157/* outlet_bang(x->x_obj.ob_outlet); only bang if there was a bang ..
158 so color black does the same as bang, but doesn't forward the bang
159*/
160}
161
162static void image_setwidget(void)
163{
164 image_widgetbehavior.w_getrectfn = image_getrect;
165 image_widgetbehavior.w_displacefn = image_displace;
166 image_widgetbehavior.w_selectfn = image_select;
167 image_widgetbehavior.w_activatefn = image_activate;
168 image_widgetbehavior.w_deletefn = image_delete;
169 image_widgetbehavior.w_visfn = image_vis;
170#if (PD_VERSION_MINOR > 31)
171 image_widgetbehavior.w_clickfn = NULL;
172 image_widgetbehavior.w_propertiesfn = NULL;
173#endif
174#if PD_MINOR_VERSION < 37
175 image_widgetbehavior.w_savefn = image_save;
176#endif
177}
178
179
180static void *image_new(t_symbol* fname)
181{
182 t_image *x = (t_image *)pd_new(image_class);
183
184 x->x_glist = (t_glist*) canvas_getcurrent();
185
186 x->x_width = 15;
187 x->x_height = 15;
188
189 x->x_fname = fname;
190 outlet_new(&x->x_obj, &s_float);
191 return (x);
192}
193
194void image_setup(void)
195{
196 image_class = class_new(gensym("image"), (t_newmethod)image_new, 0,
197 sizeof(t_image),0, A_DEFSYM,0);
198
199/*
200 class_addmethod(image_class, (t_method)image_size, gensym("size"),
201 A_FLOAT, A_FLOAT, 0);
202
203 class_addmethod(image_class, (t_method)image_color, gensym("color"),
204 A_SYMBOL, 0);
205*/
206/*
207 class_addmethod(image_class, (t_method)image_open, gensym("open"),
208 A_SYMBOL, 0);
209*/
210 image_setwidget();
211 class_setwidget(image_class,&image_widgetbehavior);
212#if PD_MINOR_VERSION >= 37
213 class_setsavefn(image_class,&image_save);
214#endif
215}
216
217
218#include "m_pd.h"
219#include "g_canvas.h"
220
221#ifdef NT
222#pragma warning( disable : 4244 )
223#pragma warning( disable : 4305 )
224#endif
225
226/* ------------------------ image ----------------------------- */
227
228static t_class *image_class;
229
230typedef struct _image
231{
232 t_object x_obj;
233 t_glist * x_glist;
234 int x_width;
235 int x_height;
236 t_symbol* x_fname;
237} t_image;
238
239/* widget helper functions */
240
241void image_drawme(t_image *x, t_glist *glist, int firsttime)
242{
243 if (firsttime) {
244 char fname[MAXPDSTRING];
245 canvas_makefilename(glist_getcanvas(x->x_glist), x->x_fname->s_name,
246 fname, MAXPDSTRING);
247
248 sys_vgui("image create photo img%x -file %s\n",x,fname);
249 sys_vgui(".x%x.c create image %d %d -image img%x -tags %xS\n",
250 glist_getcanvas(glist),text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x,x);
251
252 /* TODO callback from gui
253 sys_vgui("image_size logo");
254 */
255 }
256 else {
257 sys_vgui(".x%x.c coords %xS \
258%d %d\n",
259 glist_getcanvas(glist), x,
260 text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
261 }
262
263}
264
265
266void image_erase(t_image* x,t_glist* glist)
267{
268 int n;
269 sys_vgui(".x%x.c delete %xS\n",
270 glist_getcanvas(glist), x);
271
272}
273
274
275
276/* ------------------------ image widgetbehaviour----------------------------- */
277
278
279static void image_getrect(t_gobj *z, t_glist *glist,
280 int *xp1, int *yp1, int *xp2, int *yp2)
281{
282 int width, height;
283 t_image* x = (t_image*)z;
284
285
286 width = x->x_width;
287 height = x->x_height;
288 *xp1 = text_xpix(&x->x_obj, glist);
289 *yp1 = text_ypix(&x->x_obj, glist);
290 *xp2 = text_xpix(&x->x_obj, glist) + width;
291 *yp2 = text_ypix(&x->x_obj, glist) + height;
292}
293
294static void image_displace(t_gobj *z, t_glist *glist,
295 int dx, int dy)
296{
297 t_image *x = (t_image *)z;
298 x->x_obj.te_xpix += dx;
299 x->x_obj.te_ypix += dy;
300 sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n",
301 glist_getcanvas(glist), x,
302 text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
303 text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height);
304
305 image_drawme(x, glist, 0);
306 canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
307}
308
309static void image_select(t_gobj *z, t_glist *glist, int state)
310{
311 t_image *x = (t_image *)z;
312 if (state) {
313 sys_vgui(".x%x.c create rectangle \
314%d %d %d %d -tags %xSEL -outline blue\n",
315 glist_getcanvas(glist),
316 text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
317 text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
318 x);
319 }
320 else {
321 sys_vgui(".x%x.c delete %xSEL\n",
322 glist_getcanvas(glist), x);
323 }
324
325
326
327}
328
329
330static void image_activate(t_gobj *z, t_glist *glist, int state)
331{
332/* t_text *x = (t_text *)z;
333 t_rtext *y = glist_findrtext(glist, x);
334 if (z->g_pd != gatom_class) rtext_activate(y, state);*/
335}
336
337static void image_delete(t_gobj *z, t_glist *glist)
338{
339 t_text *x = (t_text *)z;
340 canvas_deletelinesfor(glist_getcanvas(glist), x);
341}
342
343
344static void image_vis(t_gobj *z, t_glist *glist, int vis)
345{
346 t_image* s = (t_image*)z;
347 if (vis)
348 image_drawme(s, glist, 1);
349 else
350 image_erase(s,glist);
351}
352
353/* can we use the normal text save function ?? */
354
355static void image_save(t_gobj *z, t_binbuf *b)
356{
357 t_image *x = (t_image *)z;
358 binbuf_addv(b, "ssiiss", gensym("#X"),gensym("obj"),
359 x->x_obj.te_xpix, x->x_obj.te_ypix,
360 gensym("image"),x->x_fname);
361 binbuf_addv(b, ";");
362}
363
364
365t_widgetbehavior image_widgetbehavior;
366
367void image_size(t_image* x,t_floatarg w,t_floatarg h) {
368 x->x_width = w;
369 x->x_height = h;
370}
371
372void image_color(t_image* x,t_symbol* col)
373{
374/* outlet_bang(x->x_obj.ob_outlet); only bang if there was a bang ..
375 so color black does the same as bang, but doesn't forward the bang
376*/
377}
378
379static void image_setwidget(void)
380{
381 image_widgetbehavior.w_getrectfn = image_getrect;
382 image_widgetbehavior.w_displacefn = image_displace;
383 image_widgetbehavior.w_selectfn = image_select;
384 image_widgetbehavior.w_activatefn = image_activate;
385 image_widgetbehavior.w_deletefn = image_delete;
386 image_widgetbehavior.w_visfn = image_vis;
387#if (PD_VERSION_MINOR > 31)
388 image_widgetbehavior.w_clickfn = NULL;
389 image_widgetbehavior.w_propertiesfn = NULL;
390#endif
391#if PD_MINOR_VERSION < 37
392 image_widgetbehavior.w_savefn = image_save;
393#endif
394}
395
396
397static void *image_new(t_symbol* fname)
398{
399 t_image *x = (t_image *)pd_new(image_class);
400
401 x->x_glist = (t_glist*) canvas_getcurrent();
402
403 x->x_width = 15;
404 x->x_height = 15;
405
406 x->x_fname = fname;
407 outlet_new(&x->x_obj, &s_float);
408 return (x);
409}
410
411void image_setup(void)
412{
413 image_class = class_new(gensym("image"), (t_newmethod)image_new, 0,
414 sizeof(t_image),0, A_DEFSYM,0);
415
416/*
417 class_addmethod(image_class, (t_method)image_size, gensym("size"),
418 A_FLOAT, A_FLOAT, 0);
419
420 class_addmethod(image_class, (t_method)image_color, gensym("color"),
421 A_SYMBOL, 0);
422*/
423/*
424 class_addmethod(image_class, (t_method)image_open, gensym("open"),
425 A_SYMBOL, 0);
426*/
427 image_setwidget();
428 class_setwidget(image_class,&image_widgetbehavior);
429#if PD_MINOR_VERSION >= 37
430 class_setsavefn(image_class,&image_save);
431#endif
432}
433
434