mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-27 03:35:31 +00:00
475b44e7ba
resource-file constructors (using code formerly in Pixbuf.custom) * gdk/Pixbuf.custom: Redo the stream and resource ctors in terms of the PixbufLoader ones. * gdk/PixbufAnimation.custom: Add stream and resource ctors * gtk/Image.custom: Add stream and resource ctors svn path=/trunk/gtk-sharp/; revision=42463
91 lines
3 KiB
Plaintext
91 lines
3 KiB
Plaintext
// Image.custom - Customizations to Gtk.Image
|
|
//
|
|
// Copyright (C) 2004 Novell, Inc.
|
|
//
|
|
// This program is free software; you can redistribute it and/or
|
|
// modify it under the terms of version 2 of the Lesser GNU General
|
|
// Public License as published by the Free Software Foundation.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
// Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
// License along with this program; if not, write to the
|
|
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
// Boston, MA 02111-1307, USA.
|
|
|
|
[DllImport("libgtk-win32-2.0-0.dll")]
|
|
static extern IntPtr gtk_image_new_from_icon_set(IntPtr icon_set, int size);
|
|
|
|
public Image (Gtk.IconSet icon_set, Gtk.IconSize size) : base (IntPtr.Zero)
|
|
{
|
|
if (GetType () != typeof (Image)) {
|
|
ArrayList vals = new ArrayList();
|
|
ArrayList names = new ArrayList();
|
|
names.Add ("icon_set");
|
|
vals.Add (new GLib.Value (icon_set));
|
|
names.Add ("icon_size");
|
|
vals.Add (new GLib.Value ((int)size));
|
|
CreateNativeObject ((string[])names.ToArray (typeof (string)), (GLib.Value[])vals.ToArray (typeof (GLib.Value)));
|
|
return;
|
|
}
|
|
Raw = gtk_image_new_from_icon_set(icon_set.Handle, (int) size);
|
|
}
|
|
|
|
[DllImport("libgtk-win32-2.0-0.dll")]
|
|
static extern IntPtr gtk_image_new_from_stock(IntPtr stock_id, int size);
|
|
|
|
public Image (string stock_id, Gtk.IconSize size) : base (IntPtr.Zero)
|
|
{
|
|
if (GetType () != typeof (Image)) {
|
|
ArrayList vals = new ArrayList();
|
|
ArrayList names = new ArrayList();
|
|
names.Add ("stock");
|
|
vals.Add (new GLib.Value (stock_id));
|
|
names.Add ("icon_size");
|
|
vals.Add (new GLib.Value ((int)size));
|
|
CreateNativeObject ((string[])names.ToArray (typeof (string)), (GLib.Value[])vals.ToArray (typeof (GLib.Value)));
|
|
return;
|
|
}
|
|
IntPtr native = GLib.Marshaller.StringToPtrGStrdup (stock_id);
|
|
Raw = gtk_image_new_from_stock(native, (int) size);
|
|
GLib.Marshaller.Free (native);
|
|
}
|
|
|
|
void LoadFromStream (System.IO.Stream stream)
|
|
{
|
|
try {
|
|
Gdk.PixbufAnimation anim = new Gdk.PixbufAnimation (stream);
|
|
if (anim.IsStaticImage)
|
|
Pixbuf = anim.StaticImage;
|
|
else
|
|
PixbufAnimation = anim;
|
|
} catch {
|
|
Stock = Gtk.Stock.MissingImage;
|
|
}
|
|
}
|
|
|
|
public Image (System.IO.Stream stream) : this ()
|
|
{
|
|
LoadFromStream (stream);
|
|
}
|
|
|
|
public Image (System.Reflection.Assembly assembly, string resource) : this ()
|
|
{
|
|
if (assembly == null)
|
|
assembly = System.Reflection.Assembly.GetCallingAssembly ();
|
|
|
|
System.IO.Stream s = assembly.GetManifestResourceStream (resource);
|
|
if (s == null)
|
|
throw new ArgumentException ("'" + resource + "' is not a valid resource name of assembly '" + assembly + "'.");
|
|
|
|
LoadFromStream (s);
|
|
}
|
|
|
|
static public Image LoadFromResource (string resource)
|
|
{
|
|
return new Image (System.Reflection.Assembly.GetCallingAssembly (), resource);
|
|
}
|