Mercurial > audlegacy
comparison audacious/ui_fileinfo.c @ 1710:43ae2a1bfdee trunk
[svn] improvement of filepopup:
- now filepopup respects aspect ratio of each image.
- it caches scaled image while the same path is being referred.
- its image size and delay until coming up is configurable. (no GUI currently.)
author | yaz |
---|---|
date | Fri, 15 Sep 2006 20:21:35 -0700 |
parents | 77baac5f7439 |
children | 3434eb44b304 |
comparison
equal
deleted
inserted
replaced
1709:950b24509828 | 1710:43ae2a1bfdee |
---|---|
96 fileinfo_entry_set_image(const char *entry, const char *text) | 96 fileinfo_entry_set_image(const char *entry, const char *text) |
97 { | 97 { |
98 GladeXML *xml = g_object_get_data(G_OBJECT(fileinfo_win), "glade-xml"); | 98 GladeXML *xml = g_object_get_data(G_OBJECT(fileinfo_win), "glade-xml"); |
99 GtkWidget *widget = glade_xml_get_widget(xml, entry); | 99 GtkWidget *widget = glade_xml_get_widget(xml, entry); |
100 GdkPixbuf *pixbuf; | 100 GdkPixbuf *pixbuf; |
101 int width, height; | |
102 double aspect; | |
101 | 103 |
102 if (xml == NULL || widget == NULL) | 104 if (xml == NULL || widget == NULL) |
103 return; | 105 return; |
104 | 106 |
105 pixbuf = gdk_pixbuf_new_from_file(text, NULL); | 107 pixbuf = gdk_pixbuf_new_from_file(text, NULL); |
106 | 108 |
107 if (pixbuf == NULL) | 109 if (pixbuf == NULL) |
108 return; | 110 return; |
109 | 111 |
110 if (gdk_pixbuf_get_height(GDK_PIXBUF(pixbuf)) > 150) | 112 width = gdk_pixbuf_get_width(GDK_PIXBUF(pixbuf)); |
113 height = gdk_pixbuf_get_height(GDK_PIXBUF(pixbuf)); | |
114 | |
115 if(strcmp(DATA_DIR "/images/audio.png", text)) | |
111 { | 116 { |
112 GdkPixbuf *pixbuf2 = gdk_pixbuf_scale_simple(GDK_PIXBUF(pixbuf), 150, 150, GDK_INTERP_BILINEAR); | 117 if(width == 0) |
118 width = 1; | |
119 aspect = (double)height / (double)width; | |
120 if(aspect > 1.0) { | |
121 height = (int)(cfg.filepopup_pixelsize * aspect); | |
122 width = cfg.filepopup_pixelsize; | |
123 } else { | |
124 height = cfg.filepopup_pixelsize; | |
125 width = (int)(cfg.filepopup_pixelsize / aspect); | |
126 } | |
127 GdkPixbuf *pixbuf2 = gdk_pixbuf_scale_simple(GDK_PIXBUF(pixbuf), width, height, GDK_INTERP_BILINEAR); | |
113 g_object_unref(G_OBJECT(pixbuf)); | 128 g_object_unref(G_OBJECT(pixbuf)); |
114 pixbuf = pixbuf2; | 129 pixbuf = pixbuf2; |
115 } | 130 } |
116 | 131 |
117 gtk_image_set_from_pixbuf(GTK_IMAGE(widget), GDK_PIXBUF(pixbuf)); | 132 gtk_image_set_from_pixbuf(GTK_IMAGE(widget), GDK_PIXBUF(pixbuf)); |
134 filepopup_entry_set_image(const char *entry, const char *text) | 149 filepopup_entry_set_image(const char *entry, const char *text) |
135 { | 150 { |
136 GladeXML *xml = g_object_get_data(G_OBJECT(filepopup_win), "glade-xml"); | 151 GladeXML *xml = g_object_get_data(G_OBJECT(filepopup_win), "glade-xml"); |
137 GtkWidget *widget = glade_xml_get_widget(xml, entry); | 152 GtkWidget *widget = glade_xml_get_widget(xml, entry); |
138 GdkPixbuf *pixbuf; | 153 GdkPixbuf *pixbuf; |
154 int width, height; | |
155 double aspect; | |
139 | 156 |
140 if (xml == NULL || widget == NULL) | 157 if (xml == NULL || widget == NULL) |
141 return; | 158 return; |
142 | 159 |
143 pixbuf = gdk_pixbuf_new_from_file(text, NULL); | 160 pixbuf = gdk_pixbuf_new_from_file(text, NULL); |
144 | 161 |
145 if (pixbuf == NULL) | 162 if (pixbuf == NULL) |
146 return; | 163 return; |
147 | 164 |
148 if (gdk_pixbuf_get_height(GDK_PIXBUF(pixbuf)) > 150) | 165 width = gdk_pixbuf_get_width(GDK_PIXBUF(pixbuf)); |
166 height = gdk_pixbuf_get_height(GDK_PIXBUF(pixbuf)); | |
167 | |
168 if(strcmp(DATA_DIR "/images/audio.png", text)) | |
149 { | 169 { |
150 GdkPixbuf *pixbuf2 = gdk_pixbuf_scale_simple(GDK_PIXBUF(pixbuf), 150, 150, GDK_INTERP_BILINEAR); | 170 if(width == 0) |
171 width = 1; | |
172 aspect = (double)height / (double)width; | |
173 if(aspect > 1.0) { | |
174 height = (int)(cfg.filepopup_pixelsize * aspect); | |
175 width = cfg.filepopup_pixelsize; | |
176 } else { | |
177 height = cfg.filepopup_pixelsize; | |
178 width = (int)(cfg.filepopup_pixelsize / aspect); | |
179 } | |
180 GdkPixbuf *pixbuf2 = gdk_pixbuf_scale_simple(GDK_PIXBUF(pixbuf), width, height, GDK_INTERP_BILINEAR); | |
151 g_object_unref(G_OBJECT(pixbuf)); | 181 g_object_unref(G_OBJECT(pixbuf)); |
152 pixbuf = pixbuf2; | 182 pixbuf = pixbuf2; |
153 } | 183 } |
154 | 184 |
155 gtk_image_set_from_pixbuf(GTK_IMAGE(widget), GDK_PIXBUF(pixbuf)); | 185 gtk_image_set_from_pixbuf(GTK_IMAGE(widget), GDK_PIXBUF(pixbuf)); |
210 } | 240 } |
211 | 241 |
212 if (filepopup_win->window == NULL) | 242 if (filepopup_win->window == NULL) |
213 skip = TRUE; | 243 skip = TRUE; |
214 | 244 |
215 if (ctr >= 20 && (skip == TRUE || gdk_window_is_viewable(GDK_WINDOW(filepopup_win->window)) != TRUE)) | 245 if (ctr >= cfg.filepopup_delay && (skip == TRUE || gdk_window_is_viewable(GDK_WINDOW(filepopup_win->window)) != TRUE)) |
216 { | 246 { |
217 if (pos == -1) | 247 if (pos == -1) |
218 { | 248 { |
219 filepopup_hide(NULL); | 249 filepopup_hide(NULL); |
220 return TRUE; | 250 return TRUE; |
256 filepopup_entry_set_text("label_genre", ""); | 286 filepopup_entry_set_text("label_genre", ""); |
257 filepopup_entry_set_text("label_track", ""); | 287 filepopup_entry_set_text("label_track", ""); |
258 filepopup_entry_set_text("label_year", ""); | 288 filepopup_entry_set_text("label_year", ""); |
259 filepopup_entry_set_text("label_length", ""); | 289 filepopup_entry_set_text("label_length", ""); |
260 | 290 |
261 filepopup_entry_set_image("image_artwork", DATA_DIR "/images/audio.png"); | |
262 | 291 |
263 gtk_window_resize(GTK_WINDOW(filepopup_win), 1, 1); | 292 gtk_window_resize(GTK_WINDOW(filepopup_win), 1, 1); |
264 } | 293 } |
265 | 294 |
266 void | 295 void |
460 } | 489 } |
461 | 490 |
462 void | 491 void |
463 filepopup_show_for_tuple(TitleInput *tuple) | 492 filepopup_show_for_tuple(TitleInput *tuple) |
464 { | 493 { |
465 gchar *tmp; | 494 gchar *tmp = NULL; |
466 gint x, y, x_off = 3, y_off = 3, h, w; | 495 gint x, y, x_off = 3, y_off = 3, h, w; |
496 | |
497 static gchar *lastpath = NULL; | |
467 | 498 |
468 if (tuple == NULL) | 499 if (tuple == NULL) |
469 return; | 500 return; |
470 | 501 |
471 gtk_widget_realize(filepopup_win); | 502 gtk_widget_realize(filepopup_win); |
482 filepopup_entry_set_text_free("label_year", g_strdup_printf("%d", tuple->year)); | 513 filepopup_entry_set_text_free("label_year", g_strdup_printf("%d", tuple->year)); |
483 | 514 |
484 if (tuple->track_number != 0) | 515 if (tuple->track_number != 0) |
485 filepopup_entry_set_text_free("label_track", g_strdup_printf("%d", tuple->track_number)); | 516 filepopup_entry_set_text_free("label_track", g_strdup_printf("%d", tuple->track_number)); |
486 | 517 |
487 tmp = fileinfo_recursive_get_image(tuple->file_path, 0); | 518 if(strcmp(lastpath?lastpath:"", tuple->file_path)){ |
519 tmp = fileinfo_recursive_get_image(tuple->file_path, 0); | |
488 | 520 |
489 if(tmp) | 521 if(tmp) |
490 { | 522 { |
491 filepopup_entry_set_image("image_artwork", tmp); | 523 filepopup_entry_set_image("image_artwork", tmp); |
492 g_free(tmp); | 524 g_free(tmp); |
493 } | 525 g_free(lastpath); |
494 | 526 lastpath = g_strdup(tuple->file_path); |
527 } else { | |
528 filepopup_entry_set_image("image_artwork", DATA_DIR "/images/audio.png"); | |
529 g_free(lastpath); | |
530 lastpath = g_strdup(tuple->file_path); | |
531 } | |
532 } | |
495 gdk_window_get_pointer(NULL, &x, &y, NULL); | 533 gdk_window_get_pointer(NULL, &x, &y, NULL); |
496 gtk_window_get_size(GTK_WINDOW(filepopup_win), &w, &h); | 534 gtk_window_get_size(GTK_WINDOW(filepopup_win), &w, &h); |
497 if (gdk_screen_width()-(w+3) < x) x_off = (w*-1)-3; | 535 if (gdk_screen_width()-(w+3) < x) x_off = (w*-1)-3; |
498 if (gdk_screen_height()-(h+3) < y) y_off = (h*-1)-3; | 536 if (gdk_screen_height()-(h+3) < y) y_off = (h*-1)-3; |
499 gtk_window_move(GTK_WINDOW(filepopup_win), x + x_off, y + y_off); | 537 gtk_window_move(GTK_WINDOW(filepopup_win), x + x_off, y + y_off); |