added new layers in theme Matrix
[livewp] / applet / src / livewp-home-widget.c
index e8f6edf..dec4510 100644 (file)
@@ -45,9 +45,6 @@ HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_H
 
 gint xapplet = 0, yapplet = 0;
 Scene scene;
-gint hour=8;
-gint min=0;
-gint ttt = 0;
 
 static void
 lw_applet_realize (GtkWidget *widget)
@@ -252,7 +249,7 @@ probability_sun()
 gint 
 probability_plane()
 {
-    return (fast_rnd(60));
+    return (fast_rnd(10) + 1) * 60;
 //    return 0;
 }
 
@@ -303,13 +300,13 @@ change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
                 actor->visible = TRUE;
                 create_hildon_actor(actor, desktop_plugin);
             }
-            get_sun_pos(hour, min, &alt, &azm);
+            get_sun_pos(&alt, &azm);
             get_sun_screen_pos(alt, azm, &x, &y);
             actor->x = x;
             actor->y = y;
             actor_set_position_full(actor->widget, x, y, actor->z);
             //probability_sun(actor);
-            actor->time_start_animation = time(NULL);
+            actor->time_start_animation = time(NULL) + probability_sun();
          }else if (actor->visible){
             actor->visible = FALSE;
             destroy_hildon_actor(actor);
@@ -329,7 +326,6 @@ change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
     suseconds_t ms;
     long sec;
     double t;
-    gchar *newfile;
 
     //fprintf(stderr, "change tram\n");
     gettimeofday(&tvb, NULL);
@@ -339,7 +335,7 @@ change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
     
     if (!actor->visible){
         actor->visible = TRUE;
-        if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
+        if (scene.daytime == TIME_NIGHT){
             if (actor->filename)
                 g_free(actor->filename);
             actor->filename = g_strdup("tram_dark.png");
@@ -350,20 +346,6 @@ change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
         }
         create_hildon_actor(actor, desktop_plugin);
     }
-    if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
-            newfile = g_strdup("tram_dark.png");
-        }else{
-            newfile = g_strdup("tram.png");
-        } 
-        if (strcmp(actor->filename, newfile)){
-        if (actor->filename)
-            g_free(actor->filename);
-        actor->filename = newfile;
-         
-
-        change_hildon_actor(actor, desktop_plugin);
-        }
-
     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
     x = path_line(x0, x1, t);
     y = path_line(y0, y1, t);
@@ -375,7 +357,7 @@ change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
         /* stop animation */
         actor->visible = FALSE;
         destroy_hildon_actor(actor);
-        actor->time_start_animation = sec + 20;
+        actor->time_start_animation = sec + fast_rnd(300);
     }
 }
 
@@ -389,7 +371,6 @@ change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
     suseconds_t ms;
     long sec;
     double t;
-    gchar *newfile;
 
     gettimeofday(&tvb, NULL);
     
@@ -407,24 +388,10 @@ change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
         actor->visible = TRUE;
         create_hildon_actor(actor, desktop_plugin);
     }
-if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
-            newfile = g_strdup("dot1.png");
-        }else{
-            newfile = g_strdup("tu154.png");
-        } 
-        if (strcmp(actor->filename, newfile)){
-        if (actor->filename)
-            g_free(actor->filename);
-        actor->filename = newfile;
-         
-
-        change_hildon_actor(actor, desktop_plugin);
-        }
-
     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
     x = path_line(x0, x1, t);
     y = path_line(y0, y1, t);
-    //scale line(scale0, scale1, t);
+    //scale = path_line(scale0, scale1, t);
     //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
     actor_set_position_full(actor->widget, x, y, actor->z);
     //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
@@ -435,7 +402,7 @@ if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
         if (scene.daytime == TIME_NIGHT) 
             actor->time_start_animation = 0;
         else 
-            actor->time_start_animation = sec + 10;
+            actor->time_start_animation = sec + probability_plane();
     }
 
 }
@@ -450,7 +417,6 @@ change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
     suseconds_t ms;
     long sec;
     double t;
-    gchar * newfile;
 
     gettimeofday(&tvb, NULL);
     
@@ -467,19 +433,6 @@ change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
         actor->visible = TRUE;
         create_hildon_actor(actor, desktop_plugin);
     }
-if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
-            newfile = g_strdup("dot1.png");
-        }else{
-            newfile = g_strdup("plane3.png");
-        } 
-        if (strcmp(actor->filename, newfile)){
-        if (actor->filename)
-            g_free(actor->filename);
-        actor->filename = newfile;
-         
-
-        change_hildon_actor(actor, desktop_plugin);
-        }
 
     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
     x = path_line(x0, x1, t);
@@ -495,7 +448,7 @@ if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
         if (scene.daytime == TIME_NIGHT) 
             actor->time_start_animation = 0;
         else 
-            actor->time_start_animation = sec + 15;
+            actor->time_start_animation = sec + probability_plane();
     }
 
 }
@@ -521,7 +474,7 @@ change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
    
     if (!actor->visible){
         actor->visible = TRUE;
-        if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
+        if (scene.daytime == TIME_NIGHT){
             newfile = g_strdup_printf("%s_dark.png", actor->name);
         }else{
             newfile = g_strdup_printf("%s.png", actor->name);
@@ -533,20 +486,6 @@ change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
 
         create_hildon_actor(actor, desktop_plugin);
     }
-    if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){
-            newfile = g_strdup_printf("%s_dark.png", actor->name);
-        }else{
-            newfile = g_strdup_printf("%s.png", actor->name);
-        } 
-        if (strcmp(actor->filename, newfile)){
-        if (actor->filename)
-            g_free(actor->filename);
-        actor->filename = newfile;
-         
-
-        change_hildon_actor(actor, desktop_plugin);
-        }
-
     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
     
     if (scene.wind_orientation == 1){
@@ -569,7 +508,7 @@ change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
         /* stop animation */
         actor->visible = FALSE;
         destroy_hildon_actor(actor);
-        actor->time_start_animation = sec + 10;
+        actor->time_start_animation = sec + fast_rnd(300);
         actor->y = fast_rnd(300);
     }
 
@@ -605,11 +544,11 @@ change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
     if (!actor->visible){
         actor->visible = TRUE;
         create_hildon_actor(actor, desktop_plugin);
-        actor->time_start_animation = now + 10;
+        actor->time_start_animation = now + fast_rnd(60) + 10;
     }else {
         actor->visible = FALSE;
         destroy_hildon_actor(actor);
-        actor->time_start_animation = now + 10;
+        actor->time_start_animation = now + fast_rnd(60) + 10;
     }
    
 }
@@ -627,7 +566,7 @@ change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
     g_free(actor->filename);
     actor->filename = newfile;
     change_hildon_actor(actor, desktop_plugin);
-    actor->time_start_animation = now + 5;
+    actor->time_start_animation = now + fast_rnd(30) + 10;
 }
 
 void
@@ -754,6 +693,27 @@ change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
 
 }
 
+void
+change_layer1(Actor * actor, AWallpaperPlugin *desktop_plugin)
+{
+    gint y;
+    y = actor->y + 10;
+    if (y > 480) y = -480;
+    //fprintf(stderr, "!! %s - %d\n", actor->name, y);
+    actor_set_position_full(actor->widget, actor->x, y, actor->z);
+    actor->y = y;
+}
+
+void
+change_layer2(Actor * actor, AWallpaperPlugin *desktop_plugin)
+{
+    gint y;
+    y = actor->y + 15;
+    if (y >= 480) y = -480;
+    //fprintf(stderr, "!! %s - %d\n", actor->name, y);
+    actor_set_position_full(actor->widget, actor->x, y, actor->z);
+    actor->y = y;
+}
 
 /*
 static gint 
@@ -792,9 +752,66 @@ reload_scene(AWallpaperPlugin *desktop_plugin)
         init_scene(desktop_plugin);
     else if (!strcmp(desktop_plugin->priv->theme,"Berlin")) 
         init_scene1(desktop_plugin);
+    else if (!strcmp(desktop_plugin->priv->theme,"Matrix")) 
+        init_scene2(desktop_plugin);
+
 }
 
+static void
+init_scene2(AWallpaperPlugin *desktop_plugin)
+{
+  Actor *actor;
+  gint now = time(NULL);
+
+  /* fprintf(stderr, "init scene \n");*/
+  scene.daytime = get_daytime();
+  scene.actors = NULL;
+
+  
+  actor = init_object(desktop_plugin, "background", "bg.png", 
+                      0, 0, 5, 800, 480, 
+                      TRUE, 100, 255, NULL, NULL);
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "symbols", "symbols.png", 
+                      0, 0, 10, 800, 480, 
+                      TRUE, 100, 255, NULL, NULL);
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "layer1", "layer1_2.png", 
+                      0, -480, 6, 800, 960, 
+                      TRUE, 100, 255, (gpointer)&change_layer1, NULL);
+  actor->time_start_animation = now;
+  actor->duration_animation = G_MAXINT;
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "layer1", "layer1_1.png", 
+                      0, (-480 - 480), 7, 800, 960, 
+                      TRUE, 100, 255, (gpointer)&change_layer1, NULL);
+  actor->time_start_animation = now;
+  actor->duration_animation = G_MAXINT;
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "layer2", "layer2_2.png", 
+                      0, -480, 8, 800, 960, 
+                      TRUE, 100, 255, (gpointer)&change_layer2, NULL);
+  actor->time_start_animation = now;
+  actor->duration_animation = G_MAXINT;
+  scene.actors = g_slist_append(scene.actors, actor);
 
+  actor = init_object(desktop_plugin, "layer2", "layer2_1.png", 
+                      0, (-480 - 480), 9, 800, 960, 
+                      TRUE, 100, 255, (gpointer)&change_layer2, NULL);
+  actor->time_start_animation = now;
+  actor->duration_animation = G_MAXINT;
+  scene.actors = g_slist_append(scene.actors, actor);
+
+
+    
+
+
+    run_long_timeout(desktop_plugin);
+}
 /* Init Modern Scene */
 static void
 init_scene(AWallpaperPlugin *desktop_plugin)
@@ -805,7 +822,7 @@ init_scene(AWallpaperPlugin *desktop_plugin)
   gint winds[13][2];
 
   /* fprintf(stderr, "init scene \n");*/
-  scene.daytime = get_daytime(hour, min);
+  scene.daytime = get_daytime();
   scene.actors = NULL;
   scene.wind_orientation = -1;
   scene.wind_angle = 0.3;
@@ -830,22 +847,22 @@ init_scene(AWallpaperPlugin *desktop_plugin)
     //                  TRUE, 100, 255, NULL, NULL);
   //scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, 0, 7, 150, 97, 
+  actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now;
-  actor->duration_animation = 1*60;
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 3*60;
   scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, 80, 7, 188, 75, 
+  actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now + 20;
-  actor->duration_animation = 1*60;
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 3*60;
   scene.actors = g_slist_append(scene.actors, actor);
 
-  actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, 30, 7, 150, 75, 
+  actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now + 40;
-  actor->duration_animation = 1*60;
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 5*60;
   scene.actors = g_slist_append(scene.actors, actor);
 
 
@@ -856,8 +873,8 @@ init_scene(AWallpaperPlugin *desktop_plugin)
 
   actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210, 
                       FALSE, 100, 255, (gpointer)&change_tram, NULL);
-  actor->time_start_animation = now; 
-  actor->duration_animation = 40;
+  actor->time_start_animation = time(NULL) + fast_rnd(10); 
+  actor->duration_animation = 60;
   scene.actors = g_slist_append(scene.actors, actor);
 
   actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79,
@@ -869,12 +886,12 @@ init_scene(AWallpaperPlugin *desktop_plugin)
                       FALSE, 100, 255, (gpointer)&change_moon, NULL);
   change_moon(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
-/*
+
   actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
                       FALSE, 100, 255, (gpointer)&change_wind, NULL);
   change_wind(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
-*/
+
     /* windows in 4-th house  */
 
     winds[0][0] = 482;
@@ -1088,9 +1105,9 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   gint i; 
   gint winds[13][2];
 
-  scene.daytime = get_daytime(hour, min);
+  scene.daytime = get_daytime();
   scene.actors = NULL;
-  scene.wind_orientation = 1;
+  scene.wind_orientation = -1;
   scene.wind_angle = 0.3;
   /* init value for random */
   scene.seed = time(NULL);
@@ -1120,50 +1137,50 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   change_moon(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, 300, 7, 150, 97, 
+  actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now + 20;
-  actor->duration_animation = 1*60;
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 3*60;
   scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, 100, 7, 188, 75, 
+  actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now;
-  actor->duration_animation = 1*60;
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 3*60;
   scene.actors = g_slist_append(scene.actors, actor);
 
-  actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, 200, 7, 150, 75, 
+  actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now + 40;
-  actor->duration_animation = 1*60;
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 5*60;
   scene.actors = g_slist_append(scene.actors, actor);
 
  
-  actor = init_object(desktop_plugin, "plane3", "plane3.png", 0, 45, 8, 160, 50, 
+  actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50, 
                       FALSE, 100, 255, (gpointer)&change_plane2, NULL);
-  actor->time_start_animation = now + 20;
-  actor->duration_animation = 40;
+  actor->time_start_animation = now + probability_plane();
+  actor->duration_animation = 60;
   scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "tu154", "tu154.png", 620, 233, 9, 300, 116, 
+  actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116, 
                       FALSE, 100, 255, (gpointer)&change_plane1, NULL);
-  actor->time_start_animation = now;
-  actor->duration_animation = 20;
+  actor->time_start_animation = now + probability_plane();
+  actor->duration_animation = 30;
   scene.actors = g_slist_append(scene.actors, actor);
 
   actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, 
                       TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
   change_static_actor_with_corner(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
-/*
+
   actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
                       FALSE, 100, 255, (gpointer)&change_wind, NULL);
   change_wind(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
-*/
+
   actor = init_object(desktop_plugin, "signal", "red.png", 486, 425, 10, 18, 38, 
                       TRUE, 100, 255, (gpointer)&change_signal, NULL);
-  actor->time_start_animation = now;  
+  actor->time_start_animation = now + fast_rnd(30) + 10;  
   scene.actors = g_slist_append(scene.actors, actor);winds[0][0] = 717;
     
     winds[0][0] = 389;
@@ -1304,20 +1321,14 @@ change_actor(GtkWidget * actor)
 static gboolean
 short_timeout (AWallpaperPlugin *desktop_plugin)
 {
-    //gint daytime = get_daytime();
+    gint daytime = get_daytime();
     GSList * tmp;
     void (*pfunc)(gpointer, gpointer);
     time_t now;
     Actor *actor;
     gboolean stop_flag = TRUE;
-    
-        min ++;
-        if (min == 60){
-            hour ++;
-            min = 0;
-            if (hour == 23) hour = 0;
-        }
-    if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
+
+if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
         desktop_plugin->priv->short_timer = 0;
         return FALSE;
     }
@@ -1349,17 +1360,12 @@ short_timeout (AWallpaperPlugin *desktop_plugin)
 void
 run_long_timeout(AWallpaperPlugin *desktop_plugin){
 
-    gint daytime = get_daytime(hour, min);
+    gint daytime = get_daytime();
     GSList * tmp;
     void (*pfunc)(gpointer, gpointer);
     time_t now;
     Actor *actor;
 
-    //hour = hour + 1;
-    //min = 0;
-    //if (hour == 24) hour = 0;
-    fprintf(stderr, "---- %d:%d\n", hour, min);
-
 
     //fprintf(stderr, "timer daytime=%d\n", daytime);
     if (scene.daytime != daytime){
@@ -1499,6 +1505,8 @@ animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
         init_scene(desktop_plugin);
     else if (!strcmp(priv->theme,"Berlin")) 
         init_scene1(desktop_plugin);
+    else if (!strcmp(priv->theme, "Matrix"))
+        init_scene2(desktop_plugin);
     priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
     priv->short_timer = 0;
     /* TODO Move scene to priv */