struct Animation
authorTanya <tanya@bookdmitri.oblgaz>
Tue, 6 Apr 2010 19:57:25 +0000 (22:57 +0300)
committerTanya <tanya@bookdmitri.oblgaz>
Tue, 6 Apr 2010 19:57:25 +0000 (22:57 +0300)
applet/src/livewp-home-widget.c
applet/src/livewp-home-widget.h

index c4560e6..d3692fc 100644 (file)
@@ -271,39 +271,23 @@ void change_static_actor(GtkWidget * actor, gpointer data)
 }
 
 static gint 
-path_line(gint x0, gint x1, gint t_all, gint t)
+path_line(gint x0, gint x1, double t)
 {
     // уравниение прямой
-    return ((x1 - x0) *t / t_all + x0);
+    return ((x1 - x0) * t + 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)
+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, 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);
+
+    x = path_line(x0, x1, t);
+    y = path_line(y0, y1, t);
+    scale = path_line(scale0, scale1, t);
+    fprintf(stderr, "path tram:  t=%f, 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);
 }
@@ -389,15 +373,7 @@ Animation anim;
 void
 anim_tram(GtkWidget *actor, Animation * an)
 {
-    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);
+    //change_tram1(an->actor, t, an->timeall);
 }
 
 static void
@@ -439,11 +415,12 @@ fprintf(stderr, "init scene \n");
   //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.count = 2;
   anim.actor = actor;
-  //anim.func = &change_tram;
+  anim.func_change = &change_tram;
+  anim.func_time = NULL;
   anim.timestart = time(NULL); 
-  anim.timeall = 100;
+  anim.timeall = 20;
  }
 static void
 init_scene1(AWallpaperPlugin *desktop_plugin)
@@ -623,7 +600,21 @@ plugin_on_timeout (AWallpaperPlugin *desktop_plugin)
       }
       tmp = g_slist_next(tmp);
   }
-
+    
+   // if (anim){
+        time_t now;
+        now = time(NULL);
+        gint t = now - anim.timestart;
+        if (t > anim.timeall){
+            anim.timestart = now;
+            if (anim.count != -1) anim.count--;
+            if (anim.count == 0) return;
+        } 
+        if (anim.count != 0) {
+            if (anim.func_time ) t = (*anim.func_time)(t);
+            if (anim.func_change) (*anim.func_change)(anim.actor, (double)t/anim.timeall);
+        }
+   // }
   scene.daytime = daytime;
 
   //double azm, alt;
@@ -702,7 +693,7 @@ animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
       init_scene(desktop_plugin);
   else if (!strcmp(priv->theme,"Berlin")) 
       init_scene1(desktop_plugin);
-  priv->timer = g_timeout_add(100, plugin_on_timeout, desktop_plugin);
+  priv->timer = g_timeout_add(1000*1, plugin_on_timeout, desktop_plugin);
 }
 
 static void
index 05d74d7..ea83d6c 100644 (file)
@@ -59,7 +59,8 @@ typedef struct {
     gint timeall;
     gint count;
     GtkWidget *actor;
-    //void (*pfunc)(GtkWidget *, Animation *);
+    void (*func_change)(GtkWidget *, double);
+    gint (*func_time)(gint);
 } Animation;
 
 typedef struct {