1 /*vim: set sw=4 ts=4 et: */
3 * This file is part of Live Wallpaper (livewp)
5 * Copyright (C) 2010 Vlad Vasiliev
6 * Copyright (C) 2010 Tanya Makova
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
14 * This software is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 /*******************************************************************************/
25 #include "livewp-common.h"
26 #include "livewp-home-widget.h"
27 #include <gconf/gconf-client.h>
28 #include "livewp-rules.h"
32 #define PLUGIN_NAME "livewp-home-widget.desktop-0"
33 #define GCONF_KEY_POSITION "/apps/osso/hildon-desktop/applets/%s/position"
34 #define GCONF_KEY_MODIFIED "/apps/osso/hildon-desktop/applets/%s/modified"
35 #define GCONF_KEY_VIEW "/apps/osso/hildon-desktop/applets/%s/view"
37 HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_HOME_PLUGIN_ITEM)
38 #define Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE (obj,\
39 Animation_Wallpaper_TYPE_HOME_PLUGIN,\
40 Animation_WallpaperPrivate))
42 /* Position of plugin on desktop */
43 #define Xstartposition 700
44 #define Ystartposition 448
46 gint xapplet = 0, yapplet = 0;
50 lw_applet_realize (GtkWidget *widget)
54 screen = gtk_widget_get_screen (widget);
55 gtk_widget_set_colormap (widget,
56 gdk_screen_get_rgba_colormap (screen));
57 gtk_widget_set_app_paintable (widget,
59 GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->realize (widget);
64 lw_applet_expose_event(GtkWidget *widget,
65 GdkEventExpose *event)
69 /* Create cairo context */
70 cr = gdk_cairo_create (GDK_DRAWABLE (widget->window));
71 gdk_cairo_region (cr, event->region);
74 /* Draw alpha background */
75 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
76 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
82 return GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->expose_event (widget,
87 expose_event (GtkWidget *widget,GdkEventExpose *event,
91 GdkPixbuf *pixbuf = (GdkPixbuf *) data;
93 cr = gdk_cairo_create(widget->window);
95 gdk_cairo_region(cr, event->region);
96 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
97 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
105 realize (GtkWidget *widget)
108 screen = gtk_widget_get_screen (widget);
109 gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
112 /* Set position of widget on desktop */
114 init_applet_position(void)
116 GSList *position = NULL;
120 GError *error = NULL;
121 GConfClient *gconf_client = gconf_client_get_default ();
122 position_key = g_strdup_printf (GCONF_KEY_POSITION, PLUGIN_NAME);
123 position = gconf_client_get_list (gconf_client,
127 if (position && position->data && position->next->data){
128 xapplet = GPOINTER_TO_INT (position->data);
129 yapplet = GPOINTER_TO_INT (position->next->data);
131 position = g_slist_prepend (g_slist_prepend (NULL,
132 GINT_TO_POINTER (Ystartposition)),
133 GINT_TO_POINTER (Xstartposition));
134 gconf_client_set_list (gconf_client,
139 xapplet = Xstartposition;
140 yapplet = Ystartposition;
142 g_free (position_key);
143 modified = g_strdup_printf ("%i", 0);
144 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
145 gconf_client_set_string (gconf_client,
150 g_free(modified_key);
151 gconf_client_clear_cache(gconf_client);
152 g_object_unref(gconf_client);
156 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
158 /* fprintf(stderr, "actor_set_position_full z=%d\n", z); */
159 hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
163 path_line(gint x0, gint x1, double t)
166 return ((x1 - x0) * t + x0);
171 destroy_hildon_actor(Actor *actor)
173 //fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
174 gtk_widget_destroy(actor->widget);
175 actor->widget = NULL;
179 init_object(AWallpaperPlugin *desktop_plugin,
190 void (*pfunc_change)(Actor*),
191 void (*pfunc_probability)(Actor*)
195 actor = g_new0(Actor, 1);
199 actor->width = width;
200 actor->height = height;
201 actor->visible = visible;
202 actor->scale = scale;
203 actor->opacity = opacity;
204 actor->filename = g_strdup(filename);
205 actor->name = g_strdup(name);
206 actor->func_change = (gpointer)pfunc_change;
207 actor->func_probability = (gpointer)pfunc_probability;
209 create_hildon_actor(actor, desktop_plugin);
211 actor->widget = NULL;
212 actor->time_start_animation = 0;
213 actor->duration_animation = 0;
221 //objects_list = g_slist_append(objects_list, G_OBJECT(actor));
222 //objects_list = g_slist_append(objects_list, G_OBJECT(a));
232 gint fast_rnd(gint max)
234 guint offset = 12923;
235 guint multiplier = 4079;
237 scene.seed = scene.seed * multiplier + offset;
238 return (gint)(scene.seed % max);
244 /* update sun position after ... second */
252 return (fast_rnd(10) + 1) * 60;
257 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
263 if (scene.daytime == TIME_NIGHT){
264 if (!actor->visible){
265 actor->visible = TRUE;
266 phase = get_moon_phase();
267 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
269 g_free(actor->filename);
270 actor->filename = newfile;
271 create_hildon_actor(actor, desktop_plugin);
276 // actor_set_position_full(actor->widget, x, y, actor->z);
277 //probability_sun(actor);
278 //fprintf(stderr, "after change sun %d\n", actor->time_start_animation);
279 }else if (actor->visible){
280 actor->visible = FALSE;
281 fprintf(stderr, "destroy moon \n");
282 destroy_hildon_actor(actor);
283 /* TO DO make moonrise*/
284 actor->time_start_animation = 0;
291 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
296 //fprintf(stderr, "change sun\n");
298 if (scene.daytime != TIME_NIGHT){
299 if (!actor->visible){
300 actor->visible = TRUE;
301 create_hildon_actor(actor, desktop_plugin);
303 get_sun_pos(&alt, &azm);
304 get_sun_screen_pos(alt, azm, &x, &y);
307 actor_set_position_full(actor->widget, x, y, actor->z);
308 //probability_sun(actor);
309 actor->time_start_animation = time(NULL) + probability_sun();
310 }else if (actor->visible){
311 actor->visible = FALSE;
312 destroy_hildon_actor(actor);
313 actor->time_start_animation = 0;
320 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
322 gint x0 = -300, y0 = 225, scale0 = 100,
323 x1 = 800, y1 = 162, scale1 = 130,
330 //fprintf(stderr, "change tram\n");
331 gettimeofday(&tvb, NULL);
336 if (!actor->visible){
337 actor->visible = TRUE;
338 if (scene.daytime == TIME_NIGHT){
340 g_free(actor->filename);
341 actor->filename = g_strdup("tram_dark.png");
344 g_free(actor->filename);
345 actor->filename = g_strdup("tram.png");
347 create_hildon_actor(actor, desktop_plugin);
349 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
350 x = path_line(x0, x1, t);
351 y = path_line(y0, y1, t);
352 scale = path_line(scale0, scale1, t);
353 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
354 actor_set_position_full(actor->widget, x, y, actor->z);
355 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
358 actor->visible = FALSE;
359 destroy_hildon_actor(actor);
360 actor->time_start_animation = sec + fast_rnd(300);
365 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
367 gint x0 = 620, y0 = 233, scale0 = 100,
368 x1 = 79, y1 = -146, scale1 = 100,
375 gettimeofday(&tvb, NULL);
379 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
381 if (scene.daytime != TIME_NIGHT){
382 if (actor->time_start_animation == 0){
383 actor->time_start_animation = sec + probability_plane();
387 if (!actor->visible){
388 actor->visible = TRUE;
389 create_hildon_actor(actor, desktop_plugin);
391 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
392 x = path_line(x0, x1, t);
393 y = path_line(y0, y1, t);
394 //scale = path_line(scale0, scale1, t);
395 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
396 actor_set_position_full(actor->widget, x, y, actor->z);
397 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
400 actor->visible = FALSE;
401 destroy_hildon_actor(actor);
402 if (scene.daytime == TIME_NIGHT)
403 actor->time_start_animation = 0;
405 actor->time_start_animation = sec + probability_plane();
411 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
413 gint x0 = -actor->width, y0 = 45, scale0 = 100,
414 x1 = 800, y1 = 20, scale1 = 100,
421 gettimeofday(&tvb, NULL);
425 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
426 if (scene.daytime != TIME_NIGHT){
427 if (actor->time_start_animation == 0){
428 actor->time_start_animation = sec + probability_plane();
432 if (!actor->visible){
433 actor->visible = TRUE;
434 create_hildon_actor(actor, desktop_plugin);
437 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
438 x = path_line(x0, x1, t);
439 y = path_line(y0, y1, t);
440 //scale = path_line(scale0, scale1, t);
441 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
442 actor_set_position_full(actor->widget, x, y, actor->z);
443 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
446 actor->visible = FALSE;
447 destroy_hildon_actor(actor);
448 if (scene.daytime == TIME_NIGHT)
449 actor->time_start_animation = 0;
451 actor->time_start_animation = sec + probability_plane();
457 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
459 gint x0, y0 = 300, scale0 = 100,
460 x1, y1 = -actor->height, scale1 = 150,
468 //fprintf(stderr, "change cloud\n");
469 gettimeofday(&tvb, NULL);
473 //fprintf(stderr, "c1oud %s - y0=%d\n", actor->name, actor->y);
475 if (!actor->visible){
476 actor->visible = TRUE;
477 if (scene.daytime == TIME_NIGHT){
478 newfile = g_strdup_printf("%s_dark.png", actor->name);
480 newfile = g_strdup_printf("%s.png", actor->name);
483 g_free(actor->filename);
484 actor->filename = newfile;
487 create_hildon_actor(actor, desktop_plugin);
489 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
491 if (scene.wind_orientation == 1){
500 x = path_line(x0, x1, t);
501 y = -scene.wind_angle * (x - x0) + actor->y;
502 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
504 //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
505 actor_set_position_full(actor->widget, x, y, actor->z);
506 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
507 if ((y < y1 || y > y0) || t >= 1){
509 actor->visible = FALSE;
510 destroy_hildon_actor(actor);
511 actor->time_start_animation = sec + fast_rnd(300);
512 actor->y = fast_rnd(300);
518 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
520 scene.wind_orientation = fast_rnd(2);
521 if (scene.wind_orientation == 0) scene.wind_orientation = -1;
522 scene.wind_angle = (double)(fast_rnd(200) - 100) / 100;
523 actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
524 //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
528 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
531 gint now = time(NULL);
532 if (scene.daytime == TIME_DAY){
534 actor->visible = FALSE;
535 destroy_hildon_actor(actor);
537 actor->time_start_animation = 0;
539 }else if (actor->time_start_animation == 0){
540 actor->time_start_animation = now + fast_rnd(30);
544 if (!actor->visible){
545 actor->visible = TRUE;
546 create_hildon_actor(actor, desktop_plugin);
547 actor->time_start_animation = now + fast_rnd(60) + 10;
549 actor->visible = FALSE;
550 destroy_hildon_actor(actor);
551 actor->time_start_animation = now + fast_rnd(60) + 10;
557 change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
560 gint now = time(NULL);
561 newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime);
562 if (!strcmp(actor->filename, "red.png"))
563 newfile = g_strdup_printf("%s", "green.png");
565 newfile = g_strdup_printf("%s", "red.png");
566 g_free(actor->filename);
567 actor->filename = newfile;
568 change_hildon_actor(actor, desktop_plugin);
569 actor->time_start_animation = now + fast_rnd(30) + 10;
573 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
575 GtkWidget *ha = NULL;
576 GdkPixbuf *pixbuf = NULL;
577 GtkWidget *image = NULL;
580 /* fprintf(stderr, "create_hildon_actor %s\n", actor->name);*/
581 ha = hildon_animation_actor_new();
582 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
583 desktop_plugin->priv->theme, actor->filename);
584 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
591 image = gtk_image_new_from_pixbuf (pixbuf);
592 g_object_unref(G_OBJECT(pixbuf));
595 g_signal_connect(G_OBJECT(image), "expose_event",
596 G_CALLBACK(expose_event), pixbuf);
597 gtk_container_add (GTK_CONTAINER (ha), image);
599 actor_set_position_full(ha, actor->x, actor->y, actor->z);
600 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
601 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
603 gtk_widget_show_all(ha);
608 //g_object_set_data(G_OBJECT(ha), "name", name);
609 //g_object_set_data(G_OBJECT(ha), "filename", filename);
610 g_object_set_data(G_OBJECT(ha), "image", image);
612 g_object_set_data(G_OBJECT(ha), "x", x);
613 g_object_set_data(G_OBJECT(ha), "y", y);
614 g_object_set_data(G_OBJECT(ha), "z", z);
615 g_object_set_data(G_OBJECT(ha), "width", width);
616 g_object_set_data(G_OBJECT(ha), "height", height);
617 g_object_set_data(G_OBJECT(ha), "scale", scale);
618 g_object_set_data(G_OBJECT(ha), "visible", visible);
619 g_object_set_data(G_OBJECT(ha), "opacity", opacity);
620 g_object_set_data(G_OBJECT(ha), "func", pfunc);
622 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
628 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
630 GtkWidget *image = NULL;
631 GdkPixbuf *pixbuf = NULL;
634 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
635 desktop_plugin->priv->theme, actor->filename);
637 fprintf(stderr, "55555 actor=%s filename=%s\n", actor->name, str);
638 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
645 image = gtk_image_new_from_pixbuf (pixbuf);
646 g_object_unref(G_OBJECT(pixbuf));
649 g_signal_connect(G_OBJECT(image), "expose_event",
650 G_CALLBACK(expose_event), pixbuf);
651 if (g_object_get_data(G_OBJECT(actor->widget), "image")){
652 gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));
654 g_object_set_data(G_OBJECT(actor->widget), "image", image);
655 gtk_container_add (GTK_CONTAINER (actor->widget), image);
656 realize(actor->widget);
657 gtk_widget_show_all(actor->widget);
668 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
671 newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime);
673 g_free(actor->filename);
674 actor->filename = newfile;
675 change_hildon_actor(actor, desktop_plugin);
679 change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
684 if (desktop_plugin->priv->right_corner)
685 gtk_widget_destroy(desktop_plugin->priv->right_corner);
686 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
687 THEME_PATH, desktop_plugin->priv->theme, scene.daytime);
688 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
689 if (desktop_plugin->priv->right_corner){
690 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
691 gtk_widget_show (desktop_plugin->priv->right_corner);
693 change_static_actor(actor, desktop_plugin);
698 change_layer1(Actor * actor, AWallpaperPlugin *desktop_plugin)
702 if (y > 480) y = -480;
703 //fprintf(stderr, "!! %s - %d\n", actor->name, y);
704 actor_set_position_full(actor->widget, actor->x, y, actor->z);
709 change_layer2(Actor * actor, AWallpaperPlugin *desktop_plugin)
713 if (y >= 480) y = -480;
714 //fprintf(stderr, "!! %s - %d\n", actor->name, y);
715 actor_set_position_full(actor->widget, actor->x, y, actor->z);
722 // уравнение изменения времени
728 GSList * tmp = scene.actors;
734 g_free(actor->filename);
737 gtk_widget_destroy(actor->widget);
738 //actor->widget = NULL;
741 tmp = g_slist_next(tmp);
748 reload_scene(AWallpaperPlugin *desktop_plugin)
750 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
752 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
753 init_scene(desktop_plugin);
754 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
755 init_scene1(desktop_plugin);
756 else if (!strcmp(desktop_plugin->priv->theme,"Matrix"))
757 init_scene2(desktop_plugin);
762 init_scene2(AWallpaperPlugin *desktop_plugin)
765 gint now = time(NULL);
767 fprintf(stderr, "init scene2 \n");
768 //scene.daytime = get_daytime();
772 actor = init_object(desktop_plugin, "background", "bg.png",
774 TRUE, 100, 255, NULL, NULL);
775 scene.actors = g_slist_append(scene.actors, actor);
777 actor = init_object(desktop_plugin, "symbols", "symbols.png",
779 TRUE, 100, 255, NULL, NULL);
780 scene.actors = g_slist_append(scene.actors, actor);
782 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
783 0, -480, 6, 800, 960,
784 TRUE, 100, 255, (gpointer)&change_layer1, NULL);
785 actor->time_start_animation = now;
786 actor->duration_animation = G_MAXINT;
787 scene.actors = g_slist_append(scene.actors, actor);
789 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
790 0, (-480 - 480), 7, 800, 960,
791 TRUE, 100, 255, (gpointer)&change_layer1, NULL);
792 actor->time_start_animation = now;
793 actor->duration_animation = G_MAXINT;
794 scene.actors = g_slist_append(scene.actors, actor);
796 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
797 0, -480, 8, 800, 960,
798 TRUE, 100, 255, (gpointer)&change_layer2, NULL);
799 actor->time_start_animation = now;
800 actor->duration_animation = G_MAXINT;
801 scene.actors = g_slist_append(scene.actors, actor);
803 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
804 0, (-480 - 480), 9, 800, 960,
805 TRUE, 100, 255, (gpointer)&change_layer2, NULL);
806 actor->time_start_animation = now;
807 actor->duration_animation = G_MAXINT;
808 scene.actors = g_slist_append(scene.actors, actor);
810 run_long_timeout(desktop_plugin);
812 /* Init Modern Scene */
814 init_scene(AWallpaperPlugin *desktop_plugin)
817 gint now = time(NULL);
821 /* fprintf(stderr, "init scene \n");*/
822 scene.daytime = get_daytime();
824 scene.wind_orientation = -1;
825 scene.wind_angle = 0.3;
826 /* init value for random */
827 scene.seed = time(NULL);
831 actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480,
832 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
833 change_static_actor(actor, desktop_plugin);
834 scene.actors = g_slist_append(scene.actors, actor);
836 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
837 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
838 actor->time_start_animation = now;
839 actor->duration_animation = G_MAXINT;
840 change_sun(actor, desktop_plugin);
841 scene.actors = g_slist_append(scene.actors, actor);
843 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
844 // TRUE, 100, 255, NULL, NULL);
845 //scene.actors = g_slist_append(scene.actors, actor);
847 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
848 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
849 actor->time_start_animation = now + fast_rnd(180);
850 actor->duration_animation = 3*60;
851 scene.actors = g_slist_append(scene.actors, actor);
853 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
854 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
855 actor->time_start_animation = now + fast_rnd(180);
856 actor->duration_animation = 3*60;
857 scene.actors = g_slist_append(scene.actors, actor);
859 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
860 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
861 actor->time_start_animation = now + fast_rnd(180);
862 actor->duration_animation = 5*60;
863 scene.actors = g_slist_append(scene.actors, actor);
866 actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 8, 800, 480,
867 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
868 change_static_actor(actor, desktop_plugin);
869 scene.actors = g_slist_append(scene.actors, actor);
871 actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210,
872 FALSE, 100, 255, (gpointer)&change_tram, NULL);
873 actor->time_start_animation = time(NULL) + fast_rnd(10);
874 actor->duration_animation = 60;
875 scene.actors = g_slist_append(scene.actors, actor);
877 actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79,
878 TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
879 change_static_actor_with_corner(actor, desktop_plugin);
880 scene.actors = g_slist_append(scene.actors, actor);
882 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, 6, 60, 60,
883 FALSE, 100, 255, (gpointer)&change_moon, NULL);
884 change_moon(actor, desktop_plugin);
885 scene.actors = g_slist_append(scene.actors, actor);
887 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
888 FALSE, 100, 255, (gpointer)&change_wind, NULL);
889 change_wind(actor, desktop_plugin);
890 scene.actors = g_slist_append(scene.actors, actor);
892 /* windows in 4-th house */
932 for (i=0; i<13; i++){
933 actor = init_object(desktop_plugin, "window1", "window1.png",
934 winds[i][0], winds[i][1], 8, 8, 10,
935 FALSE, 100, 255, (gpointer)&change_window1, NULL);
936 //change_window1(actor, desktop_plugin);
937 actor->time_start_animation = now + fast_rnd(30);
938 scene.actors = g_slist_append(scene.actors, actor);
942 /* windows in 1-th house */
968 actor = init_object(desktop_plugin, "window2", "window2.png",
969 winds[i][0], winds[i][1], 8, 8, 10,
970 FALSE, 100, 255, (gpointer)&change_window1, NULL);
971 //change_window1(actor, desktop_plugin);
972 actor->time_start_animation = now + fast_rnd(30);
973 scene.actors = g_slist_append(scene.actors, actor);
977 /* windows in 3-th house */
1009 for (i=0; i<10; i++){
1010 actor = init_object(desktop_plugin, "window3", "window3.png",
1011 winds[i][0], winds[i][1], 8, 8, 10,
1012 FALSE, 100, 255, (gpointer)&change_window1, NULL);
1013 //change_window1(actor, desktop_plugin);
1014 actor->time_start_animation = now + fast_rnd(30);
1015 scene.actors = g_slist_append(scene.actors, actor);
1019 /* windows in 5-th house */
1042 for (i=0; i<7; i++){
1043 actor = init_object(desktop_plugin, "window4", "window4.png",
1044 winds[i][0], winds[i][1], 8, 8, 10,
1045 FALSE, 100, 255, (gpointer)&change_window1, NULL);
1046 //change_window1(actor, desktop_plugin);
1047 actor->time_start_animation = now + fast_rnd(30);
1048 scene.actors = g_slist_append(scene.actors, actor);
1052 /* windows in 6-th house */
1072 for (i=0; i<6; i++){
1073 actor = init_object(desktop_plugin, "window5", "window5.png",
1074 winds[i][0], winds[i][1], 8, 8, 10,
1075 FALSE, 100, 255, (gpointer)&change_window1, NULL);
1076 //change_window1(actor, desktop_plugin);
1077 actor->time_start_animation = now + fast_rnd(30);
1078 scene.actors = g_slist_append(scene.actors, actor);
1082 run_long_timeout(desktop_plugin);
1084 anim = g_new0(Animation, 1);
1086 anim->actor = actor;
1087 anim->func_change = &change_tram;
1088 anim->func_time = NULL;
1089 anim->timestart = time(NULL);
1092 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
1096 /* Init Berlin Scene */
1098 init_scene1(AWallpaperPlugin *desktop_plugin)
1101 gint now = time(NULL);
1105 scene.daytime = get_daytime();
1106 scene.actors = NULL;
1107 scene.wind_orientation = -1;
1108 scene.wind_angle = 0.3;
1109 /* init value for random */
1110 scene.seed = time(NULL);
1113 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
1114 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
1115 change_static_actor(actor, desktop_plugin);
1116 scene.actors = g_slist_append(scene.actors, actor);
1119 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
1120 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
1121 actor->time_start_animation = time(NULL);
1122 actor->duration_animation = G_MAXINT;
1123 change_sun(actor, desktop_plugin);
1124 scene.actors = g_slist_append(scene.actors, actor);
1127 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
1128 TRUE, 100, 255, NULL, NULL);
1129 scene.actors = g_slist_append(scene.actors, actor);
1132 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
1133 FALSE, 100, 255, (gpointer)&change_moon, NULL);
1134 change_moon(actor, desktop_plugin);
1135 scene.actors = g_slist_append(scene.actors, actor);
1137 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
1138 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1139 actor->time_start_animation = now + fast_rnd(180);
1140 actor->duration_animation = 3*60;
1141 scene.actors = g_slist_append(scene.actors, actor);
1143 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
1144 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1145 actor->time_start_animation = now + fast_rnd(180);
1146 actor->duration_animation = 3*60;
1147 scene.actors = g_slist_append(scene.actors, actor);
1149 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
1150 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1151 actor->time_start_animation = now + fast_rnd(180);
1152 actor->duration_animation = 5*60;
1153 scene.actors = g_slist_append(scene.actors, actor);
1156 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
1157 FALSE, 100, 255, (gpointer)&change_plane2, NULL);
1158 actor->time_start_animation = now + probability_plane();
1159 actor->duration_animation = 60;
1160 scene.actors = g_slist_append(scene.actors, actor);
1162 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
1163 FALSE, 100, 255, (gpointer)&change_plane1, NULL);
1164 actor->time_start_animation = now + probability_plane();
1165 actor->duration_animation = 30;
1166 scene.actors = g_slist_append(scene.actors, actor);
1168 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
1169 TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
1170 change_static_actor_with_corner(actor, desktop_plugin);
1171 scene.actors = g_slist_append(scene.actors, actor);
1173 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
1174 FALSE, 100, 255, (gpointer)&change_wind, NULL);
1175 change_wind(actor, desktop_plugin);
1176 scene.actors = g_slist_append(scene.actors, actor);
1178 actor = init_object(desktop_plugin, "signal", "red.png", 486, 425, 10, 18, 38,
1179 TRUE, 100, 255, (gpointer)&change_signal, NULL);
1180 actor->time_start_animation = now + fast_rnd(30) + 10;
1181 scene.actors = g_slist_append(scene.actors, actor);winds[0][0] = 717;
1222 for (i=0; i<13; i++){
1223 actor = init_object(desktop_plugin, "window", "window.png",
1224 winds[i][0], winds[i][1], 10, 8, 9,
1225 FALSE, 100, 255, (gpointer)&change_window1, NULL);
1226 //change_window1(actor, desktop_plugin);
1227 actor->time_start_animation = now + fast_rnd(30);
1228 scene.actors = g_slist_append(scene.actors, actor);
1232 run_long_timeout(desktop_plugin);
1238 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
1240 gint y0 = 365;// - уровень горизонта
1241 *x = (int)(azm * 800) - 64;
1242 *y = (int)((1 - alt) * y0) - 64;
1243 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
1247 change_actor(GtkWidget * actor)
1250 gint x, y, daytime, scale;
1257 void (*pfunc)(gpointer, gpointer);
1259 name = g_object_get_data(G_OBJECT(actor), "name");
1260 fprintf(stderr, "change actor %s\n", name);
1262 pfunc = g_object_get_data(G_OBJECT(actor), "func");
1264 (*pfunc)(actor, g_strdup(name));
1265 daytime = get_daytime();
1266 if (daytime != TIME_NIGHT){
1267 hildon_animation_actor_set_show(actor, 1);
1268 get_sun_pos(&alt, &azm);
1269 get_sun_screen_pos(alt, azm, &x, &y);
1270 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1274 if (name == "cloud1"){
1275 x = g_object_get_data(G_OBJECT(actor), "x");
1276 y = g_object_get_data(G_OBJECT(actor), "y");
1277 scale = g_object_get_data(G_OBJECT(actor), "scale");
1280 image = g_object_get_data(G_OBJECT(actor), "image");
1282 gtk_container_remove(actor, image);
1283 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
1288 image = gtk_image_new_from_pixbuf (pixbuf);
1289 g_object_unref(G_OBJECT(pixbuf));
1291 g_signal_connect(G_OBJECT(image), "expose_event",
1292 G_CALLBACK(expose_event), pixbuf);
1293 gtk_container_add (GTK_CONTAINER (actor), image);
1295 gtk_widget_show_all(actor);
1307 sc = (double)scale / 100;
1308 hildon_animation_actor_set_scale(actor, sc, sc);
1309 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
1310 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1311 g_object_set_data(G_OBJECT(actor), "x", x);
1312 g_object_set_data(G_OBJECT(actor), "y", y);
1313 g_object_set_data(G_OBJECT(actor), "scale", scale);
1319 short_timeout (AWallpaperPlugin *desktop_plugin)
1321 gint daytime = get_daytime();
1323 void (*pfunc)(gpointer, gpointer);
1326 gboolean stop_flag = TRUE;
1328 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
1329 desktop_plugin->priv->short_timer = 0;
1334 //scene.daytime = daytime;
1335 /* fprintf(stderr, "Short timer %d\n", now); */
1337 while (tmp != NULL){
1339 if (now >= actor->time_start_animation
1340 && actor->time_start_animation > 0
1341 /* && now - actor->time_start_animation <= actor->duration_animation*/){
1342 pfunc = actor->func_change;
1344 (*pfunc)(actor, desktop_plugin);
1348 tmp = g_slist_next(tmp);
1351 desktop_plugin->priv->short_timer = 0;
1354 return TRUE; /* keep running this event */
1358 run_long_timeout(AWallpaperPlugin *desktop_plugin)
1361 gint daytime = get_daytime();
1363 void (*pfunc)(gpointer, gpointer);
1368 //fprintf(stderr, "!!!run long timeout short_timer=%d\n", desktop_plugin->priv->short_timer);
1369 if (scene.daytime != daytime){
1370 scene.daytime = daytime;
1372 while (tmp != NULL){
1373 //change_actor(tmp->data);
1374 pfunc =((Actor*)tmp->data)->func_change;
1376 (*pfunc)(tmp->data, desktop_plugin);
1378 tmp = g_slist_next(tmp);
1383 //fprintf(stderr, "Now %d\n", now);
1385 while (tmp != NULL){
1387 if (now >= actor->time_start_animation
1388 && actor->time_start_animation > 0
1389 && desktop_plugin->priv->short_timer == 0){
1390 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
1391 if (desktop_plugin->priv->rich_animation){
1392 actor->time_start_animation = now;
1393 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
1394 //fprintf(stderr, " start shor timer %d\n", desktop_plugin->priv->short_timer);
1397 (*actor->func_change)(actor, desktop_plugin);
1400 tmp = g_slist_next(tmp);
1406 long_timeout (AWallpaperPlugin *desktop_plugin)
1408 /* fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
1409 if (desktop_plugin->priv->long_timer == 0 )
1411 if (!desktop_plugin->priv->visible){
1412 if(desktop_plugin->priv->short_timer != 0){
1413 g_source_remove(desktop_plugin->priv->short_timer);
1414 desktop_plugin->priv->short_timer = 0;
1416 desktop_plugin->priv->long_timer = 0;
1421 run_long_timeout(desktop_plugin);
1422 return TRUE; /* keep running this event */
1426 desktop_plugin_visible_notify (GObject *object,
1428 AWallpaperPlugin *desktop_plugin)
1431 g_object_get (object, "is-on-current-desktop", &visible, NULL);
1432 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1434 desktop_plugin->priv->visible = TRUE;
1435 if (desktop_plugin->priv->long_timer == 0 ){
1436 desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1437 run_long_timeout(desktop_plugin);
1440 desktop_plugin->priv->visible = FALSE;
1441 if (desktop_plugin->priv->long_timer != 0 ){
1442 g_source_remove(desktop_plugin->priv->long_timer);
1443 desktop_plugin->priv->long_timer = 0;
1449 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1450 gpointer user_data){
1451 fprintf(stderr,"gggggggggggggggggggg2222\n");
1454 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1456 GtkWidget *rich_animation;
1460 fprintf(stderr, "!!!!!!!plugin init \n");
1461 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1462 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1466 priv->desktop_plugin = desktop_plugin;
1467 priv->visible = TRUE;
1468 priv->short_timer = 0;
1469 desktop_plugin->priv->main_widget = gtk_fixed_new();
1471 gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 100, 32);
1472 desktop_plugin->priv->right_corner = NULL;
1473 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
1474 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
1475 if (desktop_plugin->priv->right_corner){
1476 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
1477 gtk_widget_show (desktop_plugin->priv->right_corner);
1479 /* Create rich animation event */
1480 rich_animation = gtk_event_box_new();
1482 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1483 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1484 gtk_widget_set_size_request(rich_animation, 100, 32);
1485 gtk_widget_show (rich_animation);
1486 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1487 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), rich_animation, 0, 0);
1490 GtkWidget *label = gtk_label_new ("ddddddddddddd");
1491 gtk_widget_set_size_request(label, 95, 30);
1492 gtk_widget_show (label);
1493 // gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1494 gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
1496 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1497 g_signal_connect (desktop_plugin, "show-settings",
1498 G_CALLBACK (lw_settings), priv);
1499 gtk_widget_show (desktop_plugin->priv->main_widget);
1500 gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
1501 init_applet_position();
1504 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1505 if (!strcmp(priv->theme,"Modern"))
1506 init_scene(desktop_plugin);
1507 else if (!strcmp(priv->theme,"Berlin"))
1508 init_scene1(desktop_plugin);
1509 else if (!strcmp(priv->theme, "Matrix"))
1510 init_scene2(desktop_plugin);
1511 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1512 /* TODO Move scene to priv */
1513 scene.timer_type = LONG_TIMER_TYPE;
1514 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1515 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1522 lw_applet_finalize (GObject *object)
1524 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1525 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1527 fprintf(stderr,"finalaze %i\n", priv->long_timer);
1528 if (priv->long_timer){
1529 g_source_remove(priv->long_timer);
1530 priv->long_timer = 0;
1532 if (priv->short_timer){
1533 g_source_remove(priv->short_timer);
1534 priv->short_timer = 0;
1541 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1543 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1544 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1547 gobject_class->destroy = (gpointer)lw_applet_finalize;
1548 widget_class->realize = lw_applet_realize;
1549 widget_class->expose_event = lw_applet_expose_event;
1551 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1556 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {