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 425
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;
256 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
262 if (scene.daytime == TIME_NIGHT){
263 if (!actor->visible){
264 actor->visible = TRUE;
265 phase = get_moon_phase();
266 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
268 g_free(actor->filename);
269 actor->filename = newfile;
270 create_hildon_actor(actor, desktop_plugin);
275 // actor_set_position_full(actor->widget, x, y, actor->z);
276 //probability_sun(actor);
277 //fprintf(stderr, "after change sun %d\n", actor->time_start_animation);
278 }else if (actor->visible){
279 actor->visible = FALSE;
280 fprintf(stderr, "destroy moon \n");
281 destroy_hildon_actor(actor);
282 /* TO DO make moonrise*/
283 actor->time_start_animation = 0;
290 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
295 //fprintf(stderr, "change sun\n");
297 if (scene.daytime != TIME_NIGHT){
298 if (!actor->visible){
299 actor->visible = TRUE;
300 create_hildon_actor(actor, desktop_plugin);
302 get_sun_pos(&alt, &azm);
303 get_sun_screen_pos(alt, azm, &x, &y);
306 actor_set_position_full(actor->widget, x, y, actor->z);
307 //probability_sun(actor);
308 actor->time_start_animation = time(NULL) + probability_sun();
309 }else if (actor->visible){
310 actor->visible = FALSE;
311 destroy_hildon_actor(actor);
312 actor->time_start_animation = 0;
319 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
321 gint x0 = -300, y0 = 225, scale0 = 100,
322 x1 = 800, y1 = 162, scale1 = 130,
329 gettimeofday(&tvb, NULL);
334 if (!actor->visible){
335 actor->visible = TRUE;
336 if (scene.daytime == TIME_NIGHT){
338 g_free(actor->filename);
339 actor->filename = g_strdup("tram_dark.png");
342 g_free(actor->filename);
343 actor->filename = g_strdup("tram.png");
345 create_hildon_actor(actor, desktop_plugin);
347 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
348 x = path_line(x0, x1, t);
349 y = path_line(y0, y1, t);
350 scale = path_line(scale0, scale1, t);
351 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
352 actor_set_position_full(actor->widget, x, y, actor->z);
353 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
356 actor->visible = FALSE;
357 destroy_hildon_actor(actor);
358 actor->time_start_animation = sec + fast_rnd(300);
363 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
365 gint x0 = 620, y0 = 233, scale0 = 100,
366 x1 = 79, y1 = -146, scale1 = 100,
373 gettimeofday(&tvb, NULL);
377 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
379 if (scene.daytime != TIME_NIGHT){
380 if (actor->time_start_animation == 0){
381 actor->time_start_animation = sec + probability_plane();
385 if (!actor->visible){
386 actor->visible = TRUE;
387 create_hildon_actor(actor, desktop_plugin);
389 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
390 x = path_line(x0, x1, t);
391 y = path_line(y0, y1, t);
392 //scale = path_line(scale0, scale1, t);
393 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
394 actor_set_position_full(actor->widget, x, y, actor->z);
395 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
398 actor->visible = FALSE;
399 destroy_hildon_actor(actor);
400 if (scene.daytime == TIME_NIGHT)
401 actor->time_start_animation = 0;
403 actor->time_start_animation = sec + probability_plane();
409 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
411 gint x0 = -actor->width, y0 = 45, scale0 = 100,
412 x1 = 800, y1 = 20, scale1 = 100,
419 gettimeofday(&tvb, NULL);
423 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
424 if (scene.daytime != TIME_NIGHT){
425 if (actor->time_start_animation == 0){
426 actor->time_start_animation = sec + probability_plane();
430 if (!actor->visible){
431 actor->visible = TRUE;
432 create_hildon_actor(actor, desktop_plugin);
435 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
436 x = path_line(x0, x1, t);
437 y = path_line(y0, y1, t);
438 //scale = path_line(scale0, scale1, t);
439 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
440 actor_set_position_full(actor->widget, x, y, actor->z);
441 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
444 actor->visible = FALSE;
445 destroy_hildon_actor(actor);
446 if (scene.daytime == TIME_NIGHT)
447 actor->time_start_animation = 0;
449 actor->time_start_animation = sec + probability_plane();
455 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
457 gint x0, y0 = 300, scale0 = 100,
458 x1, y1 = -actor->height, scale1 = 150,
465 gettimeofday(&tvb, NULL);
469 //fprintf(stderr, "c1oud %s - y0=%d\n", actor->name, actor->y);
471 if (!actor->visible){
472 actor->visible = TRUE;
473 if (scene.daytime == TIME_NIGHT)
474 actor->filename = actor->filename;
476 actor->filename = actor->filename;
477 create_hildon_actor(actor, desktop_plugin);
479 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
481 if (scene.wind_orientation == 1){
490 x = path_line(x0, x1, t);
491 y = -scene.wind_angle * (x - x0) + actor->y;
492 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
494 //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
495 actor_set_position_full(actor->widget, x, y, actor->z);
496 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
497 if ((y < y1 || y > y0) || t >= 1){
499 actor->visible = FALSE;
500 destroy_hildon_actor(actor);
501 actor->time_start_animation = sec + fast_rnd(300);
502 actor->y = fast_rnd(300);
508 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
510 scene.wind_orientation = fast_rnd(2);
511 if (scene.wind_orientation == 0) scene.wind_orientation = -1;
512 scene.wind_angle = (double)(fast_rnd(200) - 100) / 100;
513 actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
514 fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
518 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
521 gint now = time(NULL);
523 if (scene.daytime == TIME_DAY){
525 actor->visible = FALSE;
526 destroy_hildon_actor(actor);
528 actor->time_start_animation = 0;
530 }else if (actor->time_start_animation == 0){
531 actor->time_start_animation = now + fast_rnd(30);
535 if (!actor->visible){
536 actor->visible = TRUE;
537 create_hildon_actor(actor, desktop_plugin);
538 actor->time_start_animation = now + fast_rnd(20) + 10;
540 actor->visible = FALSE;
541 destroy_hildon_actor(actor);
542 actor->time_start_animation = now + fast_rnd(20) + 10;
548 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
550 GtkWidget *ha = NULL;
551 GdkPixbuf *pixbuf = NULL;
552 GtkWidget *image = NULL;
555 /* fprintf(stderr, "create_hildon_actor %s\n", actor->name);*/
556 ha = hildon_animation_actor_new();
557 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
558 desktop_plugin->priv->theme, actor->filename);
559 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
566 image = gtk_image_new_from_pixbuf (pixbuf);
567 g_object_unref(G_OBJECT(pixbuf));
570 g_signal_connect(G_OBJECT(image), "expose_event",
571 G_CALLBACK(expose_event), pixbuf);
572 gtk_container_add (GTK_CONTAINER (ha), image);
574 actor_set_position_full(ha, actor->x, actor->y, actor->z);
575 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
576 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
578 gtk_widget_show_all(ha);
583 //g_object_set_data(G_OBJECT(ha), "name", name);
584 //g_object_set_data(G_OBJECT(ha), "filename", filename);
585 g_object_set_data(G_OBJECT(ha), "image", image);
587 g_object_set_data(G_OBJECT(ha), "x", x);
588 g_object_set_data(G_OBJECT(ha), "y", y);
589 g_object_set_data(G_OBJECT(ha), "z", z);
590 g_object_set_data(G_OBJECT(ha), "width", width);
591 g_object_set_data(G_OBJECT(ha), "height", height);
592 g_object_set_data(G_OBJECT(ha), "scale", scale);
593 g_object_set_data(G_OBJECT(ha), "visible", visible);
594 g_object_set_data(G_OBJECT(ha), "opacity", opacity);
595 g_object_set_data(G_OBJECT(ha), "func", pfunc);
597 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
603 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
605 GtkWidget *image = NULL;
606 GdkPixbuf *pixbuf = NULL;
609 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
610 desktop_plugin->priv->theme, actor->filename);
612 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
619 image = gtk_image_new_from_pixbuf (pixbuf);
620 g_object_unref(G_OBJECT(pixbuf));
623 g_signal_connect(G_OBJECT(image), "expose_event",
624 G_CALLBACK(expose_event), pixbuf);
625 if (g_object_get_data(G_OBJECT(actor->widget), "image")){
626 gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));
628 g_object_set_data(G_OBJECT(actor->widget), "image", image);
629 gtk_container_add (GTK_CONTAINER (actor->widget), image);
630 realize(actor->widget);
631 gtk_widget_show_all(actor->widget);
642 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
645 newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime);
647 g_free(actor->filename);
648 actor->filename = newfile;
649 change_hildon_actor(actor, desktop_plugin);
657 // уравнение изменения времени
663 GSList * tmp = scene.actors;
669 g_free(actor->filename);
672 gtk_widget_destroy(actor->widget);
673 //actor->widget = NULL;
676 tmp = g_slist_next(tmp);
683 reload_scene(AWallpaperPlugin *desktop_plugin)
685 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
687 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
688 init_scene(desktop_plugin);
689 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
690 init_scene1(desktop_plugin);
694 /* Init Modern Scene */
696 init_scene(AWallpaperPlugin *desktop_plugin)
699 gint now = time(NULL);
701 /* fprintf(stderr, "init scene \n");*/
702 scene.daytime = get_daytime();
704 scene.wind_orientation = -1;
705 scene.wind_angle = 0.3;
706 /* init value for random */
707 scene.seed = time(NULL);
711 actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480,
712 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
713 change_static_actor(actor, desktop_plugin);
714 scene.actors = g_slist_append(scene.actors, actor);
716 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
717 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
718 actor->time_start_animation = now;
719 actor->duration_animation = G_MAXINT;
720 change_sun(actor, desktop_plugin);
721 scene.actors = g_slist_append(scene.actors, actor);
723 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
724 TRUE, 100, 255, NULL, NULL);
725 scene.actors = g_slist_append(scene.actors, actor);
727 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
728 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
729 actor->time_start_animation = now + fast_rnd(180);
730 actor->duration_animation = 5*60;
731 scene.actors = g_slist_append(scene.actors, actor);
733 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
734 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
735 actor->time_start_animation = now + fast_rnd(180);
736 actor->duration_animation = 5*60;
737 scene.actors = g_slist_append(scene.actors, actor);
739 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
740 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
741 actor->time_start_animation = now + fast_rnd(180);
742 actor->duration_animation = 5*60;
743 scene.actors = g_slist_append(scene.actors, actor);
746 actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 8, 800, 480,
747 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
748 change_static_actor(actor, desktop_plugin);
749 scene.actors = g_slist_append(scene.actors, actor);
751 actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210,
752 FALSE, 100, 255, (gpointer)&change_tram, NULL);
753 actor->time_start_animation = time(NULL) + fast_rnd(60);
754 actor->duration_animation = 60;
755 scene.actors = g_slist_append(scene.actors, actor);
757 actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79,
758 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
759 change_static_actor(actor, desktop_plugin);
760 scene.actors = g_slist_append(scene.actors, actor);
762 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, 6, 60, 60,
763 FALSE, 100, 255, (gpointer)&change_moon, NULL);
764 change_moon(actor, desktop_plugin);
765 scene.actors = g_slist_append(scene.actors, actor);
767 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
768 FALSE, 100, 255, (gpointer)&change_wind, NULL);
769 change_wind(actor, desktop_plugin);
770 scene.actors = g_slist_append(scene.actors, actor);
772 /* windows in 4-th house */
813 for (i=0; i<13; i++){
814 actor = init_object(desktop_plugin, "window1", "window1.png",
815 winds[i][0], winds[i][1], 8, 8, 10,
816 FALSE, 100, 255, (gpointer)&change_window1, NULL);
817 //change_window1(actor, desktop_plugin);
818 actor->time_start_animation = now + fast_rnd(30);
819 scene.actors = g_slist_append(scene.actors, actor);
823 anim = g_new0(Animation, 1);
826 anim->func_change = &change_tram;
827 anim->func_time = NULL;
828 anim->timestart = time(NULL);
831 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
835 /* Init Berlin Scene */
837 init_scene1(AWallpaperPlugin *desktop_plugin)
840 gint now = time(NULL);
843 scene.daytime = get_daytime();
845 scene.wind_orientation = -1;
846 scene.wind_angle = 0.3;
847 /* init value for random */
848 scene.seed = time(NULL);
851 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
852 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
853 change_static_actor(actor, desktop_plugin);
854 scene.actors = g_slist_append(scene.actors, actor);
857 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
858 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
859 actor->time_start_animation = time(NULL);
860 actor->duration_animation = G_MAXINT;
861 change_sun(actor, desktop_plugin);
862 scene.actors = g_slist_append(scene.actors, actor);
865 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
866 TRUE, 100, 255, NULL, NULL);
867 scene.actors = g_slist_append(scene.actors, actor);
870 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
871 FALSE, 100, 255, (gpointer)&change_moon, NULL);
872 change_moon(actor, desktop_plugin);
873 scene.actors = g_slist_append(scene.actors, actor);
875 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
876 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
877 actor->time_start_animation = now + fast_rnd(180);
878 actor->duration_animation = 5*60;
879 scene.actors = g_slist_append(scene.actors, actor);
881 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
882 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
883 actor->time_start_animation = now + fast_rnd(180);
884 actor->duration_animation = 5*60;
885 scene.actors = g_slist_append(scene.actors, actor);
887 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
888 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
889 actor->time_start_animation = now + fast_rnd(180);
890 actor->duration_animation = 5*60;
891 scene.actors = g_slist_append(scene.actors, actor);
894 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
895 FALSE, 100, 255, (gpointer)&change_plane2, NULL);
896 actor->time_start_animation = now + probability_plane();
897 actor->duration_animation = 60;
898 scene.actors = g_slist_append(scene.actors, actor);
900 actor = init_object(desktop_plugin, "plane1", "tu154_small.png", 620, 233, 9, 300, 116,
901 FALSE, 100, 255, (gpointer)&change_plane1, NULL);
902 actor->time_start_animation = now + probability_plane();
903 actor->duration_animation = 30;
904 scene.actors = g_slist_append(scene.actors, actor);
906 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
907 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
908 change_static_actor(actor, desktop_plugin);
909 scene.actors = g_slist_append(scene.actors, actor);
911 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
912 FALSE, 100, 255, (gpointer)&change_wind, NULL);
913 change_wind(actor, desktop_plugin);
914 scene.actors = g_slist_append(scene.actors, actor);
920 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
922 gint y0 = 365;// - уровень горизонта
923 *x = (int)(azm * 800) - 64;
924 *y = (int)((1 - alt) * y0) - 64;
925 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
929 change_actor(GtkWidget * actor)
932 gint x, y, daytime, scale;
939 void (*pfunc)(gpointer, gpointer);
941 name = g_object_get_data(G_OBJECT(actor), "name");
942 fprintf(stderr, "change actor %s\n", name);
944 pfunc = g_object_get_data(G_OBJECT(actor), "func");
946 (*pfunc)(actor, g_strdup(name));
947 daytime = get_daytime();
948 if (daytime != TIME_NIGHT){
949 hildon_animation_actor_set_show(actor, 1);
950 get_sun_pos(&alt, &azm);
951 get_sun_screen_pos(alt, azm, &x, &y);
952 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
956 if (name == "cloud1"){
957 x = g_object_get_data(G_OBJECT(actor), "x");
958 y = g_object_get_data(G_OBJECT(actor), "y");
959 scale = g_object_get_data(G_OBJECT(actor), "scale");
962 image = g_object_get_data(G_OBJECT(actor), "image");
964 gtk_container_remove(actor, image);
965 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
970 image = gtk_image_new_from_pixbuf (pixbuf);
971 g_object_unref(G_OBJECT(pixbuf));
973 g_signal_connect(G_OBJECT(image), "expose_event",
974 G_CALLBACK(expose_event), pixbuf);
975 gtk_container_add (GTK_CONTAINER (actor), image);
977 gtk_widget_show_all(actor);
989 sc = (double)scale / 100;
990 hildon_animation_actor_set_scale(actor, sc, sc);
991 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
992 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
993 g_object_set_data(G_OBJECT(actor), "x", x);
994 g_object_set_data(G_OBJECT(actor), "y", y);
995 g_object_set_data(G_OBJECT(actor), "scale", scale);
1001 short_timeout (AWallpaperPlugin *desktop_plugin)
1003 gint daytime = get_daytime();
1005 void (*pfunc)(gpointer, gpointer);
1008 gboolean stop_flag = TRUE;
1010 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
1011 desktop_plugin->priv->short_timer = 0;
1016 //scene.daytime = daytime;
1017 /* fprintf(stderr, "Short timer %d\n", now); */
1019 while (tmp != NULL){
1021 if (now >= actor->time_start_animation
1022 && actor->time_start_animation > 0
1023 /* && now - actor->time_start_animation <= actor->duration_animation*/){
1024 pfunc = actor->func_change;
1026 (*pfunc)(actor, desktop_plugin);
1030 tmp = g_slist_next(tmp);
1033 desktop_plugin->priv->short_timer = 0;
1036 return TRUE; /* keep running this event */
1041 long_timeout (AWallpaperPlugin *desktop_plugin)
1043 gint daytime = get_daytime();
1045 void (*pfunc)(gpointer, gpointer);
1049 fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer);
1050 if (desktop_plugin->priv->long_timer == 0 )
1052 if (!desktop_plugin->priv->visible){
1053 if(desktop_plugin->priv->short_timer != 0){
1054 g_source_remove(desktop_plugin->priv->short_timer);
1055 desktop_plugin->priv->short_timer = 0;
1059 //fprintf(stderr, "timer daytime=%d\n", daytime);
1060 if (scene.daytime != daytime){
1061 scene.daytime = daytime;
1063 while (tmp != NULL){
1064 //change_actor(tmp->data);
1065 pfunc =((Actor*)tmp->data)->func_change;
1067 (*pfunc)(tmp->data, desktop_plugin);
1069 tmp = g_slist_next(tmp);
1074 //fprintf(stderr, "Now %d\n", now);
1076 while (tmp != NULL){
1078 if (now >= actor->time_start_animation
1079 && actor->time_start_animation > 0
1080 && desktop_plugin->priv->short_timer == 0){
1081 actor->time_start_animation = now;
1082 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
1083 if (desktop_plugin->priv->rich_animation)
1084 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
1086 tmp = g_slist_next(tmp);
1090 return TRUE; /* keep running this event */
1094 desktop_plugin_visible_notify (GObject *object,
1096 AWallpaperPlugin *desktop_plugin)
1099 g_object_get (object, "is-on-current-desktop", &visible, NULL);
1100 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1102 desktop_plugin->priv->visible = TRUE;
1103 if (desktop_plugin->priv->long_timer == 0 )
1104 desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1106 desktop_plugin->priv->visible = FALSE;
1107 if (desktop_plugin->priv->long_timer != 0 ){
1108 g_source_remove(desktop_plugin->priv->long_timer);
1109 desktop_plugin->priv->long_timer = 0;
1115 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1116 gpointer user_data){
1117 fprintf(stderr,"gggggggggggggggggggg2222\n");
1120 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1123 GtkWidget *rich_animation;
1126 GtkWidget *background_town = NULL;
1128 fprintf(stderr, "!!!!!!!plugin init \n");
1129 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1130 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1134 priv->desktop_plugin = desktop_plugin;
1135 widget = gtk_fixed_new();
1137 gtk_widget_set_size_request(widget, 95, 50);
1138 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town_right_corner.png");
1139 background_town = gtk_image_new_from_file (buffer);
1140 if (background_town){
1141 gtk_fixed_put(GTK_FIXED(widget), background_town, 0, 0);
1142 gtk_widget_show (background_town);
1144 /* Create rich animation event */
1145 rich_animation = gtk_event_box_new();
1147 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1148 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1149 gtk_widget_set_size_request(rich_animation, 95, 50);
1150 gtk_widget_show (rich_animation);
1151 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1152 gtk_fixed_put(GTK_FIXED(widget), rich_animation, 0, 0);
1155 GtkWidget *label = gtk_label_new ("ddddddddddddd");
1156 gtk_widget_set_size_request(label, 95, 30);
1157 gtk_widget_show (label);
1158 // gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1159 gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
1161 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1162 g_signal_connect (desktop_plugin, "show-settings",
1163 G_CALLBACK (lw_settings), priv);
1164 gtk_widget_show (widget);
1165 gtk_container_add (GTK_CONTAINER (desktop_plugin), widget);
1166 init_applet_position();
1169 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1170 if (!strcmp(priv->theme,"Modern"))
1171 init_scene(desktop_plugin);
1172 else if (!strcmp(priv->theme,"Berlin"))
1173 init_scene1(desktop_plugin);
1174 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1175 priv->short_timer = 0;
1176 /* TODO Move scene to priv */
1177 scene.timer_type = LONG_TIMER_TYPE;
1178 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1179 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1186 lw_applet_finalize (GObject *object)
1188 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1189 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1191 fprintf(stderr,"finalaze %i\n", priv->long_timer);
1192 if (priv->long_timer){
1193 g_source_remove(priv->long_timer);
1194 priv->long_timer = 0;
1196 if (priv->short_timer){
1197 g_source_remove(priv->short_timer);
1198 priv->short_timer = 0;
1205 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1207 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1208 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1211 gobject_class->destroy = (gpointer)lw_applet_finalize;
1212 widget_class->realize = lw_applet_realize;
1213 widget_class->expose_event = lw_applet_expose_event;
1215 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1220 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {