static Stream GetResource2x(this RuntimeAddin addin, string id) { var stream = addin.GetResource(Path.GetFileNameWithoutExtension(id) + "@2x" + Path.GetExtension(id)); if (stream == null) { stream = addin.GetResource(id + "@2x"); } return(stream); }
public Stream LoadImage(string fileName) { // load original resource if a mapping exists if (virtualMappings != null && virtualMappings.TryGetValue(fileName, out var mapsTo)) { return(addin.GetResource(mapsTo, true)); } else { return(addin.GetResource(fileName, true)); } }
//static void AddToAnimatedIconFactory (string stockId, AnimatedIcon aicon) //{ // animationFactory [stockId] = aicon; //} #if false static string InternalGetStockIdFromResource(RuntimeAddin addin, string id, Gtk.IconSize size) { if (!id.StartsWith("res:")) { return(id); } id = id.Substring(4); int addinId = GetAddinId(addin); Dictionary <string, string> hash = addinIcons[addinId]; string stockId = "__asm" + addinId + "__" + id + "__" + size; if (!hash.ContainsKey(stockId)) { System.IO.Stream stream = addin.GetResource(id); if (stream != null) { using (stream) { AddToIconFactory(stockId, new Gdk.Pixbuf(stream), size); } } hash[stockId] = stockId; } return(stockId); }
public static Xwt.Drawing.Image GetImageResource(this RuntimeAddin addin, string resource) { using (var s = addin.GetResource(resource)) { var img = Xwt.Drawing.Image.FromStream(s); int i = resource.LastIndexOf('.'); if (i != -1) { var resource2x = resource.Substring(0, i) + "@2x" + resource.Substring(i); var s2x = addin.GetResource(resource2x); if (s2x != null) { using (s2x) { var img2x = Xwt.Drawing.Image.FromStream(s2x); return(Xwt.Drawing.Image.CreateMultiSizeIcon(new Xwt.Drawing.Image[] { img, img2x })); } } } return(img); } }
public Stream LoadImage(string fileName) { return(addin.GetResource(fileName, true)); }
static Xwt.Drawing.Image LoadStockIcon(RuntimeAddin addin, string stockId, string resource, string imageFile, string iconId, Gtk.IconSize iconSize, string animation, bool forceWildcard) { try { Gdk.Pixbuf pixbuf = null, pixbuf2x = null; AnimatedIcon animatedIcon = null; Func <Stream[]> imageLoader = null; if (!string.IsNullOrEmpty(resource) || !string.IsNullOrEmpty(imageFile)) { // using the stream directly produces a gdk warning. byte[] buffer; if (resource != null) { imageLoader = delegate { var stream = addin.GetResource(resource); var stream2x = addin.GetResource2x(resource); if (stream2x == null) { return new [] { stream } } ; else { return new [] { stream, stream2x } }; }; } else { imageLoader = delegate { var file = addin.GetFilePath(imageFile); var stream = File.OpenRead(file); Stream stream2x = null; var file2x = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "@2x" + Path.GetExtension(file)); if (File.Exists(file2x)) { stream2x = File.OpenRead(file2x); } else { file2x = file + "@2x"; if (File.Exists(file2x)) { stream2x = File.OpenRead(file2x); } } if (stream2x == null) { return new [] { stream } } ; else { return new [] { stream, stream2x } }; }; } var streams = imageLoader(); var st = streams[0]; var st2x = streams.Length > 1 ? streams[1] : null; using (st) { if (st == null || st.Length < 0) { LoggingService.LogError("Did not find resource '{0}' in addin '{1}' for icon '{2}'", resource, addin.Id, stockId); return(null); } buffer = new byte [st.Length]; st.Read(buffer, 0, (int)st.Length); } pixbuf = new Gdk.Pixbuf(buffer); using (st2x) { if (st2x != null && st2x.Length >= 0) { buffer = new byte [st2x.Length]; st2x.Read(buffer, 0, (int)st2x.Length); pixbuf2x = new Gdk.Pixbuf(buffer); } } } else if (!string.IsNullOrEmpty(iconId)) { var id = GetStockIdForImageSpec(addin, iconId, iconSize); pixbuf = GetPixbuf(id, iconSize); pixbuf2x = Get2xIconVariant(pixbuf); // This may be an animation, get it animationFactory.TryGetValue(id, out animatedIcon); } else if (!string.IsNullOrEmpty(animation)) { string id = GetStockIdForImageSpec(addin, "animation:" + animation, iconSize); pixbuf = GetPixbuf(id, iconSize); // This *should* be an animation animationFactory.TryGetValue(id, out animatedIcon); } Gtk.IconSize size = forceWildcard? Gtk.IconSize.Invalid : iconSize; if (pixbuf != null) { AddToIconFactory(stockId, pixbuf, pixbuf2x, size); } if (animatedIcon != null) { AddToAnimatedIconFactory(stockId, animatedIcon); } var img = Xwt.Toolkit.CurrentEngine.WrapImage(pixbuf); if (pixbuf2x != null) { var img2x = Xwt.Toolkit.CurrentEngine.WrapImage(pixbuf2x); img = Xwt.Drawing.Image.CreateMultiResolutionImage(new [] { img, img2x }); } if (imageLoader != null) { img.SetStreamSource(imageLoader); } return(img); } catch (Exception ex) { LoggingService.LogError(string.Format("Error loading icon '{0}'", stockId), ex); return(null); } }
//static void AddToAnimatedIconFactory (string stockId, AnimatedIcon aicon) //{ // animationFactory [stockId] = aicon; //} static string InternalGetStockIdFromResource(RuntimeAddin addin, string id, Gtk.IconSize size) { if (!id.StartsWith ("res:")) return id; id = id.Substring (4); int addinId = GetAddinId (addin); Dictionary<string, string> hash = addinIcons[addinId]; string stockId = "__asm" + addinId + "__" + id + "__" + size; if (!hash.ContainsKey (stockId)) { System.IO.Stream stream = addin.GetResource (id); if (stream != null) { using (stream) { AddToIconFactory (stockId, new Gdk.Pixbuf (stream), size); } } hash[stockId] = stockId; } return stockId; }