public static Gdk.Pixbuf LoadIcon(Gtk.Widget widget, string name, Gtk.IconSize size, int sz) { Gdk.Pixbuf res = widget.RenderIcon(name, size, null); if ((res != null)) { return(res); } else { 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, sz)); } 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 WelcomePageLinkButton(string title, string href, Gtk.IconSize iconSize = Gtk.IconSize.Menu, string icon = null, string desc = null, string tooltip = null) : this() { this.iconSize = iconSize; if (string.IsNullOrEmpty (title)) throw new InvalidOperationException ("Link is missing title"); this.text = GettextCatalog.GetString (title); if (string.IsNullOrEmpty (href)) throw new InvalidOperationException ("Link is missing href"); this.LinkUrl = href; if (!string.IsNullOrEmpty (desc)) this.desc = GettextCatalog.GetString (desc); if (!string.IsNullOrEmpty (tooltip)) this.TooltipText = GettextCatalog.GetString (tooltip); else this.TooltipText = GetLinkTooltip (href); if (!string.IsNullOrEmpty (icon)) this.icon = icon; UpdateLabel (false); UpdateImage (); }
static string InternalGetStockIdFromAnimation(RuntimeAddin addin, string id, Gtk.IconSize size) { if (!id.StartsWith("animation:", StringComparison.Ordinal)) { return(id); } id = id.Substring(10); Dictionary <string, string> hash; int addinId; if (addin != null) { addinId = GetAddinId(addin); hash = addinIcons[addinId]; } else { addinId = -1; hash = iconSpecToStockId; } string stockId = "__asm" + addinId + "__" + id + "__" + size; if (!hash.ContainsKey(stockId)) { var aicon = new AnimatedIcon(addin, id, size); AddToAnimatedIconFactory(stockId, aicon); hash[stockId] = stockId; icons [stockId] = aicon.FirstFrame; } return(stockId); }
public static void LoadIcon(this Gtk.Image image, string iconId, Gtk.IconSize size) { AnimatedImageInfo ainfo = animatedImages.Select(a => (AnimatedImageInfo)a.Target).FirstOrDefault(a => a != null && a.Image == image); if (ainfo != null) { if (ainfo.AnimatedIcon.AnimationSpec == iconId) { return; } UnregisterImageAnimation(ainfo); } if (IsAnimation(iconId, size)) { var anim = GetAnimatedIcon(iconId); ainfo = new AnimatedImageInfo(image, anim); ainfo.Animation = anim.StartAnimation(delegate(Xwt.Drawing.Image pix) { image.Pixbuf = pix.ToPixbuf(); }); animatedImages.Add(new WeakReference(ainfo)); } else { image.SetFromStock(iconId, size); } }
public static Gtk.Image GetImage(string name, Gtk.IconSize size) { var img = new Gtk.Image(); img.LoadIcon(name, size); return(img); }
public static bool IsAnimation(string iconId, Gtk.IconSize size) { EnsureStockIconIsLoaded(iconId); string id = GetStockIdForImageSpec(iconId, size); return(animationFactory.ContainsKey(id)); }
/// <summary> /// Loads the icon for a given name and size. /// </summary> /// <returns>The icon as a Gdk.Pixbuf or missing image icon if not found.</returns> /// <param name="name">Icon Name.</param> /// <param name="size">Icon Size as a Gtk.IconSize.</param> /// <param name="flags">Lookup Flags like ForceSVG.</param> public static Gdk.Pixbuf LoadIcon(string name, Gtk.IconSize size, IconLookupFlags flags = IconLookupFlags.ForceSvg) { int sz, sy; global::Gtk.Icon.SizeLookup(size, out sz, out sy); return(LoadIcon(name, sz, flags)); }
/// <summary> /// Loads the missing icon for a given Gtk.IconSize. /// </summary> /// <returns>The missing icon. This function uses a cache internally.</returns> /// <param name="size">Size as a Gtk.IconSize.</param> public static Gdk.Pixbuf LoadMissingIcon(Gtk.IconSize size) { int sz, sy; global::Gtk.Icon.SizeLookup(size, out sz, out sy); return(LoadMissingIcon(sz)); }
static EditorStock() { // Load Window icon. WindowIcon = Gdk.Pixbuf.LoadFromResource("tuxjunior-editor.png"); AddIcon(Eye, Gtk.IconSize.Menu, "stock-eye-12.png"); AddIcon(EyeHalf, Gtk.IconSize.Menu, "stock-eye-half-12.png"); // HACK: This is needed to make tool icons show up on Windows, no idea why. // TODO: test if this is still needed with additional SizeWildcarded. // SizeWildcarded only gives fuzzy images, at least for stock-eye-12.png // It looks like windows are confusing large and small toolbar size ("SmallToolbar" causes 2x bigger buttons that "LargeToolbar"), bug in GTK for windows? bug in windows themselves? #if WINDOWS Gtk.IconSize ToolBarIconSize = Gtk.IconSize.SmallToolbar; #else Gtk.IconSize ToolBarIconSize = Gtk.IconSize.LargeToolbar; #endif AddIcon(ToolSelect, ToolBarIconSize, "stock-tool-select-24.png"); AddIcon(ToolTiles, ToolBarIconSize, "stock-tool-tiles-24.png"); AddIcon(ToolObjects, ToolBarIconSize, "stock-tool-objects-24.png"); AddIcon(ToolBrush, ToolBarIconSize, "stock-tool-brush-24.png"); AddIcon(ToolFill, ToolBarIconSize, "stock-tool-fill-24.png"); AddIcon(ToolReplace, ToolBarIconSize, "stock-tool-replace-24.png"); AddIcon(ToolPath, ToolBarIconSize, "stock-tool-path-24.png"); stock.AddDefault(); }
public static Xwt.Drawing.Image WithSize(this Xwt.Drawing.Image image, Gtk.IconSize size) { int w, h; size.GetSize(out w, out h); return(image.WithSize(w, h)); }
public WelcomePageLinkButton (XElement el, Gtk.IconSize iconSize) : this () { this.iconSize = iconSize; string title = (string) (el.Attribute ("title") ?? el.Attribute ("_title")); if (string.IsNullOrEmpty (title)) throw new InvalidOperationException ("Link is missing title"); this.text = GettextCatalog.GetString (title); string href = (string) el.Attribute ("href"); if (string.IsNullOrEmpty (href)) throw new InvalidOperationException ("Link is missing href"); this.LinkUrl = href; string desc = (string) (el.Attribute ("desc") ?? el.Attribute ("_desc")); if (!string.IsNullOrEmpty (desc)) this.desc = GettextCatalog.GetString (desc); string tooltip = (string) (el.Attribute ("tooltip") ?? el.Attribute ("_tooltip")); if (!string.IsNullOrEmpty (tooltip)) this.TooltipText = GettextCatalog.GetString (tooltip); string icon = (string) el.Attribute ("icon"); if (!string.IsNullOrEmpty (icon)) this.icon = icon; UpdateLabel (false); UpdateImage (); }
public Gdk.Pixbuf GetIcon(string name, Gtk.IconSize size) { Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault(name); if (iconset != null) { return(iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.None, Gtk.StateType.Normal, size, null, null)); } return(null); }
public static Xwt.Drawing.Image WithSize(this Xwt.Drawing.Image image, Gtk.IconSize size) { int w, h; if (!Gtk.Icon.SizeLookup(size, out w, out h)) { return(image); } return(image.WithSize(w, h)); }
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 WelcomePageLinksList(string title = null, Gtk.IconSize iconSize = IconSize.Menu, bool homogeneous = false, params WelcomePageLinkButton[] links) : base(title) { Gtk.VBox box = new VBox(); box.Homogeneous = homogeneous; foreach (var button in links) { box.PackStart(button, true, false, 0); } SetContent(box); }
/// <summary> /// Loads the stock icon for a given name and size. /// </summary> /// <returns>The stock icon.</returns> /// <param name="widget">Widget to get the icon for. Themes can modify the stock icon for a specific widget.</param> /// <param name="name">Name.</param> /// <param name="size">Size as Gtk.IconSize.</param> public static Gdk.Pixbuf LoadStockIcon(Gtk.Widget widget, string name, Gtk.IconSize size) { Gdk.Pixbuf res = widget.RenderIcon(name, size, null); if ((res != null)) { return(res); } else { return(LoadMissingIcon(size)); } }
static string GetComposedIcon(string[] ids, Gtk.IconSize size) { string id = string.Join("_", ids); string cid; if (composedIcons.TryGetValue(id, out cid)) { return(cid); } var col = size == Gtk.IconSize.Invalid ? Enum.GetValues(typeof(Gtk.IconSize)) : new object [] { size }; var frames = new List <Xwt.Drawing.Image> (col.Length); foreach (Gtk.IconSize sz in col) { if (sz == Gtk.IconSize.Invalid) { continue; } var parts = new List <Xwt.Drawing.Image> (ids.Length); 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]); break; } parts.Add(px); } if (parts.Count > 0) { frames.Add(parts.Count > 1 ? Xwt.Drawing.Image.CreateComposedImage(parts) : parts[0]); } } if (frames.Count == 1) { icons[id] = frames[0]; } else if (frames.Count > 1) { icons[id] = Xwt.Drawing.Image.CreateMultiSizeIcon(frames); } else { icons[id] = GetMissingIcon(); } 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 }; var frames = new List <Xwt.Drawing.Image> (); 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); } frames.Add(ib.ToVectorImage()); } icons [id] = Xwt.Drawing.Image.CreateMultiSizeIcon(frames); composedIcons[id] = id; return(id); }
Pixbuf GetIconForDocument(MonoDevelop.Ide.Gui.Document document, Gtk.IconSize iconSize) { if (!string.IsNullOrEmpty(document.Window.ViewContent.StockIconId)) { return(ImageService.GetPixbuf(document.Window.ViewContent.StockIconId, iconSize)); } if (string.IsNullOrEmpty(document.FileName)) { return(ImageService.GetPixbuf(MonoDevelop.Ide.Gui.Stock.MiscFiles, iconSize)); } return(DesktopService.GetPixbufForFile(document.FileName, iconSize)); }
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)); }
static string PrivGetStockId(RuntimeAddin addin, string filename, Gtk.IconSize size) { if (addin != null && filename.StartsWith("res:", StringComparison.Ordinal)) { return(InternalGetStockIdFromResource(addin, filename, size)); } if (filename.StartsWith("animation:", StringComparison.Ordinal)) { return(InternalGetStockIdFromAnimation(addin, filename, size)); } return(filename); }
public WelcomePageFeedItem (XElement el, Gtk.IconSize iconSize) : this () { this.iconSize = iconSize; string title = (string)(el.Attribute ("title") ?? el.Attribute ("_title")); if (string.IsNullOrEmpty (title)) throw new InvalidOperationException ("Link is missing title"); this.text = GettextCatalog.GetString (title); subtitle = (string)el.Attribute ("pubDate"); SetDate (subtitle); string href = (string)el.Attribute ("href"); if (string.IsNullOrEmpty (href)) throw new InvalidOperationException ("Link is missing href"); this.LinkUrl = href; string desc = (string)(el.Attribute ("desc") ?? el.Attribute ("_desc")); desc = CleanHtml (desc); if (!string.IsNullOrEmpty (desc)) { desc = desc.Replace (" [...]", "..."); desc = GettextCatalog.GetString (desc); if (desc.Length > MaxCharacters) { int truncateIndex = desc.IndexOf (" ", MaxCharacters); if (truncateIndex > 0) desc = desc.Substring (0, truncateIndex) + "..."; } this.desc = desc; } string tooltip = (string) (el.Attribute ("tooltip") ?? el.Attribute ("_tooltip")); if (!string.IsNullOrEmpty (tooltip)) this.TooltipText = GettextCatalog.GetString (tooltip); else this.TooltipText = GetLinkTooltip (href); string icon = (string) el.Attribute ("icon"); if (!string.IsNullOrEmpty (icon)) this.icon = icon; UpdateLabel (false); UpdateImage (); }
void Load() { string name = fontOutputButton.Style.FontDescription.ToString(); for (int n = 1; n < isoCodes.Length; n += 2) { comboLanguage.AppendText(GettextCatalog.GetString(isoCodes [n])); } int i = Array.IndexOf(isoCodes, IdeApp.Preferences.UserInterfaceLanguage); if (i == -1) { i = 0; } comboLanguage.Active = i / 2; comboTheme.AppendText(GettextCatalog.GetString("(Default)")); FilePath homeDir = Environment.GetFolderPath(Environment.SpecialFolder.Personal); string[] searchDirs = { homeDir.Combine(".themes"), Gtk.Rc.ThemeDir }; var themes = FindThemes(searchDirs).ToList(); themes.Sort(); foreach (string t in themes) { comboTheme.AppendText(t); } comboTheme.Active = themes.IndexOf(IdeApp.Preferences.UserInterfaceTheme) + 1; documentSwitcherButton.Active = PropertyService.Get("MonoDevelop.Core.Gui.EnableDocumentSwitchDialog", true); fontCheckbox.Active = IdeApp.Preferences.CustomPadFont != null; fontButton.FontName = IdeApp.Preferences.CustomPadFont ?? name; fontButton.Sensitive = fontCheckbox.Active; fontOutputCheckbox.Active = IdeApp.Preferences.CustomOutputPadFont != null; fontOutputButton.FontName = IdeApp.Preferences.CustomOutputPadFont ?? name; fontOutputButton.Sensitive = fontOutputCheckbox.Active; fontCheckbox.Toggled += new EventHandler(FontCheckboxToggled); fontOutputCheckbox.Toggled += new EventHandler(FontOutputCheckboxToggled); Gtk.IconSize curSize = IdeApp.Preferences.ToolbarSize; toolbarCombobox.Active = Array.IndexOf(sizes, curSize); comboCompact.Active = (int)IdeApp.Preferences.WorkbenchCompactness; }
static Gdk.Pixbuf GetPixbuf(string name, Gtk.IconSize size, bool generateDefaultIcon = true) { 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); //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 h = iconSizes[(int)size].Height; 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 WelcomePageLinkButton(XElement el, Gtk.IconSize iconSize) : this() { this.iconSize = iconSize; string title = (string)(el.Attribute("title") ?? el.Attribute("_title")); if (string.IsNullOrEmpty(title)) { throw new InvalidOperationException("Link is missing title"); } this.text = GettextCatalog.GetString(title); string href = (string)el.Attribute("href"); if (string.IsNullOrEmpty(href)) { throw new InvalidOperationException("Link is missing href"); } this.LinkUrl = href; string desc = (string)(el.Attribute("desc") ?? el.Attribute("_desc")); if (!string.IsNullOrEmpty(desc)) { this.desc = GettextCatalog.GetString(desc); } string tooltip = (string)(el.Attribute("tooltip") ?? el.Attribute("_tooltip")); if (!string.IsNullOrEmpty(tooltip)) { this.TooltipText = GettextCatalog.GetString(tooltip); } string icon = (string)el.Attribute("icon"); if (!string.IsNullOrEmpty(icon)) { this.icon = icon; } UpdateLabel(false); UpdateImage(); }
public ImageButton(string text, string iconName, Gtk.IconSize iconSize) : base() { image = new Image(); image.IconName = iconName; image.IconSize = (int)iconSize; label = new Label(); label.MarkupWithMnemonic = text; hbox = new HBox(); hbox.Spacing = 2; hbox.PackStart(image, false, false, 0); hbox.PackStart(label, true, true, 0); Child = hbox; CanDefault = true; ShowAll(); }
void SetItemSize(Gtk.Widget widget, Gtk.IconSize size) { var container = widget as Container; if (container != null) { foreach (var child in container.Children) { SetItemSize(child, size); } } var img = widget as Image; if (img != null) { img.IconSize = (int)size; } }
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); }
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); }
public Pixbuf Render(Widget w, Gtk.IconSize size) { // most basenji icons are gtk stock icons, // so try to render the icon via widget.RenderIcon() first // (RenderIcon return null if the stock_id wasn't knwon) Pixbuf pb = w.RenderIcon(this.name, size, string.Empty); if (pb == null) { // try to render the icon via Gtk.IconTheme if (Gtk.IconTheme.Default.HasIcon(this.name)) { pb = Gtk.IconTheme.Default.LoadIcon(this.name, IconUtils.GetIconSizeVal(size), 0); } else { Debug.WriteLine(string.Format("Icon.Render(): Failed to render icon \"{0}\"", this.name)); } } return(pb); }
public Gdk.Pixbuf GetIconForItem(VolumeItem item, Gtk.IconSize iconSize) { Gdk.Pixbuf pb; if ((item is FileSystemVolumeItem) && (((FileSystemVolumeItem)item).IsSymLink)) { return(iconCache.GetIcon(Icon.SymLink, iconSize)); } string mimeType = item.MimeType; if (string.IsNullOrEmpty(mimeType)) { pb = iconCache.GetIcon(DEFAULT_ICON, iconSize); } else { pb = mimeIconCache.GetIcon(mimeType, iconSize); } return(pb); }
static void AddIcon(string stockid, Gtk.IconSize iconSize, string resource) { Gtk.IconSet iconset = stock.Lookup(stockid); if (iconset == null) { iconset = new Gtk.IconSet(); Gdk.Pixbuf img = Gdk.Pixbuf.LoadFromResource(resource); //no scaling in the given size, ... IconSource source = new IconSource(); source.Size = iconSize; source.SizeWildcarded = false; source.Pixbuf = img; iconset.AddSource(source); //... but allow to use the image for all other sizes, too. source = new IconSource(); source.SizeWildcarded = true; source.Pixbuf = img; iconset.AddSource(source); stock.Add(stockid, iconset); } }