示例#1
0
 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));
             }
         }
     }
 }
示例#2
0
		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);
					}
				}
			}
		}
        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);
        }
示例#4
0
        public static Gdk.Pixbuf LoadIcon(Gtk.Widget widget, string name, Gtk.IconSize size)
        {
            #if GTK2
            Gdk.Pixbuf res = widget.RenderIcon(name, size, null);
            #elif GTK3
            Gdk.Pixbuf res = widget.RenderIconPixbuf(name, size);
            #endif

            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
                    {
                        #if GTK2
                        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));
                        #elif GTK3
                        throw new System.NotImplementedException();
                        #endif
                    }
                }
            }
        }
 public static Gdk.Pixbuf LoadIcon(string name, int sz) {
     try {
         return Gtk.IconTheme.Default.LoadIcon(name, sz, 0);
     }
     catch (System.Exception ) {
         if ((name != "gtk-missing-image")) {
             return Stetic.IconLoader.LoadIcon("gtk-missing-image", 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);
         }
     }
 }
示例#6
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);
        }
示例#7
0
文件: ImageHandler.cs 项目: mono/xwt
        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;
        }
示例#8
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);
                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);
            }
            return result;
        }