add tram
authorTanya <tanya@bookdmitri.oblgaz>
Thu, 8 Apr 2010 18:24:03 +0000 (21:24 +0300)
committerTanya <tanya@bookdmitri.oblgaz>
Thu, 8 Apr 2010 18:24:03 +0000 (21:24 +0300)
applet/src/livewp-home-widget.c
applet/src/livewp-rules.c

index 8062105..92c91d5 100644 (file)
@@ -159,6 +159,14 @@ actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
  hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
 }
 
+static gint 
+path_line(gint x0, gint x1, double t)
+{
+    // уравниение прямой
+    return ((x1 - x0) * t + x0);
+}
+
+
 void
 destroy_hildon_actor(Actor *actor)
 {
@@ -227,11 +235,10 @@ change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
             if (!actor->visible){
                 actor->visible = TRUE;
                 phase = get_moon_phase();
-                newfile = g_strdup_printf( "%s/%s/%s%d.png", THEME_PATH, desktop_plugin->priv->theme, actor->name, phase);
-
-                create_hildon_actor(actor, desktop_plugin);
+                newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
+                
                 actor->filename = newfile;
-                change_hildon_actor(actor, desktop_plugin);
+                create_hildon_actor(actor, desktop_plugin);
 
             }
             //actor->x = 400;
@@ -278,6 +285,33 @@ change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
     }
     
 }
+static void 
+change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
+{
+    gint x0 = -300, y0 = 225, scale0 = 100,
+         x1 = 800, y1 = 162, scale1 = 130, 
+         x, y, scale;
+    gint daytime = get_daytime();
+    time_t now = time(NULL);
+    double t;
+
+    if (!actor->visible){
+        actor->visible = TRUE;
+        if (daytime == TIME_NIGHT)
+            actor->filename = g_strdup("tram_dark.png");
+        else
+            actor->filename = g_strdup("tram.png");
+        create_hildon_actor(actor, desktop_plugin);
+    }
+    t = (double)(now - actor->time_start_animation) / actor->duration_animation;
+    x = path_line(x0, x1, t);
+    y = path_line(y0, y1, 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(actor->widget, (double)scale/100, (double)scale/100);
+
+}
 void
 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin) 
 {
@@ -288,7 +322,8 @@ create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
 
   fprintf(stderr, "create_hildon_actor %s\n", actor->name);
   ha = hildon_animation_actor_new();
-  str = g_strdup_printf( "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, actor->filename);
+  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, 
@@ -333,8 +368,12 @@ change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
 {
     GtkWidget *image = NULL;
     GdkPixbuf *pixbuf = NULL;
-    
-    pixbuf = gdk_pixbuf_new_from_file_at_size (actor->filename, 
+    gchar *str;
+
+    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);
@@ -364,31 +403,12 @@ change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
     gchar *newfile;
     if (!actor) return;
     daytime = get_daytime();
-    newfile = g_strdup_printf("%s/%s/%s%d.png", THEME_PATH, desktop_plugin->priv->theme, actor->name, daytime); 
+    newfile = g_strdup_printf("%s%d.png", actor->name, daytime); 
     actor->filename = newfile;
     change_hildon_actor(actor, desktop_plugin);
 }
 
-static gint 
-path_line(gint x0, gint x1, double t)
-{
-    // уравниение прямой
-    return ((x1 - x0) * t + x0);
-}
-
-static void 
-change_tram(GtkWidget * actor, double t)
-{
-    gint x0 = -300, y0 = 225, scale0 = 100,
-         x1 = 800, y1 = 162, scale1 = 130, 
-         x, y, scale;
 
-    x = path_line(x0, x1, t);
-    y = path_line(y0, y1, t);
-    scale = path_line(scale0, scale1, t);
-    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)
 {
@@ -477,38 +497,46 @@ fprintf(stderr, "init scene \n");
   //get_sun_pos(&alt, &azm);
   //get_sun_screen_pos(alt, azm, &x, &y);
   
-  actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 11, 88, 88, TRUE, 100, 255, &change_sun, &probability_sun);
+  actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 11, 88, 88, 
+                      TRUE, 100, 255, &change_sun, &probability_sun);
   actor->time_start_animation = time(NULL);
   actor->duration_animation = G_MAXINT;
   change_sun(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, 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, NULL);
+  actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480, 
+                      TRUE, 100, 255, &change_static_actor, NULL);
   change_static_actor(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
 
 
-  actor = init_object(desktop_plugin, "town", "town0.png", 0, 480-374, 10, 800, 374, 1, 100, 255, &change_static_actor, NULL);
+  actor = init_object(desktop_plugin, "town", "town0.png", 0, 480-374, 10, 800, 374, 
+                      TRUE, 100, 255, &change_static_actor, NULL);
   change_static_actor(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 30, 800, 79, 1, 100, 255, &change_static_actor, NULL);
+  actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 30, 800, 79, 
+                      TRUE, 100, 255, &change_static_actor, NULL);
   change_static_actor(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
 
-  actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 50, 7, 100, 100, 
-                        FALSE, 100, 255, &change_moon, NULL);
+  actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, 7, 70, 70, 
+                      FALSE, 100, 255, &change_moon, NULL);
   change_moon(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
 
-#if 0  
+
   //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, 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));
   
+  actor = init_object(desktop_plugin, "tram", "tram_dark.png", -300, 225, 25, 350, 210, 
+                      FALSE, 100, 255, &change_tram, NULL);
+  actor->time_start_animation = time(NULL) + 10;
+  actor->duration_animation = 60;
+  scene.actors = g_slist_append(scene.actors, actor);
+#if 0    
   anim = g_new0(Animation, 1);
   anim->count = 1;
   anim->actor = actor;
@@ -678,7 +706,7 @@ plugin_on_timeout (AWallpaperPlugin *desktop_plugin)
   time_t now;
   gint t;
   Actor *actor;
+fprintf(stderr, "timer daytime=%d\n", daytime);
   if (scene.daytime != daytime){
       tmp = scene.actors;
       while (tmp != NULL){
index e9d0fa1..796b813 100644 (file)
@@ -85,10 +85,10 @@ int get_daytime()
     get_sun_pos(&alt, &azm);
     alt = alt * 100;
     azm = azm * 100;
-    //fprintf("alt = %f azm=%f\n", alt, azm);
+    //printf("alt = %f azm=%f\n", alt, azm);
     if (alt <= -7) return TIME_NIGHT;
     if (alt > -7 && alt < 7 && azm < 50) return TIME_SUNRISE;
-    if (alt > 7 && alt < azm > 50) return TIME_SUNSET;
+    if (alt > -7 && alt < 7 && azm > 50) return TIME_SUNSET;
     if (alt >= 7) return TIME_DAY;
     
 }