checked some warnings
[livewp] / applet / src / livewp-actor.c
1 /*vim: set sw=4 ts=4 et: */
2 /*
3  * This file is part of Live Wallpaper (livewp)
4  * 
5  * Copyright (C) 2010 Vlad Vasiliev
6  * Copyright (C) 2010 Tanya Makova
7  *       for the code
8  * 
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.
13  * 
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.
18  * 
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
22  * 02110-1301 USA
23 */
24 /*******************************************************************************/
25 #include "livewp-actor.h"
26
27 Actor* 
28 init_object(AWallpaperPlugin *desktop_plugin, 
29             gchar * name, 
30             gchar * filename, 
31             gint x, 
32             gint y, 
33             gint z, 
34             gint width, 
35             gint height, 
36             gboolean visible, 
37             gboolean load_image,
38             gint scale, 
39             gint opacity, 
40             void (*pfunc_change)(Actor*),
41             void (*pfunc_probability)(Actor*),
42             GPtrArray *child
43            )
44 {
45     Actor *actor = NULL;
46     actor = g_new0(Actor, 1);
47     actor->x = x;
48     actor->y = y;
49     actor->z = z;
50     actor->width = width;
51     actor->height = height;
52     actor->visible = visible;
53     actor->scale = scale;
54     actor->opacity = opacity;
55     actor->filename = g_strdup(filename);
56     actor->name = g_strdup(name);
57     actor->func_change = (gpointer)pfunc_change; 
58     actor->func_probability = (gpointer)pfunc_probability;
59     actor->child = child;
60     if (load_image)
61         create_hildon_actor(actor, desktop_plugin);
62     else 
63          actor->widget = NULL;
64     actor->time_start_animation = 0;
65     actor->duration_animation = 0;
66     return actor;
67 }
68
69 void 
70 destroy_actor(Actor *actor)
71 {
72     if (actor){
73         if (actor->child){
74             g_ptr_array_free(actor->child, TRUE);
75         }
76         if (actor->filename)
77             g_free(actor->filename);
78         if (actor->name)
79             g_free(actor->name);
80         gtk_widget_destroy(actor->widget);
81         //actor->widget = NULL;
82         g_free(actor);
83     }
84 }
85 static gint 
86 path_line(gint x0, gint x1, double t)
87 {
88     // уравниение прямой
89     return ((x1 - x0) * t + x0);
90 }
91 void
92 set_actor_scale(Actor *actor, double scalex, double scaley)
93 {
94     hildon_animation_actor_set_scale(
95             HILDON_ANIMATION_ACTOR(actor->widget), 
96             scalex, 
97             scaley
98     );
99
100 }
101 void
102 set_actor_rotation(Actor *actor, gint axis, double degrees, gint x, gint y, gint z)
103 {
104     hildon_animation_actor_set_rotation(
105             HILDON_ANIMATION_ACTOR(actor->widget),
106             axis,
107             degrees,
108             x,
109             y,
110             z
111     );
112 }
113 void 
114 set_actor_visible(Actor *actor, gboolean visible)
115 {
116     hildon_animation_actor_set_show(HILDON_ANIMATION_ACTOR(actor->widget), visible);
117 }
118
119 void
120 set_actor_position(Actor *actor, gint x, gint y, gint z, AWallpaperPlugin *desktop_plugin)
121 {
122     hildon_animation_actor_set_position_full(HILDON_ANIMATION_ACTOR (actor->widget), 
123                                              x-desktop_plugin->priv->xapplet, 
124                                              y-desktop_plugin->priv->yapplet, 
125                                              z);
126 }
127
128 int get_notify_count(gchar *notify_type)
129 {
130     sqlite3 *db = NULL;
131     sqlite3_stmt *res = NULL;
132     gint rc = 0, result = 0;
133     gchar sql[1024];
134
135     rc = sqlite3_open("/home/user/.config/hildon-desktop/notifications.db", &db);
136     if (rc){
137         fprintf(stderr, "error open db %d %s\n", rc, sqlite3_errmsg(db));
138     }else {
139         snprintf(sql, sizeof(sql)-1, "select count(id) from notifications where icon_name='%s'", notify_type);
140         rc = sqlite3_prepare(db, sql, sizeof(sql)-1, &res, NULL);
141         if (rc != SQLITE_OK){
142             fprintf(stderr, "error prepare %d %s\n", rc, sql);
143         }
144         if (sqlite3_step(res) != SQLITE_ROW){
145             fprintf(stderr, "not sqlite_row\n");
146         }
147         result = sqlite3_column_int(res, 0);
148         //fprintf(stderr, "count missing calls = %d\n", call_count);
149         sqlite3_finalize(res);
150
151         sqlite3_close(db);
152     }
153     return result;
154 }
155 gchar * read_notification()
156 {
157     gchar *message = "";
158     gint count = 0;
159     
160     fprintf(stderr, "read notification \n");
161     count = get_notify_count("general_missed");
162     if (count > 0){
163         message = g_strdup_printf("%s: %d", _("Missed calls"), count);
164     }
165     count = get_notify_count("general_sms");
166     if (count > 0){
167         if (message){
168             message = g_strdup_printf("%s \n%s: %d", message, _("Missed sms"), count);
169         }else {
170             message = g_strdup_printf("%s: %d", _("Missed sms"), count);
171         }
172     }
173     count = get_notify_count("general_chat");
174     if (count > 0){
175         if (message){
176             message = g_strdup_printf("%s \n%s: %d", message, _("Missed chat"), count);
177         }else {
178             message = g_strdup_printf("%s: %d", _("Missed chat"), count);
179         }
180     }
181     count = get_notify_count("qgn_list_messagin");
182     if (count > 0){
183         if (message){
184             message = g_strdup_printf("%s \n%s: %d", message, _("Missed mail"), count);
185         }else {
186             message = g_strdup_printf("%s: %d", _("Missed mail"), count);
187         }
188     }
189     fprintf(stderr, "notify=%s\n", message);
190     return message;
191 }
192
193 void
194 change_obj(Actor *actor, AWallpaperPlugin *desktop_plugin)
195 {
196     char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
197     //char * accel_filename = "/home/tanya/coord";
198
199     FILE *fd = NULL;
200     int rs, ax, ay, az, dx, dy;
201     fd = fopen(accel_filename, "r");
202     if (fd == NULL){
203         fprintf(stderr, "cannot open file\n");
204         return;
205     }
206     rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
207     fclose(fd);
208     if (rs != 3){
209         fprintf(stderr, "cannot read information from file\n");
210         return;
211     }
212
213     fprintf(stderr, "change obj %i %i %i\n", ax, ay, az);
214     dx = -ax / 100;
215     dy = -ay / 100;
216
217     actor->x = actor->x + dx;
218     actor->y = actor->y + dy;
219
220     if (actor->x > 800) actor->x = 0;
221     if (actor->x < 0) actor->x = 800;
222
223     if (actor->y > 480) actor->y = 0;
224     if (actor->y < 0) actor->y = 480;
225
226     set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
227
228
229 }
230
231 void 
232 change_billboard(Actor * actor, AWallpaperPlugin *desktop_plugin)
233 {
234     gint count = 0;
235     Actor *a = NULL;
236      
237     //fprintf(stderr, "change_billboard\n");   
238     
239     if (desktop_plugin->priv->scene->notification < time(NULL)){
240         count = get_notify_count("general_missed");
241         a = g_ptr_array_index(actor->child, 0);
242         if (count > 0){
243             set_actor_visible(a, TRUE);            
244         }else {
245             set_actor_visible(a, FALSE);
246         }
247         count = get_notify_count("general_sms");
248         a = g_ptr_array_index(actor->child, 3);
249         if (count > 0){
250             set_actor_visible(a, TRUE);            
251         }else {
252             set_actor_visible(a, FALSE);
253         }
254         count = get_notify_count("general_chat");
255         a = g_ptr_array_index(actor->child, 1);
256         if (count > 0){
257             set_actor_visible(a, TRUE);            
258         }else {
259             set_actor_visible(a, FALSE);
260         }
261         count = get_notify_count("qgn_list_messagin");
262         a = g_ptr_array_index(actor->child, 2);
263         if (count > 0){
264             set_actor_visible(a, TRUE);            
265         }else {
266             set_actor_visible(a, FALSE);
267         }
268
269         desktop_plugin->priv->scene->notification = FALSE;
270     }
271     actor->time_start_animation = time(NULL) + 20;    
272 }
273
274 #if 0
275 void 
276 change_billboard1(Actor * actor, AWallpaperPlugin *desktop_plugin)
277 {
278     GtkWidget *label;
279     sqlite3 *db = NULL;
280     sqlite3_stmt *res = NULL;
281     gchar *errMsg = NULL, *message;
282     gchar sql[1024];
283     gint call_count=0, sms_count=0, rc=0;
284     GtkListStore *list = NULL;
285     PangoFontDescription *pfd = NULL;
286     
287     rc = sqlite3_open("/home/user/.rtcom-eventlogger/el.db", &db);
288     if (rc){
289         fprintf(stderr, "error open db %d %s\n", rc, sqlite3_errmsg(db));
290     }else {
291         snprintf(sql, sizeof(sql)-1, "select count(id) from Events where event_type_id=%d", 3);
292
293         rc = sqlite3_prepare(db, sql, sizeof(sql)-1, &res, NULL);
294         if (rc != SQLITE_OK){
295             fprintf(stderr, "error prepare %d %s\n", rc, sql);
296         }
297         if (sqlite3_step(res) != SQLITE_ROW){
298             fprintf(stderr, "not sqlite_row\n");
299         }
300         call_count = sqlite3_column_int(res, 0);
301         //fprintf(stderr, "count missing calls = %d\n", call_count);
302         sqlite3_finalize(res);
303
304         snprintf(sql, sizeof(sql)-1, "select count(id) from Events where event_type_id=%d and is_read=%d", 7, 0);
305         rc = sqlite3_prepare(db, sql, sizeof(sql)-1, &res, NULL);
306         if (rc != SQLITE_OK){
307             fprintf(stderr, "error prepare %d %s\n", rc, sql);
308         }
309         if (sqlite3_step(res) != SQLITE_ROW){
310             fprintf(stderr, "not sqlite_row\n");
311         }
312         sms_count = sqlite3_column_int(res, 0);
313         //fprintf(stderr, "count sms = %d\n", sms_count);
314         sqlite3_finalize(res);
315
316
317         sqlite3_close(db);
318     }
319     label = actor->image;
320     message = g_markup_printf_escaped("<span bgcolor=\"%s\" foreground=\"%s\">Missed calls: %d Unread sms: %d</span>", "#FFFFFF", "#000000", call_count, sms_count);
321     gtk_label_set_markup(GTK_LABEL(label), message);
322     g_free(message);
323     pfd = pango_font_description_from_string("Sans 14");
324     gtk_widget_modify_font(GTK_WIDGET(label), NULL);
325     gtk_widget_modify_font(GTK_WIDGET(label), pfd);
326     pango_font_description_free(pfd);
327     actor->time_start_animation = time(NULL) + 20;    
328 }
329 #endif
330
331 void 
332 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
333 {
334     gint phase;
335     char *newfile;
336     gint x0 = 150,
337          x1 = 650, 
338          x, y;
339     struct timeval tvb;     
340     suseconds_t ms;
341     long sec;
342     double t;
343 #if 0
344     gint y0, y1, x2, y2;
345     double a, b, c;
346     a = (double)(y2 - (double)(x2*(y1-y0) + x1*y0 - x0*y1)/(x1-x0))/(x2*(x2-x0-x1)+x0*x1);
347     b = (double)(y1-y0)/(x1-x0) - (double)a*(x0+x1);
348     c = (double)(x1*y0 - x0*y1)/(x1-x0) + (double)a*x0*x1;
349     fprintf(stderr, "a=%f, b=%f, c=%f\n", a, b, c);
350 #endif
351     gettimeofday(&tvb, NULL);
352     
353     ms = tvb.tv_usec;
354     sec = tvb.tv_sec;
355
356     if (actor){
357         if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
358             if (!actor->visible){
359                 actor->visible = TRUE;
360                 phase = get_moon_phase();
361                 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
362                 if (actor->filename)
363                     g_free(actor->filename);
364                 actor->filename = newfile;
365                 actor->time_start_animation = sec - fast_rnd(60 * 60);
366                 actor->duration_animation = 1 * 60 * 60;
367                 create_hildon_actor(actor, desktop_plugin);
368
369             }
370             t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
371             if (t <= 1)
372                 x = path_line(x0, x1, t);
373             else 
374                 x = path_line(x1, x0, t-1);
375             y = 0.001920*x*x - 1.536*x + 337.2;
376             //y = a*x*x + b*x + c;
377
378             set_actor_position(actor, x, y, actor->z, desktop_plugin);
379
380             if (t>=2){
381                 actor->time_start_animation = sec;
382             }
383
384          }else if (actor->visible){
385             actor->visible = FALSE;
386             fprintf(stderr, "destroy moon \n");
387             destroy_hildon_actor(actor);
388             actor->time_start_animation = 0;
389         } 
390     }
391     
392 }
393
394 void 
395 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
396 {
397     double alt, azm;
398     gint x, y;
399
400     //fprintf(stderr, "change sun\n");
401     if (actor){
402         if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
403             if (!actor->visible){
404                 actor->visible = TRUE;
405                 create_hildon_actor(actor, desktop_plugin);
406             }
407             get_sun_pos(&alt, &azm);
408             get_sun_screen_pos(alt, azm, &x, &y);
409             actor->x = x;
410             actor->y = y;
411             set_actor_position(actor, x, y, actor->z, desktop_plugin);
412             actor->time_start_animation = time(NULL) + 60;
413          }else if (actor->visible){
414             actor->visible = FALSE;
415             destroy_hildon_actor(actor);
416             actor->time_start_animation = 0;
417         } 
418     }
419     
420 }
421
422 void 
423 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
424 {
425     gint x0 = -300, y0 = 225, scale0 = 100,
426          x1 = 800, y1 = 162, scale1 = 130, 
427          x, y, scale;
428     struct timeval tvb;     
429     suseconds_t ms;
430     long sec;
431     double t;
432
433     //fprintf(stderr, "change tram\n");
434     gettimeofday(&tvb, NULL);
435     
436     ms = tvb.tv_usec;
437     sec = tvb.tv_sec;
438     
439     if (!actor->visible){
440         actor->visible = TRUE;
441         if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
442             if (actor->filename)
443                 g_free(actor->filename);
444             actor->filename = g_strdup("tram_dark.png");
445         } else{
446             if (actor->filename)
447                 g_free(actor->filename);
448             actor->filename = g_strdup("tram.png");
449         }
450         create_hildon_actor(actor, desktop_plugin);
451     }
452     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
453     x = path_line(x0, x1, t);
454     y = path_line(y0, y1, t);
455     scale = path_line(scale0, scale1, t);
456     set_actor_position(actor, x, y, actor->z, desktop_plugin);
457     set_actor_scale(actor, (double)scale/100, (double)scale/100);
458     if (t >= 1){
459         /* stop animation */
460         actor->visible = FALSE;
461         destroy_hildon_actor(actor);
462         actor->time_start_animation = sec + fast_rnd(60);
463     }
464 }
465
466 void
467 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
468 {
469     gint x0 = 620, y0 = 233,
470          x1 = 79, y1 = -146, 
471          x, y;
472     struct timeval tvb;     
473     suseconds_t ms;
474     long sec;
475     double t;
476
477     gettimeofday(&tvb, NULL);
478     
479     ms = tvb.tv_usec;
480     sec = tvb.tv_sec;
481 //    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
482    
483     if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
484         if (actor->time_start_animation == 0){
485             actor->time_start_animation = sec + fast_rnd(180);
486             return;
487         }
488     }
489     if (!actor->visible){
490         actor->visible = TRUE;
491         create_hildon_actor(actor, desktop_plugin);
492     }
493     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
494     x = path_line(x0, x1, t);
495     y = path_line(y0, y1, t);
496     //scale = path_line(scale0, scale1, t);
497     set_actor_position(actor, x, y, actor->z, desktop_plugin);
498     if (t >= 1){
499         /* stop animation */
500         actor->visible = FALSE;
501         destroy_hildon_actor(actor);
502         if (desktop_plugin->priv->scene->daytime == TIME_NIGHT) 
503             actor->time_start_animation = 0;
504         else 
505             actor->time_start_animation = sec + fast_rnd(180);
506     }
507
508 }
509
510 void
511 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
512 {
513     gint x0 = -actor->width, y0 = 45,
514          x1 = 800, y1 = 20, 
515          x, y;
516     struct timeval tvb;     
517     suseconds_t ms;
518     long sec;
519     double t;
520
521     gettimeofday(&tvb, NULL);
522     
523     ms = tvb.tv_usec;
524     sec = tvb.tv_sec;
525 //    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
526     if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
527         if (actor->time_start_animation == 0){
528             actor->time_start_animation = sec + fast_rnd(180);
529             return;
530         }
531     }
532     if (!actor->visible){
533         actor->visible = TRUE;
534         create_hildon_actor(actor, desktop_plugin);
535     }
536
537     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
538     x = path_line(x0, x1, t);
539     y = path_line(y0, y1, t);
540     //scale = path_line(scale0, scale1, t);
541     set_actor_position(actor, x, y, actor->z, desktop_plugin);
542     if (t >= 1){
543         /* stop animation */
544         actor->visible = FALSE;
545         destroy_hildon_actor(actor);
546         if (desktop_plugin->priv->scene->daytime == TIME_NIGHT) 
547             actor->time_start_animation = 0;
548         else 
549             actor->time_start_animation = sec + fast_rnd(180);
550     }
551
552 }
553
554 void
555 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
556 {
557     gint x0, y0 = 300, scale0 = 100,
558          x1, y1 = -actor->height, scale1 = 150, 
559          x, y, scale;
560     struct timeval tvb;     
561     suseconds_t ms;
562     long sec;
563     double t;
564     gchar *newfile;
565
566     //fprintf(stderr, "change cloud\n");
567     gettimeofday(&tvb, NULL);
568     
569     ms = tvb.tv_usec;
570     sec = tvb.tv_sec;
571    
572     if (!actor->visible){
573         actor->visible = TRUE;
574         if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
575             newfile = g_strdup_printf("%s_dark.png", actor->name);
576         }else{
577             newfile = g_strdup_printf("%s.png", actor->name);
578         } 
579         if (actor->filename)
580             g_free(actor->filename);
581         actor->filename = newfile;
582          
583         create_hildon_actor(actor, desktop_plugin);
584     }
585     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
586     
587     if (desktop_plugin->priv->scene->wind_orientation == 1){
588         x0 = -actor->width;
589         x1 = 800;
590     }
591     else {
592         x0 = 800;
593         x1 = -actor->width;
594     }
595
596     x = path_line(x0, x1, t);    
597     y = -desktop_plugin->priv->scene->wind_angle * (x - x0) + actor->y;
598     scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
599
600     set_actor_position(actor, x, y, actor->z, desktop_plugin);
601     set_actor_scale(actor, (double)scale/100, (double)scale/100);
602     if ((y < y1 || y > y0) || t >= 1){
603         /* stop animation */
604         actor->visible = FALSE;
605         destroy_hildon_actor(actor);
606         actor->time_start_animation = sec + fast_rnd(300);
607         actor->y = fast_rnd(300);
608     }
609
610 }
611
612 void
613 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
614 {
615     desktop_plugin->priv->scene->wind_orientation = fast_rnd(2);
616     if (desktop_plugin->priv->scene->wind_orientation == 0) desktop_plugin->priv->scene->wind_orientation = -1;
617     desktop_plugin->priv->scene->wind_angle = (double)(fast_rnd(200) - 100) / 100;
618     actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
619     //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
620 }
621
622 void 
623 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
624 {
625     gint now = time(NULL);
626     if (desktop_plugin->priv->scene->daytime == TIME_DAY){
627         if (actor->widget){
628             actor->visible = FALSE;
629             destroy_hildon_actor(actor);
630         }
631         actor->time_start_animation = 0;
632         return;
633     }else {
634         if (!actor->widget)
635             create_hildon_actor(actor, desktop_plugin);
636         if (actor->time_start_animation == 0){
637             actor->time_start_animation = now + fast_rnd(30);
638             return;
639         }
640     }
641
642     if (!actor->visible)
643         actor->visible = TRUE;
644     else 
645         actor->visible = FALSE;
646     set_actor_visible(actor, actor->visible);
647     actor->time_start_animation = now + fast_rnd(60) + 10;
648
649 }
650
651 void 
652 change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
653 {
654     gint now = time(NULL);
655     Actor *a;
656     a = g_ptr_array_index(actor->child, 0);
657     if (a->visible)
658         a->visible = FALSE;
659     else 
660         a->visible = TRUE;
661     set_actor_visible(a, a->visible);
662     
663     a = g_ptr_array_index(actor->child, 1);
664     if (a->visible)
665         a->visible = FALSE;
666     else 
667         a->visible = TRUE;
668     set_actor_visible(a, a->visible);
669
670     actor->time_start_animation = now + fast_rnd(30) + 10;
671 }
672
673 void
674 change_tape(Actor *actor, AWallpaperPlugin *desktop_plugin)
675 {
676     gint x, y, i;
677     Actor *a;
678
679     if (!desktop_plugin->priv->rich_animation) return;
680     
681     char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
682     //char * accel_filename = "/home/tanya/coord";
683
684     FILE *fd = NULL;
685     int rs, ax, ay, az;
686     fd = fopen(accel_filename, "r");
687     if (fd == NULL){
688         //fprintf(stderr, "cannot open file\n");
689         fd = fopen("/home/user/coord", "r"); 
690     }
691     rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
692     fclose(fd);
693     if (rs != 3){
694         fprintf(stderr, "cannot read information from file\n");
695         return;
696
697     }
698
699     //fprintf(stderr, "change obj %i %i %i angle rad=%f, deg=%f\n", ax, ay, az, atan2(ax, -ay), atan2(ax, -ay)*180/M_PI);
700     int ang = (int)floor(atan2(ay, ax)*180/M_PI);
701     if (ang < 0) ang = 360+ang;
702
703     if (!desktop_plugin->priv->rich_animation) return;
704
705     for (i=0; i<16; i++){
706         a = g_ptr_array_index(actor->child, i);
707         if (a->scale == 100) a->scale = ang;
708         if (abs(a->scale - ang) > 10){
709             if (a->scale > ang){
710                 if ((a->scale - ang) < (ang + (360-a->scale))) a->scale--;
711                 else a->scale++;
712             }
713             if (a->scale < ang) {
714                 if (ang - a->scale < (a->scale+(360-ang))) a->scale++;
715                 else a->scale--;
716             }
717             if (a->scale > 360) a->scale = 0;
718             if (a->scale < 0) a->scale = 360;
719         }
720     
721         x = a->x - (float)cos(a->scale*M_PI/180)*a->z;
722         y = a->y - (float)sin(a->scale*M_PI/180)*a->z;
723         //x = round(a->x - (float)cos(a->scale*M_PI/180)*a->z);
724         //y = round(a->y - (float)sin(a->scale*M_PI/180)*a->z);
725         //x = a->x - cos(angle)*a->z;
726         //y = a->y - sin(angle)*a->z;
727         if ((a->scale > 270 || a->scale < 90) && x < -a->width*cos(a->scale*M_PI/180)){ 
728             x = 800; 
729             y = fast_rnd(480);
730         } 
731         if ((a->scale > 90 && a->scale < 270) && x > 800 - a->width*cos(a->scale*M_PI/180)){
732             x = 0;
733             y = fast_rnd(480);
734         }
735         if (a->scale > 0 && a->scale < 180 && y < -a->width*sin(a->scale*M_PI/180)){
736             y = 480;
737             x = fast_rnd(800);
738         }
739         if (a->scale < 360 && a->scale > 180 && y > 480 - a->width*sin(a->scale*M_PI/180)){
740             y = 0;
741             x = fast_rnd(800);
742         }
743         //if (i ==0) fprintf(stderr, "x=%d y=%d ang=%d speed=%d\n", x, y, a->scale, a->z);
744         set_actor_rotation(a, HILDON_AA_Z_AXIS, a->scale, 0, 0, 0);
745         set_actor_position(a, x, y, a->z, desktop_plugin);
746         a->x = x;
747         a->y = y;
748     }
749     
750 }
751
752 void
753 change_layer(Actor * actor, AWallpaperPlugin *desktop_plugin)
754 {
755     gint y, speed1 = 8, speed2 = 16;
756     Actor *a;
757
758     if (!desktop_plugin->priv->rich_animation) return;
759
760     a = g_ptr_array_index(actor->child, 0);
761     y = a->y + speed1;
762     if (y > 480) y = -480;
763     set_actor_position(a, a->x, y, a->z, desktop_plugin);
764     a->y = y;
765     
766     a = g_ptr_array_index(actor->child, 1);
767     y = a->y + speed1;
768     if (y > 480) y = -480;
769     set_actor_position(a, a->x, y, a->z, desktop_plugin);
770     a->y = y;
771
772     a = g_ptr_array_index(actor->child, 2);
773     y = a->y + speed2;
774     if (y > 480) y = -480;
775     set_actor_position(a, a->x, y, a->z, desktop_plugin);
776     a->y = y;
777
778     a = g_ptr_array_index(actor->child, 3);
779     y = a->y + speed2;
780     if (y > 480) y = -480;
781     set_actor_position(a, a->x, y, a->z, desktop_plugin);
782     a->y = y;
783 }
784
785 void 
786 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
787 {
788     gchar *newfile;
789     newfile = g_strdup_printf("%s%d.png", actor->name, desktop_plugin->priv->scene->daytime); 
790     if (actor->filename)
791             g_free(actor->filename);
792     actor->filename = newfile;
793     change_hildon_actor(actor, desktop_plugin);
794 }
795
796 void 
797 change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
798 {
799     gchar buffer[2048];
800
801     if (desktop_plugin->priv->right_corner)
802         gtk_widget_destroy(desktop_plugin->priv->right_corner);
803     snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
804                                   THEME_PATH, desktop_plugin->priv->theme, desktop_plugin->priv->scene->daytime);
805     desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
806     if (desktop_plugin->priv->right_corner){
807         gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
808         gtk_widget_show (desktop_plugin->priv->right_corner);
809     }
810     change_static_actor(actor, desktop_plugin);
811
812 }