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-scene.h"
28 destroy_scene(AWallpaperPlugin *desktop_plugin)
30 if (desktop_plugin->priv->scene){
31 GSList * tmp = desktop_plugin->priv->scene->actors;
33 destroy_actor(tmp->data);
34 tmp = g_slist_next(tmp);
38 desktop_plugin->priv->scene->actors = NULL;
39 if (desktop_plugin->priv->scene){
40 g_free(desktop_plugin->priv->scene);
41 desktop_plugin->priv->scene = NULL;
47 reload_scene(AWallpaperPlugin *desktop_plugin)
49 fprintf(stderr,"Reload scene %s\n", desktop_plugin->priv->theme);
50 destroy_scene(desktop_plugin);
52 if (!strcmp(desktop_plugin->priv->theme,"Modern"))
53 init_scene_Modern(desktop_plugin);
54 else if (!strcmp(desktop_plugin->priv->theme,"Berlin"))
55 init_scene_Berlin(desktop_plugin);
56 else if (!strcmp(desktop_plugin->priv->theme,"Matrix"))
57 init_scene_Matrix(desktop_plugin);
59 init_scene_theme(desktop_plugin);
63 init_scene_Matrix(AWallpaperPlugin *desktop_plugin)
68 gint now = time(NULL);
71 if (desktop_plugin->priv->rich_animation){
79 fprintf(stderr, "init scene2 \n");
80 scene = g_new0(Scene, 1);
81 //scene.daytime = get_daytime();
83 desktop_plugin->priv->scene = scene;
85 actor = init_object(desktop_plugin, "background", "bg.png",
89 scene->actors = g_slist_append(scene->actors, actor);
91 actor = init_object(desktop_plugin, "symbols", "symbols.png",
95 scene->actors = g_slist_append(scene->actors, actor);
97 child = g_ptr_array_sized_new(4);
98 actor = init_object(desktop_plugin, "layer1", "layer1_2.png",
100 TRUE, TRUE, 100, 255,
102 //actor->time_start_animation = now;
103 //actor->duration_animation = G_MAXINT;
104 scene->actors = g_slist_append(scene->actors, actor);
105 g_ptr_array_add(child, actor);
107 actor = init_object(desktop_plugin, "layer1", "layer1_1.png",
109 TRUE, TRUE, 100, 255,
111 //actor->time_start_animation = now;
112 //actor->duration_animation = G_MAXINT;
113 scene->actors = g_slist_append(scene->actors, actor);
114 g_ptr_array_add(child, actor);
116 actor = init_object(desktop_plugin, "layer2", "layer2_2.png",
118 TRUE, TRUE, 100, 255,
120 //actor->time_start_animation = now;
121 //actor->duration_animation = G_MAXINT;
122 scene->actors = g_slist_append(scene->actors, actor);
123 g_ptr_array_add(child, actor);
125 actor = init_object(desktop_plugin, "layer2", "layer2_1.png",
127 TRUE, TRUE, 100, 255,
129 //actor->time_start_animation = now;
130 //actor->duration_animation = G_MAXINT;
131 scene->actors = g_slist_append(scene->actors, actor);
132 g_ptr_array_add(child, actor);
134 actor = init_object(desktop_plugin, "layers", "",
136 FALSE, FALSE, 100, 255,
137 (gpointer)&change_layer, NULL, child);
138 actor->time_start_animation = now;
139 actor->duration_animation = G_MAXINT;
140 scene->actors = g_slist_append(scene->actors, actor);
142 run_long_timeout(desktop_plugin);
146 /* Init Modern Scene */
148 init_scene_Modern(AWallpaperPlugin *desktop_plugin)
152 gint now = time(NULL);
156 //fprintf(stderr, "init scene \n");
157 scene = g_new0(Scene, 1);
158 scene->daytime = get_daytime();
159 scene->actors = NULL;
160 scene->wind_orientation = -1;
161 scene->wind_angle = 0.3;
162 /* init value for random */
163 scene->seed = time(NULL);
164 desktop_plugin->priv->scene = scene;
165 actor = init_object(desktop_plugin, "sky", "sky0.png",
167 TRUE , TRUE, 100, 255,
168 (gpointer)&change_static_actor, NULL, NULL);
169 scene->actors = g_slist_append(scene->actors, actor);
170 change_static_actor(actor, desktop_plugin);
172 actor = init_object(desktop_plugin, "sun", "sun.png",
174 FALSE, FALSE, 100, 255,
175 (gpointer)&change_sun, NULL, NULL);
176 actor->time_start_animation = now;
177 actor->duration_animation = G_MAXINT;
178 change_sun(actor, desktop_plugin);
179 scene->actors = g_slist_append(scene->actors, actor);
181 //actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
182 // TRUE, 100, 255, NULL, NULL);
183 //scene.actors = g_slist_append(scene.actors, actor);
185 actor = init_object(desktop_plugin, "cloud1", "cloud1.png",
186 0, fast_rnd(300)-97, 7, 150, 97,
187 FALSE, FALSE, 100, 255,
188 (gpointer)&change_cloud, NULL, NULL);
189 actor->time_start_animation = now + fast_rnd(20);
190 actor->duration_animation = 3*60;
191 scene->actors = g_slist_append(scene->actors, actor);
193 actor = init_object(desktop_plugin, "cloud2", "cloud2.png",
194 0, fast_rnd(300)-75, 7, 188, 75,
195 FALSE, FALSE, 100, 255,
196 (gpointer)&change_cloud, NULL, NULL);
197 actor->time_start_animation = now + fast_rnd(40)+10;
198 actor->duration_animation = 3*60;
199 scene->actors = g_slist_append(scene->actors, actor);
201 actor = init_object(desktop_plugin, "cloud4", "cloud4.png",
202 0, fast_rnd(300)-75, 7, 150, 75,
203 FALSE, FALSE, 100, 255,
204 (gpointer)&change_cloud, NULL, NULL);
205 actor->time_start_animation = now + fast_rnd(60) + 20;
206 actor->duration_animation = 5*60;
207 scene->actors = g_slist_append(scene->actors, actor);
210 actor = init_object(desktop_plugin, "town", "town0.png",
212 TRUE, TRUE, 100, 255,
213 (gpointer)&change_static_actor, NULL, NULL);
214 change_static_actor(actor, desktop_plugin);
215 scene->actors = g_slist_append(scene->actors, actor);
217 actor = init_object(desktop_plugin, "stend", "stend0.png",
218 482, 146, 9, 300, 305,
219 TRUE, TRUE, 100, 255,
220 (gpointer)&change_static_actor, NULL, NULL);
221 change_static_actor(actor, desktop_plugin);
222 scene->actors = g_slist_append(scene->actors, actor);
224 actor = init_object(desktop_plugin, "tram", "tram.png",
225 -300, 225, 10, 350, 210,
226 FALSE, FALSE, 100, 255,
227 (gpointer)&change_tram, NULL, NULL);
228 actor->time_start_animation = time(NULL) + fast_rnd(10);
229 actor->duration_animation = 60;
230 scene->actors = g_slist_append(scene->actors, actor);
232 actor = init_object(desktop_plugin, "border", "border0.png",
233 0, 480-79, 11, 800, 79,
234 TRUE, TRUE, 100, 255,
235 (gpointer)&change_static_actor_with_corner, NULL, NULL);
236 change_static_actor_with_corner(actor, desktop_plugin);
237 scene->actors = g_slist_append(scene->actors, actor);
239 actor = init_object(desktop_plugin, "moon", "moon1.png",
241 FALSE, FALSE, 100, 255,
242 (gpointer)&change_moon, NULL, NULL);
243 change_moon(actor, desktop_plugin);
244 scene->actors = g_slist_append(scene->actors, actor);
246 actor = init_object(desktop_plugin, "wind", "",
248 FALSE, FALSE, 100, 255,
249 (gpointer)&change_wind, NULL, NULL);
250 change_wind(actor, desktop_plugin);
251 scene->actors = g_slist_append(scene->actors, actor);
253 /* windows in 4-th house */
293 for (i=0; i<13; i++){
294 actor = init_object(desktop_plugin, "window1", "window1.png",
295 winds[i][0], winds[i][1], 8, 8, 10,
296 FALSE, FALSE, 100, 255,
297 (gpointer)&change_window1, NULL, NULL);
298 //change_window1(actor, desktop_plugin);
299 actor->time_start_animation = now + fast_rnd(30);
300 scene->actors = g_slist_append(scene->actors, actor);
304 /* windows in 1-th house */
330 actor = init_object(desktop_plugin, "window2", "window2.png",
331 winds[i][0], winds[i][1], 8, 8, 10,
332 FALSE, FALSE, 100, 255,
333 (gpointer)&change_window1, NULL, NULL);
334 //change_window1(actor, desktop_plugin);
335 actor->time_start_animation = now + fast_rnd(30);
336 scene->actors = g_slist_append(scene->actors, actor);
340 /* windows in 3-th house */
372 for (i=0; i<10; i++){
373 actor = init_object(desktop_plugin, "window3", "window3.png",
374 winds[i][0], winds[i][1], 8, 8, 10,
375 FALSE, FALSE, 100, 255,
376 (gpointer)&change_window1, NULL, NULL);
377 //change_window1(actor, desktop_plugin);
378 actor->time_start_animation = now + fast_rnd(30);
379 scene->actors = g_slist_append(scene->actors, actor);
383 /* windows in 5-th house */
407 actor = init_object(desktop_plugin, "window4", "window4.png",
408 winds[i][0], winds[i][1], 8, 8, 10,
409 FALSE, FALSE, 100, 255,
410 (gpointer)&change_window1, NULL, NULL);
411 //change_window1(actor, desktop_plugin);
412 actor->time_start_animation = now + fast_rnd(30);
413 scene->actors = g_slist_append(scene->actors, actor);
417 /* windows in 6-th house */
438 actor = init_object(desktop_plugin, "window5", "window5.png",
439 winds[i][0], winds[i][1], 8, 8, 10,
440 FALSE, FALSE, 100, 255,
441 (gpointer)&change_window1, NULL, NULL);
442 //change_window1(actor, desktop_plugin);
443 actor->time_start_animation = now + fast_rnd(30);
444 scene->actors = g_slist_append(scene->actors, actor);
447 run_long_timeout(desktop_plugin);
450 anim = g_new0(Animation, 1);
453 anim->func_change = &change_tram;
454 anim->func_time = NULL;
455 anim->timestart = time(NULL);
458 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, anim);
462 /* Init Berlin Scene */
464 init_scene_Berlin(AWallpaperPlugin *desktop_plugin)
466 Actor *actor, *actor1, *actor2;
468 gint now = time(NULL);
471 GPtrArray *child = NULL;
473 scene = g_new0(Scene, 1);
474 scene->daytime = get_daytime();
475 scene->actors = NULL;
476 scene->wind_orientation = -1;
477 scene->wind_angle = 0.3;
478 /* init value for random */
479 scene->seed = time(NULL);
480 desktop_plugin->priv->scene = scene;
482 actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480,
483 TRUE, TRUE, 100, 255,
484 (gpointer)&change_static_actor, NULL, NULL);
485 change_static_actor(actor, desktop_plugin);
486 scene->actors = g_slist_append(scene->actors, actor);
489 actor = init_object(desktop_plugin, "sun", "sun.png", 0, 0, 6, 88, 88,
490 FALSE, FALSE, 100, 255,
491 (gpointer)&change_sun, NULL, NULL);
492 actor->time_start_animation = time(NULL);
493 actor->duration_animation = G_MAXINT;
494 change_sun(actor, desktop_plugin);
495 scene->actors = g_slist_append(scene->actors, actor);
498 actor = init_object(desktop_plugin, "dot", "dot1.png", 0, 0, 11, 50, 50,
499 TRUE, 100, 255, NULL, NULL);
500 scene.actors = g_slist_append(scene.actors, actor);
503 actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60,
504 FALSE, FALSE, 100, 255,
505 (gpointer)&change_moon, NULL, NULL);
506 change_moon(actor, desktop_plugin);
507 scene->actors = g_slist_append(scene->actors, actor);
509 actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97,
510 FALSE, FALSE, 100, 255,
511 (gpointer)&change_cloud, NULL, NULL);
512 actor->time_start_animation = now + fast_rnd(30) + 10;
513 actor->duration_animation = 3*60;
514 scene->actors = g_slist_append(scene->actors, actor);
516 actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75,
517 FALSE, FALSE, 100, 255,
518 (gpointer)&change_cloud, NULL, NULL);
519 actor->time_start_animation = now + fast_rnd(10);
520 actor->duration_animation = 3*60;
521 scene->actors = g_slist_append(scene->actors, actor);
523 actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75,
524 FALSE, FALSE, 100, 255,
525 (gpointer)&change_cloud, NULL, NULL);
526 actor->time_start_animation = now + fast_rnd(60) + 20;
527 actor->duration_animation = 5*60;
528 scene->actors = g_slist_append(scene->actors, actor);
531 actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50,
532 FALSE, FALSE, 100, 255,
533 (gpointer)&change_plane2, NULL, NULL);
534 actor->time_start_animation = now + fast_rnd(40) + 20;
535 actor->duration_animation = 60;
536 scene->actors = g_slist_append(scene->actors, actor);
538 actor = init_object(desktop_plugin, "plane1", "tu154.png", 620, 233, 9, 300, 116,
539 FALSE, FALSE, 100, 255,
540 (gpointer)&change_plane1, NULL, NULL);
541 actor->time_start_animation = now + fast_rnd(20);
542 actor->duration_animation = 30;
543 scene->actors = g_slist_append(scene->actors, actor);
545 actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480,
546 TRUE, TRUE, 100, 255,
547 (gpointer)&change_static_actor_with_corner, NULL, NULL);
548 change_static_actor_with_corner(actor, desktop_plugin);
549 scene->actors = g_slist_append(scene->actors, actor);
551 actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0,
552 FALSE, FALSE, 100, 255,
553 (gpointer)&change_wind, NULL, NULL);
554 change_wind(actor, desktop_plugin);
555 scene->actors = g_slist_append(scene->actors, actor);
557 actor1 = init_object(desktop_plugin, "signal_red", "red.png",
558 486, 425, 10, 18, 38,
559 FALSE, TRUE, 100, 255, NULL, NULL, NULL);
560 //actor->time_start_animation = now + fast_rnd(30) + 10;
561 scene->actors = g_slist_append(scene->actors, actor1);
563 actor2 = init_object(desktop_plugin, "signal_green", "green.png",
564 486, 425, 10, 18, 38,
565 TRUE, TRUE, 100, 255, NULL, NULL, NULL);
566 //actor->time_start_animation = now + fast_rnd(30) + 10;
567 scene->actors = g_slist_append(scene->actors, actor2);
568 child = g_ptr_array_sized_new(2);
569 g_ptr_array_add(child, actor1);
570 g_ptr_array_add(child, actor2);
571 actor = init_object(desktop_plugin, "signal", "",
572 486, 425, 10, 18, 38,
573 FALSE, FALSE, 100, 255,
574 (gpointer)&change_signal, NULL, child);
575 actor->time_start_animation = now + fast_rnd(30) + 10;
576 scene->actors = g_slist_append(scene->actors, actor);
617 for (i=0; i<13; i++){
618 actor = init_object(desktop_plugin, "window", "window.png",
619 winds[i][0], winds[i][1], 10, 8, 9,
620 FALSE, TRUE, 100, 255,
621 (gpointer)&change_window1, NULL, NULL);
622 //change_window1(actor, desktop_plugin);
623 actor->time_start_animation = now + fast_rnd(30);
624 scene->actors = g_slist_append(scene->actors, actor);
628 run_long_timeout(desktop_plugin);
633 init_scene_theme(AWallpaperPlugin *desktop_plugin)
635 void (*func)(gpointer);
636 func = g_hash_table_lookup(desktop_plugin->priv->hash_scene_func, desktop_plugin->priv->theme);
638 (*func)(desktop_plugin);