diff -r 24d9a92fd048 -r 3756725aeaf4 ui/gtk/image.c --- a/ui/gtk/image.c Fri Feb 16 19:00:53 2024 +0100 +++ b/ui/gtk/image.c Fri Feb 16 19:17:30 2024 +0100 @@ -59,7 +59,7 @@ } } -// **** new functions **** +// **** deprecated2**** static UiIcon* get_icon(const char *name, int size, int scale) { #ifdef UI_SUPPORTS_SCALE @@ -70,25 +70,52 @@ if(info) { UiIcon *icon = malloc(sizeof(UiIcon)); icon->info = info; + icon->pixbuf = NULL; return icon; } return NULL; } -/* -UiIcon* ui_icon(const char *name, int size) { +UiIcon* ui_icon(const char* name, size_t size) { return get_icon(name, size, ui_get_scalefactor()); } -*/ + +UiIcon* ui_imageicon(const char* file) { + GError *error = NULL; + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(file, &error); + if(!pixbuf) { + fprintf(stderr, "UiError: Cannot load image: %s\n", file); + return NULL; + } + + UiIcon *icon = malloc(sizeof(UiIcon)); + icon->info = NULL; + icon->pixbuf = pixbuf; + return icon; +} + +void ui_icon_free(UiIcon* icon) { + if(icon->info) { + g_object_unref(icon->info); + } + if(icon->pixbuf) { + g_object_unref(icon->pixbuf); + } + free(icon); +} + +UiIcon* ui_foldericon(size_t size) { + return ui_icon("folder", size); +} + +UiIcon* ui_fileicon(size_t size) { + return ui_icon("application-x-generic", size); +} UiIcon* ui_icon_unscaled(const char *name, int size) { return get_icon(name, size, 1); } -void ui_free_icon(UiIcon *icon) { - g_object_unref(icon->info); - free(icon); -} UiImage* ui_icon_image(UiIcon *icon) { GError *error = NULL;