not finished
authortanya <tanya@tanin.oblgaz>
Tue, 6 Apr 2010 15:26:46 +0000 (18:26 +0300)
committertanya <tanya@tanin.oblgaz>
Tue, 6 Apr 2010 15:26:46 +0000 (18:26 +0300)
applet/data/theme/Modern/tram.png
applet/data/theme/Modern/tram_dark.png
applet/src/livewp-home-widget.c
applet/src/livewp-home-widget.h

index 5bc08fd..0df33e7 100755 (executable)
Binary files a/applet/data/theme/Modern/tram.png and b/applet/data/theme/Modern/tram.png differ
index 0f6e225..42b2755 100755 (executable)
Binary files a/applet/data/theme/Modern/tram_dark.png and b/applet/data/theme/Modern/tram_dark.png differ
index 83415a4..c4560e6 100644 (file)
@@ -144,6 +144,8 @@ init_applet_position(void)
                            modified_key,
                            modified,
                            &error);
+  g_free(modified);
+  g_free(modified_key);
   gconf_client_clear_cache(gconf_client);
   g_object_unref(gconf_client);
 }
@@ -198,7 +200,7 @@ init_object(AWallpaperPlugin *desktop_plugin, gchar * name, gchar * filename, gi
   g_object_set_data(G_OBJECT(actor), "opacity", opacity);
   g_object_set_data(G_OBJECT(actor), "func", pfunc);
   
-  hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), scene.window);
+  hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), desktop_plugin);
 /*
   a.widget = actor;
   a.name = name;
@@ -267,29 +269,43 @@ void change_static_actor(GtkWidget * actor, gpointer data)
     realize(actor);
     gtk_widget_show_all(actor);
 }
-void change_tram1(GtkWidget * actor, gpointer data)
-{    
-    double alt, azm;
-    gint x, y, z, scale, width, height, daytime;
-    fprintf(stderr, "change tram %i \n", data);
-    if (actor){
-        x = g_object_get_data(G_OBJECT(actor), "x");
-        y = g_object_get_data(G_OBJECT(actor), "y");
-        scale = g_object_get_data(G_OBJECT(actor), "scale");
-        width = g_object_get_data(G_OBJECT(actor), "width");
-        height = g_object_get_data(G_OBJECT(actor), "height");
-        x = x + 1;
-        if (x > 480+width) x = -width;
-        scale = (x + 400) * 50 / 880 + 100;
-        y = y - height * (scale-100) / 100;
-        
-        //fprintf(stderr, "scale =%i y=%i\n", y,scale);
-        actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
-        g_object_set_data(G_OBJECT(actor), "x", x);
-        //g_object_set_data(G_OBJECT(actor), "y", y);
-        hildon_animation_actor_set_scale(actor, (double)scale/100, (double)scale/100);
-        g_object_set_data(G_OBJECT(actor), "scale", scale);
-    }
+
+static gint 
+path_line(gint x0, gint x1, gint t_all, gint t)
+{
+    // уравниение прямой
+    return ((x1 - x0) *t / t_all + x0);
+}
+
+static void 
+change_tram(GtkWidget * actor, gpointer data)
+{
+    gint x0 = -300, y0 = 225, scale0 = 100, t0 = 0,
+         x1 = 800, y1 = 162, scale1 = 130, t1 = 100, 
+         x, y, scale;
+    gint t = data;
+
+    x = path_line(x0, x1, t1, t);
+    y = path_line(y0, y1, t1, t);
+    scale = path_line(scale0, scale1, t1, t);
+    //fprintf(stderr, "path tram:  t=%i, x=%i, y=%i, scale=%i\n", t, x, y, scale);
+    actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
+    hildon_animation_actor_set_scale(actor, (double)scale/100, (double)scale/100);
+}
+
+static void 
+change_tram1(GtkWidget * actor, gint t, gint timeall)
+{
+    gint x0 = -300, y0 = 225, scale0 = 100,
+         x1 = 800, y1 = 162, scale1 = 130, 
+         x, y, scale;
+    
+    x = path_line(x0, x1, timeall, t);
+    y = path_line(y0, y1, timeall, t);
+    scale = path_line(scale0, scale1, timeall, t);
+    //fprintf(stderr, "path tram:  t=%i, x=%i, y=%i, scale=%i\n", t, x, y, scale);
+    actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
+    hildon_animation_actor_set_scale(actor, (double)scale/100, (double)scale/100);
 }
 
 void change_sky(GtkWidget * actor, gpointer data)
@@ -313,7 +329,8 @@ void change_sky(GtkWidget * actor, gpointer data)
         }
     }
 }
-void change_background(GtkWidget * actor, gpointer data)
+void 
+change_background(GtkWidget * actor, gpointer data)
 {
     gint opacity;
     if (actor){
@@ -325,36 +342,62 @@ void change_background(GtkWidget * actor, gpointer data)
     }
 }
 
-static gint path_line(gint x0, gint x1, gint t_all, gint t)
+static gint 
+get_time(gint t)
 {
-    // уравниение прямой
-    return ((x1 - x0) / t_all * t + x0);
+    // уравнение изменения времени
+    return t*1.1;
 }
 
-static void change_tram(GtkWidget * actor, gpointer data)
+static void 
+destroy_scene(void)
 {
-    gint x0 = -300, y0 = 191, scale0 = 100, t0 = 0,
-         x1 = 800, y1 = 119, scale1 = 130, t1 = 100, 
-         x, y, scale;
-    gint t = data;
-    x = path_line(x0, x1, t1, t);
-    y = path_line(y0, y1, t1, t);
-    scale = path_line(scale0, scale1, t1, t);
-    //fprintf(stderr, "path tram:  t=%i, x=%i, y=%i, scale=%i\n", t, x, y, scale);
-    actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
-    hildon_animation_actor_set_scale(actor, (double)scale/100, (double)scale/100);
+    GSList * tmp = scene.dynamic_actors;
+    while (tmp != NULL){
+        if (tmp->data){
+            gtk_widget_destroy(tmp->data);
+            tmp->data = NULL;
+        }
+        tmp = g_slist_next(tmp);
+    }
+    g_slist_free(tmp);
+    tmp = scene.static_actors;
+    while (tmp != NULL){        
+        if (tmp->data){
+            gtk_widget_destroy(tmp->data);
+            tmp->data = NULL;
+        }
+        tmp = g_slist_next(tmp);
+    }
+    g_slist_free(tmp);
+
 }
-static gint get_time(gint t)
+
+void
+reload_scene(AWallpaperPlugin *desktop_plugin)
 {
-    // уравнение изменения времени
-    return t*1.1;
+    fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);  
+    destroy_scene();
+    if (!strcmp(desktop_plugin->priv->theme,"Modern"))
+        init_scene(desktop_plugin);
+    else if (!strcmp(desktop_plugin->priv->theme,"Berlin")) 
+        init_scene1(desktop_plugin);
 }
 
+Animation anim;
 
 void
-reload_scene(AWallpaperPlugin *desktop_plugin)
+anim_tram(GtkWidget *actor, Animation * an)
 {
-    fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
+    time_t now;
+    now = time(NULL);
+    gint t = now - an->timestart;
+    if (t > an->timeall){
+        an->timestart = now;
+        if (an->count != -1) an->count--;
+        if (an->count == 0) return;
+    }
+    change_tram1(an->actor, t, an->timeall);
 }
 
 static void
@@ -369,7 +412,6 @@ init_scene(AWallpaperPlugin *desktop_plugin)
   gchar str[256];
 
 fprintf(stderr, "init scene \n");
-  scene.window = desktop_plugin;
   scene.daytime = get_daytime();
   scene.dynamic_actors = NULL;
   scene.static_actors = NULL;
@@ -377,26 +419,31 @@ fprintf(stderr, "init scene \n");
   //get_sun_screen_pos(alt, azm, &x, &y);
   actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 11, 88, 88, 1, 100, 255, &change_sun);
   change_sun(actor, NULL);
-  //scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
-  scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
+  scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
+  //scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
 
   actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480, 1, 100, 255, &change_static_actor);
   change_static_actor(G_OBJECT(actor), desktop_plugin);
   scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
 
-  actor = init_object(desktop_plugin, "town", "town.png", 0, 480-374, 10, 800, 374, 1, 100, 255, &change_static_actor);
+  actor = init_object(desktop_plugin, "town", "town0.png", 0, 480-374, 10, 800, 374, 1, 100, 255, &change_static_actor);
   change_static_actor(G_OBJECT(actor), desktop_plugin);
   scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
   
-  actor = init_object(desktop_plugin, "border", "border.png", 0, 480-79, 30, 800, 79, 1, 100, 255, &change_static_actor);
+  actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 30, 800, 79, 1, 100, 255, &change_static_actor);
   change_static_actor(G_OBJECT(actor), desktop_plugin);
   scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
   
   //if (scene.daytime == TIME_DAY) snprintf(str, 255, "tram.png");
   //else snprintf(str, 255, "tram_dark.png");
-  //actor = init_object("tram", "tram.png", -300, 191, 25, 350, 240, 1, 100, 255, NULL);
-  actor = init_object(desktop_plugin, "tram", "tram.png", -300, 191, 25, 350, 240, 1, 100, 255, &change_tram);
-  scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
+  //actor = init_object("tram", "tram.png", -300, 191, 25, 350, 210, 1, 100, 255, NULL);
+  actor = init_object(desktop_plugin, "tram", "tram_dark.png", -300, 225, 25, 350, 210, 1, 100, 255, NULL);
+  //scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
+  anim.count = 4;
+  anim.actor = actor;
+  //anim.func = &change_tram;
+  anim.timestart = time(NULL); 
+  anim.timeall = 100;
  }
 static void
 init_scene1(AWallpaperPlugin *desktop_plugin)
@@ -408,7 +455,6 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   gint x, y;
   GSList * list = NULL;
 
-  scene.window = desktop_plugin;
   scene.daytime = get_daytime();
   scene.dynamic_actors = NULL;
   scene.static_actors = NULL;
@@ -421,11 +467,11 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   actor = init_object(desktop_plugin, "background", "sky_dark.png", 0, 0, 4, 800, 480, 1, 100, 255, NULL);
   scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
 */
-  actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480, 1, 100, 255, &change_static_actor);
+  actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480, 1, 100, 255, &change_static_actor);
   change_static_actor(actor, NULL);
   scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
 
-  actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 10, 800, 480, 1, 100, 255, &change_static_actor);
+  actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, 1, 100, 255, &change_static_actor);
   change_static_actor(actor, NULL);
   scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
   
@@ -554,7 +600,6 @@ plugin_on_timeout (AWallpaperPlugin *desktop_plugin)
   GSList * tmp;
   gchar * name;
   void (*pfunc)(gpointer, gpointer);
-  //fprintf(stderr, "on timeout\n");
 
   if (scene.daytime == daytime){
       /* Change dynamic actors */
@@ -568,7 +613,8 @@ plugin_on_timeout (AWallpaperPlugin *desktop_plugin)
       pfunc = g_object_get_data(G_OBJECT(tmp->data), "func");
       name = g_object_get_data(G_OBJECT(tmp->data), "name");
       if (name == "tram"){
-          (*pfunc)(tmp->data, ttt);
+          if (pfunc)
+            (*pfunc)(tmp->data, ttt);
           ttt = get_time(ttt+1);
           if (ttt >= 100) ttt = 0;
         }else
@@ -652,10 +698,10 @@ animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
   gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
   init_applet_position();
   fprintf(stderr, "!!!theme = %s\n", priv->theme);
-  //if (priv->theme == "Modern")
+  if (!strcmp(priv->theme,"Modern"))
       init_scene(desktop_plugin);
-  //else if (priv->theme == "Berlin") 
-   //   init_scene1(desktop_plugin);
+  else if (!strcmp(priv->theme,"Berlin")) 
+      init_scene1(desktop_plugin);
   priv->timer = g_timeout_add(100, plugin_on_timeout, desktop_plugin);
 }
 
@@ -669,6 +715,7 @@ lw_applet_finalize (GObject *object)
         g_source_remove(priv->timer);
         priv->timer = NULL;
      }
+     destroy_scene();
 }
 
 static void
index aaf949f..05d74d7 100644 (file)
@@ -49,13 +49,20 @@ G_BEGIN_DECLS
 
 
 typedef struct {
-    GtkWidget * window;
     GSList * static_actors;
     GSList * dynamic_actors;
     gint daytime;
 } Scene;
 
 typedef struct {
+    time_t timestart;
+    gint timeall;
+    gint count;
+    GtkWidget *actor;
+    //void (*pfunc)(GtkWidget *, Animation *);
+} Animation;
+
+typedef struct {
     GtkWidget * widget;
     gchar * name;
     GtkWidget * image;
@@ -79,5 +86,7 @@ void multiactor_set_position(MultiActor *ma, gint dx, gint dy, gint dz);
 void actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z);
 gint read_config(Animation_WallpaperPrivate *priv);
 void save_config(Animation_WallpaperPrivate *priv);
+static void init_scene(AWallpaperPlugin *desktop_plugin);
+static void init_scene1(AWallpaperPlugin *desktop_plugin);
 
 #endif