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;
47 GSList * objects_list = NULL;
51 lw_applet_realize (GtkWidget *widget)
55 screen = gtk_widget_get_screen (widget);
56 gtk_widget_set_colormap (widget,
57 gdk_screen_get_rgba_colormap (screen));
58 gtk_widget_set_app_paintable (widget,
60 GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->realize (widget);
65 lw_applet_expose_event(GtkWidget *widget,
66 GdkEventExpose *event)
70 /* Create cairo context */
71 cr = gdk_cairo_create (GDK_DRAWABLE (widget->window));
72 gdk_cairo_region (cr, event->region);
75 /* Draw alpha background */
76 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
77 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
83 return GTK_WIDGET_CLASS (animation_wallpaper_plugin_parent_class)->expose_event (widget,
88 expose_event (GtkWidget *widget,GdkEventExpose *event,
92 GdkPixbuf *pixbuf = (GdkPixbuf *) data;
94 cr = gdk_cairo_create(widget->window);
96 gdk_cairo_region(cr, event->region);
97 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
98 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
106 realize (GtkWidget *widget)
109 screen = gtk_widget_get_screen (widget);
110 gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
113 /* Set position of widget on desktop */
115 init_applet_position(void)
117 GSList *position = NULL;
121 GError *error = NULL;
122 GConfClient *gconf_client = gconf_client_get_default ();
123 position_key = g_strdup_printf (GCONF_KEY_POSITION, PLUGIN_NAME);
124 position = gconf_client_get_list (gconf_client,
128 if (position && position->data && position->next->data){
129 xapplet = GPOINTER_TO_INT (position->data);
130 yapplet = GPOINTER_TO_INT (position->next->data);
132 position = g_slist_prepend (g_slist_prepend (NULL,
133 GINT_TO_POINTER (Ystartposition)),
134 GINT_TO_POINTER (Xstartposition));
135 gconf_client_set_list (gconf_client,
140 xapplet = Xstartposition;
141 yapplet = Ystartposition;
143 g_free (position_key);
144 modified = g_strdup_printf ("%i", 0);
145 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
146 gconf_client_set_string (gconf_client,
151 g_free(modified_key);
152 gconf_client_clear_cache(gconf_client);
153 g_object_unref(gconf_client);
157 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
159 /* fprintf(stderr, "actor_set_position_full z=%d\n", z); */
160 hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
164 path_line(gint x0, gint x1, double t)
167 return ((x1 - x0) * t + x0);
172 destroy_hildon_actor(Actor *actor)
174 fprintf(stderr, "estroy_hildon_actor %p\n",actor->widget);
175 gtk_widget_destroy(actor->widget);
176 actor->widget = NULL;
180 init_object(AWallpaperPlugin *desktop_plugin,
191 void (*pfunc_change)(Actor*),
192 void (*pfunc_probability)(Actor*)
196 actor = g_new0(Actor, 1);
200 actor->width = width;
201 actor->height = height;
202 actor->visible = visible;
203 actor->scale = scale;
204 actor->opacity = opacity;
205 actor->filename = g_strdup(filename);
206 actor->name = g_strdup(name);
207 actor->func_change = (gpointer)pfunc_change;
208 actor->func_probability = (gpointer)pfunc_probability;
210 create_hildon_actor(actor, desktop_plugin);
212 actor->widget = NULL;
213 actor->time_start_animation = 0;
214 actor->duration_animation = 0;
222 //objects_list = g_slist_append(objects_list, G_OBJECT(actor));
223 //objects_list = g_slist_append(objects_list, G_OBJECT(a));
234 gint fast_rnd(gint max)
236 guint offset = 12923;
237 guint multiplier = 4079;
239 seed = seed * multiplier + offset;
240 return (gint)(seed % max);
246 /* update sun position after ... second */
254 return (fast_rnd(10) + 1) * 60;
258 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
264 if (get_daytime() == TIME_NIGHT){
265 if (!actor->visible){
266 actor->visible = TRUE;
267 phase = get_moon_phase();
268 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
270 g_free(actor->filename);
271 actor->filename = newfile;
272 create_hildon_actor(actor, desktop_plugin);
277 // actor_set_position_full(actor->widget, x, y, actor->z);
278 //probability_sun(actor);
279 //fprintf(stderr, "after change sun %d\n", actor->time_start_animation);
280 }else if (actor->visible){
281 actor->visible = FALSE;
282 fprintf(stderr, "destroy moon \n");
283 destroy_hildon_actor(actor);
284 /* TO DO make moonrise*/
285 actor->time_start_animation = 0;
292 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
297 //fprintf(stderr, "change sun\n");
299 if (scene.daytime != TIME_NIGHT){
300 if (!actor->visible){
301 actor->visible = TRUE;
302 create_hildon_actor(actor, desktop_plugin);
304 get_sun_pos(&alt, &azm);
305 get_sun_screen_pos(alt, azm, &x, &y);
308 actor_set_position_full(actor->widget, x, y, actor->z);
309 //probability_sun(actor);
310 actor->time_start_animation = time(NULL) + probability_sun();
311 }else if (actor->visible){
312 actor->visible = FALSE;
313 destroy_hildon_actor(actor);
314 actor->time_start_animation = 0;
321 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
323 gint x0 = -300, y0 = 225, scale0 = 100,
324 x1 = 800, y1 = 162, scale1 = 130,
331 gettimeofday(&tvb, NULL);
335 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
337 if (!actor->visible){
338 actor->visible = TRUE;
339 if (scene.daytime == TIME_NIGHT){
341 g_free(actor->filename);
342 actor->filename = g_strdup("tram_dark.png");
345 g_free(actor->filename);
346 actor->filename = g_strdup("tram.png");
348 create_hildon_actor(actor, desktop_plugin);
350 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
351 x = path_line(x0, x1, t);
352 y = path_line(y0, y1, t);
353 scale = path_line(scale0, scale1, t);
354 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
355 actor_set_position_full(actor->widget, x, y, actor->z);
356 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
359 actor->visible = FALSE;
360 destroy_hildon_actor(actor);
361 actor->time_start_animation = sec + fast_rnd(300);
366 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
368 gint x0 = 620, y0 = 233, scale0 = 100,
369 x1 = 79, y1 = -146, scale1 = 100,
376 gettimeofday(&tvb, NULL);
380 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
382 if (!actor->visible){
383 actor->visible = TRUE;
384 if (scene.daytime == TIME_NIGHT){
386 g_free(actor->filename);
387 actor->filename = g_strdup("tu154.png");
390 g_free(actor->filename);
391 actor->filename = g_strdup("tu154.png");
393 create_hildon_actor(actor, desktop_plugin);
395 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
396 x = path_line(x0, x1, t);
397 y = path_line(y0, y1, t);
398 //scale = path_line(scale0, scale1, t);
399 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
400 actor_set_position_full(actor->widget, x, y, actor->z);
401 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
404 actor->visible = FALSE;
405 destroy_hildon_actor(actor);
406 actor->time_start_animation = sec + probability_plane();
412 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
414 gint x0 = -actor->width, y0 = 45, scale0 = 100,
415 x1 = 800, y1 = 20, scale1 = 100,
422 gettimeofday(&tvb, NULL);
426 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
428 if (!actor->visible){
429 actor->visible = TRUE;
430 if (scene.daytime == TIME_NIGHT){
432 g_free(actor->filename);
433 if (scene.daytime == TIME_NIGHT)
434 actor->filename = g_strdup("plane3.png");
437 g_free(actor->filename);
438 actor->filename = g_strdup("plane3.png");
440 create_hildon_actor(actor, desktop_plugin);
442 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
443 x = path_line(x0, x1, t);
444 y = path_line(y0, y1, t);
445 //scale = path_line(scale0, scale1, t);
446 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
447 actor_set_position_full(actor->widget, x, y, actor->z);
448 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
451 actor->visible = FALSE;
452 destroy_hildon_actor(actor);
453 actor->time_start_animation = sec + probability_plane();
459 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
461 gint x0, y0 = 300, scale0 = 100,
462 x1, y1 = -actor->height, scale1 = 150,
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 actor->filename = actor->filename;
480 actor->filename = actor->filename;
481 create_hildon_actor(actor, desktop_plugin);
483 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
485 if (scene.wind_orientation == 1){
494 x = path_line(x0, x1, t);
495 y = -scene.wind_angle * (x - x0) + actor->y;
496 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
498 //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
499 actor_set_position_full(actor->widget, x, y, actor->z);
500 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
501 if ((y < y1 || y > y0) || t >= 1){
503 actor->visible = FALSE;
504 destroy_hildon_actor(actor);
505 actor->time_start_animation = sec + fast_rnd(300);
506 actor->y = fast_rnd(300);
512 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
514 scene.wind_orientation = fast_rnd(2) - 1;
515 scene.wind_angle = (double)(fast_rnd(400) - 200) / 100;
516 actor->time_start_animation = time(NULL) + (fast_rnd(20) + 10) * 60;
517 fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
521 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
523 GtkWidget *ha = NULL;
524 GdkPixbuf *pixbuf = NULL;
525 GtkWidget *image = NULL;
528 /* fprintf(stderr, "create_hildon_actor %s\n", actor->name);*/
529 ha = hildon_animation_actor_new();
530 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
531 desktop_plugin->priv->theme, actor->filename);
532 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
539 image = gtk_image_new_from_pixbuf (pixbuf);
540 g_object_unref(G_OBJECT(pixbuf));
543 g_signal_connect(G_OBJECT(image), "expose_event",
544 G_CALLBACK(expose_event), pixbuf);
545 gtk_container_add (GTK_CONTAINER (ha), image);
547 actor_set_position_full(ha, actor->x, actor->y, actor->z);
548 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
549 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
551 gtk_widget_show_all(ha);
556 //g_object_set_data(G_OBJECT(ha), "name", name);
557 //g_object_set_data(G_OBJECT(ha), "filename", filename);
558 g_object_set_data(G_OBJECT(ha), "image", image);
560 g_object_set_data(G_OBJECT(ha), "x", x);
561 g_object_set_data(G_OBJECT(ha), "y", y);
562 g_object_set_data(G_OBJECT(ha), "z", z);
563 g_object_set_data(G_OBJECT(ha), "width", width);
564 g_object_set_data(G_OBJECT(ha), "height", height);
565 g_object_set_data(G_OBJECT(ha), "scale", scale);
566 g_object_set_data(G_OBJECT(ha), "visible", visible);
567 g_object_set_data(G_OBJECT(ha), "opacity", opacity);
568 g_object_set_data(G_OBJECT(ha), "func", pfunc);
570 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
576 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
578 GtkWidget *image = NULL;
579 GdkPixbuf *pixbuf = NULL;
582 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
583 desktop_plugin->priv->theme, actor->filename);
585 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
592 image = gtk_image_new_from_pixbuf (pixbuf);
593 g_object_unref(G_OBJECT(pixbuf));
596 g_signal_connect(G_OBJECT(image), "expose_event",
597 G_CALLBACK(expose_event), pixbuf);
598 if (g_object_get_data(G_OBJECT(actor->widget), "image")){
599 gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));
601 g_object_set_data(G_OBJECT(actor->widget), "image", image);
602 gtk_container_add (GTK_CONTAINER (actor->widget), image);
603 realize(actor->widget);
604 gtk_widget_show_all(actor->widget);
615 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
620 daytime = get_daytime();
621 newfile = g_strdup_printf("%s%d.png", actor->name, daytime);
623 g_free(actor->filename);
624 actor->filename = newfile;
625 change_hildon_actor(actor, desktop_plugin);
633 // уравнение изменения времени
639 GSList * tmp = scene.actors;
645 g_free(actor->filename);
648 gtk_widget_destroy(actor->widget);
649 //actor->widget = NULL;
652 tmp = g_slist_next(tmp);
659 reload_scene(AWallpaperPlugin *desktop_plugin)
661 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
663 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
664 init_scene(desktop_plugin);
665 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
666 init_scene1(desktop_plugin);
670 /* Init Modern Scene */
672 init_scene(AWallpaperPlugin *desktop_plugin)
675 gint now = time(NULL);
677 /* fprintf(stderr, "init scene \n");*/
678 scene.daytime = get_daytime();
680 scene.wind_orientation = -1;
681 scene.wind_angle = 0.3;
684 actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480,
685 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
686 change_static_actor(actor, desktop_plugin);
687 scene.actors = g_slist_append(scene.actors, actor);
689 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
690 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
691 actor->time_start_animation = time(NULL);
692 actor->duration_animation = G_MAXINT;
693 change_sun(actor, desktop_plugin);
694 scene.actors = g_slist_append(scene.actors, actor);
696 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
697 TRUE, 100, 255, NULL, NULL);
698 scene.actors = g_slist_append(scene.actors, actor);
700 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
701 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
702 actor->time_start_animation = now + fast_rnd(180);
703 actor->duration_animation = 5*60;
704 scene.actors = g_slist_append(scene.actors, actor);
706 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
707 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
708 actor->time_start_animation = now + fast_rnd(180);
709 actor->duration_animation = 5*60;
710 scene.actors = g_slist_append(scene.actors, actor);
712 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
713 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
714 actor->time_start_animation = now + fast_rnd(180);
715 actor->duration_animation = 5*60;
716 scene.actors = g_slist_append(scene.actors, actor);
719 actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 8, 800, 480,
720 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
721 change_static_actor(actor, desktop_plugin);
722 scene.actors = g_slist_append(scene.actors, actor);
724 actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210,
725 FALSE, 100, 255, (gpointer)&change_tram, NULL);
726 actor->time_start_animation = time(NULL) + fast_rnd(60);
727 actor->duration_animation = 60;
728 scene.actors = g_slist_append(scene.actors, actor);
730 actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79,
731 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
732 change_static_actor(actor, desktop_plugin);
733 scene.actors = g_slist_append(scene.actors, actor);
735 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, 6, 60, 60,
736 FALSE, 100, 255, (gpointer)&change_moon, NULL);
737 change_moon(actor, desktop_plugin);
738 scene.actors = g_slist_append(scene.actors, actor);
740 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
741 FALSE, 100, 255, (gpointer)&change_wind, NULL);
742 change_wind(actor, desktop_plugin);
743 scene.actors = g_slist_append(scene.actors, actor);
746 anim = g_new0(Animation, 1);
749 anim->func_change = &change_tram;
750 anim->func_time = NULL;
751 anim->timestart = time(NULL);
754 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
758 /* Init Berlin Scene */
760 init_scene1(AWallpaperPlugin *desktop_plugin)
763 gint now = time(NULL);
766 scene.daytime = get_daytime();
768 scene.wind_orientation = -1;
769 scene.wind_angle = 0.3;
771 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
772 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
773 change_static_actor(actor, desktop_plugin);
774 scene.actors = g_slist_append(scene.actors, actor);
777 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
778 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
779 actor->time_start_animation = time(NULL);
780 actor->duration_animation = G_MAXINT;
781 change_sun(actor, desktop_plugin);
782 scene.actors = g_slist_append(scene.actors, actor);
785 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
786 TRUE, 100, 255, NULL, NULL);
787 scene.actors = g_slist_append(scene.actors, actor);
790 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
791 FALSE, 100, 255, (gpointer)&change_moon, NULL);
792 change_moon(actor, desktop_plugin);
793 scene.actors = g_slist_append(scene.actors, actor);
795 actor = init_object(desktop_plugin, "cloud1", "cloud2.png", 0, fast_rnd(300), 7, 188, 75,
796 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
797 actor->time_start_animation = now + fast_rnd(3) * 60;
798 actor->duration_animation = 5*60;
799 scene.actors = g_slist_append(scene.actors, actor);
801 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
802 FALSE, 100, 255, (gpointer)&change_plane2, NULL);
803 actor->time_start_animation = now + probability_plane();
804 actor->duration_animation = 60;
805 scene.actors = g_slist_append(scene.actors, actor);
807 actor = init_object(desktop_plugin, "plane1", "tu154_small.png", 620, 233, 9, 300, 116,
808 FALSE, 100, 255, (gpointer)&change_plane1, NULL);
809 actor->time_start_animation = now + probability_plane();
810 actor->duration_animation = 30;
811 scene.actors = g_slist_append(scene.actors, actor);
813 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
814 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
815 change_static_actor(actor, desktop_plugin);
816 scene.actors = g_slist_append(scene.actors, actor);
823 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
825 gint y0 = 365;// - уровень горизонта
826 *x = (int)(azm * 800) - 64;
827 *y = (int)((1 - alt) * y0) - 64;
828 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
832 change_actor(GtkWidget * actor)
835 gint x, y, daytime, scale;
842 void (*pfunc)(gpointer, gpointer);
844 name = g_object_get_data(G_OBJECT(actor), "name");
845 fprintf(stderr, "change actor %s\n", name);
847 pfunc = g_object_get_data(G_OBJECT(actor), "func");
849 (*pfunc)(actor, g_strdup(name));
850 daytime = get_daytime();
851 if (daytime != TIME_NIGHT){
852 hildon_animation_actor_set_show(actor, 1);
853 get_sun_pos(&alt, &azm);
854 get_sun_screen_pos(alt, azm, &x, &y);
855 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
859 if (name == "cloud1"){
860 x = g_object_get_data(G_OBJECT(actor), "x");
861 y = g_object_get_data(G_OBJECT(actor), "y");
862 scale = g_object_get_data(G_OBJECT(actor), "scale");
865 image = g_object_get_data(G_OBJECT(actor), "image");
867 gtk_container_remove(actor, image);
868 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
873 image = gtk_image_new_from_pixbuf (pixbuf);
874 g_object_unref(G_OBJECT(pixbuf));
876 g_signal_connect(G_OBJECT(image), "expose_event",
877 G_CALLBACK(expose_event), pixbuf);
878 gtk_container_add (GTK_CONTAINER (actor), image);
880 gtk_widget_show_all(actor);
892 sc = (double)scale / 100;
893 hildon_animation_actor_set_scale(actor, sc, sc);
894 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
895 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
896 g_object_set_data(G_OBJECT(actor), "x", x);
897 g_object_set_data(G_OBJECT(actor), "y", y);
898 g_object_set_data(G_OBJECT(actor), "scale", scale);
904 short_timeout (AWallpaperPlugin *desktop_plugin)
906 gint daytime = get_daytime();
908 void (*pfunc)(gpointer, gpointer);
911 gboolean stop_flag = TRUE;
913 if (!desktop_plugin->priv->visible)
917 //scene.daytime = daytime;
918 /* fprintf(stderr, "Short timer %d\n", now); */
922 if (now >= actor->time_start_animation
923 && actor->time_start_animation > 0
924 /* && now - actor->time_start_animation <= actor->duration_animation*/){
925 pfunc = actor->func_change;
927 (*pfunc)(actor, desktop_plugin);
931 tmp = g_slist_next(tmp);
934 desktop_plugin->priv->short_timer = 0;
937 return TRUE; /* keep running this event */
942 long_timeout (AWallpaperPlugin *desktop_plugin)
944 gint daytime = get_daytime();
946 void (*pfunc)(gpointer, gpointer);
950 /* TODO remove timeout */
951 if (!desktop_plugin->priv->visible)
953 //fprintf(stderr, "timer daytime=%d\n", daytime);
954 if (scene.daytime != daytime){
957 //change_actor(tmp->data);
958 pfunc =((Actor*)tmp->data)->func_change;
960 (*pfunc)(tmp->data, desktop_plugin);
962 tmp = g_slist_next(tmp);
967 //fprintf(stderr, "Now %d\n", now);
971 if (now >= actor->time_start_animation
972 && actor->time_start_animation > 0
973 && desktop_plugin->priv->short_timer == 0){
974 actor->time_start_animation = now;
975 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
976 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
978 tmp = g_slist_next(tmp);
981 scene.daytime = daytime;
983 return TRUE; /* keep running this event */
987 desktop_plugin_visible_notify (GObject *object,
989 AWallpaperPlugin *desktop_plugin)
992 g_object_get (object, "is-on-current-desktop", &visible, NULL);
994 desktop_plugin->priv->visible = TRUE;
996 desktop_plugin->priv->visible = FALSE;
997 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1001 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1002 gpointer user_data){
1003 fprintf(stderr,"gggggggggggggggggggg\n");
1006 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1009 GtkWidget *rich_animation;
1010 fprintf(stderr, "!!!!!!!plugin init \n");
1011 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1012 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1015 priv->desktop_plugin = desktop_plugin;
1016 /* Create rich animation event */
1017 rich_animation = gtk_event_box_new();
1019 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1020 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1021 gtk_widget_set_size_request(rich_animation, 95, 30);
1022 gtk_widget_show (rich_animation);
1023 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1026 label = gtk_label_new ("");
1027 gtk_widget_set_size_request(label, 95, 30);
1028 gtk_widget_show (label);
1029 gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1031 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1032 g_signal_connect (desktop_plugin, "show-settings",
1033 G_CALLBACK (lw_settings), priv);
1034 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1035 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1037 gtk_container_add (GTK_CONTAINER (desktop_plugin), rich_animation);
1038 init_applet_position();
1040 /* start value for random */
1043 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1044 if (!strcmp(priv->theme,"Modern"))
1045 init_scene(desktop_plugin);
1046 else if (!strcmp(priv->theme,"Berlin"))
1047 init_scene1(desktop_plugin);
1048 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1049 priv->short_timer = 0;
1050 /* TODO Move scene to priv */
1051 scene.timer_type = LONG_TIMER_TYPE;
1057 lw_applet_finalize (GObject *object)
1059 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1060 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1062 if (priv->long_timer){
1063 g_source_remove(priv->long_timer);
1064 priv->long_timer = 0;
1066 if (priv->short_timer){
1067 g_source_remove(priv->short_timer);
1068 priv->short_timer = 0;
1075 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1077 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1078 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1081 gobject_class->destroy = (gpointer)lw_applet_finalize;
1082 widget_class->realize = lw_applet_realize;
1083 widget_class->expose_event = lw_applet_expose_event;
1085 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1090 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {}