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