Commit 25f98eeb authored by Andreas Brauchli's avatar Andreas Brauchli Committed by Jens Georg

map: Create Clutter.Image icon loader method

parent c492b7e1
......@@ -256,31 +256,14 @@ private class MapWidget : Gtk.Bin {
button_press_event.connect(map_zoom_handler);
set_size_request(200, 200);
// Load gdk pixbuf via Resources class
Gdk.Pixbuf gdk_marker = Resources.get_icon(Resources.ICON_GPS_MARKER);
Gdk.Pixbuf gdk_marker_selected = Resources.get_icon(Resources.ICON_GPS_MARKER_SELECTED);
try {
// this is what GtkClutter.Texture.set_from_pixmap does
marker_image = new Clutter.Image();
marker_image.set_data(gdk_marker.get_pixels(),
gdk_marker.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888,
gdk_marker.get_width(),
gdk_marker.get_height(),
gdk_marker.get_rowstride());
marker_selected_image = new Clutter.Image();
marker_selected_image.set_data(gdk_marker_selected.get_pixels(),
gdk_marker_selected.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888,
gdk_marker_selected.get_width(),
gdk_marker_selected.get_height(),
gdk_marker_selected.get_rowstride());
marker_image_width = gdk_marker.get_width();
marker_image_height = gdk_marker.get_height();
} catch (GLib.Error e) {
// Fall back to the generic champlain marker
marker_image = null;
marker_selected_image = null;
// Load icons
float w, h;
marker_image = Resources.get_icon_as_clutter_image(
Resources.ICON_GPS_MARKER, out w, out h);
marker_image_width = w;
marker_image_height = h;
marker_selected_image = Resources.get_icon_as_clutter_image(
Resources.ICON_GPS_MARKER_SELECTED, out w, out h);
}
}
......
......@@ -1068,6 +1068,27 @@ along with Shotwell; if not, write to the Free Software Foundation, Inc.,
return (scale > 0) ? scale_pixbuf(pixbuf, scale, Gdk.InterpType.BILINEAR, false) : pixbuf;
}
// Helper method for loading the result of get_icon into a Clutter.Image
// Returns null on error, in which case width and height are set to 0.
public static Clutter.Image? get_icon_as_clutter_image(string name, out float width, out float height) {
Gdk.Pixbuf pixbuf = Resources.get_icon(name);
Clutter.Image clutter_image = new Clutter.Image();
try {
clutter_image.set_data(pixbuf.get_pixels(),
pixbuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888,
pixbuf.get_width(),
pixbuf.get_height(),
pixbuf.get_rowstride());
width = pixbuf.get_width();
height = pixbuf.get_height();
} catch (GLib.Error e) {
width = 0;
height = 0;
return null;
}
return clutter_image;
}
// Get the directory where our help files live. Returns a string
// describing the help path we want, or, if we're installed system
// -wide already, returns null.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment