diff --git a/externals/moonlib/image.c b/externals/moonlib/image.c index edb3b7bd6fd16411bb08b7101a4796b78da9528f..d1514a0990914e8225ef21355bc0fd352ced5fd2 100644 --- a/externals/moonlib/image.c +++ b/externals/moonlib/image.c @@ -54,7 +54,6 @@ void image_drawme(t_image *x, t_glist *glist, int firsttime) char key2[MAXPDSTRING]; if (firsttime) { -post("about to make a new object. xpix is %d and ypix is %d", text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)); @@ -90,7 +89,7 @@ post("about to make a new object. xpix is %d and ypix is %d", } else { - //sprintf(key, "x%lx", (long unsigned int)x); + sprintf(key, "x%lx", (long unsigned int)x); const char *fname = image_get_filename(x, x->x_image->s_name); if (!x->x_localimage) { @@ -103,7 +102,7 @@ post("about to make a new object. xpix is %d and ypix is %d", //sys_vgui("::moonlib::image::configure .x%lx img%x {%s}\n", // x, x, fname); gui_vmess("gui_load_image", "xss", - glist_getcanvas(glist), x->x_image->s_name, fname); + glist_getcanvas(glist), key, fname); } //sys_vgui(".x%lx.c create image %d %d -image img%x -tags %xS\n", // glist_getcanvas(glist), @@ -112,7 +111,7 @@ post("about to make a new object. xpix is %d and ypix is %d", // x, // x); gui_vmess("gui_gobj_draw_image", "xxs", - glist_getcanvas(glist), x, x->x_image->s_name); + glist_getcanvas(glist), x, key); } /* TODO callback from gui sys_vgui("image_size logo"); @@ -247,12 +246,11 @@ void image_open(t_gobj *z, t_symbol *file) const char *fname; char key[MAXPDSTRING]; int oldtype = x->x_type; - fname = image_get_filename(x, file->s_name); if (fname) { sprintf(key, "x%lx", (long unsigned int)x); - x->x_image = gensym(key); + x->x_image = gensym(fname); x->x_type = 0; if (glist_isvisible(x->x_glist)) { @@ -264,13 +262,13 @@ void image_open(t_gobj *z, t_symbol *file) //sys_vgui("img%x blank\n", x); //sys_vgui("::moonlib::image::configure .x%lx img%x {%s}\n", // x, x, fname); - gui_vmess("gui_load_image", "xsss", + gui_vmess("gui_load_image", "xss", glist_getcanvas(x->x_glist), key, fname); - if (oldtype) + if (oldtype == 0) { //sys_vgui(".x%lx.c itemconfigure %xS -image img%x\n", // glist_getcanvas(x->x_glist), x, x); - gui_vmess("gui_gobj_draw_image", "xxs", + gui_vmess("gui_image_configure", "xxs", glist_getcanvas(x->x_glist), x, key); } } @@ -315,7 +313,7 @@ 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_gobj_draw_image", "xxs", + gui_vmess("gui_image_configure", "xxs", glist_getcanvas(x->x_glist), x, key); } } @@ -351,9 +349,16 @@ static void *image_new(t_symbol *image, t_float type) x->x_localimage = 0; if (image != &s_) { - sprintf(key, "x%lx", (long unsigned int)pd_class(&x->x_obj.te_pd)); - strcat(key, image->s_name); - x->x_image = gensym(key); + if (x->x_type) + { + sprintf(key, "x%lx", (long unsigned int)pd_class(&x->x_obj.te_pd)); + strcat(key, image->s_name); + x->x_image = gensym(key); + } + else + { + x->x_image = image; + } } else x->x_image = &s_; diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index fc3fceccf059cc7ca1e56d9fdd163c2f73ace34b..2017b39f3f93cc28cdd36034cf7e5d293d9b7187 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -2954,7 +2954,7 @@ function gui_load_default_image(dummy_cid, key) { // Load an image and cache the base64 data function gui_load_image(cid, key, filepath) { - var data = fs.readFileSync(filepath,"base64"); + var data = fs.readFileSync(filepath,"base64"), ext = path.extname(filepath); pd_cache.set(key, { type: ext === ".jpeg" ? "jpg" : ext.slice(1), @@ -2980,14 +2980,19 @@ function gui_gobj_draw_image(cid, tag, image_key) { // Switch the data for an existing svg image function gui_image_configure(cid, tag, image_key) { - var i = get_item(tag + "image"); - item.setAttributeNS("http://www.w3.org/1999/xlink", "href", + 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); } +// Move an image +function gui_image_coords(cid, tag, x, y) { + elem_move(get_gobj(cid, tag), x, y); +} + function add_popup(cid, popup) { popup_menu[cid] = popup; }