add moon
authortanya <tanya@tanin.oblgaz>
Thu, 8 Apr 2010 12:08:42 +0000 (15:08 +0300)
committertanya <tanya@tanin.oblgaz>
Thu, 8 Apr 2010 12:08:42 +0000 (15:08 +0300)
applet/src/livewp-home-widget.c
applet/src/livewp-rules.c
applet/src/livewp-rules.h

index cc064ba..b9a626f 100644 (file)
@@ -164,56 +164,6 @@ destroy_hildon_actor(Actor *actor)
     actor->widget = NULL;
 }
 
-void
-create_hildon_actor(AWallpaperPlugin *desktop_plugin, Actor *actor) 
-{
-  GtkWidget *ha = NULL;
-  GdkPixbuf *pixbuf = NULL;
-  GtkWidget *image = NULL;
-
-  ha = hildon_animation_actor_new();
-  gchar str[256];
-  snprintf(str, 255, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, actor->filename);
-  fprintf(stderr, "!!!init object !!!!file = %s\n", str);
-  pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
-                                             actor->width, 
-                                             actor->height, 
-                                             NULL);
-  if (pixbuf){
-      image = gtk_image_new_from_pixbuf (pixbuf);
-      g_object_unref(G_OBJECT(pixbuf));
-  }
-  if (image){
-    g_signal_connect(G_OBJECT(image), "expose_event",
-                           G_CALLBACK(expose_event), pixbuf);
-    gtk_container_add (GTK_CONTAINER (ha), image);
-  }  
-
-  actor_set_position_full(ha, actor->x, actor->y, actor->z);
-  hildon_animation_actor_set_show (ha, actor->visible);
-  hildon_animation_actor_set_scale(ha, (double)actor->scale/100, (double)actor->scale/100);
-  realize(ha);
-  gtk_widget_show_all(ha);
-
-  //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), desktop_plugin);
-
-  actor->widget = ha;
-}
-
 static Actor* 
 init_object(AWallpaperPlugin *desktop_plugin, 
             gchar * name, 
@@ -245,7 +195,9 @@ init_object(AWallpaperPlugin *desktop_plugin,
   actor->func_change = pfunc_change; 
   actor->func_probability = pfunc_probability;
   if (visible)
-    create_hildon_actor(desktop_plugin, actor);
+    create_hildon_actor(actor, desktop_plugin);
+  else 
+    actor->widget = NULL;
   actor->time_start_animation = 0;
   actor->duration_animation = 0;
   /*
@@ -260,6 +212,45 @@ init_object(AWallpaperPlugin *desktop_plugin,
   return actor;
 }
 
+void 
+change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
+{
+    gint x, y, z, daytime, phase;
+    char *newfile;
+
+    if (actor){
+        daytime = get_daytime();
+        if (daytime == TIME_NIGHT){
+            if (!actor->visible){
+                actor->visible = TRUE;
+#if 0
+                phase = get_moon_phase();
+    fprintf(stderr, "change moon %d\n", phase);
+    fprintf(stderr, "actor name %s\n", actor->name);
+    fprintf(stderr, "actor ytghg %s\n", desktop_plugin->priv->theme);
+                newfile = g_strdup_printf( "%s/%s/%s%d.png", THEME_PATH, desktop_plugin->priv->theme, actor->name, phase);
+#endif
+
+                create_hildon_actor(actor, desktop_plugin);
+                //actor->filename = newfile;
+                //change_hildon_actor(actor, desktop_plugin);
+
+            }
+            //actor->x = 400;
+            //actor->y = 10;
+           // actor_set_position_full(actor->widget, x, y, actor->z);
+            //probability_sun(actor);
+            //fprintf(stderr, "after change sun %d\n", actor->time_start_animation);
+         }else if (actor->visible){
+            actor->visible = FALSE;
+            fprintf(stderr, "destroy moon \n");
+            destroy_hildon_actor(actor);
+            /* TO DO make moonrise*/
+            actor->time_start_animation = get_next_sunset();
+        } 
+    }
+    
+}
 
 void 
 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
@@ -291,6 +282,57 @@ change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
     
 }
 void
+create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin) 
+{
+  GtkWidget *ha = NULL;
+  GdkPixbuf *pixbuf = NULL;
+  GtkWidget *image = NULL;
+
+  ha = hildon_animation_actor_new();
+  gchar str[256];
+  snprintf(str, 255, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, actor->filename);
+  fprintf(stderr, "!!!create ha !!!!file = %s\n", str);
+  pixbuf = gdk_pixbuf_new_from_file_at_size (str, 
+                                             actor->width, 
+                                             actor->height, 
+                                             NULL);
+  if (pixbuf){
+      image = gtk_image_new_from_pixbuf (pixbuf);
+      g_object_unref(G_OBJECT(pixbuf));
+  }
+  if (image){
+    g_signal_connect(G_OBJECT(image), "expose_event",
+                           G_CALLBACK(expose_event), pixbuf);
+    gtk_container_add (GTK_CONTAINER (ha), image);
+  }  
+fprintf(stderr, "creage ha x=%d y=%d z=%d visible=%d w=%i h=>%i ", actor->x, actor->y, actor->z, actor->visible, actor->width, actor->height);
+  actor_set_position_full(ha, actor->x, actor->y, actor->z);
+  hildon_animation_actor_set_show (ha, actor->visible);
+  hildon_animation_actor_set_scale(ha, (double)actor->scale/100, (double)actor->scale/100);
+  realize(ha);
+  gtk_widget_show_all(ha);
+
+  //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), desktop_plugin);
+      fprintf(stderr, "image %p\n", desktop_plugin);
+  actor->widget = ha;
+}
+
+
+void
 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
 {
     GtkWidget *image = NULL;
@@ -317,7 +359,10 @@ change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
     }
 
 }
-void change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
+
+
+void 
+change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
 {
     gint daytime;
     gchar newfile[2048];
@@ -440,7 +485,7 @@ fprintf(stderr, "init scene modern\n");
   scene.actors = NULL;
   //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->time_start_animation = time(NULL);
   actor->duration_animation = G_MAXINT;
@@ -452,7 +497,7 @@ fprintf(stderr, "init scene modern\n");
   change_static_actor(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
 
-#if 0
+
   actor = init_object(desktop_plugin, "town", "town0.png", 0, 480-374, 10, 800, 374, 1, 100, 255, &change_static_actor, NULL);
   change_static_actor(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
@@ -460,7 +505,11 @@ fprintf(stderr, "init scene modern\n");
   actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 30, 800, 79, 1, 100, 255, &change_static_actor, NULL);
   change_static_actor(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
-#endif
+
+  actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 50, 7, 150, 150, 
+                        FALSE, 100, 255, &change_moon, NULL);
+  //change_static_actor(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
 
 #if 0  
   //if (scene.daytime == TIME_DAY) snprintf(str, 255, "tram.png");
index 63719d7..e9d0fa1 100644 (file)
@@ -74,6 +74,11 @@ time_t get_next_sunrise()
 {
     return time(NULL) + 60*60*8;
 }
+time_t get_next_sunset()
+{
+        return time(NULL) + 60*60*12;
+}
+
 int get_daytime()
 {
     double alt, azm;
index caffce4..38b8d46 100644 (file)
 #define TIME_SUNSET     2
 
 #define MOON_NONE               0
-#define MOON_GROWS              1
+#define MOON_GROWS              5
 #define MOON_GROWSHALF          2
-#define MOON_FULL               3 
-#define MOON_DECREASHALF        4
-#define MOON_DECREAS            5
+#define MOON_FULL               1 
+#define MOON_DECREASHALF        3
+#define MOON_DECREAS            4
 
 /*******************************************************************************/
 void get_localtime(int * year, int * month, int * day, int * hour, int * min, int * zone);
@@ -46,6 +46,6 @@ void get_sun_pos(double * alt, double * azm);
 int get_daytime();
 int get_moon_phase();
 time_t get_next_sunrise();
-
+time_t get_next_sunset();
 /*******************************************************************************/
 #endif