ui/gtk/image.c

changeset 44
473954dc6b74
parent 32
e5f4d8af567e
child 50
9c25e2616bfa
equal deleted inserted replaced
43:ef01d2c90128 44:473954dc6b74
37 37
38 static CxMap *image_map; 38 static CxMap *image_map;
39 39
40 static GtkIconTheme *icon_theme; 40 static GtkIconTheme *icon_theme;
41 41
42 #if GTK_MAJOR_VERSION >= 4
43 #define ICONTHEME_GET_DEFAULT() gtk_icon_theme_get_for_display(gdk_display_get_default())
44 #else
45 #define ICONTHEME_GET_DEFAULT() gtk_icon_theme_get_default()
46 #endif
47
42 void ui_image_init(void) { 48 void ui_image_init(void) {
43 image_map = cxHashMapCreateSimple(CX_STORE_POINTERS); 49 image_map = cxHashMapCreateSimple(CX_STORE_POINTERS);
44 50
45 icon_theme = gtk_icon_theme_get_default(); 51 icon_theme = ICONTHEME_GET_DEFAULT();
46 } 52 }
47 53
48 // **** deprecated functions **** 54 // **** deprecated functions ****
49 55
50 GdkPixbuf* ui_get_image(const char *name) { 56 GdkPixbuf* ui_get_image(const char *name) {
60 } 66 }
61 67
62 // **** deprecated2**** 68 // **** deprecated2****
63 69
64 static UiIcon* get_icon(const char *name, int size, int scale) { 70 static UiIcon* get_icon(const char *name, int size, int scale) {
65 #ifdef UI_SUPPORTS_SCALE 71 #if GTK_MAJOR_VERSION >= 4
72 GtkIconPaintable *info = gtk_icon_theme_lookup_icon(icon_theme, name, NULL, size, scale, GTK_TEXT_DIR_LTR, GTK_ICON_LOOKUP_FORCE_REGULAR);
73 #elif defined(UI_SUPPORTS_SCALE)
66 GtkIconInfo *info = gtk_icon_theme_lookup_icon_for_scale(icon_theme, name, size, scale, 0); 74 GtkIconInfo *info = gtk_icon_theme_lookup_icon_for_scale(icon_theme, name, size, scale, 0);
67 #else 75 #else
68 GtkIconInfo *info = gtk_icon_theme_lookup_icon(icon_theme, name, size, 0); 76 GtkIconInfo *info = gtk_icon_theme_lookup_icon(icon_theme, name, size, 0);
69 #endif 77 #endif
70 if(info) { 78 if(info) {
114 122
115 UiIcon* ui_icon_unscaled(const char *name, int size) { 123 UiIcon* ui_icon_unscaled(const char *name, int size) {
116 return get_icon(name, size, 1); 124 return get_icon(name, size, 1);
117 } 125 }
118 126
127 #if GTK_MAJOR_VERSION >= 4
128 GdkPixbuf* ui_icon_pixbuf(UiIcon *icon) {
129 if(!icon->pixbuf) {
130 GFile *file = gtk_icon_paintable_get_file(icon->info);
131 GError *error = NULL;
132 icon->pixbuf = gdk_pixbuf_new_from_file(g_file_get_path(file), &error);
133 }
134 return icon->pixbuf;
135 }
136 #else
119 GdkPixbuf* ui_icon_pixbuf(UiIcon *icon) { 137 GdkPixbuf* ui_icon_pixbuf(UiIcon *icon) {
120 if(!icon->pixbuf) { 138 if(!icon->pixbuf) {
121 GError *error = NULL; 139 GError *error = NULL;
122 icon->pixbuf = gtk_icon_info_load_icon(icon->info, &error); 140 icon->pixbuf = gtk_icon_info_load_icon(icon->info, &error);
123 } 141 }
124 return icon->pixbuf; 142 return icon->pixbuf;
125 } 143 }
144 #endif
126 145
146 /*
127 UiImage* ui_icon_image(UiIcon *icon) { 147 UiImage* ui_icon_image(UiIcon *icon) {
128 GError *error = NULL; 148 GError *error = NULL;
129 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error); 149 GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
130 if(pixbuf) { 150 if(pixbuf) {
131 UiImage *img = malloc(sizeof(UiImage)); 151 UiImage *img = malloc(sizeof(UiImage));
132 img->pixbuf = pixbuf; 152 img->pixbuf = pixbuf;
133 return img; 153 return img;
134 } 154 }
135 return NULL; 155 return NULL;
136 } 156 }
157 */
137 158
138 /* 159 /*
139 UiImage* ui_image(const char *filename) { 160 UiImage* ui_image(const char *filename) {
140 return ui_named_image(filename, NULL); 161 return ui_named_image(filename, NULL);
141 } 162 }

mercurial