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);
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 (!actor->visible){
382 actor->visible = TRUE;
383 if (scene.daytime == TIME_NIGHT){
385 g_free(actor->filename);
386 actor->filename = g_strdup("tu154.png");
389 g_free(actor->filename);
390 actor->filename = g_strdup("tu154.png");
392 create_hildon_actor(actor, desktop_plugin);
394 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
395 x = path_line(x0, x1, t);
396 y = path_line(y0, y1, t);
397 //scale = path_line(scale0, scale1, t);
398 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
399 actor_set_position_full(actor->widget, x, y, actor->z);
400 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
403 actor->visible = FALSE;
404 destroy_hildon_actor(actor);
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);
427 if (!actor->visible){
428 actor->visible = TRUE;
429 if (scene.daytime == TIME_NIGHT){
431 g_free(actor->filename);
432 if (scene.daytime == TIME_NIGHT)
433 actor->filename = g_strdup("plane3.png");
436 g_free(actor->filename);
437 actor->filename = g_strdup("plane3.png");
439 create_hildon_actor(actor, desktop_plugin);
441 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
442 x = path_line(x0, x1, t);
443 y = path_line(y0, y1, t);
444 //scale = path_line(scale0, scale1, t);
445 //fprintf(stderr, "change tram t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
446 actor_set_position_full(actor->widget, x, y, actor->z);
447 //hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
450 actor->visible = FALSE;
451 destroy_hildon_actor(actor);
452 actor->time_start_animation = sec + probability_plane();
458 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
460 gint x0, y0 = 300, scale0 = 100,
461 x1, y1 = -actor->height, scale1 = 150,
468 gettimeofday(&tvb, NULL);
472 //fprintf(stderr, "c1oud %s - y0=%d\n", actor->name, actor->y);
474 if (!actor->visible){
475 actor->visible = TRUE;
476 if (scene.daytime == TIME_NIGHT)
477 actor->filename = actor->filename;
479 actor->filename = actor->filename;
480 create_hildon_actor(actor, desktop_plugin);
482 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
484 if (scene.wind_orientation == 1){
493 x = path_line(x0, x1, t);
494 y = -scene.wind_angle * (x - x0) + actor->y;
495 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
497 //fprintf(stderr, "change cloud t=%f x=%d y=%d scale=%d\n", t, x, y, scale);
498 actor_set_position_full(actor->widget, x, y, actor->z);
499 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(actor->widget), (double)scale/100, (double)scale/100);
500 if ((y < y1 || y > y0) || t >= 1){
502 actor->visible = FALSE;
503 destroy_hildon_actor(actor);
504 actor->time_start_animation = sec + fast_rnd(300);
505 actor->y = fast_rnd(300);
511 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
513 scene.wind_orientation = fast_rnd(2) - 1;
514 scene.wind_angle = (double)(fast_rnd(400) - 200) / 100;
515 actor->time_start_animation = time(NULL) + (fast_rnd(20) + 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 create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
522 GtkWidget *ha = NULL;
523 GdkPixbuf *pixbuf = NULL;
524 GtkWidget *image = NULL;
527 /* fprintf(stderr, "create_hildon_actor %s\n", actor->name);*/
528 ha = hildon_animation_actor_new();
529 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
530 desktop_plugin->priv->theme, actor->filename);
531 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
538 image = gtk_image_new_from_pixbuf (pixbuf);
539 g_object_unref(G_OBJECT(pixbuf));
542 g_signal_connect(G_OBJECT(image), "expose_event",
543 G_CALLBACK(expose_event), pixbuf);
544 gtk_container_add (GTK_CONTAINER (ha), image);
546 actor_set_position_full(ha, actor->x, actor->y, actor->z);
547 hildon_animation_actor_set_show (HILDON_ANIMATION_ACTOR(ha), actor->visible);
548 hildon_animation_actor_set_scale(HILDON_ANIMATION_ACTOR(ha), (double)actor->scale/100, (double)actor->scale/100);
550 gtk_widget_show_all(ha);
555 //g_object_set_data(G_OBJECT(ha), "name", name);
556 //g_object_set_data(G_OBJECT(ha), "filename", filename);
557 g_object_set_data(G_OBJECT(ha), "image", image);
559 g_object_set_data(G_OBJECT(ha), "x", x);
560 g_object_set_data(G_OBJECT(ha), "y", y);
561 g_object_set_data(G_OBJECT(ha), "z", z);
562 g_object_set_data(G_OBJECT(ha), "width", width);
563 g_object_set_data(G_OBJECT(ha), "height", height);
564 g_object_set_data(G_OBJECT(ha), "scale", scale);
565 g_object_set_data(G_OBJECT(ha), "visible", visible);
566 g_object_set_data(G_OBJECT(ha), "opacity", opacity);
567 g_object_set_data(G_OBJECT(ha), "func", pfunc);
569 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin));
575 change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
577 GtkWidget *image = NULL;
578 GdkPixbuf *pixbuf = NULL;
581 str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
582 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 if (g_object_get_data(G_OBJECT(actor->widget), "image")){
598 gtk_container_remove(GTK_CONTAINER(actor->widget), g_object_get_data(G_OBJECT(actor->widget), "image"));
600 g_object_set_data(G_OBJECT(actor->widget), "image", image);
601 gtk_container_add (GTK_CONTAINER (actor->widget), image);
602 realize(actor->widget);
603 gtk_widget_show_all(actor->widget);
614 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
619 daytime = get_daytime();
620 newfile = g_strdup_printf("%s%d.png", actor->name, daytime);
622 g_free(actor->filename);
623 actor->filename = newfile;
624 change_hildon_actor(actor, desktop_plugin);
632 // уравнение изменения времени
638 GSList * tmp = scene.actors;
644 g_free(actor->filename);
647 gtk_widget_destroy(actor->widget);
648 //actor->widget = NULL;
651 tmp = g_slist_next(tmp);
658 reload_scene(AWallpaperPlugin *desktop_plugin)
660 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
662 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
663 init_scene(desktop_plugin);
664 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
665 init_scene1(desktop_plugin);
669 /* Init Modern Scene */
671 init_scene(AWallpaperPlugin *desktop_plugin)
674 gint now = time(NULL);
676 /* fprintf(stderr, "init scene \n");*/
677 scene.daytime = get_daytime();
679 scene.wind_orientation = -1;
680 scene.wind_angle = 0.3;
683 actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480,
684 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
685 change_static_actor(actor, desktop_plugin);
686 scene.actors = g_slist_append(scene.actors, actor);
688 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
689 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
690 actor->time_start_animation = time(NULL);
691 actor->duration_animation = G_MAXINT;
692 change_sun(actor, desktop_plugin);
693 scene.actors = g_slist_append(scene.actors, actor);
695 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
696 TRUE, 100, 255, NULL, NULL);
697 scene.actors = g_slist_append(scene.actors, actor);
699 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
700 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
701 actor->time_start_animation = now + fast_rnd(180);
702 actor->duration_animation = 5*60;
703 scene.actors = g_slist_append(scene.actors, actor);
705 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
706 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
707 actor->time_start_animation = now + fast_rnd(180);
708 actor->duration_animation = 5*60;
709 scene.actors = g_slist_append(scene.actors, actor);
711 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
712 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
713 actor->time_start_animation = now + fast_rnd(180);
714 actor->duration_animation = 5*60;
715 scene.actors = g_slist_append(scene.actors, actor);
718 actor = init_object(desktop_plugin, "town", "town0.png", 0, 0, 8, 800, 480,
719 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
720 change_static_actor(actor, desktop_plugin);
721 scene.actors = g_slist_append(scene.actors, actor);
723 actor = init_object(desktop_plugin, "tram", "tram.png", -300, 225, 9, 350, 210,
724 FALSE, 100, 255, (gpointer)&change_tram, NULL);
725 actor->time_start_animation = time(NULL) + fast_rnd(60);
726 actor->duration_animation = 60;
727 scene.actors = g_slist_append(scene.actors, actor);
729 actor = init_object(desktop_plugin, "border", "border0.png", 0, 480-79, 10, 800, 79,
730 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
731 change_static_actor(actor, desktop_plugin);
732 scene.actors = g_slist_append(scene.actors, actor);
734 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 20, 6, 60, 60,
735 FALSE, 100, 255, (gpointer)&change_moon, NULL);
736 change_moon(actor, desktop_plugin);
737 scene.actors = g_slist_append(scene.actors, actor);
739 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
740 FALSE, 100, 255, (gpointer)&change_wind, NULL);
741 change_wind(actor, desktop_plugin);
742 scene.actors = g_slist_append(scene.actors, actor);
745 anim = g_new0(Animation, 1);
748 anim->func_change = &change_tram;
749 anim->func_time = NULL;
750 anim->timestart = time(NULL);
753 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
757 /* Init Berlin Scene */
759 init_scene1(AWallpaperPlugin *desktop_plugin)
762 gint now = time(NULL);
765 scene.daytime = get_daytime();
767 scene.wind_orientation = -1;
768 scene.wind_angle = 0.3;
770 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
771 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
772 change_static_actor(actor, desktop_plugin);
773 scene.actors = g_slist_append(scene.actors, actor);
776 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
777 TRUE, 100, 255, (gpointer)&change_sun, &probability_sun);
778 actor->time_start_animation = time(NULL);
779 actor->duration_animation = G_MAXINT;
780 change_sun(actor, desktop_plugin);
781 scene.actors = g_slist_append(scene.actors, actor);
784 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
785 TRUE, 100, 255, NULL, NULL);
786 scene.actors = g_slist_append(scene.actors, actor);
789 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
790 FALSE, 100, 255, (gpointer)&change_moon, NULL);
791 change_moon(actor, desktop_plugin);
792 scene.actors = g_slist_append(scene.actors, actor);
794 actor = init_object(desktop_plugin, "cloud1", "cloud2.png", 0, fast_rnd(300), 7, 188, 75,
795 FALSE, 100, 255, (gpointer)&change_cloud, NULL);
796 actor->time_start_animation = now + fast_rnd(3) * 60;
797 actor->duration_animation = 5*60;
798 scene.actors = g_slist_append(scene.actors, actor);
800 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
801 FALSE, 100, 255, (gpointer)&change_plane2, NULL);
802 actor->time_start_animation = now + probability_plane();
803 actor->duration_animation = 60;
804 scene.actors = g_slist_append(scene.actors, actor);
806 actor = init_object(desktop_plugin, "plane1", "tu154_small.png", 620, 233, 9, 300, 116,
807 FALSE, 100, 255, (gpointer)&change_plane1, NULL);
808 actor->time_start_animation = now + probability_plane();
809 actor->duration_animation = 30;
810 scene.actors = g_slist_append(scene.actors, actor);
812 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
813 TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
814 change_static_actor(actor, desktop_plugin);
815 scene.actors = g_slist_append(scene.actors, actor);
822 get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
824 gint y0 = 365;// - уровень горизонта
825 *x = (int)(azm * 800) - 64;
826 *y = (int)((1 - alt) * y0) - 64;
827 //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
831 change_actor(GtkWidget * actor)
834 gint x, y, daytime, scale;
841 void (*pfunc)(gpointer, gpointer);
843 name = g_object_get_data(G_OBJECT(actor), "name");
844 fprintf(stderr, "change actor %s\n", name);
846 pfunc = g_object_get_data(G_OBJECT(actor), "func");
848 (*pfunc)(actor, g_strdup(name));
849 daytime = get_daytime();
850 if (daytime != TIME_NIGHT){
851 hildon_animation_actor_set_show(actor, 1);
852 get_sun_pos(&alt, &azm);
853 get_sun_screen_pos(alt, azm, &x, &y);
854 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
858 if (name == "cloud1"){
859 x = g_object_get_data(G_OBJECT(actor), "x");
860 y = g_object_get_data(G_OBJECT(actor), "y");
861 scale = g_object_get_data(G_OBJECT(actor), "scale");
864 image = g_object_get_data(G_OBJECT(actor), "image");
866 gtk_container_remove(actor, image);
867 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/livewp/theme/Modern/sun.png",
872 image = gtk_image_new_from_pixbuf (pixbuf);
873 g_object_unref(G_OBJECT(pixbuf));
875 g_signal_connect(G_OBJECT(image), "expose_event",
876 G_CALLBACK(expose_event), pixbuf);
877 gtk_container_add (GTK_CONTAINER (actor), image);
879 gtk_widget_show_all(actor);
891 sc = (double)scale / 100;
892 hildon_animation_actor_set_scale(actor, sc, sc);
893 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, sc);
894 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
895 g_object_set_data(G_OBJECT(actor), "x", x);
896 g_object_set_data(G_OBJECT(actor), "y", y);
897 g_object_set_data(G_OBJECT(actor), "scale", scale);
903 short_timeout (AWallpaperPlugin *desktop_plugin)
905 gint daytime = get_daytime();
907 void (*pfunc)(gpointer, gpointer);
910 gboolean stop_flag = TRUE;
912 if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
913 desktop_plugin->priv->short_timer = 0;
918 //scene.daytime = daytime;
919 /* fprintf(stderr, "Short timer %d\n", now); */
923 if (now >= actor->time_start_animation
924 && actor->time_start_animation > 0
925 /* && now - actor->time_start_animation <= actor->duration_animation*/){
926 pfunc = actor->func_change;
928 (*pfunc)(actor, desktop_plugin);
932 tmp = g_slist_next(tmp);
935 desktop_plugin->priv->short_timer = 0;
938 return TRUE; /* keep running this event */
943 long_timeout (AWallpaperPlugin *desktop_plugin)
945 gint daytime = get_daytime();
947 void (*pfunc)(gpointer, gpointer);
951 /* TODO remove timeout */
952 if (!desktop_plugin->priv->visible){
953 desktop_plugin->priv->short_timer = 0;
956 //fprintf(stderr, "timer daytime=%d\n", daytime);
957 if (scene.daytime != daytime){
960 //change_actor(tmp->data);
961 pfunc =((Actor*)tmp->data)->func_change;
963 (*pfunc)(tmp->data, desktop_plugin);
965 tmp = g_slist_next(tmp);
970 //fprintf(stderr, "Now %d\n", now);
974 if (now >= actor->time_start_animation
975 && actor->time_start_animation > 0
976 && desktop_plugin->priv->short_timer == 0){
977 actor->time_start_animation = now;
978 /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
979 if (desktop_plugin->priv->rich_animation)
980 desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
982 tmp = g_slist_next(tmp);
985 scene.daytime = daytime;
987 return TRUE; /* keep running this event */
991 desktop_plugin_visible_notify (GObject *object,
993 AWallpaperPlugin *desktop_plugin)
996 g_object_get (object, "is-on-current-desktop", &visible, NULL);
998 desktop_plugin->priv->visible = TRUE;
999 desktop_plugin->priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1001 desktop_plugin->priv->visible = FALSE;
1002 /* fprintf (stderr, "is-on-current-desktop changed. visible: %u", visible); */
1006 rich_animation_press(GtkWidget *widget, GdkEvent *event,
1007 gpointer user_data){
1008 fprintf(stderr,"gggggggggggggggggggg\n");
1011 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
1014 GtkWidget *rich_animation;
1015 fprintf(stderr, "!!!!!!!plugin init \n");
1016 Animation_WallpaperPrivate *priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1017 desktop_plugin->priv = Animation_Wallpaper_HOME_PLUGIN_GET_PRIVATE (desktop_plugin);
1020 priv->desktop_plugin = desktop_plugin;
1021 /* Create rich animation event */
1022 rich_animation = gtk_event_box_new();
1024 gtk_widget_set_events(rich_animation, GDK_BUTTON_PRESS_MASK);
1025 gtk_event_box_set_visible_window(GTK_EVENT_BOX(rich_animation), FALSE);
1026 gtk_widget_set_size_request(rich_animation, 95, 30);
1027 gtk_widget_show (rich_animation);
1028 g_signal_connect(rich_animation, "button-press-event", G_CALLBACK(rich_animation_press), desktop_plugin);
1031 label = gtk_label_new ("");
1032 gtk_widget_set_size_request(label, 95, 30);
1033 gtk_widget_show (label);
1034 gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
1036 hd_home_plugin_item_set_settings (HD_HOME_PLUGIN_ITEM (desktop_plugin), TRUE);
1037 g_signal_connect (desktop_plugin, "show-settings",
1038 G_CALLBACK (lw_settings), priv);
1039 g_signal_connect (desktop_plugin, "notify::is-on-current-desktop",
1040 G_CALLBACK (desktop_plugin_visible_notify), desktop_plugin);
1042 gtk_container_add (GTK_CONTAINER (desktop_plugin), rich_animation);
1043 init_applet_position();
1045 /* start value for random */
1048 fprintf(stderr, "!!!theme = %s\n", priv->theme);
1049 if (!strcmp(priv->theme,"Modern"))
1050 init_scene(desktop_plugin);
1051 else if (!strcmp(priv->theme,"Berlin"))
1052 init_scene1(desktop_plugin);
1053 priv->long_timer = g_timeout_add(LONG_TIMER, (GtkFunction)long_timeout, desktop_plugin);
1054 priv->short_timer = 0;
1055 /* TODO Move scene to priv */
1056 scene.timer_type = LONG_TIMER_TYPE;
1062 lw_applet_finalize (GObject *object)
1064 AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object);
1065 Animation_WallpaperPrivate *priv = desktop_plugin->priv;
1067 if (priv->long_timer){
1068 g_source_remove(priv->long_timer);
1069 priv->long_timer = 0;
1071 if (priv->short_timer){
1072 g_source_remove(priv->short_timer);
1073 priv->short_timer = 0;
1080 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {
1082 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1083 GtkObjectClass *gobject_class = GTK_OBJECT_CLASS (klass);
1086 gobject_class->destroy = (gpointer)lw_applet_finalize;
1087 widget_class->realize = lw_applet_realize;
1088 widget_class->expose_event = lw_applet_expose_event;
1090 g_type_class_add_private (klass, sizeof (Animation_WallpaperPrivate));
1095 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {}