public AnimatedIcon (RuntimeAddin addin, string animationSpec, Gtk.IconSize size) { this.addin = addin; this.size = size; this.animationSpec = animationSpec; Parse (animationSpec); }
public void GetIconSet(out Gtk.IconSet icon_set, out Gtk.IconSize size) { IntPtr native_icon_set; int native_size; gtk_image_get_icon_set(Handle, out native_icon_set, out native_size); icon_set = native_icon_set == IntPtr.Zero ? null : (Gtk.IconSet)GLib.Opaque.GetOpaque(native_icon_set, typeof(Gtk.IconSet), false); size = (Gtk.IconSize)native_size; }
public void GetIcon(out GLib.IIcon gicon, out Gtk.IconSize size) { IntPtr native_gicon; int native_size; gtk_image_get_gicon(Handle, out native_gicon, out native_size); gicon = GLib.IconAdapter.GetObject(native_gicon, false); size = (Gtk.IconSize)native_size; }
public static AnimatedIcon GetAnimatedIcon(string iconId, Gtk.IconSize size) { EnsureStockIconIsLoaded(iconId); string id = GetStockIdForImageSpec(iconId, size); AnimatedIcon aicon; animationFactory.TryGetValue(id, out aicon); return(aicon); }
public static Gdk.Pixbuf LoadIcon(Gtk.Widget widget, string name, Gtk.IconSize size) { Gdk.Pixbuf res = widget.RenderIcon(name, size, null); if ((res != null)) { return(res); } else { int sz; int sy; global::Gtk.Icon.SizeLookup(size, out sz, out sy); try { return(Gtk.IconTheme.Default.LoadIcon(name, sz, 0)); } catch (System.Exception) { if ((name != "gtk-missing-image")) { return(Stetic.IconLoader.LoadIcon(widget, "gtk-missing-image", size)); } else { Gdk.Pixmap pmap = new Gdk.Pixmap(Gdk.Screen.Default.RootWindow, sz, sz); Gdk.GC gc = new Gdk.GC(pmap); gc.RgbFgColor = new Gdk.Color(255, 255, 255); pmap.DrawRectangle(gc, true, 0, 0, sz, sz); gc.RgbFgColor = new Gdk.Color(0, 0, 0); pmap.DrawRectangle(gc, false, 0, 0, (sz - 1), (sz - 1)); gc.SetLineAttributes( 3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round ); gc.RgbFgColor = new Gdk.Color(255, 0, 0); pmap.DrawLine( gc, (sz / 4), (sz / 4), ((sz - 1) - (sz / 4)), ((sz - 1) - (sz / 4)) ); pmap.DrawLine( gc, ((sz - 1) - (sz / 4)), (sz / 4), (sz / 4), ((sz - 1) - (sz / 4)) ); return(Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, sz, sz)); } } } }
public MDSpinner(Gtk.IconSize size, Image idleImage = null) { Content = imageView = new Xwt.ImageView(); if (size == Gtk.IconSize.Menu) { spinner = ImageService.GetAnimatedIcon("md-spinner-16", size); } else { spinner = ImageService.GetAnimatedIcon("md-spinner-18", size); } IdleImage = idleImage; }
public static string GetStockId(Gdk.Pixbuf pixbuf, Gtk.IconSize size) { string id; if (namedIcons.TryGetValue(pixbuf, out id)) { return(id); } id = "__ni_" + namedIcons.Count; namedIcons[pixbuf] = id; AddToIconFactory(id, pixbuf, size); return(id); }
static string GetComposedIcon(string[] ids, Gtk.IconSize size) { string id = string.Join("_", ids); string cid; if (composedIcons.TryGetValue(id, out cid)) { return(cid); } System.Collections.ICollection col = size == Gtk.IconSize.Invalid ? Enum.GetValues(typeof(Gtk.IconSize)) : new object [] { size }; foreach (Gtk.IconSize sz in col) { if (sz == Gtk.IconSize.Invalid) { continue; } Xwt.Drawing.ImageBuilder ib = null; Xwt.Drawing.Image icon = null; for (int n = 0; n < ids.Length; n++) { var px = GetIcon(ids[n], sz); if (px == null) { LoggingService.LogError("Error creating composed icon {0} at size {1}. Icon {2} is missing.", id, sz, ids[n]); icon = null; break; } if (n == 0) { ib = new Xwt.Drawing.ImageBuilder(px.Width, px.Height); ib.Context.DrawImage(px, 0, 0); icon = px; continue; } if (icon.Width != px.Width || icon.Height != px.Height) { px = px.WithSize(icon.Width, icon.Height); } ib.Context.DrawImage(px, 0, 0); } if (icon != null) { AddToIconFactory(id, ib.ToBitmap().ToPixbuf(), ib.ToBitmap(2f).WithSize(icon.Width * 2, icon.Height * 2).ToPixbuf(), sz); } } composedIcons[id] = id; return(id); }
static string GetComposedIcon(string[] ids, Gtk.IconSize size) { string id = string.Join("_", ids); string cid; if (composedIcons.TryGetValue(id, out cid)) { return(cid); } System.Collections.ICollection col = size == Gtk.IconSize.Invalid ? Enum.GetValues(typeof(Gtk.IconSize)) : new object [] { size }; foreach (Gtk.IconSize sz in col) { if (sz == Gtk.IconSize.Invalid) { continue; } Gdk.Pixbuf icon = null; for (int n = 0; n < ids.Length; n++) { Gdk.Pixbuf px = GetPixbuf(ids[n], sz); if (px == null) { LoggingService.LogError("Error creating composed icon {0} at size {1}. Icon {2} is missing.", id, sz, ids[n]); icon = null; break; } if (n == 0) { icon = px; continue; } if (icon.Width != px.Width || icon.Height != px.Height) { LoggingService.LogWarning("Error creating composed icon {0} at size {1}. Icon {2} is {3}x{4}, expected {5}x{6}.", id, sz, ids[n], px.Width, px.Height, icon.Width, icon.Height); // icon = null; // break; } icon = MergeIcons(icon, px); } if (icon != null) { AddToIconFactory(id, icon, sz); } } composedIcons[id] = id; return(id); }
internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor) { Gdk.Pixbuf result = null; Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault(stockId); if (iconset != null) { // Find the size that better fits the requested size Gtk.IconSize gsize = Util.GetBestSizeFit(width); result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor); if (result == null || result.Width < width * scaleFactor) { var gsize2x = Util.GetBestSizeFit(width * scaleFactor, iconset.Sizes); if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize) { // Don't dispose the previous result since the icon is owned by the IconSet result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null); } } } if (result == null && Gtk.IconTheme.Default.HasIcon(stockId)) { result = Gtk.IconTheme.Default.LoadIcon(stockId, (int)width, (Gtk.IconLookupFlags) 0); } if (result == null) { #if XWT_GTK3 // TODO: GTK3: render a custom gtk-missing-image icon if the stock icon // if Gtk.Stock.MissingImage can not be loaded return(CreateBitmap(Gtk.Stock.MissingImage, width, height, scaleFactor)); #else int w = (int)width; int h = (int)height; Gdk.Pixmap pmap = new Gdk.Pixmap(Gdk.Screen.Default.RootWindow, w, h); Gdk.GC gc = new Gdk.GC(pmap); gc.RgbFgColor = new Gdk.Color(255, 255, 255); pmap.DrawRectangle(gc, true, 0, 0, w, h); gc.RgbFgColor = new Gdk.Color(0, 0, 0); pmap.DrawRectangle(gc, false, 0, 0, (w - 1), (h - 1)); gc.SetLineAttributes(3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round); gc.RgbFgColor = new Gdk.Color(255, 0, 0); pmap.DrawLine(gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4))); pmap.DrawLine(gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4))); return(Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, w, h)); #endif } return(result); }
static string PrivGetStockId(RuntimeAddin addin, string filename, Gtk.IconSize size) { if (addin != null && filename.StartsWith("res:")) { return(InternalGetStockIdFromResource(addin, filename, size)); } if (filename.StartsWith("animation:")) { return(InternalGetStockIdFromAnimation(addin, filename, size)); } return(filename); }
public Button(string icon_name, Gtk.IconSize size) : base(IntPtr.Zero) { if (GetType() != typeof(Button)) { var vals = new List <GLib.Value> (); var names = new List <string> (); CreateNativeObject(names.ToArray(), vals.ToArray()); return; } IntPtr native_icon_name = GLib.Marshaller.StringToPtrGStrdup(icon_name); Raw = gtk_button_new_from_icon_name(native_icon_name, (int)size); GLib.Marshaller.Free(native_icon_name); }
public static Gdk.Pixbuf pixbufFromStock(String stock_id, Gtk.IconSize size) { Gdk.Pixbuf ret = null; try { Gtk.IconSet iset = Gtk.IconFactory.LookupDefault(stock_id); ret = iset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.None, Gtk.StateType.Normal, size, null, ""); } catch (Exception ex) { Console.WriteLine(ex.Message + ex.StackTrace); } return(ret); }
static void GetDefaults() { if (!gotDefault) { // Is there a better way of getting the default? Gtk.Window d = new Gtk.Window(""); Gtk.Toolbar t = new Gtk.Toolbar(); d.Add(t); defaultStyle = t.ToolbarStyle; defaultSize = t.IconSize; d.Destroy(); gotDefault = true; } }
//static string GetStockIdForImageSpec (string filename, Gtk.IconSize size) //{ // return GetStockIdForImageSpec (null, filename, size); //} #if false static string GetStockIdForImageSpec(RuntimeAddin addin, string filename, Gtk.IconSize size) { if (filename.IndexOf('|') == -1) { return(PrivGetStockId(addin, filename, size)); } string[] parts = filename.Split('|'); for (int n = 0; n < parts.Length; n++) { parts[n] = PrivGetStockId(addin, parts[n], size); } return(GetComposedIcon(parts, size)); }
public Image(Gtk.IconSet icon_set, Gtk.IconSize size) : base(IntPtr.Zero) { if (GetType() != typeof(Image)) { ArrayList vals = new ArrayList(); ArrayList names = new ArrayList(); names.Add("icon_set"); vals.Add(new GLib.Value(icon_set)); names.Add("icon_size"); vals.Add(new GLib.Value((int)size)); CreateNativeObject((string[])names.ToArray(typeof(string)), (GLib.Value[])vals.ToArray(typeof(GLib.Value))); return; } Raw = gtk_image_new_from_icon_set(icon_set.Handle, (int)size); }
/// <summary> /// Create Pixbuf from stockId. /// </summary> /// <param name="iconName">Image stock id.</param> /// <param name="size">Icon Size.</param> /// <returns>Return Pixbuf</returns> public Gdk.Pixbuf GetIconFromStock(string iconName, Gtk.IconSize size) { string stockid = iconName; if (stockid != null) { Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault(stockid); if (iconset != null) { return(iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.None, Gtk.StateType.Normal, size, null, null)); } } return(null); }
internal static void EnsureStockIconIsLoaded(string stockId, Gtk.IconSize size) { if (string.IsNullOrEmpty(stockId)) { return; } List <StockIconCodon> stockIcon; if (iconStock.TryGetValue(stockId, out stockIcon)) { stockIcon.ForEach(i => LoadStockIcon(i)); iconStock.Remove(stockId); } }
public Image(Gtk.IconSet icon_set, Gtk.IconSize size) : base(IntPtr.Zero) { if (GetType() != typeof(Image)) { var vals = new List <GLib.Value> (); var names = new List <string> (); names.Add("icon_set"); vals.Add(new GLib.Value(icon_set)); names.Add("icon_size"); vals.Add(new GLib.Value((int)size)); CreateNativeObject(names.ToArray(), vals.ToArray()); return; } Raw = gtk_image_new_from_icon_set(icon_set.Handle, (int)size); }
protected static NSImage GetImage(string name, Gtk.IconSize size, params string[] styles) { var icon = ImageService.GetIcon(name, size); if (styles != null && styles.Length > 0) { icon = icon.WithStyles(styles); } try { return(icon.ToNSImage()); } catch (Exception ex) { Core.LoggingService.LogError($"Failed to load '{name}' as an NSImage", ex); return(icon.ToBitmap(NSScreen.MainScreen.BackingScaleFactor).ToNSImage()); } }
static void AddToIconFactory(string stockId, Gdk.Pixbuf pixbuf, Gtk.IconSize iconSize) { Gtk.IconSet iconSet = iconFactory.Lookup(stockId); if (iconSet == null) { iconSet = new Gtk.IconSet(); iconFactory.Add(stockId, iconSet); } Gtk.IconSource source = new Gtk.IconSource(); source.Pixbuf = pixbuf; source.Size = iconSize; source.SizeWildcarded = iconSize == Gtk.IconSize.Invalid; iconSet.AddSource(source); }
public Image(GLib.IIcon icon, Gtk.IconSize size) : base(IntPtr.Zero) { if (GetType() != typeof(Image)) { var vals = new List <GLib.Value> (); var names = new List <string> (); if (icon != null) { names.Add("icon"); vals.Add(new GLib.Value(icon)); } CreateNativeObject(names.ToArray(), vals.ToArray()); return; } Raw = gtk_image_new_from_gicon(icon == null ? IntPtr.Zero : ((icon is GLib.Object) ? (icon as GLib.Object).Handle : (icon as GLib.IconAdapter).Handle), (int)size); }
protected static NSImage GetImage(string name, Gtk.IconSize size, double alpha, bool selected = false) { var icon = ImageService.GetIcon(name, size).WithAlpha(alpha); if (selected) { icon = icon.WithStyles("sel"); } try { return(icon.ToNSImage()); } catch (Exception ex) { Core.LoggingService.LogError($"Failed to load '{name}' as an NSImage", ex); return(icon.ToBitmap(NSScreen.MainScreen.BackingScaleFactor).ToNSImage()); } }
protected override Gdk.Pixbuf OnGetPixbufForFile(string filename, Gtk.IconSize size) { //this only works on MacOS 10.6.0 and greater if (systemVersion < 0x1060) { return(base.OnGetPixbufForFile(filename, size)); } NSImage icon = null; if (Path.IsPathRooted(filename) && File.Exists(filename)) { icon = NSWorkspace.SharedWorkspace.IconForFile(filename); } else { string extension = Path.GetExtension(filename); if (!string.IsNullOrEmpty(extension)) { icon = NSWorkspace.SharedWorkspace.IconForFileType(extension); } } if (icon == null) { return(base.OnGetPixbufForFile(filename, size)); } int w, h; if (!Gtk.Icon.SizeLookup(Gtk.IconSize.Menu, out w, out h)) { w = h = 22; } var rect = new System.Drawing.RectangleF(0, 0, w, h); using (var rep = icon.BestRepresentation(rect, null, null)) { if (rep == null) { return(base.OnGetPixbufForFile(filename, size)); } return(GetPixbufFromNSImageRep(rep, w, h)); } }
public static Gdk.Pixbuf GetPixbuf(string name, Gtk.IconSize size, bool generateDefaultIcon) { if (string.IsNullOrEmpty(name)) { LoggingService.LogWarning("Empty icon requested. Stack Trace: " + Environment.NewLine + Environment.StackTrace); return(CreateColorBlock("#FF0000", size)); } // If this name refers to an icon defined in an extension point, the images for the icon will now be laoded EnsureStockIconIsLoaded(name, size); //if an icon name begins with '#', we assume it's a hex colour if (name[0] == '#') { return(CreateColorBlock(name, size)); } // Converts an image spec into a real stock icon id string stockid = GetStockIdForImageSpec(name, size); if (string.IsNullOrEmpty(stockid)) { LoggingService.LogWarning("Can't get stock id for " + name + " : " + Environment.NewLine + Environment.StackTrace); return(CreateColorBlock("#FF0000", size)); } Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault(stockid); if (iconset != null) { return(iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, size, null, null)); } if (Gtk.IconTheme.Default.HasIcon(stockid)) { int w, h; Gtk.Icon.SizeLookup(size, out w, out h); Gdk.Pixbuf result = Gtk.IconTheme.Default.LoadIcon(stockid, h, (Gtk.IconLookupFlags) 0); return(result); } if (generateDefaultIcon) { LoggingService.LogWarning("Can't lookup icon: " + name); return(CreateColorBlock("#FF0000FF", size)); } return(null); }
public Gtk.Widget CreateIcon(Gtk.IconSize size) { if (GtkAction.StockId == null) { return(null); } Gdk.Pixbuf px = Project.IconFactory.RenderIcon(Project, GtkAction.StockId, size); if (px != null) { return(new Gtk.Image(px)); } else { return(GtkAction.CreateIcon(size)); } }
static void LoadStockIcon(StockIconCodon iconCodon, bool forceWildcard) { try { Gdk.Pixbuf pixbuf = null; if (!string.IsNullOrEmpty(iconCodon.Resource) || !string.IsNullOrEmpty(iconCodon.File)) { // using the stream directly produces a gdk warning. byte[] buffer; Stream stream; if (iconCodon.Resource != null) { stream = iconCodon.Addin.GetResource(iconCodon.Resource); } else { stream = File.OpenRead(iconCodon.Addin.GetFilePath(iconCodon.File)); } using (stream) { if (stream == null || stream.Length < 0) { LoggingService.LogError("Did not find resource '{0}' in addin '{1}' for icon '{2}'", iconCodon.Resource, iconCodon.Addin.Id, iconCodon.StockId); return; } buffer = new byte [stream.Length]; stream.Read(buffer, 0, (int)stream.Length); } pixbuf = new Gdk.Pixbuf(buffer); } else if (!string.IsNullOrEmpty(iconCodon.IconId)) { pixbuf = GetPixbuf(InternalGetStockId(iconCodon.Addin, iconCodon.IconId, iconCodon.IconSize), iconCodon.IconSize); } if (pixbuf != null) { Gtk.IconSize size = forceWildcard? Gtk.IconSize.Invalid : iconCodon.IconSize; AddToIconFactory(iconCodon.StockId, pixbuf, size); } } catch (Exception ex) { LoggingService.LogError(string.Format("Error loading icon '{0}'", iconCodon.StockId), ex); } }
internal static void EnsureStockIconIsLoaded(string stockId, Gtk.IconSize size) { if (string.IsNullOrEmpty(stockId)) { return; } #if false List <StockIconCodon> stockIcon; if (iconStock.TryGetValue(stockId, out stockIcon)) { //determine whether there's a wildcarded image bool hasWildcard = false; foreach (var i in stockIcon) { if (i.IconSize == Gtk.IconSize.Invalid) { hasWildcard = true; } } //load all the images foreach (var i in stockIcon) { LoadStockIcon(i, false); } //if there's no wildcard, find the "biggest" version and make it a wildcard if (!hasWildcard) { int biggest = 0, biggestSize = iconSizes[(int)stockIcon[0].IconSize].Width; for (int i = 1; i < stockIcon.Count; i++) { int w = iconSizes[(int)stockIcon[i].IconSize].Width; if (w > biggestSize) { biggest = i; biggestSize = w; } } // LoggingService.LogWarning ("Stock icon '{0}' registered without wildcarded version.", stockId); LoadStockIcon(stockIcon[biggest], true); } // Icon loaded, it can be removed from the pending icon collection iconStock.Remove(stockId); } #endif }
public Image(string stock_id, Gtk.IconSize size) : base(IntPtr.Zero) { if (GetType() != typeof(Image)) { var vals = new List <GLib.Value> (); var names = new List <string> (); names.Add("stock"); vals.Add(new GLib.Value(stock_id)); names.Add("icon_size"); vals.Add(new GLib.Value((int)size)); CreateNativeObject(names.ToArray(), vals.ToArray()); return; } IntPtr native = GLib.Marshaller.StringToPtrGStrdup(stock_id); Raw = gtk_image_new_from_stock(native, (int)size); GLib.Marshaller.Free(native); }
static string InternalGetStockIdFromResource(RuntimeAddin addin, string id, Gtk.IconSize size) { if (!id.StartsWith("res:", StringComparison.Ordinal)) { 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)) { icons[stockId] = LoadStockIcon(addin, stockId, id, null, null, size, null, false); hash[stockId] = stockId; } return(stockId); }
static Gdk.Pixbuf CreateColorBlock(string name, Gtk.IconSize size) { int w, h; if (!Gtk.Icon.SizeLookup(Gtk.IconSize.Menu, out w, out h)) { w = h = 22; } Gdk.Pixbuf p = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, w, h); uint color; if (!TryParseColourFromHex(name, false, out color)) { //if lookup fails, make it transparent color = 0xffffff00u; } p.Fill(color); return(p); }
void IconSizeChanged (object o, GLib.NotifyArgs args) { this.lastSize = ((Gtk.Toolbar) o).IconSize; UpdateCustomItems ((Gtk.Toolbar) o); }
public void Track (Gtk.Toolbar toolbar) { lastSize = toolbar.IconSize; toolbar.AddNotification ("icon-size", IconSizeChanged); toolbar.OrientationChanged += HandleToolbarOrientationChanged; toolbar.StyleChanged += HandleToolbarStyleChanged; toolbar.Destroyed += delegate { toolbar.StyleChanged -= HandleToolbarStyleChanged; toolbar.OrientationChanged -= HandleToolbarOrientationChanged; toolbar.RemoveNotification ("icon-size", IconSizeChanged); }; }
void OnToolbarPropChanged (object ob, GLib.NotifyArgs args) { Gtk.Toolbar t = (Gtk.Toolbar) ob; if (lastSize != t.IconSize || args.Property == "orientation" || args.Property == "toolbar-style") UpdateCustomItems (t); lastSize = t.IconSize; }
public void Track (Gtk.Toolbar toolbar) { lastSize = toolbar.IconSize; toolbar.AddNotification (OnToolbarPropChanged); toolbar.Destroyed += delegate { toolbar.RemoveNotification (OnToolbarPropChanged); }; }
static void GetDefaults () { if (!gotDefault) { // Is there a better way of getting the default? Gtk.Window d = new Gtk.Window (""); Gtk.Toolbar t = new Gtk.Toolbar (); d.Add (t); defaultStyle = t.ToolbarStyle; defaultSize = t.IconSize; d.Destroy (); gotDefault = true; } }