Ejemplo n.º 1
0
        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)
            {
                return(CreateBitmap(Gtk.Stock.MissingImage, width, height, scaleFactor));
            }
            return(result);
        }
        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);
        }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height)
        {
            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);
            }

            if (result == null && Gtk.IconTheme.Default.HasIcon(stockId))
            {
                result = Gtk.IconTheme.Default.LoadIcon(stockId, (int)width, (Gtk.IconLookupFlags) 0);
            }

            return(result);
        }
Ejemplo n.º 7
0
        public override object LoadFromIcon(string id, IconSize size)
        {
            string stockId = Util.ToGtkStock(id);
            var    gsize   = Util.ToGtkSize(size);

            Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault(stockId);
            if (iconset != null)
            {
                return(iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null));
            }

            if (Gtk.IconTheme.Default.HasIcon(stockId))
            {
                int w, h;
                Gtk.Icon.SizeLookup(gsize, out w, out h);
                Gdk.Pixbuf result = Gtk.IconTheme.Default.LoadIcon(stockId, h, (Gtk.IconLookupFlags) 0);
                return(result);
            }
            return(null);
        }
Ejemplo n.º 8
0
        public Gdk.Pixbuf RenderIcon(Gtk.IconSize size)
        {
            if (GtkAction.StockId == null)
            {
                return(null);
            }

            Gdk.Pixbuf px = Project.IconFactory.RenderIcon(Project, GtkAction.StockId, size);
            if (px != null)
            {
                return(px);
            }

            Gtk.IconSet iset = Gtk.IconFactory.LookupDefault(GtkAction.StockId);
            if (iset == null)
            {
                return(WidgetUtils.MissingIcon);
            }
            else
            {
                return(iset.RenderIcon(new Gtk.Style(), Gtk.TextDirection.Ltr, Gtk.StateType.Normal, size, null, ""));
            }
        }
        protected override void Initialize()
        {
            base.Initialize();
            string name = (string)Value;

            if (name != null)
            {
                Stetic.ObjectWrapper w       = Stetic.ObjectWrapper.Lookup(Instance);
                Stetic.IProject      project = w.Project;
                Gdk.Pixbuf           px      = project.IconFactory.RenderIcon(project, name, ImageSize);
                if (px != null)
                {
                    Image = px;
                    label = name;
                    return;
                }

                Gtk.StockItem item = Gtk.Stock.Lookup(name);
                label = item.Label != null && item.Label.Length > 0 ? item.Label : name;
                label = label.Replace("_", "");

                Gtk.IconSet iset = Gtk.IconFactory.LookupDefault(name);
                if (iset == null)
                {
                    Image = WidgetUtils.MissingIcon;
                }
                else
                {
                    Image = iset.RenderIcon(new Gtk.Style(), Gtk.TextDirection.Ltr, Gtk.StateType.Normal, Gtk.IconSize.Menu, null, "");
                }
            }
            else
            {
                Image = null;
                label = "";
            }
        }
Ejemplo n.º 10
0
        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)
            {
                // render a custom gtk-missing-image icon
                // if Gtk.Stock.MissingImage is not found
                int w = (int)width;
                int h = (int)height;
                                #if XWT_GTK3
                Cairo.ImageSurface s  = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
                Cairo.Context      cr = new Cairo.Context(s);
                cr.SetSourceRGB(255, 255, 255);
                cr.Rectangle(0, 0, w, h);
                cr.Fill();
                cr.SetSourceRGB(0, 0, 0);
                cr.LineWidth = 1;
                cr.Rectangle(0.5, 0.5, w - 1, h - 1);
                cr.Stroke();
                cr.SetSourceRGB(255, 0, 0);
                cr.LineWidth = 3;
                cr.LineCap   = Cairo.LineCap.Round;
                cr.LineJoin  = Cairo.LineJoin.Round;
                cr.MoveTo(w / 4, h / 4);
                cr.LineTo((w - 1) - w / 4, (h - 1) - h / 4);
                cr.MoveTo(w / 4, (h - 1) - h / 4);
                cr.LineTo((w - 1) - w / 4, h / 4);
                cr.Stroke();
                result = Gtk3Extensions.GetFromSurface(s, 0, 0, w, h);
                                #else
                using (Gdk.Pixmap pmap = new Gdk.Pixmap(Gdk.Screen.Default.RootWindow, w, h))
                    using (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)));
                        result = Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, w, h);
                    }
                                #endif
            }
            return(result);
        }