From 9c2bb4e88b1754e75197326fb98b40f4404e0a38 Mon Sep 17 00:00:00 2001 From: Emmanuel Jourdan Date: Mon, 23 Aug 2021 22:53:08 +0200 Subject: [PATCH 1/4] moved images to the media folder --- {source/ui/uires => media}/idrewitmyself.png | Bin {source/ui/uires => media}/idrewitmyselftongue.png | Bin 2 files changed, 0 insertions(+), 0 deletions(-) rename {source/ui/uires => media}/idrewitmyself.png (100%) rename {source/ui/uires => media}/idrewitmyselftongue.png (100%) diff --git a/source/ui/uires/idrewitmyself.png b/media/idrewitmyself.png similarity index 100% rename from source/ui/uires/idrewitmyself.png rename to media/idrewitmyself.png diff --git a/source/ui/uires/idrewitmyselftongue.png b/media/idrewitmyselftongue.png similarity index 100% rename from source/ui/uires/idrewitmyselftongue.png rename to media/idrewitmyselftongue.png From 73444aef9c4234e23fd9f5374244eb62f5497f75 Mon Sep 17 00:00:00 2001 From: Emmanuel Jourdan Date: Mon, 23 Aug 2021 22:53:29 +0200 Subject: [PATCH 2/4] removed resource file --- source/ui/uires/uires.rc | 7 ------- 1 file changed, 7 deletions(-) delete mode 100755 source/ui/uires/uires.rc diff --git a/source/ui/uires/uires.rc b/source/ui/uires/uires.rc deleted file mode 100755 index 7b4172d3..00000000 --- a/source/ui/uires/uires.rc +++ /dev/null @@ -1,7 +0,0 @@ - -#ifdef APSTUDIO_INVOKED - #error this file is not editable by Microsoft Visual C++ -#endif //APSTUDIO_INVOKED - -IDREWITMYSELF RCDATA "idrewitmyself.png" -IDREWITMYSELFTONGUE RCDATA "idrewitmyselftongue.png" From 789af14ba36356e548d90ce9881303f31262bc5a Mon Sep 17 00:00:00 2001 From: Emmanuel Jourdan Date: Mon, 23 Aug 2021 22:55:42 +0200 Subject: [PATCH 3/4] uires: locate images in the search path we also load images per instance instead of per class. --- source/ui/uires/uires.c | 56 +++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/source/ui/uires/uires.c b/source/ui/uires/uires.c index 86e22c84..13798547 100644 --- a/source/ui/uires/uires.c +++ b/source/ui/uires/uires.c @@ -18,6 +18,8 @@ typedef struct _uires { t_jbox j_box; char j_clicked; char j_hover; + t_jsurface *j_idrewitmyself; + t_jsurface *j_idrewitmyselftongue; } t_uires; @@ -27,6 +29,8 @@ typedef struct _uires { void uires_initclass(); t_uires *uires_new(t_symbol *s, short argc, t_atom *argv); void uires_free(t_uires *x); +void uires_load_surfaces(t_uires *x); +t_jsurface * uires_load_surface_from_name(char *name); void uires_setmouse(t_uires *x, long which); void uires_mousedown(t_uires *x, t_object *patcherview, t_pt pt, long modifiers); @@ -41,7 +45,6 @@ void uires_paint(t_uires *x, t_object *view); // Globals and Statics static t_class *s_uires_class = NULL; -static t_jsurface *s_surf_idrewitmyself, *s_surf_idrewitmyselftongue; /**********************************************************************/ @@ -71,9 +74,6 @@ void ext_main(void *moduleRef) class_register(CLASS_BOX, c); s_uires_class = c; - - s_surf_idrewitmyself = jgraphics_image_surface_create_from_resource(moduleRef, "idrewitmyself"); - s_surf_idrewitmyselftongue = jgraphics_image_surface_create_from_resource(moduleRef, "idrewitmyselftongue"); } @@ -100,6 +100,9 @@ t_uires *uires_new(t_symbol *s, short argc, t_atom *argv) jbox_new(&x->j_box, flags, argc, argv); x->j_box.b_firstin = (t_object *) x; + + // find the images in the search path, and load them. + uires_load_surfaces(x); jbox_ready(&x->j_box); } @@ -107,11 +110,42 @@ t_uires *uires_new(t_symbol *s, short argc, t_atom *argv) } +void uires_load_surfaces(t_uires *x) +{ + if (x->j_idrewitmyself == NULL) { + x->j_idrewitmyself = uires_load_surface_from_name("idrewitmyself.png"); + } + if (x->j_idrewitmyselftongue == NULL) { + x->j_idrewitmyselftongue = uires_load_surface_from_name("idrewitmyselftongue.png"); + } +} + +t_jsurface * uires_load_surface_from_name(char *name) +{ + short path; + t_fourcc outtype; + char filename[MAX_FILENAME_CHARS]; + + strncpy_zero(filename, name, MAX_FILENAME_CHARS); + if (!locatefile_extended(filename, &path, &outtype, NULL, 0)) { + // found the image, get the t_jsurface* from the file + return jgraphics_image_surface_create_from_file(filename, path); + } else { + return NULL; + } +} + void uires_free(t_uires *x) { + if (x->j_idrewitmyself) { + jgraphics_surface_destroy(x->j_idrewitmyself); + x->j_idrewitmyself = NULL; + } + if (x->j_idrewitmyselftongue) { + jgraphics_surface_destroy(x->j_idrewitmyselftongue); + x->j_idrewitmyselftongue = NULL; + } jbox_free(&x->j_box); - - // don't free s_surf_idrewitmyself or s_surf_idrewitmyselftongue! it's used by other uires objects } @@ -153,21 +187,21 @@ void uires_paint(t_uires *x, t_object *view) jbox_get_rect_for_view((t_object *) x, view, &rect); jgraphics_set_source_rgba(g, 0, 0, 0, 1); - if (s_surf_idrewitmyself) { + if (x->j_idrewitmyself && x->j_idrewitmyselftongue) { t_rect src, dst; src.x = src.y = 0.; - src.width = jgraphics_image_surface_get_width(s_surf_idrewitmyself); - src.height = jgraphics_image_surface_get_height(s_surf_idrewitmyself); + src.width = jgraphics_image_surface_get_width(x->j_idrewitmyself); // we know that both images + src.height = jgraphics_image_surface_get_height(x->j_idrewitmyself); // have the same dimensions. dst.x = dst.y = 0.; dst.width = rect.width; dst.height = rect.height; if (x->j_clicked) - jgraphics_image_surface_draw(g, s_surf_idrewitmyselftongue, src, dst); + jgraphics_image_surface_draw(g, x->j_idrewitmyselftongue, src, dst); else - jgraphics_image_surface_draw(g, s_surf_idrewitmyself, src, dst); + jgraphics_image_surface_draw(g, x->j_idrewitmyself, src, dst); } if (x->j_hover) { From f18d07b82e7a45e4deb584471414799afee69c66 Mon Sep 17 00:00:00 2001 From: Emmanuel Jourdan Date: Mon, 23 Aug 2021 22:58:56 +0200 Subject: [PATCH 4/4] adding a warning when the image can't be located --- source/ui/uires/uires.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/ui/uires/uires.c b/source/ui/uires/uires.c index 13798547..b4dd3eed 100644 --- a/source/ui/uires/uires.c +++ b/source/ui/uires/uires.c @@ -30,7 +30,7 @@ void uires_initclass(); t_uires *uires_new(t_symbol *s, short argc, t_atom *argv); void uires_free(t_uires *x); void uires_load_surfaces(t_uires *x); -t_jsurface * uires_load_surface_from_name(char *name); +t_jsurface * uires_load_surface_from_name(t_uires *, char *name); void uires_setmouse(t_uires *x, long which); void uires_mousedown(t_uires *x, t_object *patcherview, t_pt pt, long modifiers); @@ -113,14 +113,14 @@ t_uires *uires_new(t_symbol *s, short argc, t_atom *argv) void uires_load_surfaces(t_uires *x) { if (x->j_idrewitmyself == NULL) { - x->j_idrewitmyself = uires_load_surface_from_name("idrewitmyself.png"); + x->j_idrewitmyself = uires_load_surface_from_name(x, "idrewitmyself.png"); } if (x->j_idrewitmyselftongue == NULL) { - x->j_idrewitmyselftongue = uires_load_surface_from_name("idrewitmyselftongue.png"); + x->j_idrewitmyselftongue = uires_load_surface_from_name(x, "idrewitmyselftongue.png"); } } -t_jsurface * uires_load_surface_from_name(char *name) +t_jsurface * uires_load_surface_from_name(t_uires *x, char *name) { short path; t_fourcc outtype; @@ -131,6 +131,7 @@ t_jsurface * uires_load_surface_from_name(char *name) // found the image, get the t_jsurface* from the file return jgraphics_image_surface_create_from_file(filename, path); } else { + object_warn((t_object *)x, "Couldn't locate image (%s)", name); return NULL; } }