1 #include "../src/m_pd.h"
5 #pragma warning( disable : 4244 )
6 #pragma warning( disable : 4305 )
9 /* ------------------------ image ----------------------------- */
11 static t_class
*image_class
;
22 /* widget helper functions */
24 void image_drawme(t_image
*x
, t_glist
*glist
, int firsttime
)
32 char fname
[MAXPDSTRING
];
33 canvas_makefilename(glist_getcanvas(x
->x_glist
), x
->x_fname
->s_name
,
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");
45 sys_vgui(".x%x.c coords %xS \
47 glist_getcanvas(glist
), x
,
48 text_xpix(&x
->x_obj
, glist
), text_ypix(&x
->x_obj
, glist
));
54 void image_erase(t_image
* x
,t_glist
* glist
)
61 sys_vgui(".x%x.c delete %xS\n",
62 glist_getcanvas(glist
), x
);
68 /* ------------------------ image widgetbehaviour----------------------------- */
71 static void image_getrect(t_gobj
*z
, t_glist
*glist
,
72 int *xp1
, int *yp1
, int *xp2
, int *yp2
)
75 t_image
* x
= (t_image
*)z
;
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
,
89 t_image
*x
= (t_image
*)z
;
90 x
->x_obj
.te_xpix
+= dx
;
91 x
->x_obj
.te_ypix
+= dy
;
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
);
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
)
109 t_image
*x
= (t_image
*)z
;
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
,
119 sys_vgui(".x%x.c delete %xSEL\n",
120 glist_getcanvas(glist
), x
);
126 static void image_activate(t_gobj
*z
, t_glist
*glist
, int state
)
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
;
149 image_drawme(s
, glist
, 1);
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
);
166 t_widgetbehavior image_widgetbehavior
;
168 void image_size(t_image
* x
,t_floatarg w
,t_floatarg h
) {
173 void image_color(t_image
* x
,t_symbol
* col
)
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
;
196 #if defined(PD_VERSION_MINOR) && PD_MINOR_VERSION < 37
197 image_widgetbehavior
.w_savefn
= image_save
;
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();
212 outlet_new(&x
->x_obj
, &s_float
);
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"),
229 class_addmethod(image_class, (t_method)image_open, gensym("open"),
233 class_setwidget(image_class
,&image_widgetbehavior
);
234 #if PD_MINOR_VERSION >= 37
235 class_setsavefn(image_class
,&image_save
);