Beispiel #1
0
        static void AddToIconFactory(string stockId, Gdk.Pixbuf pixbuf, Gdk.Pixbuf pixbuf2x, 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();
            Gtk.IconSource source2x = null;

            if (Platform.IsWindows)
            {
                var pixel_scale = GtkWorkarounds.GetPixelScale();
                source.Pixbuf = pixbuf.ScaleSimple((int)(pixbuf.Width * pixel_scale), (int)(pixbuf.Height * pixel_scale), Gdk.InterpType.Bilinear);
            }
            else
            {
                source.Pixbuf = pixbuf;
            }

            source.Size           = iconSize;
            source.SizeWildcarded = iconSize == Gtk.IconSize.Invalid;

            if (pixbuf2x != null)
            {
                if (GtkWorkarounds.SetSourceScale(source, 1))
                {
                    GtkWorkarounds.SetSourceScaleWildcarded(source, false);
                    source2x                = new Gtk.IconSource();
                    source2x.Pixbuf         = pixbuf2x;
                    source2x.Size           = iconSize;
                    source2x.SizeWildcarded = iconSize == Gtk.IconSize.Invalid;
                    GtkWorkarounds.SetSourceScale(source2x, 2);
                    GtkWorkarounds.SetSourceScaleWildcarded(source2x, false);
                }
            }
            else
            {
                GtkWorkarounds.SetSourceScaleWildcarded(source, true);
            }

            iconSet.AddSource(source);
            if (source2x != null)
            {
                iconSet.AddSource(source2x);
            }
        }
Beispiel #2
0
        private static void LoadIcon(IconSet iconSet, string resourceID, Assembly callingAssembly)
        {
            Pixbuf     pixbuf1     = ImageIcon.LoadResource(resourceID, callingAssembly);
            Pixbuf     pixbuf2     = ImageIcon.LoadResource2x(resourceID, callingAssembly);
            IconSource iconSource1 = new IconSource();

            ImageIcon.ConfigIconSource(pixbuf1, iconSource1);
            if (pixbuf2 != null)
            {
                GtkWorkarounds.SetSourceScale(iconSource1, 1.0);
                GtkWorkarounds.SetSourceScaleWildcarded(iconSource1, false);
                IconSource iconSource2 = new IconSource();
                ImageIcon.ConfigIconSource(pixbuf2, iconSource2);
                GtkWorkarounds.SetSourceScale(iconSource2, ImageIcon.ScaleFactor);
                GtkWorkarounds.SetSourceScaleWildcarded(iconSource2, false);
                iconSet.AddSource(iconSource2);
            }
            else
            {
                iconSet.AddSource(iconSource1);
            }
        }