Blame platform-demos/ca/photo-wall.c.page

Packit 1470ea
Packit 1470ea
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" type="topic" id="photo-wall.c" xml:lang="ca">
Packit 1470ea
  <info>
Packit 1470ea
    <title type="text">Photo wall (C)</title>
Packit 1470ea
    <link type="guide" xref="c#examples"/>
Packit 1470ea
Packit 1470ea
    <desc>Un visualitzador d'imatges fet amb Clutter</desc>
Packit 1470ea
Packit 1470ea
    <revision pkgversion="0.1" version="0.1" date="2011-03-22" status="review"/>
Packit 1470ea
    <credit type="author">
Packit 1470ea
      <name>Chris Kühl</name>
Packit 1470ea
      <email its:translate="no">chrisk@openismus.com</email>
Packit 1470ea
    </credit>
Packit 1470ea
    <credit type="author">
Packit 1470ea
      <name>Johannes Schmid</name>
Packit 1470ea
      <email its:translate="no">jhs@gnome.org</email>
Packit 1470ea
    </credit>
Packit 1470ea
    <credit type="editor">
Packit 1470ea
      <name>Marta Maria Casetti</name>
Packit 1470ea
      <email its:translate="no">mmcasetti@gmail.com</email>
Packit 1470ea
      <years>2013</years>
Packit 1470ea
    </credit>
Packit 1470ea
  </info>
Packit 1470ea
Packit 1470ea
<title>Photo wall</title>
Packit 1470ea
Packit 1470ea
<synopsis>
Packit 1470ea
  

En aquest exemple es construirà un visualitzador d'imatges senzill amb la Clutter. Aprendreu a:

Packit 1470ea
  <list>
Packit 1470ea
    <item>

Com dimensionar i posicionar els ClutterActor

</item>
Packit 1470ea
    <item>

Com posar una imatge en un ClutterActor

</item>
Packit 1470ea
    <item>

Com fer transicions senzilles utilitzant l'entorn de treball d'animacions de la Clutter

</item>
Packit 1470ea
    <item>

Com fer que els ClutterActor responguin a esdeveniments del ratolí

</item>
Packit 1470ea
    <item>

Com obtenir els noms dels fitxers d'un directori

</item>
Packit 1470ea
  </list>
Packit 1470ea
</synopsis>
Packit 1470ea
Packit 1470ea
<section id="intro">
Packit 1470ea
  <title>Introducció</title>
Packit 1470ea
  

Packit 1470ea
    Clutter is a library for creating dynamic user interfaces using OpenGL for hardware acceleration. This example demonstrates a small, but central, part of the Clutter library to create a simple but attractive image viewing program.
Packit 1470ea
  

Packit 1470ea
  

Packit 1470ea
    To help us reach our goal we will be utilising a few other common pieces of GLib as well. Most importantly, we'll use one GPtrArray, a dynamic array of pointers, to hold the file path names. We will also use GDir, a utility for working with directories, to access our image directory and gather file paths.
Packit 1470ea
  

Packit 1470ea
</section>
Packit 1470ea
Packit 1470ea
<section id="anjuta">
Packit 1470ea
  <title>Creació d'un projecte a l'Anjuta</title>
Packit 1470ea
  

Abans de començar a programar, heu de crear un projecte nou a l'Anjuta. L'Anjuta crearà tots els fitxers necessaris per, més endavant, construir i executar el codi. És molt útil per així mantenir-ho tot junt.

Packit 1470ea
  <steps>
Packit 1470ea
    <item>
Packit 1470ea
    

Inicieu l'Anjuta i feu clic a <guiseq><gui>Fitxer</gui><gui>Nou</gui><gui>Projecte</gui></guiseq> per obrir l'auxiliar de projectes.

Packit 1470ea
    </item>
Packit 1470ea
    <item>
Packit 1470ea
    

Choose <gui>GTK+ (simple)</gui> from the <gui>C</gui> tab, click <gui>Continue</gui>, and fill out your details on the next few pages. Use <file>photo-wall</file> as project name and directory.

Packit 1470ea
   	</item>
Packit 1470ea
    <item>
Packit 1470ea
    

Assegureu-vos que <gui>Utilitza el GtkBuilder per a la interfície d'usuari</gui> està desactivat ja que en aquest programa d'aprenentatge es crearà la interfície d'usuari manualment. Feu una ullada al programa d'aprenentatge <link xref="guitar-tuner.c">Afinació de guitarres</link> que utilitza el constructor d'interfícies (GtkBuilder).

Packit 1470ea
    </item>
Packit 1470ea
    <item>
Packit 1470ea
    

Habiliteu <gui>Configura els paquets externs</gui>. A la llista de la pàgina següent seleccioneu clutter-1.0 per incloure la biblioteca Clutter al projecte.

Packit 1470ea
    </item>
Packit 1470ea
    <item>
Packit 1470ea
    

Feu clic a <gui>Aplica</gui> i es crearà el projecte. Obriu <file>src/main.c</file> des de les pestanyes <gui>Projecte</gui> o <gui>Fitxer</gui>. Hauríeu de veure una mica de codi que comença amb les línies:

Packit 1470ea
    
Packit 1470ea
#include <config.h>
Packit 1470ea
#include <gtk/gtk.h>]]>
Packit 1470ea
    </item>
Packit 1470ea
  </steps>
Packit 1470ea
</section>
Packit 1470ea
Packit 1470ea
<section id="look">
Packit 1470ea
  <title>Una mirada al Mur de Fotografies</title>
Packit 1470ea
  

El visualitzador d'imatges mostra un mur d'imatges a l'usuari.

Packit 1470ea
  <media type="image" mime="image/png" src="media/photo-wall.png"/>
Packit 1470ea
  

Quan es fa clic a una imatge, aquesta s'anima per cobrir l'àrea de visualització. Quan es fa clic a la imatge que té el focus, aquesta retorna a la seva posició original amb una animació que dura exactament 500 mil·lisegons.

Packit 1470ea
  <media type="image" mime="image/png" src="media/photo-wall-focused.png"/>
Packit 1470ea
</section>
Packit 1470ea
Packit 1470ea
<section id="setup">
Packit 1470ea
  <title>Configuració inicial</title>
Packit 1470ea
  

El segment de codi que ve a continuació conté la majoria de definicions i variables que utilitzarem en les seccions següents. Podeu utilitzar-ho com a referència per a les seccions posteriors. Copieu aquest codi a l'inici de <file>src/main.c</file>:

Packit 1470ea
Packit 1470ea
#include <gdk-pixbuf/gdk-pixbuf.h>
Packit 1470ea
#include <clutter/clutter.h>
Packit 1470ea
Packit 1470ea
#define STAGE_WIDTH  800
Packit 1470ea
#define STAGE_HEIGHT 600
Packit 1470ea
Packit 1470ea
#define THUMBNAIL_SIZE 200
Packit 1470ea
#define ROW_COUNT (STAGE_HEIGHT / THUMBNAIL_SIZE)
Packit 1470ea
#define COL_COUNT (STAGE_WIDTH  / THUMBNAIL_SIZE)
Packit 1470ea
#define THUMBNAIL_COUNT (ROW_COUNT * COL_COUNT)
Packit 1470ea
Packit 1470ea
#define ANIMATION_DURATION_MS 500
Packit 1470ea
Packit 1470ea
#define IMAGE_DIR_PATH "./berlin_images/"
Packit 1470ea
Packit 1470ea
static GPtrArray *img_paths;
Packit 1470ea
Packit 1470ea
static ClutterPoint unfocused_pos;
Packit 1470ea
]]>
Packit 1470ea
Packit 1470ea
</section>
Packit 1470ea
Packit 1470ea
<section id="code">
Packit 1470ea
  <title>Primers passos en el codi</title>
Packit 1470ea
  

Es farà primer una ullada general a la funció main(). Després es mirarà la resta de seccions del codi en més profunditat. Canvieu el fitxer <file>src/main.c</file> perquè contingui aquesta funció main(). Podeu esborrar la funció create_window() perquè no fa falta per aquest exemple.

Packit 1470ea
  
Packit 1470ea
int
Packit 1470ea
main(int argc, char *argv[])
Packit 1470ea
{
Packit 1470ea
    ClutterColor stage_color = { 16, 16, 16, 255 };
Packit 1470ea
    ClutterActor *stage = NULL;
Packit 1470ea
Packit 1470ea
    if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
Packit 1470ea
        return 1;
Packit 1470ea
Packit 1470ea
    stage = clutter_stage_new();
Packit 1470ea
    clutter_actor_set_size(stage, STAGE_WIDTH, STAGE_HEIGHT);
Packit 1470ea
    clutter_actor_set_background_color(stage, &stage_color);
Packit 1470ea
    clutter_stage_set_title(CLUTTER_STAGE (stage), "Photo Wall");
Packit 1470ea
    g_signal_connect(stage, "destroy", G_CALLBACK(clutter_main_quit), NULL);
Packit 1470ea
Packit 1470ea
    load_image_path_names();
Packit 1470ea
Packit 1470ea
    guint row = 0;
Packit 1470ea
    guint col = 0;
Packit 1470ea
    for(row=0; row < ROW_COUNT; ++row)
Packit 1470ea
    {
Packit 1470ea
        for(col=0; col < COL_COUNT; ++col)
Packit 1470ea
        {
Packit 1470ea
            const char *img_path = g_ptr_array_index(img_paths, (row * COL_COUNT) + col);
Packit 1470ea
            GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(img_path, STAGE_HEIGHT, STAGE_HEIGHT, NULL);
Packit 1470ea
            ClutterContent *image = clutter_image_new ();
Packit 1470ea
            ClutterActor *actor = clutter_actor_new ();
Packit 1470ea
Packit 1470ea
            if (pixbuf != NULL)
Packit 1470ea
            {
Packit 1470ea
                clutter_image_set_data(CLUTTER_IMAGE(image),
Packit 1470ea
                                       gdk_pixbuf_get_pixels(pixbuf),
Packit 1470ea
                                       gdk_pixbuf_get_has_alpha(pixbuf)
Packit 1470ea
                                           ? COGL_PIXEL_FORMAT_RGBA_8888
Packit 1470ea
                                           : COGL_PIXEL_FORMAT_RGB_888,
Packit 1470ea
                                       gdk_pixbuf_get_width(pixbuf),
Packit 1470ea
                                       gdk_pixbuf_get_height(pixbuf),
Packit 1470ea
                                       gdk_pixbuf_get_rowstride(pixbuf),
Packit 1470ea
                                       NULL);
Packit 1470ea
            }
Packit 1470ea
Packit 1470ea
            clutter_actor_set_content(actor, image);
Packit 1470ea
            g_object_unref(image);
Packit 1470ea
            g_object_unref(pixbuf);
Packit 1470ea
Packit 1470ea
            initialize_actor(actor, row, col);
Packit 1470ea
            clutter_actor_add_child(stage, actor);
Packit 1470ea
        }
Packit 1470ea
    }
Packit 1470ea
Packit 1470ea
    /* Show the stage. */
Packit 1470ea
    clutter_actor_show(stage);
Packit 1470ea
Packit 1470ea
    /* Start the clutter main loop. */
Packit 1470ea
    clutter_main();
Packit 1470ea
Packit 1470ea
    g_ptr_array_unref(img_paths);
Packit 1470ea
Packit 1470ea
    return 0;
Packit 1470ea
}]]>
Packit 1470ea
  <list>
Packit 1470ea
    <item>

Línia 4: el ClutterColor es defineix establint els valors del vermell, el verd, el blau i de la transparència (alfa). El rang de valors és de 0 a 255. Per la transparència un valor de 255 és opac.

</item>
Packit 1470ea
    <item>

Línia 7: heu d'inicialitzar la Clutter. Si us en descuideu, obtindreu errors molt estranys. Tingueu-ho en compte.

</item>
Packit 1470ea
    <item>

Lines 10‒14: Here we create a new ClutterStage . We then set the size using the defines from the previous section and the address of the ClutterColor we just defined.

Packit 1470ea
      <note>

Un ClutterStage és el ClutterActor de més alt nivell on es posen d'altres ClutterActor.

</note>
Packit 1470ea
</item>
Packit 1470ea
    <item>

Line 16: Here we call our function for getting the image file paths. We'll look at this in a bit.

</item>
Packit 1470ea
    <item>

Lines 18‒49: This is where we set up the ClutterActors, load the images and place them into their spot in the image wall. We will look at this in detail in the next section.

</item>
Packit 1470ea
    <item>

Line 52: Show the stage and all its children, meaning our images.

</item>
Packit 1470ea
    <item>

Line 55: Start the Clutter main loop.

</item>
Packit 1470ea
  </list>
Packit 1470ea
</section>
Packit 1470ea
Packit 1470ea
<section id="actors">
Packit 1470ea
  <title>Configuració dels actors d'imatges</title>
Packit 1470ea
 <note>

A la Clutter un actor és l'element visual bàsic. Tot el que es veu és un actor.

</note>
Packit 1470ea

En aquesta secció, es farà una repassada amb més detall al bucle que s'utilitza per definir els ClutterActor que mostraran les imatges.

Packit 1470ea
  
Packit 1470ea
guint row = 0;
Packit 1470ea
guint col = 0;
Packit 1470ea
for(row=0; row < ROW_COUNT; ++row)
Packit 1470ea
{
Packit 1470ea
    for(col=0; col < COL_COUNT; ++col)
Packit 1470ea
    {
Packit 1470ea
        const char *img_path = g_ptr_array_index(img_paths, (row * COL_COUNT) + col);
Packit 1470ea
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(img_path, STAGE_HEIGHT, STAGE_HEIGHT, NULL);
Packit 1470ea
        ClutterContent *image = clutter_image_new ();
Packit 1470ea
        ClutterActor *actor = clutter_actor_new ();
Packit 1470ea
Packit 1470ea
        if (pixbuf != NULL)
Packit 1470ea
        {
Packit 1470ea
            clutter_image_set_data(CLUTTER_IMAGE(image),
Packit 1470ea
                                   gdk_pixbuf_get_pixels(pixbuf),
Packit 1470ea
                                   gdk_pixbuf_get_has_alpha(pixbuf)
Packit 1470ea
                                       ? COGL_PIXEL_FORMAT_RGBA_8888
Packit 1470ea
                                       : COGL_PIXEL_FORMAT_RGB_888,
Packit 1470ea
                                   gdk_pixbuf_get_width(pixbuf),
Packit 1470ea
                                   gdk_pixbuf_get_height(pixbuf),
Packit 1470ea
                                   gdk_pixbuf_get_rowstride(pixbuf),
Packit 1470ea
                                   NULL);
Packit 1470ea
        }
Packit 1470ea
Packit 1470ea
        clutter_actor_set_content(actor, image);
Packit 1470ea
        g_object_unref(image);
Packit 1470ea
        g_object_unref(pixbuf);
Packit 1470ea
Packit 1470ea
        initialize_actor(actor, row, col);
Packit 1470ea
        clutter_actor_add_child(stage, actor);
Packit 1470ea
    }
Packit 1470ea
}
Packit 1470ea
]]>
Packit 1470ea
Packit 1470ea
<list>
Packit 1470ea
  <item>

Line 7: Here we want to get the path at the nth location in the GPtrArray that is holding our image path names. The nth position is calculated based on row and col.

Packit 1470ea
  </item>
Packit 1470ea
  <item>

Line 8‒23: This is where we actually create the ClutterActor and place the image into the actor. The first argument is the path which we access through our GSList node. The second argument is for error reporting but we are ignoring that to keep things short.

Packit 1470ea
  </item>
Packit 1470ea
  <item>

Line 47: This adds the ClutterActor to the stage, which is a container. It also assumes ownership of the ClutterActor which is something you'll want to look into as you get deeper into GNOME development. See the <link href="http://library.gnome.org/devel/gobject/stable/gobject-memory.html">GObject documentation</link> for the gory details.

Packit 1470ea
  </item>
Packit 1470ea
</list>
Packit 1470ea
</section>
Packit 1470ea
Packit 1470ea
<section id="load">
Packit 1470ea
  <title>Càrrega de les imatges</title>
Packit 1470ea
  

Abans de continuar amb la Clutter s'explica a continuació com es poden obtenir els noms dels fitxers del directori d'imatges de l'usuari.

Packit 1470ea
  
Packit 1470ea
static void
Packit 1470ea
load_image_path_names()
Packit 1470ea
{
Packit 1470ea
    /* Ensure we can access the directory. */
Packit 1470ea
    GError *error = NULL;
Packit 1470ea
    GDir *dir = g_dir_open(IMAGE_DIR_PATH, 0, &error);
Packit 1470ea
    if(error)
Packit 1470ea
    {
Packit 1470ea
        g_warning("g_dir_open() failed with error: %s\n", error->message);
Packit 1470ea
        g_clear_error(&error);
Packit 1470ea
        return;
Packit 1470ea
    }
Packit 1470ea
Packit 1470ea
    img_paths = g_ptr_array_new_with_free_func (g_free);
Packit 1470ea
Packit 1470ea
    const gchar *filename = g_dir_read_name(dir);
Packit 1470ea
    while(filename)
Packit 1470ea
    {
Packit 1470ea
        if(g_str_has_suffix(filename, ".jpg") || g_str_has_suffix(filename, ".png"))
Packit 1470ea
        {
Packit 1470ea
            gchar *path = g_build_filename(IMAGE_DIR_PATH, filename, NULL);
Packit 1470ea
            g_ptr_array_add (img_paths, path);
Packit 1470ea
        }
Packit 1470ea
        filename = g_dir_read_name(dir);
Packit 1470ea
    }
Packit 1470ea
}]]>
Packit 1470ea
  <list>
Packit 1470ea
    <item>

Lines 5 and 12: This opens our directory or, if an error occurred, returns after printing an error message.

</item>
Packit 1470ea
    <item>

Lines 16‒25: The first line gets another file name from the GDir we opened earlier. If there was an image file (which we check by looking at its extension, ".png" or ".jpg") in the directory we proceed to prepend the image directory path to the filename and prepend that to the list we set up earlier. Lastly we attempt to get the next path name and reenter the loop if another file was found.

</item>
Packit 1470ea
  </list>
Packit 1470ea
</section>
Packit 1470ea
Packit 1470ea
<section id="actors2">
Packit 1470ea
  <title>Configuració dels actors</title>
Packit 1470ea
  

En aquesta secció es descriu com dimensionar i posicionar els ClutterActor i com preparar-los per la interacció amb l'usuari.

Packit 1470ea
  
Packit 1470ea
/* This function handles setting up and placing the rectangles. */
Packit 1470ea
static void
Packit 1470ea
initialize_actor(ClutterActor *actor, guint row, guint col)
Packit 1470ea
{
Packit 1470ea
    clutter_actor_set_size(actor, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
Packit 1470ea
    clutter_actor_set_position(actor, col * THUMBNAIL_SIZE, row * THUMBNAIL_SIZE);
Packit 1470ea
    clutter_actor_set_reactive(actor, TRUE);
Packit 1470ea
Packit 1470ea
    g_signal_connect(actor,
Packit 1470ea
                     "button-press-event",
Packit 1470ea
                     G_CALLBACK(actor_clicked_cb),
Packit 1470ea
                     NULL);
Packit 1470ea
}]]>
Packit 1470ea
  <list>
Packit 1470ea
    <item>
Packit 1470ea
      

Línia 7: establir un actor en mode reactiu significa que reaccionarà als esdeveniments, com ara el button-press-event de l'exemple que segueix. Pel mur de fotografies, tots els ClutterActor del mur s'han d'establir com a reactius inicialment.

Packit 1470ea
    </item>
Packit 1470ea
    <item>
Packit 1470ea
      

Línia 9 a 12: es connecta el button-press-event a la crida de retorn actor_clicked_cb, que es detallarà tot més endavant.

Packit 1470ea
    </item>
Packit 1470ea
  </list>
Packit 1470ea
  

En aquest moment ja s'ha obtingut un mur de fotografies a punt per visualitzar-se.

Packit 1470ea
</section>
Packit 1470ea
Packit 1470ea
<section id="click">
Packit 1470ea
  <title>Reacció als clics</title>
Packit 1470ea
  

Packit 1470ea
Packit 1470ea
  

Packit 1470ea
  
Packit 1470ea
static gboolean
Packit 1470ea
actor_clicked_cb(ClutterActor *actor,
Packit 1470ea
                 ClutterEvent *event,
Packit 1470ea
                 gpointer      user_data)
Packit 1470ea
{
Packit 1470ea
    /* Flag to keep track of our state. */
Packit 1470ea
    static gboolean is_focused = FALSE;
Packit 1470ea
    ClutterActorIter iter;
Packit 1470ea
    ClutterActor *child;
Packit 1470ea
Packit 1470ea
    /* Reset the focus state on all the images */
Packit 1470ea
    clutter_actor_iter_init (&iter, clutter_actor_get_parent(actor));
Packit 1470ea
    while (clutter_actor_iter_next(&iter, &child))
Packit 1470ea
      clutter_actor_set_reactive(child, is_focused);
Packit 1470ea
Packit 1470ea
    clutter_actor_save_easing_state(actor);
Packit 1470ea
    clutter_actor_set_easing_duration(actor, ANIMATION_DURATION_MS);
Packit 1470ea
Packit 1470ea
    if(is_focused)
Packit 1470ea
    {
Packit 1470ea
        /* Restore the old location and size. */
Packit 1470ea
        clutter_actor_set_position(actor, unfocused_pos.x, unfocused_pos.y);
Packit 1470ea
        clutter_actor_set_size(actor, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
Packit 1470ea
    }
Packit 1470ea
    else
Packit 1470ea
    {
Packit 1470ea
        /* Save the current location before animating. */
Packit 1470ea
        clutter_actor_get_position(actor, &unfocused_pos.x, &unfocused_pos.y);
Packit 1470ea
        /* Only the currently focused image should receive events. */
Packit 1470ea
        clutter_actor_set_reactive(actor, TRUE);
Packit 1470ea
Packit 1470ea
        /* Put the focused image on top. */
Packit 1470ea
        clutter_actor_set_child_above_sibling(clutter_actor_get_parent(actor), actor, NULL);
Packit 1470ea
Packit 1470ea
        clutter_actor_set_position(actor, (STAGE_WIDTH - STAGE_HEIGHT) / 2.0, 0);
Packit 1470ea
        clutter_actor_set_size(actor, STAGE_HEIGHT, STAGE_HEIGHT);
Packit 1470ea
    }
Packit 1470ea
Packit 1470ea
    clutter_actor_restore_easing_state(actor);
Packit 1470ea
Packit 1470ea
    /* Toggle our flag. */
Packit 1470ea
    is_focused = !is_focused;
Packit 1470ea
Packit 1470ea
    return TRUE;
Packit 1470ea
}]]>
Packit 1470ea
  <list>
Packit 1470ea
    <item>

Línies 1 a 4: assegureu-vos que la funció de crida de retorn coincideix amb la signatura de la senyal button_clicked_event. A l'exemple només es fa servir el primer argument, el ClutterActor al que es fa clic.

Packit 1470ea
<note>
Packit 1470ea
  

Un breu resum sobre els arguments que no s'utilitzen en aquest exemple. El ClutterEvent és diferent depenent de quin esdeveniment es gestiona. Per exemple, un esdeveniment de tecla produeix un ClutterKeyEvent del qual podeu obtenir la tecla premuda a més d'altra informació. Pels esdeveniments de ratolí obteniu un ClutterButtonEvent del qual obtindreu els valors x i y. Vegeu la documentació de la Clutter per altres tipus de ClutterEvent.

Packit 1470ea
  

Packit 1470ea
    The user_data is what one uses to pass data into the function. A pointer to any data type can be passed in. If you need multiple data to be passed into the callback, you can place the data into a struct and pass its address in.
Packit 1470ea
  

Packit 1470ea
</note></item>
Packit 1470ea
    <item>

Línia 7: s'estableix un indicador estàtic per fer un seguiment de l'esta d'execució: en mode mur o en mode focus. A l'inici s'està en mode mur i per tan cap imatge té el focus. Així, s'estableix l'indicador a FALSE.

</item>
Packit 1470ea
    <item>

Line 12‒14: These set the image actors to receive events if they are focused.

</item>
Packit 1470ea
    <item>

Line 16‒17: Here we set the animation duration and save the current state.

</item>
Packit 1470ea
    <item>

Lines 21‒23: Reaching this code means that one image currently has focus and we want to return to wall mode. Setting a position on a ClutterActor begins an animation with the duration that we set in line 17.

Packit 1470ea
    </item>
Packit 1470ea
    <item>

Línia 24: si s'arriba a aquesta línia de codi és que ens l'aplicació està en l'estat de mur i s'ha de donar el focus a un ClutterActor. Es desa la posició inicial per poder tornar-hi més endavant.

</item>
Packit 1470ea
    <item>

Línia 25: s'estableix la propietat reactive del ClutterActor a TRUE permetent que reaccioni als esdeveniments. En el mode focus l'únic ClutterActor que ha de rebre esdeveniments és el ClutterActor que es visualitza. Fent-li clic tornarà a la seva posició inicial.

</item>
Packit 1470ea
    <item>

Lines 27‒36: This is where we save the current position of the image, set it to receive events and then make it appear above the other images and start animating it to fill the stage.

</item>
Packit 1470ea
    <item>

Line 39: Here we restore the easing state to what was set before we changed it in line 16.

</item>
Packit 1470ea
    <item>

Line 42: Here we toggle the is_focused flag to the current state.

</item>
Packit 1470ea
<item>

Com s'ha comentat més amunt, els ClutterActor amb el valor de depth més alt rebran els esdeveniments però poden passar-lo als ClutterActor de sota seu. Si retorna TRUE no es passarà l'esdeveniment als ClutterActor de sota, mentre que si es retorna FALSE es passarà.

Packit 1470ea
 <note>
Packit 1470ea
   

Recordeu, però, que per rebre esdeveniments els ClutterActor s'han d'establir com a reactive.

Packit 1470ea
 </note>
Packit 1470ea
</item>
Packit 1470ea
 </list>
Packit 1470ea
</section>
Packit 1470ea
Packit 1470ea
<section id="run">
Packit 1470ea
  <title>Muntatge i execució de l'aplicació</title>
Packit 1470ea
  

Tot el codi hauria d'estar llest per funcionar. Només fan falta les imatges per carregar. Per defecte, les imatges es carreguen des del directori <file>berlin_images</file>. Si voleu, podeu canviar-lo a línia #define IMAGE_DIR_PATH que està al principi del fitxer perquè apunti al directori de fotos de l'usuari, o podeu crear un directori <file>berlin_images</file> fent clic a <guiseq><gui>Projecte</gui><gui>Directori nou...</gui></guiseq>. El directori <file>berlin_images</file> serà un subdirectori del directori <file>photo-wall</file>. Comproveu que poseu com a mínim dotze imatges en el directori.

Packit 1470ea
  

Un cop ho hàgiu fet, feu clic a <guiseq><gui>Munta</gui><gui>Munta el projecte</gui></guiseq> per tornar-ho a muntar tot, llavors seleccioneu <guiseq><gui>Executa</gui><gui>Executa</gui></guiseq> per iniciar l'aplicació.

Packit 1470ea
  

Si encara no ho heu fet, seleccioneu l'aplicació <file>Debug/src/photo-wall</file> en el diàleg que apareix. Per acabar, premeu <gui>Executa</gui> i ja podreu provar l'aplicació.

Packit 1470ea
</section>
Packit 1470ea
Packit 1470ea
<section id="impl">
Packit 1470ea
 <title>Implementació de referència</title>
Packit 1470ea
 

Si teniu algun problema amb el programa d'aprenentatge, compareu el codi amb el <link href="photo-wall/photo-wall.c">codi de referència</link>.

Packit 1470ea
</section>
Packit 1470ea
Packit 1470ea
</page>