Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Guess we were working on the same thing! My fix is a little more robust I think. #15

Merged
merged 3 commits into from

2 participants

@jpobst

No description provided.

Pinta.Resources/ResourceManager.cs
((38 lines not shown))
- return icon;
+ // Try to return gtk's default missing image
+ if (name != "gtk-missing-image")
@cameronwhite Owner

I'd prefer to use Gtk.Stock.MissingImage here instead of hard-coding the string.

@jpobst
jpobst added a note

Good point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@cameronwhite

Agreed, this is definitely a more robust way to solve the issue.

@cameronwhite cameronwhite merged commit f5dfe28 into PintaProject:master
@cameronwhite

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 37 additions and 24 deletions.
  1. +37 −24 Pinta.Resources/ResourceManager.cs
View
61 Pinta.Resources/ResourceManager.cs
@@ -33,32 +33,45 @@ public static class ResourceLoader
{
public static Pixbuf GetIcon (string name, int size)
{
- Pixbuf icon = null;
+ try {
+ // First see if it's a built-in gtk icon, like gtk-new
+ if (Gtk.IconTheme.Default.HasIcon (name))
+ return Gtk.IconTheme.Default.LoadIcon (name, size, Gtk.IconLookupFlags.UseBuiltin);
- try
- {
- // First see if it's a built-in gtk icon, like gtk-new
- if (Gtk.IconTheme.Default.HasIcon(name))
- {
- icon = Gtk.IconTheme.Default.LoadIcon(name, size, Gtk.IconLookupFlags.UseBuiltin);
- }
- // Otherwise, get it from our embedded resources.
- else
- {
- icon = Gdk.Pixbuf.LoadFromResource(name);
- }
- }
- // Ensure that we don't crash if an icon is missing for some reason, and provide a "missing image" icon if possible.
- catch (Exception e)
- {
- System.Console.Error.WriteLine (e.ToString());
- if (Gtk.IconTheme.Default.HasIcon (Gtk.Stock.MissingImage))
- {
- icon = Gtk.IconTheme.Default.LoadIcon (Gtk.Stock.MissingImage, size, Gtk.IconLookupFlags.UseBuiltin);
- }
- }
+ // Otherwise, get it from our embedded resources.
+ return Gdk.Pixbuf.LoadFromResource (name);
+ }
+ catch (Exception ex) {
+ // Ensure that we don't crash if an icon is missing for some reason.
+ System.Console.Error.WriteLine (ex.Message);
- return icon;
+ // Try to return gtk's default missing image
+ if (name != Gtk.Stock.MissingImage)
+ return GetIcon (Gtk.Stock.MissingImage, size);
+
+ // If gtk is missing it's "missing image", we'll create one on the fly
+ return CreateMissingImage (size);
+ }
+ }
+
+ // From MonoDevelop:
+ // https://github.com/mono/monodevelop/blob/master/main/src/core/MonoDevelop.Ide/gtk-gui/generated.cs
+ private static Pixbuf CreateMissingImage (int size)
+ {
+ var pmap = new Gdk.Pixmap (Gdk.Screen.Default.RootWindow, size, size);
+ var gc = new Gdk.GC (pmap);
+
+ gc.RgbFgColor = new Gdk.Color (255, 255, 255);
+ pmap.DrawRectangle (gc, true, 0, 0, size, size);
+ gc.RgbFgColor = new Gdk.Color (0, 0, 0);
+ pmap.DrawRectangle (gc, false, 0, 0, (size - 1), (size - 1));
+
+ gc.SetLineAttributes (3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
+ gc.RgbFgColor = new Gdk.Color (255, 0, 0);
+ pmap.DrawLine (gc, (size / 4), (size / 4), ((size - 1) - (size / 4)), ((size - 1) - (size / 4)));
+ pmap.DrawLine (gc, ((size - 1) - (size / 4)), (size / 4), (size / 4), ((size - 1) - (size / 4)));
+
+ return Gdk.Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, size, size);
}
}
}
Something went wrong with that request. Please try again.