Hello everyone,

I have a little problem with the function clutter_texture_set_load_async. Nothing is displayed unless a timer is triggered or action keyboard or mouse is sent, here is my code:

#include <string.h>
#include <clutter/clutter.h>

void
load_finished (
        ClutterActor *image,
        GParamSpec *args1,
        gpointer data)
{
        printf("load_finished()\n");
        clutter_actor_set_size (image, 100, 100);
}

int main(int argc, char **argv)
{
        ClutterActor *stage;
        ClutterColor black = {0x00, 0x00, 0x00, 0xff};

        clutter_init (&argc, &argv);
        g_thread_init (NULL);
        
        // Stage
        stage = clutter_stage_get_default();
        clutter_stage_set_color (CLUTTER_STAGE (stage), &black);
        clutter_stage_set_title (CLUTTER_STAGE (stage), "Async");
        clutter_actor_set_size (stage, 400, 400);

        // Load texture
        GError *error = NULL;
        const gchar *directory_path = "../cover";
        GDir* directory = g_dir_open(directory_path, 0, &error);

        if (error)
        {
                g_warning("g_dir_open() failed: %s\n", error->message);
                g_clear_error(&error);
                return 0;
        }
        
        const gchar* filename = NULL;
        int x = 0, y = 0;
        
        while ((filename = g_dir_read_name(directory)))
        {
                if (g_str_has_suffix(filename, "png"))
                {
                        gchar* path = g_build_filename (directory_path, 
filename, NULL);
                        ClutterActor *image;

                        printf("file: %s, x: %i\n", path, x);
                        
                        image = clutter_texture_new ();
clutter_texture_set_filter_quality ((ClutterTexture *) image, CLUTTER_TEXTURE_QUALITY_MEDIUM);
                        clutter_texture_set_load_async ((ClutterTexture *) 
image, TRUE);
                        clutter_actor_set_position (image, x, y);
                        clutter_container_add (CLUTTER_CONTAINER (stage), 
image, NULL);

                        // Connect load finished and set texture file
g_signal_connect (image, "load-finished", G_CALLBACK (load_finished), NULL);
                        clutter_texture_set_from_file ((ClutterTexture *) 
image, path, NULL);
                        
                        x += 15;
                        y += 15;

                        g_free (path);
                }
        }

        clutter_actor_show (stage);
        clutter_main();
        return 0;
}
--
To unsubscribe send a mail to [email protected]

Reply via email to