not finished
authorTanya <tanya@bookdmitri.oblgaz>
Sat, 27 Mar 2010 01:43:51 +0000 (03:43 +0200)
committerTanya <tanya@bookdmitri.oblgaz>
Sat, 27 Mar 2010 01:43:51 +0000 (03:43 +0200)
applet/Makefile.am
applet/livewp-astro.c
applet/livewp-home-widget.c
applet/livewp-home-widget.h
applet/livewp-rules.c [new file with mode: 0644]
applet/livewp-rules.h [new file with mode: 0644]

index 38d5792..caf52fb 100644 (file)
@@ -4,7 +4,7 @@ SUBDIRS = data
 desktoplib_LTLIBRARIES =  liblivewp-home-widget.la
 desktoplibdir = $(HILDON_DESKTOP_LIB_DIR)
 
-liblivewp_home_widget_la_SOURCES = livewp-home-widget.c livewp-home-widget.h livewp-astro.c livewp-astro.h
+liblivewp_home_widget_la_SOURCES = livewp-home-widget.c livewp-home-widget.h livewp-astro.c livewp-astro.h livewp-rules.c livewp-rules.h
 liblivewp_home_widget_la_LIBADD = $(EXAMPLE_LIBS) 
 
 AM_CFLAGS = -Wall $(EXAMPLE_CFLAGS) 
index 9fcceb1..ec2a8eb 100644 (file)
@@ -64,7 +64,6 @@ double azimuth(double lon, double lat, int year, int month, int day, int hour, i
 {
     double uu, jj, T, k, M, Lo, DL, L, eps, delta, RA, GMST, LMST, H, eqt, azm;
     uu = ut(hour, min, zone);
-    fprintf(stderr, "%f, %f, %i.%i.%i %i:%i %i uu=%f", lon, lat, year, month, day, hour, min, zone, uu);
     jj = jd(year, month, day, uu);
     T = jj / 36525;
     k = M_PI / 180;
@@ -89,8 +88,8 @@ double azimuth(double lon, double lat, int year, int month, int day, int hour, i
 }
 double moon_phase(int year, int month, int day)
 {
-    int yy, mm, dd, k1, k2, k3, lg;
-    double agepart, ageday, ge, moonday, jd, moonfill;
+    int lg;
+    double agepart, ge, jd, moonday;
     ge = 1721425.5;
     moonday = 29.530588853;
     if (month <= 2) lg = 0;
index dc43759..694958a 100644 (file)
@@ -26,7 +26,7 @@
 #include "livewp-home-widget.h"
 #include <libhildondesktop/libhildondesktop.h>
 #include <gconf/gconf-client.h>
-#include "livewp-astro.h"
+#include "livewp-rules.h"
 
 #define PLUGIN_NAME "livewp-home-widget.desktop-0"
 #define GCONF_KEY_POSITION "/apps/osso/hildon-desktop/applets/%s/position"
@@ -115,6 +115,7 @@ actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
 
 GtkWidget* init_object(gchar * name, gint x, gint y, gint z, gint width, gint height)
 {
+  Actor  a;  
   GtkWidget *actor;
   GdkPixbuf *pixbuf;
   GtkWidget *image;
@@ -143,7 +144,9 @@ GtkWidget* init_object(gchar * name, gint x, gint y, gint z, gint width, gint he
   g_object_set_data(G_OBJECT(actor), "posX", x);
   g_object_set_data(G_OBJECT(actor), "posY", y);
 
+  
   objects_list = g_slist_append(objects_list, G_OBJECT(actor));
+  //objects_list = g_slist_append(objects_list, G_OBJECT(a));
   return actor;
 }
 
@@ -158,9 +161,8 @@ init_scene(GtkWidget *window)
 
   get_sun_pos(&alt, &azm);
   get_sun_screen_pos(alt, azm, &x, &y);
-  if (x > 800) x = 700;
-  if (y > 480) y = 400;
-  actor = init_object("sun", x, y, 1, 88, 88);
+  fprintf(stderr, "init scene  alt=%f, azm=%f, x=%d, y=%d", alt, azm, x, y);
+  actor = init_object("sun", x, y, 20, 88, 88);
   hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), window);
   actor = init_object("sky", 0, 0, 0, 800, 480);
   hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), window);
@@ -177,34 +179,6 @@ static void
 example_label_home_applet_realize (GtkWidget *widget)
 {
 }
-void get_coord(double * lat, double * lon)
-{
-    *lat = 55.166666;
-    *lon = 30.166666;
-}
-void get_sun_pos(double * alt, double * azm)
-{
-  double lon ,lat;
-  time_t timet;
-  struct tm nowtime;
-  get_coord(&lat, &lon);
-  time(&timet);
-  localtime_r(&timet, &nowtime);
-  //fprintf(stderr, "plugin on timeout %i.%i.%i (%i) %i:%i:%i\n", nowtime.tm_mday, nowtime.tm_mon+1, nowtime.tm_year+1900, abs(nowtime.tm_gmtoff/3600), nowtime.tm_hour, nowtime.tm_min, nowtime.tm_sec);
- fprintf(stderr, "before altitude\n"); 
-    *alt = altitude(lon, lat, nowtime.tm_year+1900, nowtime.tm_mon+1, nowtime.tm_mday, nowtime.tm_hour, nowtime.tm_min, nowtime.tm_gmtoff/3600);
-    *alt = *alt / 70;
-    *azm = azimuth(lon, lat, nowtime.tm_year+1900, nowtime.tm_mon+1, nowtime.tm_mday, nowtime.tm_hour, nowtime.tm_min, nowtime.tm_gmtoff/3600);
-    //если южная широта
-    if (lat < 0){
-        *azm = 90 + (90 - *azm);
-        *azm = fmod(*azm, 360);
-    } 
-    *azm = (*azm - 90) / 180;
-    //fprintf(stderr, "alt=%5.6f azm=%5.6f\n", alt, azm);
-    
-}
-
 void get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
 {
     gint y0 = 400;// - уровень горизонта
@@ -213,28 +187,57 @@ void get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
     *x = (int)(azm * 800) - 64;
     *y = (int)((1 - alt) * y0) - 64;
 }
+/*
+void processing(GtkWidget * actor)
+{
+    char * name;
+    gint x, y;
+    double alt, azm;
+    gint daytime = get_daytime();
+    gint moonphase = get_moon_phase();
+    name = g_object_get_data(G_OBJECT(tmp->data), "name");
+    if (name == "sun"){
+        if (daytime != TIME_NIGHT){
+            hildon_animation_actor_set_show(tmp->data, 1);
+            get_sun_pos(&alt, &azm);
+            get_sun_screen_pos(alt, azm, &x, &y);
+            actor_set_position_full(tmp->data, x, y, );
+        }
+    }
+    
+
+}*/
 
 static gboolean
 plugin_on_timeout (gpointer data)
 {
   gchar * str;
   gint x, y;
-  
-  double azm, alt;
-  get_sun_pos(&alt, &azm);
+  Actor * a;
+  fprintf(stderr, "on timeout\n");
+  //double azm, alt;
+  //get_sun_pos(&alt, &azm);
 
   GSList * tmp = objects_list;
   while (tmp != NULL){
+      //processing(tmp->data);
+      /*
       str = g_object_get_data(G_OBJECT(tmp->data), "name");
       fprintf(stderr, "object: %s\n", str);
       if (str == "sun"){
-        get_sun_screen_pos(alt, azm, &x, &y);
-        actor_set_position_full(tmp->data, x, y, 0);
+        //get_sun_screen_pos(alt, azm, &x, &y);
+        //x = tmp->data
+        actor_set_position_full(tmp->data, x, y, 20);
         fprintf(stderr, "x = %i, y = %i\n", x, y);
         //g_object_set_data(G_OBJECT(tmp->data), "posX", x);
         //g_object_set_data(G_OBJECT(tmp->data), "posY", y);
         fprintf(stderr, "x = %d y = %d\n", x, y);
       }
+      if (str == "town"){
+          //hildon_animation_actor_set_show(tmp->data, 0);
+      }*/
+      //a = tmp->data;
+      //fprintf(stderr, "--timeout %s\n", a->name);
       tmp = g_slist_next(tmp);
   }
   
@@ -250,7 +253,7 @@ animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
   gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
   init_applet_position();
   init_scene(desktop_plugin);
-  desktop_plugin->timer = g_timeout_add(1000*60*1, plugin_on_timeout, desktop_plugin);
+  //desktop_plugin->timer = g_timeout_add(1000*20, plugin_on_timeout, desktop_plugin);
 }
 
 static void
index bf4f721..d38fdf2 100644 (file)
@@ -63,6 +63,23 @@ struct _AWallpaperPluginClass
 
 };
 
+typedef struct {
+    GtkWidget * window;
+    GSList * actors;
+}Scene;
+
+typedef struct {
+    GtkWidget * widget;
+    gchar * name;
+    gint x;
+    gint y;
+    gint z;
+    gint widht;
+    gint height;
+    gboolean visible;
+
+}Actor;
+
 GType animation_wallpaper_home_plugin_get_type(void);
 
 G_END_DECLS
diff --git a/applet/livewp-rules.c b/applet/livewp-rules.c
new file mode 100644 (file)
index 0000000..791ba94
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * This file is part of Live Wallpaper (livewp)
+ * 
+ * Copyright (C) 2010 Vlad Vasiliev
+ * Copyright (C) 2010 Tanya Makova
+ *       for the code
+ * 
+ * This software is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+*/
+/*******************************************************************************/
+
+#include "livewp-rules.h"
+
+/*******************************************************************************/
+
+void get_localtime(int * year, int * month, int * day, int * hour, int * min, int * zone)
+{
+    time_t timet;
+    struct tm nt;
+    time(&timet);
+    localtime_r(&timet, &nt);
+    *year = nt.tm_year + 1900;
+    *month = nt.tm_mon + 1;
+    *day = nt.tm_mday;
+    *hour = nt.tm_hour;
+    *min = nt.tm_min;
+    *zone = nt.tm_gmtoff/3600;
+  /* 
+ *year = 2010;
+    *month = 3;
+    *day = 24;
+    *hour = 16;
+    *min = 20;
+    *zone = 2;*/
+}
+
+void get_coord(double * lat, double * lon)
+{
+    *lat = 55.166666;
+    *lon = 30.166666;
+}
+
+void get_sun_pos(double * alt, double * azm)
+{
+    int year, month, day, hour, min, zone;
+    double lat, lon;
+    get_localtime(&year, &month, &day, &hour, &min, &zone);
+    get_coord(&lat, &lon);
+    *alt = altitude(lon, lat, year, month, day, hour, min, zone);
+    *alt = *alt / 70; // sun height in percent
+
+    *azm = azimuth(lon, lat, year, month, day, hour, min, zone);
+    //if south latitude
+    if (lat < 0){
+        *azm = 90 + (90 - *azm);
+        *azm = fmod(*azm, 360);
+    }
+    *azm = (*azm - 90) / 180; // sun azimuth in percent
+}
+int get_daytime()
+{
+    double alt, azm;
+    get_sun_pos(&alt, &azm);
+    alt = alt * 100;
+    azm = azm * 100;
+    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) return TIME_DAY;
+    
+}
+int get_moon_phase()
+{ 
+    int year, month, day, hour, min, zone;
+    double phase;
+    get_localtime(&year, &month, &day, &hour, &min, &zone);
+    phase = moon_phase(year, month, day) * 100;
+    printf("ph = %f\n", phase);
+    if (phase <= 3 || phase >=97) return MOON_NONE;
+    if (phase > 5 && phase <= 25) return MOON_GROWS;
+    if (phase > 25 && phase <= 45) return MOON_GROWSHALF;
+    if (phase > 45 && phase <= 55) return MOON_FULL;
+    if (phase > 55 && phase <= 75) return MOON_DECREASHALF;
+    if (phase > 75 && phase < 97) return MOON_DECREAS;
+}
diff --git a/applet/livewp-rules.h b/applet/livewp-rules.h
new file mode 100644 (file)
index 0000000..3cba194
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * This file is part of Live Wallpaper (livewp)
+ * 
+ * Copyright (C) 2010 Vlad Vasiliev
+ * Copyright (C) 2010 Tanya Makova
+ *       for the code
+ * 
+ * This software is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+*/
+/*******************************************************************************/
+#ifndef _livewp_rules_h
+#define _livewp_rules_h 1
+/*******************************************************************************/
+#include <time.h>
+#include "livewp-astro.h"
+/*******************************************************************************/
+#define TIME_DAY        0
+#define TIME_NIGHT      1
+#define TIME_SUNRISE    2
+#define TIME_SUNSET     3
+
+#define MOON_NONE               0
+#define MOON_GROWS              1
+#define MOON_GROWSHALF          2
+#define MOON_FULL               3 
+#define MOON_DECREASHALF        4
+#define MOON_DECREAS            5
+
+/*******************************************************************************/
+void get_localtime(int * year, int * month, int * day, int * hour, int * min, int * zone);
+void get_coord(double * lat, double * lon);
+void get_sun_pos(double * alt, double * azm);
+int get_daytime();
+int get_moon_phase();
+/*******************************************************************************/
+#endif