ui/gtk/image.c

branch
newapi
changeset 265
3756725aeaf4
parent 253
087cc9216f28
child 275
132c7bcc6997
equal deleted inserted replaced
264:24d9a92fd048 265:3756725aeaf4
57 // TODO 57 // TODO
58 return NULL; 58 return NULL;
59 } 59 }
60 } 60 }
61 61
62 // **** new functions **** 62 // **** deprecated2****
63 63
64 static UiIcon* get_icon(const char *name, int size, int scale) { 64 static UiIcon* get_icon(const char *name, int size, int scale) {
65 #ifdef UI_SUPPORTS_SCALE 65 #ifdef UI_SUPPORTS_SCALE
66 GtkIconInfo *info = gtk_icon_theme_lookup_icon_for_scale(icon_theme, name, size, scale, 0); 66 GtkIconInfo *info = gtk_icon_theme_lookup_icon_for_scale(icon_theme, name, size, scale, 0);
67 #else 67 #else
68 GtkIconInfo *info = gtk_icon_theme_lookup_icon(icon_theme, name, size, 0); 68 GtkIconInfo *info = gtk_icon_theme_lookup_icon(icon_theme, name, size, 0);
69 #endif 69 #endif
70 if(info) { 70 if(info) {
71 UiIcon *icon = malloc(sizeof(UiIcon)); 71 UiIcon *icon = malloc(sizeof(UiIcon));
72 icon->info = info; 72 icon->info = info;
73 icon->pixbuf = NULL;
73 return icon; 74 return icon;
74 } 75 }
75 return NULL; 76 return NULL;
76 } 77 }
77 78
78 /* 79 UiIcon* ui_icon(const char* name, size_t size) {
79 UiIcon* ui_icon(const char *name, int size) {
80 return get_icon(name, size, ui_get_scalefactor()); 80 return get_icon(name, size, ui_get_scalefactor());
81 } 81 }
82 */ 82
83 UiIcon* ui_imageicon(const char* file) {
84 GError *error = NULL;
85 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(file, &error);
86 if(!pixbuf) {
87 fprintf(stderr, "UiError: Cannot load image: %s\n", file);
88 return NULL;
89 }
90
91 UiIcon *icon = malloc(sizeof(UiIcon));
92 icon->info = NULL;
93 icon->pixbuf = pixbuf;
94 return icon;
95 }
96
97 void ui_icon_free(UiIcon* icon) {
98 if(icon->info) {
99 g_object_unref(icon->info);
100 }
101 if(icon->pixbuf) {
102 g_object_unref(icon->pixbuf);
103 }
104 free(icon);
105 }
106
107 UiIcon* ui_foldericon(size_t size) {
108 return ui_icon("folder", size);
109 }
110
111 UiIcon* ui_fileicon(size_t size) {
112 return ui_icon("application-x-generic", size);
113 }
83 114
84 UiIcon* ui_icon_unscaled(const char *name, int size) { 115 UiIcon* ui_icon_unscaled(const char *name, int size) {
85 return get_icon(name, size, 1); 116 return get_icon(name, size, 1);
86 } 117 }
87 118
88 void ui_free_icon(UiIcon *icon) {
89 g_object_unref(icon->info);
90 free(icon);
91 }
92 119
93 UiImage* ui_icon_image(UiIcon *icon) { 120 UiImage* ui_icon_image(UiIcon *icon) {
94 GError *error = NULL; 121 GError *error = NULL;
95 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error); 122 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
96 if(pixbuf) { 123 if(pixbuf) {

mercurial