1 /* vim:set et sts=4 sw=4:
5 * Copyright(c) 2011 Peng Huang <shawn.p.huang@gmail.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or(at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307 USA
23 class IconWidget: Gtk.Image {
24 public IconWidget(string icon, int size) {
25 Gdk.Pixbuf pixbuf = null;
28 pixbuf = new Gdk.Pixbuf.from_file(icon);
30 var theme = Gtk.IconTheme.get_default();
31 pixbuf = theme.load_icon(icon, size, 0);
33 } catch (GLib.Error e) {
35 var theme = Gtk.IconTheme.get_default();
36 pixbuf = theme.load_icon(Gtk.Stock.MISSING_IMAGE, size, 0);
37 } catch (GLib.Error e) {}
42 float width = (float)pixbuf.get_width();
43 float height = (float)pixbuf.get_height();
44 float scale = size / (width > height ? width : height);
48 pixbuf = pixbuf.scale_simple((int)width, (int)height, Gdk.InterpType.BILINEAR);
49 set_from_pixbuf(pixbuf);