start stop function is done
[livewp] / applet / src / livewp-scene.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-scene.h" 
26
27 void 
28 destroy_scene(AWallpaperPlugin *desktop_plugin)
29 {
30     GSList * tmp = desktop_plugin->priv->scene->actors;
31     while (tmp != NULL){
32         destroy_actor(tmp->data);
33         tmp = g_slist_next(tmp);
34     }
35     g_slist_free(tmp);
36     desktop_plugin->priv->scene->actors = NULL;
37     if (desktop_plugin->priv->scene){
38         g_free(desktop_plugin->priv->scene);
39         desktop_plugin->priv->scene = NULL;
40     }
41 }
42
43 void
44 reload_scene(AWallpaperPlugin *desktop_plugin)
45 {
46     fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);  
47     destroy_scene(desktop_plugin);
48     if (!strcmp(desktop_plugin->priv->theme,"Modern"))
49         init_scene(desktop_plugin);
50     else if (!strcmp(desktop_plugin->priv->theme,"Berlin")) 
51         init_scene1(desktop_plugin);
52     else if (!strcmp(desktop_plugin->priv->theme,"Matrix")) 
53         init_scene2(desktop_plugin);
54 }
55
56 void
57 init_scene2(AWallpaperPlugin *desktop_plugin)
58 {
59   Actor *actor;
60   Scene *scene;
61   GPtrArray *child;
62   gint now = time(NULL);
63   gint y1, y2;
64
65   if (desktop_plugin->priv->rich_animation){
66       y1 = -480;
67       y2 = -480-480;
68   }else {
69       y1 = 0;
70       y2 = -480;
71   }
72
73   fprintf(stderr, "init scene2 \n");
74   scene = g_new0(Scene, 1);
75   //scene.daytime = get_daytime();
76   scene->actors = NULL;
77   desktop_plugin->priv->scene = scene;
78   
79   actor = init_object(desktop_plugin, "background", "bg.png", 
80                       0, 0, 5, 800, 480, 
81                       TRUE, TRUE, 100, 255, 
82                       NULL, NULL, NULL);
83   scene->actors = g_slist_append(scene->actors, actor);
84
85   actor = init_object(desktop_plugin, "symbols", "symbols.png", 
86                       0, 0, 10, 800, 480, 
87                       TRUE, TRUE, 100, 255, 
88                       NULL, NULL, NULL);
89   scene->actors = g_slist_append(scene->actors, actor);
90
91   child = g_ptr_array_sized_new(4);
92   actor = init_object(desktop_plugin, "layer1", "layer1_2.png", 
93                       0, y1, 6, 800, 960, 
94                       TRUE, TRUE, 100, 255, 
95                       NULL, NULL, NULL);
96   //actor->time_start_animation = now;
97   //actor->duration_animation = G_MAXINT;
98   scene->actors = g_slist_append(scene->actors, actor);
99   g_ptr_array_add(child, actor);
100
101   actor = init_object(desktop_plugin, "layer1", "layer1_1.png", 
102                       0, y2, 7, 800, 960, 
103                       TRUE, TRUE, 100, 255, 
104                       NULL, NULL, NULL);
105   //actor->time_start_animation = now;
106   //actor->duration_animation = G_MAXINT;
107   scene->actors = g_slist_append(scene->actors, actor);
108   g_ptr_array_add(child, actor);
109
110   actor = init_object(desktop_plugin, "layer2", "layer2_2.png", 
111                       0, y1, 8, 800, 960, 
112                       TRUE, TRUE, 100, 255, 
113                       NULL, NULL, NULL);
114   //actor->time_start_animation = now;
115   //actor->duration_animation = G_MAXINT;
116   scene->actors = g_slist_append(scene->actors, actor);
117   g_ptr_array_add(child, actor);
118
119   actor = init_object(desktop_plugin, "layer2", "layer2_1.png", 
120                       0, y2, 9, 800, 960, 
121                       TRUE, TRUE, 100, 255, 
122                       NULL, NULL, NULL);
123   //actor->time_start_animation = now;
124   //actor->duration_animation = G_MAXINT;
125   scene->actors = g_slist_append(scene->actors, actor);
126   g_ptr_array_add(child, actor);
127
128   actor = init_object(desktop_plugin, "layers", "", 
129                       0, y2, 9, 800, 960, 
130                       FALSE, FALSE, 100, 255, 
131                       (gpointer)&change_layer, NULL, child);
132   actor->time_start_animation = now;
133   actor->duration_animation = G_MAXINT;
134   scene->actors = g_slist_append(scene->actors, actor);
135
136   run_long_timeout(desktop_plugin);
137
138 }
139
140 /* Init Modern Scene */
141 void
142 init_scene(AWallpaperPlugin *desktop_plugin)
143 {
144   Actor *actor;
145   Scene *scene;
146   gint now = time(NULL);
147   gint i;
148   gint winds[13][2];
149
150   //fprintf(stderr, "init scene \n");
151   scene = g_new0(Scene, 1);
152   scene->daytime = get_daytime();
153   scene->actors = NULL;
154   scene->wind_orientation = -1;
155   scene->wind_angle = 0.3;
156   /* init value for random */
157   scene->seed = time(NULL);
158   desktop_plugin->priv->scene = scene;
159
160   actor = init_object(desktop_plugin, "sky", "sky0.png", 
161                       0, 0, 5, 800, 480, 
162                       TRUE , TRUE, 100, 255, 
163                       (gpointer)&change_static_actor, NULL, NULL);
164   change_static_actor(actor, desktop_plugin);
165   scene->actors = g_slist_append(scene->actors, actor);
166   
167   actor = init_object(desktop_plugin, "sun", "sun.png", 
168                       0, 0, 6, 88, 88, 
169                       FALSE, FALSE, 100, 255, 
170                       (gpointer)&change_sun, NULL, NULL);
171   actor->time_start_animation = now;
172   actor->duration_animation = G_MAXINT;
173   change_sun(actor, desktop_plugin);
174   scene->actors = g_slist_append(scene->actors, actor);
175
176   //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50, 
177     //                  TRUE, 100, 255, NULL, NULL);
178   //scene.actors = g_slist_append(scene.actors, actor);
179   
180   actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 
181                       0, fast_rnd(300)-97, 7, 150, 97, 
182                       FALSE, FALSE, 100, 255, 
183                       (gpointer)&change_cloud, NULL, NULL);
184   actor->time_start_animation = now + fast_rnd(20);
185   actor->duration_animation = 3*60;
186   scene->actors = g_slist_append(scene->actors, actor);
187   
188   actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 
189                       0, fast_rnd(300)-75, 7, 188, 75, 
190                       FALSE, FALSE, 100, 255, 
191                       (gpointer)&change_cloud, NULL, NULL);
192   actor->time_start_animation = now + fast_rnd(40)+10;
193   actor->duration_animation = 3*60;
194   scene->actors = g_slist_append(scene->actors, actor);
195
196   actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 
197                       0, fast_rnd(300)-75, 7, 150, 75, 
198                       FALSE, FALSE, 100, 255, 
199                       (gpointer)&change_cloud, NULL, NULL);
200   actor->time_start_animation = now + fast_rnd(60) + 20;
201   actor->duration_animation = 5*60;
202   scene->actors = g_slist_append(scene->actors, actor);
203
204
205   actor = init_object(desktop_plugin, "town", "town0.png", 
206                       0, 0, 8, 800, 480, 
207                       TRUE, TRUE, 100, 255, 
208                       (gpointer)&change_static_actor, NULL, NULL);
209   change_static_actor(actor, desktop_plugin);
210   scene->actors = g_slist_append(scene->actors, actor);
211
212   actor = init_object(desktop_plugin, "stend", "stend0.png", 
213                       482, 146, 9, 300, 305, 
214                       TRUE, TRUE, 100, 255, 
215                       (gpointer)&change_static_actor, NULL, NULL);
216   change_static_actor(actor, desktop_plugin);
217   scene->actors = g_slist_append(scene->actors, actor);
218
219   actor = init_object(desktop_plugin, "tram", "tram.png", 
220                       -300, 225, 10, 350, 210, 
221                       FALSE, FALSE, 100, 255, 
222                       (gpointer)&change_tram, NULL, NULL);
223   actor->time_start_animation = time(NULL) + fast_rnd(10); 
224   actor->duration_animation = 60;
225   scene->actors = g_slist_append(scene->actors, actor);
226
227   actor = init_object(desktop_plugin, "border", "border0.png", 
228                       0, 480-79, 11, 800, 79,
229                       TRUE, TRUE, 100, 255, 
230                       (gpointer)&change_static_actor_with_corner, NULL, NULL);
231   change_static_actor_with_corner(actor, desktop_plugin);
232   scene->actors = g_slist_append(scene->actors, actor);
233   
234   actor = init_object(desktop_plugin, "moon", "moon1.png", 
235                       400, 20, 6, 60, 60, 
236                       FALSE, FALSE, 100, 255, 
237                       (gpointer)&change_moon, NULL, NULL);
238   change_moon(actor, desktop_plugin);
239   scene->actors = g_slist_append(scene->actors, actor);
240
241   actor = init_object(desktop_plugin, "wind", "", 
242                       0, 0, 5, 0, 0, 
243                       FALSE, FALSE, 100, 255, 
244                       (gpointer)&change_wind, NULL, NULL);
245   change_wind(actor, desktop_plugin);
246   scene->actors = g_slist_append(scene->actors, actor);
247
248     /* windows in 4-th house  */
249
250     winds[0][0] = 482;
251     winds[0][1] = 180;
252
253     winds[1][0] = 495;
254     winds[1][1] = 179;
255
256     winds[2][0] = 482;
257     winds[2][1] = 191;
258
259     winds[3][0] = 495;
260     winds[3][1] = 190;
261     
262     winds[4][0] = 482;
263     winds[4][1] = 201;
264     
265     winds[5][0] = 495;
266     winds[5][1] = 210;
267     
268     winds[6][0] = 482;
269     winds[6][1] = 222;
270     
271     winds[7][0] = 495;
272     winds[7][1] = 221;
273     
274     winds[8][0] = 459;
275     winds[8][1] = 203;
276     
277     winds[9][0] = 495;
278     winds[9][1] = 241;
279     
280     winds[10][0] = 495;
281     winds[10][1] = 252;
282     
283     winds[11][0] = 482;
284     winds[11][1] = 273;
285     
286     winds[12][0] = 495;
287     winds[12][1] = 303;
288     for (i=0; i<13; i++){
289         actor = init_object(desktop_plugin, "window1", "window1.png", 
290                             winds[i][0], winds[i][1], 8, 8, 10, 
291                             FALSE, FALSE, 100, 255, 
292                             (gpointer)&change_window1, NULL, NULL);
293         //change_window1(actor, desktop_plugin);
294         actor->time_start_animation = now + fast_rnd(30);
295         scene->actors = g_slist_append(scene->actors, actor);
296
297     }
298     
299     /* windows in 1-th house  */
300     
301     winds[0][0] = 86;
302     winds[0][1] = 321;
303
304     winds[1][0] = 86;
305     winds[1][1] = 363;
306
307     winds[2][0] = 86;
308     winds[2][1] = 385;
309
310     winds[3][0] = 86;
311     winds[3][1] = 286;
312     
313     winds[4][0] = 94;
314     winds[4][1] = 232;
315     
316     winds[5][0] = 94;
317     winds[5][1] = 243;
318     
319     winds[6][0] = 94;
320     winds[6][1] = 265;
321     
322     winds[7][0] = 94;
323     winds[7][1] = 331;
324     for (i=0; i<8; i++){
325         actor = init_object(desktop_plugin, "window2", "window2.png", 
326                             winds[i][0], winds[i][1], 8, 8, 10, 
327                             FALSE, FALSE, 100, 255, 
328                             (gpointer)&change_window1, NULL, NULL);
329         //change_window1(actor, desktop_plugin);
330         actor->time_start_animation = now + fast_rnd(30);
331         scene->actors = g_slist_append(scene->actors, actor);
332
333     }
334     
335     /* windows in 3-th house  */
336     
337     winds[0][0] = 251;
338     winds[0][1] = 162;
339
340     winds[1][0] = 251;
341     winds[1][1] = 196;
342
343     winds[2][0] = 251;
344     winds[2][1] = 278;
345
346     winds[3][0] = 251;
347     winds[3][1] = 289;
348     
349     winds[4][0] = 313;
350     winds[4][1] = 173;
351     
352     winds[5][0] = 322;
353     winds[5][1] = 160;
354     
355     winds[6][0] = 303;
356     winds[6][1] = 217;
357     
358     winds[7][0] = 322;
359     winds[7][1] = 224;
360     
361     winds[8][0] = 323;
362     winds[8][1] = 217;
363     
364     winds[9][0] = 322;
365     winds[9][1] = 288;
366     
367     for (i=0; i<10; i++){
368         actor = init_object(desktop_plugin, "window3", "window3.png", 
369                             winds[i][0], winds[i][1], 8, 8, 10, 
370                             FALSE, FALSE, 100, 255, 
371                             (gpointer)&change_window1, NULL, NULL);
372         //change_window1(actor, desktop_plugin);
373         actor->time_start_animation = now + fast_rnd(30);
374         scene->actors = g_slist_append(scene->actors, actor);
375
376     }
377
378     /* windows in 5-th house  */
379     
380     winds[0][0] = 610;
381     winds[0][1] = 224;
382
383     winds[1][0] = 602;
384     winds[1][1] = 245;
385
386     winds[2][0] = 602;
387     winds[2][1] = 264;
388
389     winds[3][0] = 610;
390     winds[3][1] = 301;
391     
392     winds[4][0] = 610;
393     winds[4][1] = 320;
394     
395     winds[5][0] = 593;
396     winds[5][1] = 352;
397     
398     winds[6][0] = 610;
399     winds[6][1] = 368;
400     
401     for (i=0; i<7; i++){
402         actor = init_object(desktop_plugin, "window4", "window4.png", 
403                             winds[i][0], winds[i][1], 8, 8, 10, 
404                             FALSE, FALSE, 100, 255, 
405                             (gpointer)&change_window1, NULL, NULL);
406         //change_window1(actor, desktop_plugin);
407         actor->time_start_animation = now + fast_rnd(30);
408         scene->actors = g_slist_append(scene->actors, actor);
409
410     }
411
412     /* windows in 6-th house  */
413     
414     winds[0][0] = 717;
415     winds[0][1] = 283;
416
417     winds[1][0] = 698;
418     winds[1][1] = 293;
419
420     winds[2][0] = 717;
421     winds[2][1] = 315;
422
423     winds[3][0] = 717;
424     winds[3][1] = 323;
425     
426     winds[4][0] = 698;
427     winds[4][1] = 362;
428     
429     winds[5][0] = 698;
430     winds[5][1] = 400;
431     
432     for (i=0; i<6; i++){
433         actor = init_object(desktop_plugin, "window5", "window5.png", 
434                             winds[i][0], winds[i][1], 8, 8, 10, 
435                             FALSE, FALSE, 100, 255, 
436                             (gpointer)&change_window1, NULL, NULL);
437         //change_window1(actor, desktop_plugin);
438         actor->time_start_animation = now + fast_rnd(30);
439         scene->actors = g_slist_append(scene->actors, actor);
440
441     }
442     run_long_timeout(desktop_plugin);
443
444 #if 0    
445   anim = g_new0(Animation, 1);
446   anim->count = 1;
447   anim->actor = actor;
448   anim->func_change = &change_tram;
449   anim->func_time = NULL;
450   anim->timestart = time(NULL); 
451   anim->timeall = 10;
452   
453   scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
454 #endif  
455 }
456
457 /* Init Berlin Scene */
458 void
459 init_scene1(AWallpaperPlugin *desktop_plugin)
460 {
461   Actor *actor, *actor1, *actor2;
462   Scene *scene;
463   gint now = time(NULL);
464   gint i; 
465   gint winds[13][2];
466   GPtrArray *child = NULL;
467
468   scene = g_new0(Scene, 1);
469   scene->daytime = get_daytime();
470   scene->actors = NULL;
471   scene->wind_orientation = -1;
472   scene->wind_angle = 0.3;
473   /* init value for random */
474   scene->seed = time(NULL);
475   desktop_plugin->priv->scene = scene;
476   
477   actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480, 
478                       TRUE, TRUE, 100, 255, 
479                       (gpointer)&change_static_actor, NULL, NULL);
480   change_static_actor(actor, desktop_plugin);
481   scene->actors = g_slist_append(scene->actors, actor);
482
483   
484   actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88, 
485                       FALSE, FALSE, 100, 255, 
486                       (gpointer)&change_sun, NULL, NULL);
487   actor->time_start_animation = time(NULL);
488   actor->duration_animation = G_MAXINT;
489   change_sun(actor, desktop_plugin);
490   scene->actors = g_slist_append(scene->actors, actor);
491
492 #if 0
493   actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50, 
494                       TRUE, 100, 255, NULL, NULL);
495   scene.actors = g_slist_append(scene.actors, actor);
496 #endif
497
498   actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60, 
499                       FALSE, FALSE, 100, 255, 
500                       (gpointer)&change_moon, NULL, NULL);
501   change_moon(actor, desktop_plugin);
502   scene->actors = g_slist_append(scene->actors, actor);
503   
504   actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
505                       FALSE, FALSE, 100, 255, 
506                       (gpointer)&change_cloud, NULL, NULL);
507   actor->time_start_animation = now + fast_rnd(30) + 10;
508   actor->duration_animation = 3*60;
509   scene->actors = g_slist_append(scene->actors, actor);
510   
511   actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
512                       FALSE, FALSE, 100, 255, 
513                       (gpointer)&change_cloud, NULL, NULL);
514   actor->time_start_animation = now + fast_rnd(10);
515   actor->duration_animation = 3*60;
516   scene->actors = g_slist_append(scene->actors, actor);
517
518   actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
519                       FALSE, FALSE, 100, 255, 
520                       (gpointer)&change_cloud, NULL, NULL);
521   actor->time_start_animation = now + fast_rnd(60) + 20;
522   actor->duration_animation = 5*60;
523   scene->actors = g_slist_append(scene->actors, actor);
524
525  
526   actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50, 
527                       FALSE, FALSE, 100, 255, 
528                       (gpointer)&change_plane2, NULL, NULL);
529   actor->time_start_animation = now + fast_rnd(40) + 20;
530   actor->duration_animation = 60;
531   scene->actors = g_slist_append(scene->actors, actor);
532   
533   actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116, 
534                       FALSE, FALSE, 100, 255, 
535                       (gpointer)&change_plane1, NULL, NULL);
536   actor->time_start_animation = now + fast_rnd(20);
537   actor->duration_animation = 30;
538   scene->actors = g_slist_append(scene->actors, actor);
539
540   actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, 
541                       TRUE, TRUE, 100, 255, 
542                       (gpointer)&change_static_actor_with_corner, NULL, NULL);
543   change_static_actor_with_corner(actor, desktop_plugin);
544   scene->actors = g_slist_append(scene->actors, actor);
545
546   actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
547                       FALSE, FALSE, 100, 255, 
548                       (gpointer)&change_wind, NULL, NULL);
549   change_wind(actor, desktop_plugin);
550   scene->actors = g_slist_append(scene->actors, actor);
551
552   actor1 = init_object(desktop_plugin, "signal_red", "red.png", 
553                       486, 425, 10, 18, 38, 
554                       FALSE, TRUE, 100, 255, NULL, NULL, NULL);
555   //actor->time_start_animation = now + fast_rnd(30) + 10;  
556   scene->actors = g_slist_append(scene->actors, actor1);
557    
558   actor2 = init_object(desktop_plugin, "signal_green", "green.png", 
559                       486, 425, 10, 18, 38, 
560                       TRUE, TRUE, 100, 255, NULL, NULL, NULL);
561   //actor->time_start_animation = now + fast_rnd(30) + 10;  
562   scene->actors = g_slist_append(scene->actors, actor2);
563   child = g_ptr_array_sized_new(2);
564   g_ptr_array_add(child, actor1);
565   g_ptr_array_add(child, actor2);
566   actor = init_object(desktop_plugin, "signal", "",
567                       486, 425, 10, 18, 38,
568                       FALSE, FALSE, 100, 255, 
569                       (gpointer)&change_signal, NULL, child);
570   actor->time_start_animation = now + fast_rnd(30) + 10;
571   scene->actors = g_slist_append(scene->actors, actor);
572     
573     winds[0][0] = 389;
574     winds[0][1] = 305;
575
576     winds[1][0] = 373;
577     winds[1][1] = 306;
578
579     winds[2][0] = 355;
580     winds[2][1] = 306;
581
582     winds[3][0] = 356;
583     winds[3][1] = 288;
584     
585     winds[4][0] = 337;
586     winds[4][1] = 269;
587     
588     winds[5][0] = 372;
589     winds[5][1] = 268;
590   
591     winds[6][0] = 372;
592     winds[6][1] = 249;
593     
594     winds[7][0] = 388;
595     winds[7][1] = 249;
596     
597     winds[8][0] = 387;
598     winds[8][1] = 230;
599     
600     winds[9][0] = 372;
601     winds[9][1] = 211;
602     
603     winds[10][0] = 355;
604     winds[10][1] = 159;
605     
606     winds[11][0] = 335;
607     winds[11][1] = 158;
608     
609     winds[12][0] = 386;
610     winds[12][1] = 119;
611   
612     for (i=0; i<13; i++){
613         actor = init_object(desktop_plugin, "window", "window.png", 
614                             winds[i][0], winds[i][1], 10, 8, 9, 
615                             FALSE, TRUE, 100, 255, 
616                             (gpointer)&change_window1, NULL, NULL);
617         //change_window1(actor, desktop_plugin);
618         actor->time_start_animation = now + fast_rnd(30);
619         scene->actors = g_slist_append(scene->actors, actor);
620
621     }
622     
623     run_long_timeout(desktop_plugin);
624
625 }
626