started restructuring
[livewp] / applet / src / livewp-home-widget.c
index 43edf61..a181dc5 100644 (file)
@@ -24,6 +24,7 @@
 /*******************************************************************************/
 #include "livewp-common.h" 
 #include "livewp-home-widget.h"
+#include "livewp-actor.h"
 #include <gconf/gconf-client.h>
 #include "livewp-rules.h"
 #include <sys/time.h>
@@ -159,13 +160,6 @@ 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)
@@ -175,56 +169,6 @@ destroy_hildon_actor(Actor *actor)
     actor->widget = NULL;
 }
 
-static Actor* 
-init_object(AWallpaperPlugin *desktop_plugin, 
-            gchar * name, 
-            gchar * filename, 
-            gint x, 
-            gint y, 
-            gint z, 
-            gint width, 
-            gint height, 
-            gboolean visible, 
-            gboolean load_image,
-            gint scale, 
-            gint opacity, 
-            void (*pfunc_change)(Actor*),
-            void (*pfunc_probability)(Actor*),
-            GPtrArray *child
-           )
-{
-  Actor *actor = NULL;
-  actor = g_new0(Actor, 1);
-  actor->x = x;
-  actor->y = y;
-  actor->z = z;
-  actor->width = width;
-  actor->height = height;
-  actor->visible = visible;
-  actor->scale = scale;
-  actor->opacity = opacity;
-  actor->filename = g_strdup(filename);
-  actor->name = g_strdup(name);
-  actor->func_change = (gpointer)pfunc_change; 
-  actor->func_probability = (gpointer)pfunc_probability;
-  actor->child = child;
-  if (load_image)
-    create_hildon_actor(actor, desktop_plugin);
-  else 
-    actor->widget = NULL;
-  actor->time_start_animation = 0;
-  actor->duration_animation = 0;
-  /*
-  a.widget = actor;
-  a.name = name;
-  a.x = x;
-  a.y = y;
-  a.z = z;
-  */
-  //objects_list = g_slist_append(objects_list, G_OBJECT(actor));
-  //objects_list = g_slist_append(objects_list, G_OBJECT(a));
-  return actor;
-}
 
 gint 
 rnd(gint max)
@@ -243,412 +187,6 @@ gint fast_rnd(gint max)
     return (gint)(seed % max);
 }
 
-gint 
-probability_sun()
-{
-    /* update sun position after ...  second */
-    return 60;
-}
-
-
-gint 
-probability_plane()
-{
-    //return (fast_rnd(10) + 1) * 60;
-    return fast_rnd(180);
-}
-
-void 
-change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
-{
-    gint phase;
-    char *newfile;
-    gint x0 = 150,
-         x1 = 650, 
-         x, y,
-         y0=150, y1 = 150, x2=400, y2=30;
-    double a, b, c;
-    struct timeval tvb;     
-    suseconds_t ms;
-    long sec;
-    double t;
-#if 0
-    a = (double)(y2 - (double)(x2*(y1-y0) + x1*y0 - x0*y1)/(x1-x0))/(x2*(x2-x0-x1)+x0*x1);
-    b = (double)(y1-y0)/(x1-x0) - (double)a*(x0+x1);
-    c = (double)(x1*y0 - x0*y1)/(x1-x0) + (double)a*x0*x1;
-    fprintf(stderr, "a=%f, b=%f, c=%f\n", a, b, c);
-#endif
-    gettimeofday(&tvb, NULL);
-    
-    ms = tvb.tv_usec;
-    sec = tvb.tv_sec;
-
-    if (actor){
-        if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
-            if (!actor->visible){
-                actor->visible = TRUE;
-                phase = get_moon_phase();
-                newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
-                if (actor->filename)
-                    g_free(actor->filename);
-                actor->filename = newfile;
-                actor->time_start_animation = sec - fast_rnd(60 * 60);
-                actor->duration_animation = 1 * 60 * 60;
-                create_hildon_actor(actor, desktop_plugin);
-
-            }
-            t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
-            if (t <= 1)
-                x = path_line(x0, x1, t);
-            else 
-                x = path_line(x1, x0, t-1);
-            //y = path_line(y0, y1, t);
-            y = 0.001920*x*x - 1.536*x + 337.2;
-            //y = a*x*x + b*x + c;
-
-            actor_set_position_full(actor->widget, x, y, actor->z);
-
-            if (t>=2){
-                actor->time_start_animation = sec;
-            }
-
-         }else if (actor->visible){
-            actor->visible = FALSE;
-            fprintf(stderr, "destroy moon \n");
-            destroy_hildon_actor(actor);
-            /* TO DO make moonrise*/
-            actor->time_start_animation = 0;
-        } 
-    }
-    
-}
-
-void 
-change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
-{
-    double alt, azm;
-    gint x, y;
-
-    //fprintf(stderr, "change sun\n");
-    if (actor){
-        if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
-            if (!actor->visible){
-                actor->visible = TRUE;
-                create_hildon_actor(actor, desktop_plugin);
-            }
-            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) + probability_sun();
-         }else if (actor->visible){
-            actor->visible = FALSE;
-            destroy_hildon_actor(actor);
-            actor->time_start_animation = 0;
-        } 
-    }
-    
-}
-
-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;
-    struct timeval tvb;     
-    suseconds_t ms;
-    long sec;
-    double t;
-
-    //fprintf(stderr, "change tram\n");
-    gettimeofday(&tvb, NULL);
-    
-    ms = tvb.tv_usec;
-    sec = tvb.tv_sec;
-    
-    if (!actor->visible){
-        actor->visible = TRUE;
-        if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
-            if (actor->filename)
-                g_free(actor->filename);
-            actor->filename = g_strdup("tram_dark.png");
-        } else{
-            if (actor->filename)
-                g_free(actor->filename);
-            actor->filename = g_strdup("tram.png");
-        }
-        create_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 = 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);
-    set_actor_scale(actor, (double)scale/100, (double)scale/100);
-    if (t >= 1){
-        /* stop animation */
-        actor->visible = FALSE;
-        destroy_hildon_actor(actor);
-        actor->time_start_animation = sec + fast_rnd(60);
-    }
-}
-
-void
-change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
-{
-    gint x0 = 620, y0 = 233,
-         x1 = 79, y1 = -146, 
-         x, y;
-    struct timeval tvb;     
-    suseconds_t ms;
-    long sec;
-    double t;
-
-    gettimeofday(&tvb, NULL);
-    
-    ms = tvb.tv_usec;
-    sec = tvb.tv_sec;
-//    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
-   
-    if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
-        if (actor->time_start_animation == 0){
-            actor->time_start_animation = sec + probability_plane();
-            return;
-        }
-    }
-    if (!actor->visible){
-        actor->visible = TRUE;
-        create_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 = 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);
-    if (t >= 1){
-        /* stop animation */
-        actor->visible = FALSE;
-        destroy_hildon_actor(actor);
-        if (desktop_plugin->priv->scene->daytime == TIME_NIGHT) 
-            actor->time_start_animation = 0;
-        else 
-            actor->time_start_animation = sec + probability_plane();
-    }
-
-}
-
-void
-change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
-{
-    gint x0 = -actor->width, y0 = 45,
-         x1 = 800, y1 = 20, 
-         x, y;
-    struct timeval tvb;     
-    suseconds_t ms;
-    long sec;
-    double t;
-
-    gettimeofday(&tvb, NULL);
-    
-    ms = tvb.tv_usec;
-    sec = tvb.tv_sec;
-//    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
-    if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
-        if (actor->time_start_animation == 0){
-            actor->time_start_animation = sec + probability_plane();
-            return;
-        }
-    }
-    if (!actor->visible){
-        actor->visible = TRUE;
-        create_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 = 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);
-    if (t >= 1){
-        /* stop animation */
-        actor->visible = FALSE;
-        destroy_hildon_actor(actor);
-        if (desktop_plugin->priv->scene->daytime == TIME_NIGHT) 
-            actor->time_start_animation = 0;
-        else 
-            actor->time_start_animation = sec + probability_plane();
-    }
-
-}
-
-void
-change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
-{
-    gint x0, y0 = 300, scale0 = 100,
-         x1, y1 = -actor->height, scale1 = 150, 
-         x, y, scale;
-    struct timeval tvb;     
-    suseconds_t ms;
-    long sec;
-    double t;
-    gchar *newfile;
-
-    //fprintf(stderr, "change cloud\n");
-    gettimeofday(&tvb, NULL);
-    
-    ms = tvb.tv_usec;
-    sec = tvb.tv_sec;
-    //fprintf(stderr, "c1oud %s - y0=%d\n", actor->name, actor->y);
-   
-    if (!actor->visible){
-        actor->visible = TRUE;
-        if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
-            newfile = g_strdup_printf("%s_dark.png", actor->name);
-        }else{
-            newfile = g_strdup_printf("%s.png", actor->name);
-        } 
-        if (actor->filename)
-            g_free(actor->filename);
-        actor->filename = newfile;
-         
-        create_hildon_actor(actor, desktop_plugin);
-    }
-    t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
-    
-    if (desktop_plugin->priv->scene->wind_orientation == 1){
-        x0 = -actor->width;
-        x1 = 800;
-    }
-    else {
-        x0 = 800;
-        x1 = -actor->width;
-    }
-
-    x = path_line(x0, x1, t);    
-    y = -desktop_plugin->priv->scene->wind_angle * (x - x0) + actor->y;
-    scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
-
-    //fprintf(stderr, "change cloud 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);
-    set_actor_scale(actor, (double)scale/100, (double)scale/100);
-    if ((y < y1 || y > y0) || t >= 1){
-        /* stop animation */
-        actor->visible = FALSE;
-        destroy_hildon_actor(actor);
-        actor->time_start_animation = sec + fast_rnd(300);
-        actor->y = fast_rnd(300);
-    }
-
-}
-
-void
-change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
-{
-    desktop_plugin->priv->scene->wind_orientation = fast_rnd(2);
-    if (desktop_plugin->priv->scene->wind_orientation == 0) desktop_plugin->priv->scene->wind_orientation = -1;
-    desktop_plugin->priv->scene->wind_angle = (double)(fast_rnd(200) - 100) / 100;
-    actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
-    //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
-}
-
-void 
-change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
-{
-    gint now = time(NULL);
-    if (desktop_plugin->priv->scene->daytime == TIME_DAY){
-        if (actor->widget){
-            actor->visible = FALSE;
-            destroy_hildon_actor(actor);
-        }
-        actor->time_start_animation = 0;
-        return;
-    }else {
-        if (!actor->widget)
-            create_hildon_actor(actor, desktop_plugin);
-        if (actor->time_start_animation == 0){
-            actor->time_start_animation = now + fast_rnd(30);
-            return;
-        }
-    }
-
-    if (!actor->visible)
-        actor->visible = TRUE;
-    else 
-        actor->visible = FALSE;
-    //hildon_animation_actor_set_show(
-      //      HILDON_ANIMATION_ACTOR(actor->widget), 
-        //    actor->visible
-    //);
-    set_actor_visible(actor, actor->visible);
-    actor->time_start_animation = now + fast_rnd(60) + 10;
-
-}
-
-void 
-change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
-{
-    gint now = time(NULL);
-    Actor *a;
-#if 0
-    gchar *newfile;
-    gint now = time(NULL);
-    newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime); 
-    if (!strcmp(actor->filename, "red.png"))
-        newfile = g_strdup_printf("%s", "green.png");
-    else 
-        newfile = g_strdup_printf("%s", "red.png");
-    g_free(actor->filename);
-    actor->filename = newfile;
-    change_hildon_actor(actor, desktop_plugin);
-    actor->time_start_animation = now + fast_rnd(30) + 10;
-#endif
-    a = g_ptr_array_index(actor->child, 0);
-    //fprintf(stderr, "actor name= %p \n", child->widget);
-    if (a->visible)
-        a->visible = FALSE;
-    else 
-        a->visible = TRUE;
-    //hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(a->widget), a->visible);
-    set_actor_visible(a, a->visible);
-    
-    a = g_ptr_array_index(actor->child, 1);
-    //fprintf(stderr, "actor name= %s \n", child->name);
-    if (a->visible)
-        a->visible = FALSE;
-    else 
-        a->visible = TRUE;
-    //hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(a->widget), a->visible);
-    set_actor_visible(a, a->visible);
-
-    actor->time_start_animation = now + fast_rnd(30) + 10;
-}
-
-void
-set_actor_scale(Actor *actor, double scalex, double scaley)
-{
-    hildon_animation_actor_set_scale(
-            HILDON_ANIMATION_ACTOR(actor->widget), 
-            scalex, 
-            scaley
-    );
-
-}
-
-void 
-set_actor_visible(Actor *actor, gboolean visible)
-{
-    hildon_animation_actor_set_show(HILDON_ANIMATION_ACTOR(actor->widget), visible);
-}
 void
 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin) 
 {
@@ -685,20 +223,7 @@ create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
   /* TO DO check it */
   /*  gdk_flush (); */
 
-  //g_object_set_data(G_OBJECT(ha), "name", name);
-  //g_object_set_data(G_OBJECT(ha), "filename", filename);
   g_object_set_data(G_OBJECT(ha), "image", image);
-  /*
-  g_object_set_data(G_OBJECT(ha), "x", x);
-  g_object_set_data(G_OBJECT(ha), "y", y);
-  g_object_set_data(G_OBJECT(ha), "z", z);
-  g_object_set_data(G_OBJECT(ha), "width", width);
-  g_object_set_data(G_OBJECT(ha), "height", height);
-  g_object_set_data(G_OBJECT(ha), "scale", scale);
-  g_object_set_data(G_OBJECT(ha), "visible", visible);
-  g_object_set_data(G_OBJECT(ha), "opacity", opacity);
-  g_object_set_data(G_OBJECT(ha), "func", pfunc);
-  */
   hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
   actor->widget = ha;
 }
@@ -783,40 +308,35 @@ change_layer(Actor * actor, AWallpaperPlugin *desktop_plugin)
     a = g_ptr_array_index(actor->child, 0);
     y = a->y + 10;
     if (y > 480) y = -480;
-    //fprintf(stderr, "!! %s - %d\n", actor->name, y);
     actor_set_position_full(a->widget, a->x, y, a->z);
     a->y = y;
     
     a = g_ptr_array_index(actor->child, 1);
     y = a->y + 10;
     if (y > 480) y = -480;
-    //fprintf(stderr, "!! %s - %d\n", actor->name, y);
     actor_set_position_full(a->widget, a->x, y, a->z);
     a->y = y;
 
     a = g_ptr_array_index(actor->child, 2);
     y = a->y + 20;
     if (y > 480) y = -480;
-    //fprintf(stderr, "!! %s - %d\n", actor->name, y);
     actor_set_position_full(a->widget, a->x, y, a->z);
     a->y = y;
 
     a = g_ptr_array_index(actor->child, 3);
     y = a->y + 20;
     if (y > 480) y = -480;
-    //fprintf(stderr, "!! %s - %d\n", actor->name, y);
     actor_set_position_full(a->widget, a->x, y, a->z);
     a->y = y;
 
 }
-
+#if 0
 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;
 }
@@ -827,11 +347,10 @@ 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;
 }
-
+#endif
 /*
 static gint 
 get_time(gint t){
@@ -991,7 +510,7 @@ init_scene(AWallpaperPlugin *desktop_plugin)
   actor = init_object(desktop_plugin, "sun", "sun.png", 
                       0, 0, 6, 88, 88, 
                       FALSE, FALSE, 100, 255, 
-                      (gpointer)&change_sun, (gpointer)&probability_sun, NULL);
+                      (gpointer)&change_sun, NULL, NULL);
   actor->time_start_animation = now;
   actor->duration_animation = G_MAXINT;
   change_sun(actor, desktop_plugin);
@@ -1307,7 +826,7 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   
   actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88, 
                       FALSE, FALSE, 100, 255, 
-                      (gpointer)&change_sun, (gpointer)&probability_sun, NULL);
+                      (gpointer)&change_sun, NULL, NULL);
   actor->time_start_animation = time(NULL);
   actor->duration_animation = G_MAXINT;
   change_sun(actor, desktop_plugin);