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;
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 //fprintf(stderr, "change tram\n");
330 gettimeofday(&tvb, NULL);
335 if (!actor->visible){
336 actor->visible = TRUE;
337 if (scene.daytime == TIME_NIGHT){
339 g_free(actor->filename);
340 actor->filename = g_strdup("tram_dark.png");
343 g_free(actor->filename);
344 actor->filename = g_strdup("tram.png");
346 create_hildon_actor(actor, desktop_plugin);
348 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
349 x = path_line(x0, x1, t);
350 y = path_line(y0, y1, t);
351 scale = path_line(scale0, scale1, t);
352 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
353 actor_set_position_full(actor->widget, x, y, actor->z);
354 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
357 actor->visible = FALSE;
358 destroy_hildon_actor(actor);
359 actor->time_start_animation = sec + fast_rnd(300);
364 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
366 gint x0 = 620, y0 = 233, scale0 = 100,
367 x1 = 79, y1 = -146, scale1 = 100,
374 gettimeofday(&tvb, NULL);
378 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
380 if (scene.daytime != TIME_NIGHT){
381 if (actor->time_start_animation == 0){
382 actor->time_start_animation = sec + probability_plane();
386 if (!actor->visible){
387 actor->visible = TRUE;
388 create_hildon_actor(actor, desktop_plugin);
390 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
391 x = path_line(x0, x1, t);
392 y = path_line(y0, y1, t);
393 //scale = path_line(scale0, scale1, t);
394 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
395 actor_set_position_full(actor->widget, x, y, actor->z);
396 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
399 actor->visible = FALSE;
400 destroy_hildon_actor(actor);
401 if (scene.daytime == TIME_NIGHT)
402 actor->time_start_animation = 0;
404 actor->time_start_animation = sec + probability_plane();
410 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
412 gint x0 = -actor->width, y0 = 45, scale0 = 100,
413 x1 = 800, y1 = 20, scale1 = 100,
420 gettimeofday(&tvb, NULL);
424 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
425 if (scene.daytime != TIME_NIGHT){
426 if (actor->time_start_animation == 0){
427 actor->time_start_animation = sec + probability_plane();
431 if (!actor->visible){
432 actor->visible = TRUE;
433 create_hildon_actor(actor, desktop_plugin);
436 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
437 x = path_line(x0, x1, t);
438 y = path_line(y0, y1, t);
439 //scale = path_line(scale0, scale1, t);
440 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
441 actor_set_position_full(actor->widget, x, y, actor->z);
442 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
445 actor->visible = FALSE;
446 destroy_hildon_actor(actor);
447 if (scene.daytime == TIME_NIGHT)
448 actor->time_start_animation = 0;
450 actor->time_start_animation = sec + probability_plane();
456 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
458 gint x0, y0 = 300, scale0 = 100,
459 x1, y1 = -actor->height, scale1 = 150,
466 //fprintf(stderr, "change cloud\n");
467 gettimeofday(&tvb, NULL);
471 //fprintf(stderr, "c1oud %s - y0=%d\n", actor->name, actor->y);
473 if (!actor->visible){
474 actor->visible = TRUE;
475 if (scene.daytime == TIME_NIGHT)
476 actor->filename = actor->filename;
478 actor->filename = actor->filename;
479 create_hildon_actor(actor, desktop_plugin);
481 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
483 if (scene.wind_orientation == 1){
492 x = path_line(x0, x1, t);
493 y = -scene.wind_angle * (x - x0) + actor->y;
494 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
496 //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
497 actor_set_position_full(actor->widget, x, y, actor->z);
498 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
499 if ((y < y1 || y > y0) || t >= 1){
501 actor->visible = FALSE;
502 destroy_hildon_actor(actor);
503 actor->time_start_animation = sec + fast_rnd(300);
504 actor->y = fast_rnd(300);
510 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
512 scene.wind_orientation = fast_rnd(2);
513 if (scene.wind_orientation == 0) scene.wind_orientation = -1;
514 scene.wind_angle = (double)(fast_rnd(200) - 100) / 100;
515 actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
516 //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
520 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
523 gint now = time(NULL);
525 if (scene.daytime == TIME_DAY){
527 actor->visible = FALSE;
528 destroy_hildon_actor(actor);
530 actor->time_start_animation = 0;
532 }else if (actor->time_start_animation == 0){
533 actor->time_start_animation = now + fast_rnd(30);
537 if (!actor->visible){
538 actor->visible = TRUE;
539 create_hildon_actor(actor, desktop_plugin);
540 actor->time_start_animation = now + fast_rnd(60) + 10;
542 actor->visible = FALSE;
543 destroy_hildon_actor(actor);
544 actor->time_start_animation = now + fast_rnd(60) + 10;
550 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
552 GtkWidget *ha = NULL;
553 GdkPixbuf *pixbuf = NULL;
554 GtkWidget *image = NULL;
557 /* fprintf(stderr, "create_hildon_actor %s\n", actor->name);*/
558 ha = hildon_animation_actor_new();
559 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
560 desktop_plugin->priv->theme, actor->filename);
561 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
568 image = gtk_image_new_from_pixbuf (pixbuf);
569 g_object_unref(G_OBJECT(pixbuf));
572 g_signal_connect(G_OBJECT(image), "expose_event",
573 G_CALLBACK(expose_event), pixbuf);
574 gtk_container_add (GTK_CONTAINER (ha), image);
576 actor_set_position_full(ha, actor->x, actor->y, actor->z);
577 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
578 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
580 gtk_widget_show_all(ha);
585 //g_object_set_data(G_OBJECT(ha), "name", name);
586 //g_object_set_data(G_OBJECT(ha), "filename", filename);
587 g_object_set_data(G_OBJECT(ha), "image", image);
589 g_object_set_data(G_OBJECT(ha), "x", x);
590 g_object_set_data(G_OBJECT(ha), "y", y);
591 g_object_set_data(G_OBJECT(ha), "z", z);
592 g_object_set_data(G_OBJECT(ha), "width", width);
593 g_object_set_data(G_OBJECT(ha), "height", height);
594 g_object_set_data(G_OBJECT(ha), "scale", scale);
595 g_object_set_data(G_OBJECT(ha), "visible", visible);
596 g_object_set_data(G_OBJECT(ha), "opacity", opacity);
597 g_object_set_data(G_OBJECT(ha), "func", pfunc);
599 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
605 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
607 GtkWidget *image = NULL;
608 GdkPixbuf *pixbuf = NULL;
611 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
612 desktop_plugin->priv->theme, actor->filename);
614 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
621 image = gtk_image_new_from_pixbuf (pixbuf);
622 g_object_unref(G_OBJECT(pixbuf));
625 g_signal_connect(G_OBJECT(image), "expose_event",
626 G_CALLBACK(expose_event), pixbuf);
627 if (g_object_get_data(G_OBJECT(actor->widget), "image")){
628 gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));
630 g_object_set_data(G_OBJECT(actor->widget), "image", image);
631 gtk_container_add (GTK_CONTAINER (actor->widget), image);
632 realize(actor->widget);
633 gtk_widget_show_all(actor->widget);
644 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
647 newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime);
649 g_free(actor->filename);
650 actor->filename = newfile;
651 change_hildon_actor(actor, desktop_plugin);
655 change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
660 if (desktop_plugin->priv->right_corner)
661 gtk_widget_destroy(desktop_plugin->priv->right_corner);
662 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
663 THEME_PATH, desktop_plugin->priv->theme, scene.daytime);
664 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
665 if (desktop_plugin->priv->right_corner){
666 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
667 gtk_widget_show (desktop_plugin->priv->right_corner);
669 change_static_actor(actor, desktop_plugin);
677 // уравнение изменения времени
683 GSList * tmp = scene.actors;
689 g_free(actor->filename);
692 gtk_widget_destroy(actor->widget);
693 //actor->widget = NULL;
696 tmp = g_slist_next(tmp);
703 reload_scene(AWallpaperPlugin *desktop_plugin)
705 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
707 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
708 init_scene(desktop_plugin);
709 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
710 init_scene1(desktop_plugin);
714 /* Init Modern Scene */
716 init_scene(AWallpaperPlugin *desktop_plugin)
719 gint now = time(NULL);
722 /* fprintf(stderr, "init scene \n");*/
723 scene.daytime = get_daytime();
725 scene.wind_orientation = -1;
726 scene.wind_angle = 0.3;
727 /* init value for random */
728 scene.seed = time(NULL);
732 actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480,
733 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
734 change_static_actor(actor, desktop_plugin);
735 scene.actors = g_slist_append(scene.actors, actor);
737 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
738 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
739 actor->time_start_animation = now;
740 actor->duration_animation = G_MAXINT;
741 change_sun(actor, desktop_plugin);
742 scene.actors = g_slist_append(scene.actors, actor);
744 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
745 // TRUE, 100, 255, NULL, NULL);
746 //scene.actors = g_slist_append(scene.actors, actor);
748 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
749 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
750 actor->time_start_animation = now + fast_rnd(180);
751 actor->duration_animation = 3*60;
752 scene.actors = g_slist_append(scene.actors, actor);
754 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
755 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
756 actor->time_start_animation = now + fast_rnd(180);
757 actor->duration_animation = 3*60;
758 scene.actors = g_slist_append(scene.actors, actor);
760 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
761 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
762 actor->time_start_animation = now + fast_rnd(180);
763 actor->duration_animation = 5*60;
764 scene.actors = g_slist_append(scene.actors, actor);
767 actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 8, 800, 480,
768 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
769 change_static_actor(actor, desktop_plugin);
770 scene.actors = g_slist_append(scene.actors, actor);
772 actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210,
773 FALSE, 100, 255, (gpointer)&change_tram, NULL);
774 actor->time_start_animation = time(NULL) + fast_rnd(60);
775 actor->duration_animation = 60;
776 scene.actors = g_slist_append(scene.actors, actor);
778 actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79,
779 TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
780 change_static_actor_with_corner(actor, desktop_plugin);
781 scene.actors = g_slist_append(scene.actors, actor);
783 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, 6, 60, 60,
784 FALSE, 100, 255, (gpointer)&change_moon, NULL);
785 change_moon(actor, desktop_plugin);
786 scene.actors = g_slist_append(scene.actors, actor);
788 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
789 FALSE, 100, 255, (gpointer)&change_wind, NULL);
790 change_wind(actor, desktop_plugin);
791 scene.actors = g_slist_append(scene.actors, actor);
793 /* windows in 4-th house */
834 for (i=0; i<13; i++){
835 actor = init_object(desktop_plugin, "window1", "window1.png",
836 winds[i][0], winds[i][1], 8, 8, 10,
837 FALSE, 100, 255, (gpointer)&change_window1, NULL);
838 //change_window1(actor, desktop_plugin);
839 actor->time_start_animation = now + fast_rnd(30);
840 scene.actors = g_slist_append(scene.actors, actor);
844 /* windows in 1-th house */
870 actor = init_object(desktop_plugin, "window2", "window2.png",
871 winds[i][0], winds[i][1], 8, 8, 10,
872 TRUE, 100, 255, (gpointer)&change_window1, NULL);
873 //change_window1(actor, desktop_plugin);
874 actor->time_start_animation = now + fast_rnd(30);
875 scene.actors = g_slist_append(scene.actors, actor);
879 /* windows in 3-th house */
911 for (i=0; i<10; i++){
912 actor = init_object(desktop_plugin, "window3", "window3.png",
913 winds[i][0], winds[i][1], 8, 8, 10,
914 FALSE, 100, 255, (gpointer)&change_window1, NULL);
915 //change_window1(actor, desktop_plugin);
916 actor->time_start_animation = now + fast_rnd(30);
917 scene.actors = g_slist_append(scene.actors, actor);
921 /* windows in 5-th house */
945 actor = init_object(desktop_plugin, "window4", "window4.png",
946 winds[i][0], winds[i][1], 8, 8, 10,
947 FALSE, 100, 255, (gpointer)&change_window1, NULL);
948 //change_window1(actor, desktop_plugin);
949 actor->time_start_animation = now + fast_rnd(30);
950 scene.actors = g_slist_append(scene.actors, actor);
954 /* windows in 6-th house */
975 actor = init_object(desktop_plugin, "window5", "window5.png",
976 winds[i][0], winds[i][1], 8, 8, 10,
977 FALSE, 100, 255, (gpointer)&change_window1, NULL);
978 //change_window1(actor, desktop_plugin);
979 actor->time_start_animation = now + fast_rnd(30);
980 scene.actors = g_slist_append(scene.actors, actor);
985 anim = g_new0(Animation, 1);
988 anim->func_change = &change_tram;
989 anim->func_time = NULL;
990 anim->timestart = time(NULL);
993 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
997 /* Init Berlin Scene */
999 init_scene1(AWallpaperPlugin *desktop_plugin)
1002 gint now = time(NULL);
1005 scene.daytime = get_daytime();
1006 scene.actors = NULL;
1007 scene.wind_orientation = -1;
1008 scene.wind_angle = 0.3;
1009 /* init value for random */
1010 scene.seed = time(NULL);
1013 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
1014 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
1015 change_static_actor(actor, desktop_plugin);
1016 scene.actors = g_slist_append(scene.actors, actor);
1019 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
1020 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
1021 actor->time_start_animation = time(NULL);
1022 actor->duration_animation = G_MAXINT;
1023 change_sun(actor, desktop_plugin);
1024 scene.actors = g_slist_append(scene.actors, actor);
1027 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
1028 TRUE, 100, 255, NULL, NULL);
1029 scene.actors = g_slist_append(scene.actors, actor);
1032 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
1033 FALSE, 100, 255, (gpointer)&change_moon, NULL);
1034 change_moon(actor, desktop_plugin);
1035 scene.actors = g_slist_append(scene.actors, actor);
1037 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
1038 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1039 actor->time_start_animation = now + fast_rnd(180);
1040 actor->duration_animation = 3*60;
1041 scene.actors = g_slist_append(scene.actors, actor);
1043 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
1044 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1045 actor->time_start_animation = now + fast_rnd(180);
1046 actor->duration_animation = 3*60;
1047 scene.actors = g_slist_append(scene.actors, actor);
1049 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
1050 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
1051 actor->time_start_animation = now + fast_rnd(180);
1052 actor->duration_animation = 5*60;
1053 scene.actors = g_slist_append(scene.actors, actor);
1056 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
1057 FALSE, 100, 255, (gpointer)&change_plane2, NULL);
1058 actor->time_start_animation = now/* + probability_plane()*/;
1059 actor->duration_animation = 60;
1060 scene.actors = g_slist_append(scene.actors, actor);
1062 actor = init_object(desktop_plugin, "plane1", "tu154_small.png", 620, 233, 9, 300, 116,
1063 FALSE, 100, 255, (gpointer)&change_plane1, NULL);
1064 actor->time_start_animation = now + probability_plane();
1065 actor->duration_animation = 30;
1066 scene.actors = g_slist_append(scene.actors, actor);
1068 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
1069 TRUE, 100, 255, (gpointer)&change_static_actor_with_corner, NULL);
1070 change_static_actor_with_corner(actor, desktop_plugin);
1071 scene.actors = g_slist_append(scene.actors, actor);
1073 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
1074 FALSE, 100, 255, (gpointer)&change_wind, NULL);
1075 change_wind(actor, desktop_plugin);
1076 scene.actors = g_slist_append(scene.actors, actor);
1082 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
1084 gint y0 = 365;// - уровень горизонта
1085 *x = (int)(azm * 800) - 64;
1086 *y = (int)((1 - alt) * y0) - 64;
1087 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
1091 change_actor(GtkWidget * actor)
1094 gint x, y, daytime, scale;
1101 void (*pfunc)(gpointer, gpointer);
1103 name = g_object_get_data(G_OBJECT(actor), "name");
1104 fprintf(stderr, "change actor %s\n", name);
1106 pfunc = g_object_get_data(G_OBJECT(actor), "func");
1108 (*pfunc)(actor, g_strdup(name));
1109 daytime = get_daytime();
1110 if (daytime != TIME_NIGHT){
1111 hildon_animation_actor_set_show(actor, 1);
1112 get_sun_pos(&alt, &azm);
1113 get_sun_screen_pos(alt, azm, &x, &y);
1114 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1118 if (name == "cloud1"){
1119 x = g_object_get_data(G_OBJECT(actor), "x");
1120 y = g_object_get_data(G_OBJECT(actor), "y");
1121 scale = g_object_get_data(G_OBJECT(actor), "scale");
1124 image = g_object_get_data(G_OBJECT(actor), "image");
1126 gtk_container_remove(actor, image);
1127 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
1132 image = gtk_image_new_from_pixbuf (pixbuf);
1133 g_object_unref(G_OBJECT(pixbuf));
1135 g_signal_connect(G_OBJECT(image), "expose_event",
1136 G_CALLBACK(expose_event), pixbuf);
1137 gtk_container_add (GTK_CONTAINER (actor), image);
1139 gtk_widget_show_all(actor);
1151 sc = (double)scale / 100;
1152 hildon_animation_actor_set_scale(actor, sc, sc);
1153 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
1154 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
1155 g_object_set_data(G_OBJECT(actor), "x", x);
1156 g_object_set_data(G_OBJECT(actor), "y", y);
1157 g_object_set_data(G_OBJECT(actor), "scale", scale);
1163 short_timeout (AWallpaperPlugin *desktop_plugin)
1165 gint daytime = get_daytime();
1167 void (*pfunc)(gpointer, gpointer);
1170 gboolean stop_flag = TRUE;
1172 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
1173 desktop_plugin->priv->short_timer = 0;
1178 //scene.daytime = daytime;
1179 /* fprintf(stderr, "Short timer %d\n", now); */
1181 while (tmp != NULL){
1183 if (now >= actor->time_start_animation
1184 && actor->time_start_animation > 0
1185 /* && now - actor->time_start_animation <= actor->duration_animation*/){
1186 pfunc = actor->func_change;
1188 (*pfunc)(actor, desktop_plugin);
1192 tmp = g_slist_next(tmp);
1195 desktop_plugin->priv->short_timer = 0;
1198 return TRUE; /* keep running this event */
1202 run_long_timeout(AWallpaperPlugin *desktop_plugin){
1204 gint daytime = get_daytime();
1206 void (*pfunc)(gpointer, gpointer);
1211 //fprintf(stderr, "timer daytime=%d\n", daytime);
1212 if (scene.daytime != daytime){
1213 scene.daytime = daytime;
1215 while (tmp != NULL){
1216 //change_actor(tmp->data);
1217 pfunc =((Actor*)tmp->data)->func_change;
1219 (*pfunc)(tmp->data, desktop_plugin);
1221 tmp = g_slist_next(tmp);
1226 //fprintf(stderr, "Now %d\n", now);
1228 while (tmp != NULL){
1230 if (now >= actor->time_start_animation
1231 && actor->time_start_animation > 0
1232 && desktop_plugin->priv->short_timer == 0){
1233 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
1234 if (desktop_plugin->priv->rich_animation){
1235 actor->time_start_animation = now;
1236 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
1239 (*actor->func_change)(actor, desktop_plugin);
1242 tmp = g_slist_next(tmp);
1248 long_timeout (AWallpaperPlugin *desktop_plugin)
1250 /* fprintf(stderr, "long_timeout %i\n", desktop_plugin->priv->long_timer); */
1251 if (desktop_plugin->priv->long_timer == 0 )
1253 if (!desktop_plugin->priv->visible){
1254 if(desktop_plugin->priv->short_timer != 0){
1255 g_source_remove(desktop_plugin->priv->short_timer);
1256 desktop_plugin->priv->short_timer = 0;
1258 desktop_plugin->priv->long_timer = 0;
1263 run_long_timeout(desktop_plugin);
1264 return TRUE; /* keep running this event */
1268 desktop_plugin_visible_notify (GObject *object,
1270 AWallpaperPlugin *desktop_plugin)
1273 g_object_get (object, "is-on-current-desktop", &visible, NULL);
1274 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1276 desktop_plugin->priv->visible = TRUE;
1277 if (desktop_plugin->priv->long_timer == 0 ){
1278 desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1279 run_long_timeout(desktop_plugin);
1282 desktop_plugin->priv->visible = FALSE;
1283 if (desktop_plugin->priv->long_timer != 0 ){
1284 g_source_remove(desktop_plugin->priv->long_timer);
1285 desktop_plugin->priv->long_timer = 0;
1291 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1292 gpointer user_data){
1293 fprintf(stderr,"gggggggggggggggggggg2222\n");
1296 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1298 GtkWidget *rich_animation;
1302 fprintf(stderr, "!!!!!!!plugin init \n");
1303 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1304 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1308 priv->desktop_plugin = desktop_plugin;
1309 desktop_plugin->priv->main_widget = gtk_fixed_new();
1311 gtk_widget_set_size_request(desktop_plugin->priv->main_widget, 100, 32);
1312 desktop_plugin->priv->right_corner = NULL;
1313 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/%s", THEME_PATH, desktop_plugin->priv->theme, "town0_right_corner.png");
1314 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
1315 if (desktop_plugin->priv->right_corner){
1316 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
1317 gtk_widget_show (desktop_plugin->priv->right_corner);
1319 /* Create rich animation event */
1320 rich_animation = gtk_event_box_new();
1322 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1323 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1324 gtk_widget_set_size_request(rich_animation, 100, 32);
1325 gtk_widget_show (rich_animation);
1326 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1327 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), rich_animation, 0, 0);
1330 GtkWidget *label = gtk_label_new ("ddddddddddddd");
1331 gtk_widget_set_size_request(label, 95, 30);
1332 gtk_widget_show (label);
1333 // gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1334 gtk_fixed_put(GTK_FIXED(widget), label, 0, 0);
1336 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1337 g_signal_connect (desktop_plugin, "show-settings",
1338 G_CALLBACK (lw_settings), priv);
1339 gtk_widget_show (desktop_plugin->priv->main_widget);
1340 gtk_container_add (GTK_CONTAINER (desktop_plugin), desktop_plugin->priv->main_widget);
1341 init_applet_position();
1344 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1345 if (!strcmp(priv->theme,"Modern"))
1346 init_scene(desktop_plugin);
1347 else if (!strcmp(priv->theme,"Berlin"))
1348 init_scene1(desktop_plugin);
1349 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1350 priv->short_timer = 0;
1351 /* TODO Move scene to priv */
1352 scene.timer_type = LONG_TIMER_TYPE;
1353 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1354 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1361 lw_applet_finalize (GObject *object)
1363 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1364 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1366 fprintf(stderr,"finalaze %i\n", priv->long_timer);
1367 if (priv->long_timer){
1368 g_source_remove(priv->long_timer);
1369 priv->long_timer = 0;
1371 if (priv->short_timer){
1372 g_source_remove(priv->short_timer);
1373 priv->short_timer = 0;
1380 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1382 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1383 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1386 gobject_class->destroy = (gpointer)lw_applet_finalize;
1387 widget_class->realize = lw_applet_realize;
1388 widget_class->expose_event = lw_applet_expose_event;
1390 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1395 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {