Merge branch 'master' of https://vcs.maemo.org/git/livewp
[livewp] / applet / src / livewp-actor.c
index ad6ffcd..30f8002 100644 (file)
@@ -7,8 +7,8 @@
  *       for the code
  * 
  * This software is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2 of
  * the License, or (at your option) any later version.
  * 
  * This software is distributed in the hope that it will be useful, but
 /*******************************************************************************/
 #include "livewp-actor.h"
 
+static void
+realize (GtkWidget *widget)
+{
+    GdkScreen *screen;
+    screen = gtk_widget_get_screen (widget);
+    gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
+}
+
+static gboolean
+expose_event (GtkWidget *widget,GdkEventExpose *event,
+     gpointer data)
+{
+    cairo_t *cr;
+    GdkPixbuf *pixbuf = (GdkPixbuf *) data;
+       
+    cr = gdk_cairo_create(widget->window);
+    if (cr){
+        gdk_cairo_region(cr, event->region);
+        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+        gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
+        cairo_paint(cr);
+        cairo_destroy(cr);
+    }
+    return TRUE;
+}
+
+void
+destroy_hildon_actor(Actor *actor)
+{
+    //fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
+    gtk_widget_destroy(actor->widget);
+    actor->widget = NULL;
+}
+
+void
+create_hildon_actor_text(Actor *actor, AWallpaperPlugin *desktop_plugin) 
+{
+  GtkWidget *ha = NULL;
+  GtkWidget *label = NULL;
+
+  ha = hildon_animation_actor_new();
+  label = gtk_label_new(NULL);  
+
+  if (label){
+    //g_signal_connect(G_OBJECT(label), "expose_event", G_CALLBACK(expose_event), NULL);
+
+    gtk_container_add (GTK_CONTAINER (ha), label);
+  }  
+  realize(ha);
+  gtk_widget_show(label);
+  gtk_widget_show_all(ha);
+  
+  /* TO DO check it */
+  /*  gdk_flush (); */
+
+  //g_object_set_data(G_OBJECT(ha), "image", image);
+  actor->image = label;
+  hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin->priv->window));
+  actor->widget = ha;
+  set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
+  set_actor_scale(actor, (double)actor->scale/100, (double)actor->scale/100);
+  set_actor_visible(actor, actor->visible);
+}
+
+void
+create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin) 
+{
+  GtkWidget *ha = NULL;
+  GdkPixbuf *pixbuf = NULL;
+  GtkWidget *image = NULL;
+  gchar     *str = NULL;
+
+  ha = hildon_animation_actor_new();
+  if (!strcmp(actor->name, "original"))
+      str = g_strdup(actor->filename);
+  else 
+      str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
+                        desktop_plugin->priv->theme, actor->filename);
+  pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
+                                             actor->width, 
+                                             actor->height, 
+                                             NULL);
+  if (str)
+      g_free(str);
+  if (pixbuf){
+      image = gtk_image_new_from_pixbuf (pixbuf);
+      g_object_unref(G_OBJECT(pixbuf));
+  }
+  if (image){
+    g_signal_connect(G_OBJECT(image), "expose_event",
+                           G_CALLBACK(expose_event), pixbuf);
+    gtk_container_add (GTK_CONTAINER (ha), image);
+  }  
+  realize(ha);
+  gtk_widget_show_all(ha);
+  
+  /* TO DO check it */
+  /*  gdk_flush (); */
+
+  //g_object_set_data(G_OBJECT(ha), "image", image);
+  actor->image = image;
+  hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin->priv->window));
+
+  actor->widget = ha;
+  set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
+  set_actor_scale(actor, (double)actor->scale/100, (double)actor->scale/100);
+  set_actor_visible(actor, actor->visible);
+}
+
+void
+change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
+{
+    GtkWidget *image = NULL;
+    GdkPixbuf *pixbuf = NULL;
+    gchar     *str = NULL;
+
+    str = g_strdup_printf( "%s/%s/%s", THEME_PATH, 
+                            desktop_plugin->priv->theme, actor->filename);
+    pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
+                                               actor->width, 
+                                               actor->height, 
+                                               NULL);
+    if(str)
+        g_free(str);
+    if (pixbuf){
+        image = gtk_image_new_from_pixbuf (pixbuf);
+        g_object_unref(G_OBJECT(pixbuf));
+    }
+    if (image){ 
+        g_signal_connect(G_OBJECT(image), "expose_event",
+                                       G_CALLBACK(expose_event), pixbuf);
+        //if (g_object_get_data(G_OBJECT(actor->widget), "image")){
+        if (actor->image){
+            gtk_container_remove(GTK_CONTAINER(actor->widget), actor->image);  
+        }
+        //g_object_set_data(G_OBJECT(actor->widget), "image", image);
+        actor->image = image;
+        gtk_container_add (GTK_CONTAINER (actor->widget), image);
+        realize(actor->widget);
+        gtk_widget_show_all(actor->widget);
+        /* TO DO check it */
+       /*  gdk_flush (); */
+
+
+    }
+}
+
 Actor* 
 init_object(AWallpaperPlugin *desktop_plugin, 
             gchar * name, 
@@ -57,8 +205,9 @@ init_object(AWallpaperPlugin *desktop_plugin,
     actor->func_change = (gpointer)pfunc_change; 
     actor->func_probability = (gpointer)pfunc_probability;
     actor->child = child;
-    if (load_image)
+    if (load_image){
         create_hildon_actor(actor, desktop_plugin);
+    }
     else 
          actor->widget = NULL;
     actor->time_start_animation = 0;
@@ -119,6 +268,7 @@ set_actor_visible(Actor *actor, gboolean visible)
 void
 set_actor_position(Actor *actor, gint x, gint y, gint z, AWallpaperPlugin *desktop_plugin)
 {
+    //fprintf(stderr, "set actor position %d, %d, %d\n", x, y, z);
     hildon_animation_actor_set_position_full(HILDON_ANIMATION_ACTOR (actor->widget), 
                                              x-desktop_plugin->priv->xapplet, 
                                              y-desktop_plugin->priv->yapplet,