From 0695dae1f7ca9c171d77d03520bc1b415c46ce6d Mon Sep 17 00:00:00 2001 From: tanya Date: Wed, 14 Apr 2010 17:16:28 +0300 Subject: [PATCH] destronig --- applet/src/livewp-common.h | 2 +- applet/src/livewp-home-widget.c | 175 ++++++++++++++++++++++++++++----------- applet/src/livewp-rules.c | 51 ++++++++++-- applet/src/livewp-rules.h | 4 +- 4 files changed, 174 insertions(+), 58 deletions(-) diff --git a/applet/src/livewp-common.h b/applet/src/livewp-common.h index 4757fdd..837d9d1 100644 --- a/applet/src/livewp-common.h +++ b/applet/src/livewp-common.h @@ -33,7 +33,7 @@ #define THEME_PATH "/usr/share/livewp/theme" #define SHORT_TIMER 50 /* 100 milisecond */ //#define LONG_TIMER 5*60*1000 /* 10 minutes */ -#define LONG_TIMER 10*1000 /* 10 minutes */ +#define LONG_TIMER 5*1000 /* 10 minutes */ enum { SHORT_TIMER_TYPE, LONG_TIMER_TYPE }; #define SKY_LEVEL 0 #define SUN_LEVEL 0 diff --git a/applet/src/livewp-home-widget.c b/applet/src/livewp-home-widget.c index f309794..8ad44f5 100644 --- a/applet/src/livewp-home-widget.c +++ b/applet/src/livewp-home-widget.c @@ -45,6 +45,9 @@ HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_H gint xapplet = 0, yapplet = 0; Scene scene; +gint hour=8; +gint min=0; +gint ttt = 0; static void lw_applet_realize (GtkWidget *widget) @@ -249,7 +252,7 @@ probability_sun() gint probability_plane() { - return (fast_rnd(10) + 1) * 60; + return (fast_rnd(60)); // return 0; } @@ -300,13 +303,13 @@ change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin) actor->visible = TRUE; create_hildon_actor(actor, desktop_plugin); } - get_sun_pos(&alt, &azm); + get_sun_pos(hour, min, &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(); + actor->time_start_animation = time(NULL); }else if (actor->visible){ actor->visible = FALSE; destroy_hildon_actor(actor); @@ -326,6 +329,7 @@ change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin) suseconds_t ms; long sec; double t; + gchar *newfile; //fprintf(stderr, "change tram\n"); gettimeofday(&tvb, NULL); @@ -335,7 +339,7 @@ change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin) if (!actor->visible){ actor->visible = TRUE; - if (scene.daytime == TIME_NIGHT){ + if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){ if (actor->filename) g_free(actor->filename); actor->filename = g_strdup("tram_dark.png"); @@ -346,6 +350,20 @@ change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin) } create_hildon_actor(actor, desktop_plugin); } + if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){ + newfile = g_strdup("tram_dark.png"); + }else{ + newfile = g_strdup("tram.png"); + } + if (strcmp(actor->filename, newfile)){ + if (actor->filename) + g_free(actor->filename); + actor->filename = newfile; + + + change_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); @@ -357,7 +375,7 @@ change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin) /* stop animation */ actor->visible = FALSE; destroy_hildon_actor(actor); - actor->time_start_animation = sec + fast_rnd(300); + actor->time_start_animation = sec + 20; } } @@ -371,6 +389,7 @@ change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin) suseconds_t ms; long sec; double t; + gchar *newfile; gettimeofday(&tvb, NULL); @@ -388,10 +407,24 @@ change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin) actor->visible = TRUE; create_hildon_actor(actor, desktop_plugin); } +if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){ + newfile = g_strdup("dot1.png"); + }else{ + newfile = g_strdup("tu154.png"); + } + if (strcmp(actor->filename, newfile)){ + if (actor->filename) + g_free(actor->filename); + actor->filename = newfile; + + + change_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); + //scale 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); @@ -402,7 +435,7 @@ change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin) if (scene.daytime == TIME_NIGHT) actor->time_start_animation = 0; else - actor->time_start_animation = sec + probability_plane(); + actor->time_start_animation = sec + 10; } } @@ -417,6 +450,7 @@ change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin) suseconds_t ms; long sec; double t; + gchar * newfile; gettimeofday(&tvb, NULL); @@ -433,6 +467,19 @@ change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin) actor->visible = TRUE; create_hildon_actor(actor, desktop_plugin); } +if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){ + newfile = g_strdup("dot1.png"); + }else{ + newfile = g_strdup("plane3.png"); + } + if (strcmp(actor->filename, newfile)){ + if (actor->filename) + g_free(actor->filename); + actor->filename = newfile; + + + change_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); @@ -448,7 +495,7 @@ change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin) if (scene.daytime == TIME_NIGHT) actor->time_start_animation = 0; else - actor->time_start_animation = sec + probability_plane(); + actor->time_start_animation = sec + 15; } } @@ -474,7 +521,7 @@ change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin) if (!actor->visible){ actor->visible = TRUE; - if (scene.daytime == TIME_NIGHT){ + if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){ newfile = g_strdup_printf("%s_dark.png", actor->name); }else{ newfile = g_strdup_printf("%s.png", actor->name); @@ -486,6 +533,20 @@ change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin) create_hildon_actor(actor, desktop_plugin); } + if (scene.daytime == TIME_NIGHT || (hour > 20 || hour < 6)){ + newfile = g_strdup_printf("%s_dark.png", actor->name); + }else{ + newfile = g_strdup_printf("%s.png", actor->name); + } + if (strcmp(actor->filename, newfile)){ + if (actor->filename) + g_free(actor->filename); + actor->filename = newfile; + + + change_hildon_actor(actor, desktop_plugin); + } + t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation; if (scene.wind_orientation == 1){ @@ -508,7 +569,7 @@ change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin) /* stop animation */ actor->visible = FALSE; destroy_hildon_actor(actor); - actor->time_start_animation = sec + fast_rnd(300); + actor->time_start_animation = sec + 10; actor->y = fast_rnd(300); } @@ -544,11 +605,11 @@ change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin) if (!actor->visible){ actor->visible = TRUE; create_hildon_actor(actor, desktop_plugin); - actor->time_start_animation = now + fast_rnd(60) + 10; + actor->time_start_animation = now + 10; }else { actor->visible = FALSE; destroy_hildon_actor(actor); - actor->time_start_animation = now + fast_rnd(60) + 10; + actor->time_start_animation = now + 10; } } @@ -566,7 +627,7 @@ change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin) g_free(actor->filename); actor->filename = newfile; change_hildon_actor(actor, desktop_plugin); - actor->time_start_animation = now + fast_rnd(30) + 10; + actor->time_start_animation = now + 5; } void @@ -744,7 +805,7 @@ init_scene(AWallpaperPlugin *desktop_plugin) gint winds[13][2]; /* fprintf(stderr, "init scene \n");*/ - scene.daytime = get_daytime(); + scene.daytime = get_daytime(hour, min); scene.actors = NULL; scene.wind_orientation = -1; scene.wind_angle = 0.3; @@ -769,22 +830,22 @@ init_scene(AWallpaperPlugin *desktop_plugin) // TRUE, 100, 255, NULL, NULL); //scene.actors = g_slist_append(scene.actors, actor); - actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, + actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, 0, 7, 150, 97, FALSE, 100, 255, (gpointer)&change_cloud, NULL); - actor->time_start_animation = now + fast_rnd(180); - actor->duration_animation = 3*60; + actor->time_start_animation = now; + actor->duration_animation = 1*60; scene.actors = g_slist_append(scene.actors, actor); - actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, + actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, 80, 7, 188, 75, FALSE, 100, 255, (gpointer)&change_cloud, NULL); - actor->time_start_animation = now + fast_rnd(180); - actor->duration_animation = 3*60; + actor->time_start_animation = now + 20; + actor->duration_animation = 1*60; scene.actors = g_slist_append(scene.actors, actor); - actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, + actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, 30, 7, 150, 75, FALSE, 100, 255, (gpointer)&change_cloud, NULL); - actor->time_start_animation = now + fast_rnd(180); - actor->duration_animation = 5*60; + actor->time_start_animation = now + 40; + actor->duration_animation = 1*60; scene.actors = g_slist_append(scene.actors, actor); @@ -795,8 +856,8 @@ init_scene(AWallpaperPlugin *desktop_plugin) actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210, FALSE, 100, 255, (gpointer)&change_tram, NULL); - actor->time_start_animation = time(NULL) + fast_rnd(10); - actor->duration_animation = 60; + actor->time_start_animation = now; + actor->duration_animation = 40; scene.actors = g_slist_append(scene.actors, actor); actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79, @@ -808,12 +869,12 @@ init_scene(AWallpaperPlugin *desktop_plugin) FALSE, 100, 255, (gpointer)&change_moon, NULL); change_moon(actor, desktop_plugin); scene.actors = g_slist_append(scene.actors, actor); - +/* actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, FALSE, 100, 255, (gpointer)&change_wind, NULL); change_wind(actor, desktop_plugin); scene.actors = g_slist_append(scene.actors, actor); - +*/ /* windows in 4-th house */ winds[0][0] = 482; @@ -1027,9 +1088,9 @@ init_scene1(AWallpaperPlugin *desktop_plugin) gint i; gint winds[13][2]; - scene.daytime = get_daytime(); + scene.daytime = get_daytime(hour, min); scene.actors = NULL; - scene.wind_orientation = -1; + scene.wind_orientation = 1; scene.wind_angle = 0.3; /* init value for random */ scene.seed = time(NULL); @@ -1059,50 +1120,50 @@ init_scene1(AWallpaperPlugin *desktop_plugin) change_moon(actor, desktop_plugin); scene.actors = g_slist_append(scene.actors, actor); - actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, + actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, 300, 7, 150, 97, FALSE, 100, 255, (gpointer)&change_cloud, NULL); - actor->time_start_animation = now + fast_rnd(180); - actor->duration_animation = 3*60; + actor->time_start_animation = now + 20; + actor->duration_animation = 1*60; scene.actors = g_slist_append(scene.actors, actor); - actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, + actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, 100, 7, 188, 75, FALSE, 100, 255, (gpointer)&change_cloud, NULL); - actor->time_start_animation = now + fast_rnd(180); - actor->duration_animation = 3*60; + actor->time_start_animation = now; + actor->duration_animation = 1*60; scene.actors = g_slist_append(scene.actors, actor); - actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, + actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, 200, 7, 150, 75, FALSE, 100, 255, (gpointer)&change_cloud, NULL); - actor->time_start_animation = now + fast_rnd(180); - actor->duration_animation = 5*60; + actor->time_start_animation = now + 40; + actor->duration_animation = 1*60; scene.actors = g_slist_append(scene.actors, actor); - actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50, + actor = init_object(desktop_plugin, "plane3", "plane3.png", 0, 45, 8, 160, 50, FALSE, 100, 255, (gpointer)&change_plane2, NULL); - actor->time_start_animation = now + probability_plane(); - actor->duration_animation = 60; + actor->time_start_animation = now + 20; + actor->duration_animation = 40; scene.actors = g_slist_append(scene.actors, actor); - actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116, + actor = init_object(desktop_plugin, "tu154", "tu154.png", 620, 233, 9, 300, 116, FALSE, 100, 255, (gpointer)&change_plane1, NULL); - actor->time_start_animation = now + probability_plane(); - actor->duration_animation = 30; + actor->time_start_animation = now; + actor->duration_animation = 20; scene.actors = g_slist_append(scene.actors, actor); actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL); change_static_actor_with_corner(actor, desktop_plugin); scene.actors = g_slist_append(scene.actors, actor); - +/* actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, FALSE, 100, 255, (gpointer)&change_wind, NULL); change_wind(actor, desktop_plugin); scene.actors = g_slist_append(scene.actors, actor); - +*/ actor = init_object(desktop_plugin, "signal", "red.png", 486, 425, 10, 18, 38, TRUE, 100, 255, (gpointer)&change_signal, NULL); - actor->time_start_animation = now + fast_rnd(30) + 10; + actor->time_start_animation = now; scene.actors = g_slist_append(scene.actors, actor);winds[0][0] = 717; winds[0][0] = 389; @@ -1243,13 +1304,22 @@ change_actor(GtkWidget * actor) static gboolean short_timeout (AWallpaperPlugin *desktop_plugin) { - gint daytime = get_daytime(); + //gint daytime = get_daytime(); GSList * tmp; void (*pfunc)(gpointer, gpointer); time_t now; Actor *actor; gboolean stop_flag = TRUE; - + + if (ttt == 1){ + min ++; + if (min == 60){ + hour ++; + min = 0; + if (hour == 23) hour = 0; + } + ttt = 0; + }else ttt ++; if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){ desktop_plugin->priv->short_timer = 0; return FALSE; @@ -1282,12 +1352,17 @@ short_timeout (AWallpaperPlugin *desktop_plugin) void run_long_timeout(AWallpaperPlugin *desktop_plugin){ - gint daytime = get_daytime(); + gint daytime = get_daytime(hour, min); GSList * tmp; void (*pfunc)(gpointer, gpointer); time_t now; Actor *actor; + //hour = hour + 1; + //min = 0; + //if (hour == 24) hour = 0; + fprintf(stderr, "---- %d:%d\n", hour, min); + //fprintf(stderr, "timer daytime=%d\n", daytime); if (scene.daytime != daytime){ diff --git a/applet/src/livewp-rules.c b/applet/src/livewp-rules.c index 545147a..cd264f0 100644 --- a/applet/src/livewp-rules.c +++ b/applet/src/livewp-rules.c @@ -84,8 +84,36 @@ get_max_sun_alt(double lon, double lat, int year, int month, int day, int zone) //printf("alt = %f \n", alt); return alt; } +void get_sun_pos(int h, int m, double * alt, double * azm) +{ + int year, month, day, hour, min, zone; + double lat, lon, alt_max; + //get_localtime(&year, &month, &day, &hour, &min, &zone); + year = 2010; + month = 4; + day = 14; + hour = h; + min = m; + zone = 3; + get_coord(&lat, &lon); + alt_max = get_max_sun_alt(lon, lat, year, month, day, zone); + *alt = altitude(lon, lat, year, month, day, hour, min, zone); + //printf("max = %f alt = %f ",alt_max, *alt); + *alt = *alt / (alt_max + 10); // sun height in percent + //printf("alt1 = %f \n", *alt); + + *azm = azimuth(lon, lat, year, month, day, hour, min, zone); + //printf("azm = %f ", *azm); + //if south latitude + if (lat < 0){ + *azm = 75 + (75 - *azm); + *azm = fmod(*azm, 380); + } + *azm = (*azm - 75) / 210; // sun azimuth in percent + //printf("azm1 = %f \n", *azm); +} -void get_sun_pos(double * alt, double * azm) +void get_sun_pos1(double * alt, double * azm) { int year, month, day, hour, min, zone; double lat, lon, alt_max; @@ -116,10 +144,23 @@ time_t get_next_sunset() return time(NULL) + 60*60*12; } -int get_daytime() +int get_daytime(int h, int m) { double alt, azm; - get_sun_pos(&alt, &azm); + get_sun_pos(h, m, &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 < 7 && azm > 50) return TIME_SUNSET; + if (alt >= 7) return TIME_DAY; + return TIME_DAY; +} +int get_daytime1() +{ + double alt, azm; + get_sun_pos1(&alt, &azm); alt = alt * 100; azm = azm * 100; //printf("alt = %f azm=%f\n", alt, azm); @@ -129,7 +170,6 @@ int get_daytime() if (alt >= 7) return TIME_DAY; return TIME_DAY; } - int get_moon_phase() { int year, month, day, hour, min, zone; @@ -143,6 +183,7 @@ int get_moon_phase() if (phase > 45 && phase <= 55) return MOON_FULL; if (phase > 55 && phase <= 75) return MOON_DECREASHALF; if (phase > 75 && phase < 97) return MOON_DECREAS; - return MOON_NONE; + //return MOON_NONE; + return MOON_GROWSHALF; } diff --git a/applet/src/livewp-rules.h b/applet/src/livewp-rules.h index 38b8d46..66678d6 100644 --- a/applet/src/livewp-rules.h +++ b/applet/src/livewp-rules.h @@ -42,8 +42,8 @@ /*******************************************************************************/ 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(); +void get_sun_pos(int h, int m, double * alt, double * azm); +int get_daytime(int h, int m); int get_moon_phase(); time_t get_next_sunrise(); time_t get_next_sunset(); -- 1.7.9.5