diff --git a/externals/moonlib/image.c b/externals/moonlib/image.c index d1514a0990914e8225ef21355bc0fd352ced5fd2..8cb429b232c305fbccd845d8ea8fc4083e8847af 100644 --- a/externals/moonlib/image.c +++ b/externals/moonlib/image.c @@ -54,9 +54,6 @@ void image_drawme(t_image *x, t_glist *glist, int firsttime) char key2[MAXPDSTRING]; if (firsttime) { - text_xpix(&x->x_obj, glist), - text_ypix(&x->x_obj, glist)); - gui_vmess("gui_gobj_new", "xxsiii", glist_getcanvas(glist), x, @@ -84,8 +81,11 @@ void image_drawme(t_image *x, t_glist *glist, int firsttime) // x); //sys_vgui(".x%lx.c itemconfigure %xS -image %s\n", // glist_getcanvas(glist), x, x->x_image->s_name); - gui_vmess("gui_gobj_draw_image", "xxs", - glist_getcanvas(glist), x, x->x_image->s_name); + gui_vmess("gui_gobj_draw_image", "xxss", + glist_getcanvas(glist), + x, + x->x_image->s_name, + "center"); } else { @@ -110,8 +110,11 @@ void image_drawme(t_image *x, t_glist *glist, int firsttime) // text_ypix(&x->x_obj, glist), // x, // x); - gui_vmess("gui_gobj_draw_image", "xxs", - glist_getcanvas(glist), x, key); + gui_vmess("gui_gobj_draw_image", "xxss", + glist_getcanvas(glist), + x, + key, + "center"); } /* TODO callback from gui sys_vgui("image_size logo"); @@ -268,8 +271,11 @@ void image_open(t_gobj *z, t_symbol *file) { //sys_vgui(".x%lx.c itemconfigure %xS -image img%x\n", // glist_getcanvas(x->x_glist), x, x); - gui_vmess("gui_image_configure", "xxs", - glist_getcanvas(x->x_glist), x, key); + gui_vmess("gui_image_configure", "xxss", + glist_getcanvas(x->x_glist), + x, + key, + "center"); } } } @@ -313,8 +319,11 @@ void image_set(t_gobj *z, t_symbol *image) { //sys_vgui(".x%lx.c itemconfigure %xS -image %s\n", // glist_getcanvas(x->x_glist), x, x->x_image->s_name); - gui_vmess("gui_image_configure", "xxs", - glist_getcanvas(x->x_glist), x, key); + gui_vmess("gui_image_configure", "xxss", + glist_getcanvas(x->x_glist), + x, + key, + "center"); } } diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index 2017b39f3f93cc28cdd36034cf7e5d293d9b7187..3b89ecba445a5bb8ce536163174a3e017b548827 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -2868,7 +2868,11 @@ function gui_drawimage_free(obj_tag) { // to calculate the dimensions. We then use those dimensions for // our svg image x/y, after which point the Image below _should_ // get garbage collected. -function img_size_setter(cid, svg_image_tag, type, data) { +// We add the "tk_anchor" parameter so that we can match the awful interface +// of moonlib/image. We only check for the value "center"-- otherwise we +// assume "nw" (top-left corner) when tk_anchor is undefined, as this matches +// the svg spec. +function img_size_setter(cid, svg_image_tag, type, data, tk_anchor) { var img = new pd_window.window.Image(), w, h; img.onload = function() { @@ -2876,7 +2880,9 @@ function img_size_setter(cid, svg_image_tag, type, data) { h = this.height; configure_item(get_item(cid, svg_image_tag), { width: w, - height: h + height: h, + x: tk_anchor === "center" ? 0 - w/2 : 0, + y: tk_anchor === "center" ? 0 - h/2 : 0 }); }; img.src = "data:image/" + type + ";base64," + data; @@ -2963,8 +2969,8 @@ function gui_load_image(cid, key, filepath) { } // Draw an image in an object-- used for ggee/image and -// moonlib/image -function gui_gobj_draw_image(cid, tag, image_key) { +// moonlib/image. For the meaning of tk_anchor see img_size_setter. +function gui_gobj_draw_image(cid, tag, image_key, tk_anchor) { var g = get_gobj(cid, tag), i = create_item(cid, "image", { id: tag, @@ -2974,18 +2980,18 @@ function gui_gobj_draw_image(cid, tag, image_key) { "data:image/" + pd_cache.get(image_key).type + ";base64," + pd_cache.get(image_key).data); img_size_setter(cid, tag, pd_cache.get(image_key).type, - pd_cache.get(image_key).data); + pd_cache.get(image_key).data, tk_anchor); g.appendChild(i); } // Switch the data for an existing svg image -function gui_image_configure(cid, tag, image_key) { +function gui_image_configure(cid, tag, image_key, tk_anchor) { var i = get_item(cid, tag); i.setAttributeNS("http://www.w3.org/1999/xlink", "href", "data:image/" + pd_cache.get(image_key).type + ";base64," + pd_cache.get(image_key).data); img_size_setter(cid, tag, pd_cache.get(image_key).type, - pd_cache.get(image_key).data); + pd_cache.get(image_key).data, tk_anchor); } // Move an image