Add the identifying header
[kugel-rb.git] / apps / plugins / pdbox / PDa / extra / image.c
blob23bee8d73324f69ad64726afece2582ba083e7fc
1 #include "../src/m_pd.h"
2 #include "g_canvas.h"
4 #ifdef NT
5 #pragma warning( disable : 4244 )
6 #pragma warning( disable : 4305 )
7 #endif
9 /* ------------------------ image ----------------------------- */
11 static t_class *image_class;
13 typedef struct _image
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;
22 /* widget helper functions */
24 void image_drawme(t_image *x, t_glist *glist, int firsttime)
26 #ifdef ROCKBOX
27 (void) x;
28 (void) glist;
29 (void) firsttime;
30 #else /* ROCKBOX */
31 if (firsttime) {
32 char fname[MAXPDSTRING];
33 canvas_makefilename(glist_getcanvas(x->x_glist), x->x_fname->s_name,
34 fname, MAXPDSTRING);
36 sys_vgui("image create photo img%x -file %s\n",x,fname);
37 sys_vgui(".x%x.c create image %d %d -image img%x -tags %xS\n",
38 glist_getcanvas(glist),text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x,x);
40 /* TODO callback from gui
41 sys_vgui("image_size logo");
44 else {
45 sys_vgui(".x%x.c coords %xS \
46 %d %d\n",
47 glist_getcanvas(glist), x,
48 text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
50 #endif /* ROCKBOX */
54 void image_erase(t_image* x,t_glist* glist)
56 #ifdef ROCKBOX
57 (void) x;
58 (void) glist;
59 #else /* ROCKBOX */
60 int n;
61 sys_vgui(".x%x.c delete %xS\n",
62 glist_getcanvas(glist), x);
63 #endif /* ROCKBOX */
68 /* ------------------------ image widgetbehaviour----------------------------- */
71 static void image_getrect(t_gobj *z, t_glist *glist,
72 int *xp1, int *yp1, int *xp2, int *yp2)
74 int width, height;
75 t_image* x = (t_image*)z;
78 width = x->x_width;
79 height = x->x_height;
80 *xp1 = text_xpix(&x->x_obj, glist);
81 *yp1 = text_ypix(&x->x_obj, glist);
82 *xp2 = text_xpix(&x->x_obj, glist) + width;
83 *yp2 = text_ypix(&x->x_obj, glist) + height;
86 static void image_displace(t_gobj *z, t_glist *glist,
87 int dx, int dy)
89 t_image *x = (t_image *)z;
90 x->x_obj.te_xpix += dx;
91 x->x_obj.te_ypix += dy;
92 #ifndef ROCKBOX
93 sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n",
94 glist_getcanvas(glist), x,
95 text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
96 text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height);
97 #endif
98 image_drawme(x, glist, 0);
99 canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
102 static void image_select(t_gobj *z, t_glist *glist, int state)
104 #ifdef ROCKBOX
105 (void) z;
106 (void) glist;
107 (void) state;
108 #else /* ROCKBOX */
109 t_image *x = (t_image *)z;
110 if (state) {
111 sys_vgui(".x%x.c create rectangle \
112 %d %d %d %d -tags %xSEL -outline blue\n",
113 glist_getcanvas(glist),
114 text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
115 text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
118 else {
119 sys_vgui(".x%x.c delete %xSEL\n",
120 glist_getcanvas(glist), x);
122 #endif /* ROCKBOX */
126 static void image_activate(t_gobj *z, t_glist *glist, int state)
128 #ifdef ROCKBOX
129 (void) z;
130 (void) glist;
131 (void) state;
132 #endif
133 /* t_text *x = (t_text *)z;
134 t_rtext *y = glist_findrtext(glist, x);
135 if (z->g_pd != gatom_class) rtext_activate(y, state);*/
138 static void image_delete(t_gobj *z, t_glist *glist)
140 t_text *x = (t_text *)z;
141 canvas_deletelinesfor(glist_getcanvas(glist), x);
145 static void image_vis(t_gobj *z, t_glist *glist, int vis)
147 t_image* s = (t_image*)z;
148 if (vis)
149 image_drawme(s, glist, 1);
150 else
151 image_erase(s,glist);
154 /* can we use the normal text save function ?? */
156 static void image_save(t_gobj *z, t_binbuf *b)
158 t_image *x = (t_image *)z;
159 binbuf_addv(b, "ssiiss", gensym("#X"),gensym("obj"),
160 x->x_obj.te_xpix, x->x_obj.te_ypix,
161 gensym("image"),x->x_fname);
162 binbuf_addv(b, ";");
166 t_widgetbehavior image_widgetbehavior;
168 void image_size(t_image* x,t_floatarg w,t_floatarg h) {
169 x->x_width = w;
170 x->x_height = h;
173 void image_color(t_image* x,t_symbol* col)
175 #ifdef ROCKBOX
176 (void) x;
177 (void) col;
178 #endif
179 /* outlet_bang(x->x_obj.ob_outlet); only bang if there was a bang ..
180 so color black does the same as bang, but doesn't forward the bang
184 static void image_setwidget(void)
186 image_widgetbehavior.w_getrectfn = image_getrect;
187 image_widgetbehavior.w_displacefn = image_displace;
188 image_widgetbehavior.w_selectfn = image_select;
189 image_widgetbehavior.w_activatefn = image_activate;
190 image_widgetbehavior.w_deletefn = image_delete;
191 image_widgetbehavior.w_visfn = image_vis;
192 #if defined(PD_VERSION_MINOR) && (PD_VERSION_MINOR > 31)
193 image_widgetbehavior.w_clickfn = NULL;
194 image_widgetbehavior.w_propertiesfn = NULL;
195 #endif
196 #if defined(PD_VERSION_MINOR) && PD_MINOR_VERSION < 37
197 image_widgetbehavior.w_savefn = image_save;
198 #endif
202 static void *image_new(t_symbol* fname)
204 t_image *x = (t_image *)pd_new(image_class);
206 x->x_glist = (t_glist*) canvas_getcurrent();
208 x->x_width = 15;
209 x->x_height = 15;
211 x->x_fname = fname;
212 outlet_new(&x->x_obj, &s_float);
213 return (x);
216 void image_setup(void)
218 image_class = class_new(gensym("image"), (t_newmethod)image_new, 0,
219 sizeof(t_image),0, A_DEFSYM,0);
222 class_addmethod(image_class, (t_method)image_size, gensym("size"),
223 A_FLOAT, A_FLOAT, 0);
225 class_addmethod(image_class, (t_method)image_color, gensym("color"),
226 A_SYMBOL, 0);
229 class_addmethod(image_class, (t_method)image_open, gensym("open"),
230 A_SYMBOL, 0);
232 image_setwidget();
233 class_setwidget(image_class,&image_widgetbehavior);
234 #if PD_MINOR_VERSION >= 37
235 class_setsavefn(image_class,&image_save);
236 #endif