Xwt.Drawing.Image ExpandImageVertically(Xwt.Drawing.Image img, int newHeight) { if (newHeight <= img.Height) { return(img); } Xwt.Drawing.ImageBuilder ib = new Xwt.Drawing.ImageBuilder(img.Width, newHeight); int h1 = (int)img.Height / 2; int h2 = (int)img.Height - h1; var ctx = ib.Context; ctx.Save(); ctx.Rectangle(0, 0, img.Width, h1); ctx.Clip(); ctx.DrawImage(img, 0, 0); ctx.Restore(); ctx.Save(); ctx.Rectangle(0, newHeight - h2, img.Width, h2); ctx.Clip(); ctx.DrawImage(img, 0, newHeight - img.Height); ctx.Restore(); ctx.Rectangle(0, h1, img.Width, newHeight - h1 - h2); ctx.Clip(); ctx.DrawImage(img, 0, 0, img.Width, newHeight); return(ib.ToVectorImage()); }
public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, NodeInfo nodeInfo) { ProjectFile file = (ProjectFile)dataObject; nodeInfo.Label = GLib.Markup.EscapeText(file.Link.IsNullOrEmpty ? file.FilePath.FileName : file.Link.FileName); if (!File.Exists(file.FilePath)) { nodeInfo.Label = "<span foreground='red'>" + nodeInfo.Label + "</span>"; } nodeInfo.Icon = DesktopService.GetIconForFile(file.FilePath, Gtk.IconSize.Menu); if (file.IsLink && nodeInfo.Icon != null) { var overlay = ImageService.GetIcon("md-link-overlay").WithSize(Xwt.IconSize.Small); var cached = Context.GetComposedIcon(nodeInfo.Icon, overlay); if (cached != null) { nodeInfo.Icon = cached; } else { var ib = new Xwt.Drawing.ImageBuilder(nodeInfo.Icon.Width, nodeInfo.Icon.Height); ib.Context.DrawImage(nodeInfo.Icon, 0, 0); ib.Context.DrawImage(overlay, 0, 0); var res = ib.ToVectorImage(); ib.Dispose(); Context.CacheComposedIcon(nodeInfo.Icon, overlay, res); nodeInfo.Icon = res; } } }
public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, NodeInfo nodeInfo) { ProtobuildPackage package = (ProtobuildPackage) dataObject; nodeInfo.Icon = Context.GetIcon(MonoDevelop.Ide.Gui.Stock.Reference); if (package.IsBinary) { var overlay = ImageService.GetIcon ("md-command").WithSize (Xwt.IconSize.Small); var cached = Context.GetComposedIcon (nodeInfo.Icon, overlay); if (cached != null) nodeInfo.Icon = cached; else { var ib = new Xwt.Drawing.ImageBuilder (nodeInfo.Icon.Width, nodeInfo.Icon.Height); ib.Context.DrawImage (nodeInfo.Icon, 0, 0); ib.Context.DrawImage (overlay, 8, 8, 8, 8); var res = ib.ToVectorImage (); ib.Dispose (); Context.CacheComposedIcon (nodeInfo.Icon, overlay, res); nodeInfo.Icon = res; } } nodeInfo.Label = GettextCatalog.GetString( "{0} <span foreground='grey'><span size='small'>({1}@{2})</span></span>", GLib.Markup.EscapeText(package.Folder), GLib.Markup.EscapeText(package.Uri), GLib.Markup.EscapeText(package.GitRef)); }
static Xwt.Drawing.Image CreateColorIcon(string name) { var color = Xwt.Drawing.Color.FromName(name); using (var ib = new Xwt.Drawing.ImageBuilder(16, 16)) { ib.Context.Rectangle(0, 0, 16, 16); ib.Context.SetColor(color); ib.Context.Fill(); return(ib.ToVectorImage()); } }
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); }
public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, NodeInfo nodeInfo) { ProtobuildContentSourceRule rule = (ProtobuildContentSourceRule) dataObject; nodeInfo.Icon = Context.GetIcon(Stock.OpenReferenceFolder); nodeInfo.ClosedIcon = Context.GetIcon(Stock.ClosedReferenceFolder); if (rule.Primary) { var overlay = ImageService.GetIcon ("md-done").WithSize (Xwt.IconSize.Small); var cached = Context.GetComposedIcon (nodeInfo.Icon, overlay); if (cached != null) nodeInfo.Icon = cached; else { var ib = new Xwt.Drawing.ImageBuilder (nodeInfo.Icon.Width, nodeInfo.Icon.Height); ib.Context.DrawImage (nodeInfo.Icon, 0, 0); ib.Context.DrawImage (overlay, 8, 8, 8, 8); var res = ib.ToVectorImage (); ib.Dispose (); Context.CacheComposedIcon (nodeInfo.Icon, overlay, res); nodeInfo.Icon = res; } cached = Context.GetComposedIcon (nodeInfo.ClosedIcon, overlay); if (cached != null) nodeInfo.ClosedIcon = cached; else { var ib = new Xwt.Drawing.ImageBuilder (nodeInfo.ClosedIcon.Width, nodeInfo.ClosedIcon.Height); ib.Context.DrawImage (nodeInfo.ClosedIcon, 0, 0); ib.Context.DrawImage (overlay, 8, 8, 8, 8); var res = ib.ToVectorImage (); ib.Dispose (); Context.CacheComposedIcon (nodeInfo.ClosedIcon, overlay, res); nodeInfo.ClosedIcon = res; } } nodeInfo.Label = GettextCatalog.GetString( "{0} <span foreground='grey'><span size='small'>(files matching {1})</span></span>", GLib.Markup.EscapeText(rule.Include), GLib.Markup.EscapeText(rule.Match)); }
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 Xwt.Drawing.Image CreateColorIcon (string name) { var color = Xwt.Drawing.Color.FromName (name); using (var ib = new Xwt.Drawing.ImageBuilder (16, 16)) { ib.Context.Rectangle (0, 0, 16, 16); ib.Context.SetColor (color); ib.Context.Fill (); return ib.ToVectorImage (); } }
public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, NodeInfo nodeInfo) { ProjectFile file = (ProjectFile) dataObject; nodeInfo.Label = GLib.Markup.EscapeText (file.Link.IsNullOrEmpty ? file.FilePath.FileName : file.Link.FileName); if (!File.Exists (file.FilePath)) { nodeInfo.Label = "<span foreground='red'>" + nodeInfo.Label + "</span>"; } nodeInfo.Icon = DesktopService.GetIconForFile (file.FilePath, Gtk.IconSize.Menu); if (file.IsLink && nodeInfo.Icon != null) { var overlay = ImageService.GetIcon ("md-link-overlay").WithSize (Xwt.IconSize.Small); var cached = Context.GetComposedIcon (nodeInfo.Icon, overlay); if (cached != null) nodeInfo.Icon = cached; else { var ib = new Xwt.Drawing.ImageBuilder (nodeInfo.Icon.Width, nodeInfo.Icon.Height); ib.Context.DrawImage (nodeInfo.Icon, 0, 0); ib.Context.DrawImage (overlay, 0, 0); var res = ib.ToVectorImage (); ib.Dispose (); Context.CacheComposedIcon (nodeInfo.Icon, overlay, res); nodeInfo.Icon = res; } } }
Xwt.Drawing.Image ExpandImageVertically (Xwt.Drawing.Image img, int newHeight) { if (newHeight <= img.Height) return img; Xwt.Drawing.ImageBuilder ib = new Xwt.Drawing.ImageBuilder (img.Width, newHeight); int h1 = (int)img.Height / 2; int h2 = (int)img.Height - h1; var ctx = ib.Context; ctx.Save (); ctx.Rectangle (0, 0, img.Width, h1); ctx.Clip (); ctx.DrawImage (img, 0, 0); ctx.Restore (); ctx.Save (); ctx.Rectangle (0, newHeight - h2, img.Width, h2); ctx.Clip (); ctx.DrawImage (img, 0, newHeight - img.Height); ctx.Restore (); ctx.Rectangle (0, h1, img.Width, newHeight - h1 - h2); ctx.Clip (); ctx.DrawImage (img, 0, 0, img.Width, newHeight); return ib.ToVectorImage (); }