Question

i'm trying to load a folder icon as a texture. i have tried almost everything now and i can't get it to work for some reason

i think this thread is just what i'm looking for but it's too advanced. i want it simple for now.

and for some reason i can't get this to work / translate it.

this is the code i have ended up with. don't know what to do now.

class nicholas
{

Gtk.Window window;
GtkClutter.Embed clutter;
Clutter.Rectangle r;
Clutter.Texture t;

public nicholas () 
{
    window = new Gtk.Window ();
    clutter = new GtkClutter.Embed ();
    var stage = clutter.get_stage () as Clutter.Stage;

    stage.background_color = Clutter.Color.from_string ("black");

    var o = new     Cogl.Texture.from_file("/usr/share/icons/gnome/48x48/places/folder.png",     Cogl.TextureFlags.NONE, Cogl.PixelFormat.ANY);
    t = new Clutter.Texture.set_cogl_texture(o);
    t.x = 80;
    t.y = 80;
    stage.add_child (t);

    window.add (clutter);
    window.destroy.connect (Gtk.main_quit);
    window.set_default_size (500, 300);
    window.show_all ();
    }
    }
    public static void main (string [] args)
    {
    GtkClutter.init (ref args);

    nicholas nicholas = new nicholas ();

    Gtk.main ();
    }
Était-ce utile?

La solution

I don't see anything too advanced about Emmanuele's answer… here is a Vala port, with a bit of extra code to actually use the Clutter.Image as a Clutter.Actor's content:

private static Clutter.Actor create_clutter_actor_from_file (string filename) throwsGLib.Error {
  Gdk.Pixbuf pixbuf = new Gdk.Pixbuf.from_file (filename);
  Clutter.Image image = new Clutter.Image ();
  image.set_data (pixbuf.get_pixels (),
                  pixbuf.has_alpha ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888,
                  pixbuf.width,
                  pixbuf.height,
                  pixbuf.rowstride);
  Clutter.Actor actor = new Clutter.Actor ();
  actor.content = image;
  actor.set_size (pixbuf.width, pixbuf.height);
  return actor;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top