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-actor.h"
27 #include "livewp-rules.h"
30 init_object(AWallpaperPlugin *desktop_plugin,
42 void (*pfunc_change)(Actor*),
43 void (*pfunc_probability)(Actor*),
48 actor = g_new0(Actor, 1);
53 actor->height = height;
54 actor->visible = visible;
56 actor->opacity = opacity;
57 actor->filename = g_strdup(filename);
58 actor->name = g_strdup(name);
59 actor->func_change = (gpointer)pfunc_change;
60 actor->func_probability = (gpointer)pfunc_probability;
63 create_hildon_actor(actor, desktop_plugin);
66 actor->time_start_animation = 0;
67 actor->duration_animation = 0;
72 destroy_actor(Actor *actor)
76 g_ptr_array_free(actor->child, TRUE);
79 g_free(actor->filename);
82 gtk_widget_destroy(actor->widget);
83 //actor->widget = NULL;
88 path_line(gint x0, gint x1, double t)
91 return ((x1 - x0) * t + x0);
94 set_actor_scale(Actor *actor, double scalex, double scaley)
96 hildon_animation_actor_set_scale(
97 HILDON_ANIMATION_ACTOR(actor->widget),
105 set_actor_visible(Actor *actor, gboolean visible)
107 hildon_animation_actor_set_show(HILDON_ANIMATION_ACTOR(actor->widget), visible);
111 set_actor_position(Actor *actor, gint x, gint y, gint z, AWallpaperPlugin *desktop_plugin)
113 hildon_animation_actor_set_position_full(HILDON_ANIMATION_ACTOR (actor->widget),
114 x-desktop_plugin->priv->xapplet,
115 y-desktop_plugin->priv->yapplet,
120 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
134 a = (double)(y2 - (double)(x2*(y1-y0) + x1*y0 - x0*y1)/(x1-x0))/(x2*(x2-x0-x1)+x0*x1);
135 b = (double)(y1-y0)/(x1-x0) - (double)a*(x0+x1);
136 c = (double)(x1*y0 - x0*y1)/(x1-x0) + (double)a*x0*x1;
137 fprintf(stderr, "a=%f, b=%f, c=%f\n", a, b, c);
139 gettimeofday(&tvb, NULL);
145 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
146 if (!actor->visible){
147 actor->visible = TRUE;
148 phase = get_moon_phase();
149 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
151 g_free(actor->filename);
152 actor->filename = newfile;
153 actor->time_start_animation = sec - fast_rnd(60 * 60);
154 actor->duration_animation = 1 * 60 * 60;
155 create_hildon_actor(actor, desktop_plugin);
158 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
160 x = path_line(x0, x1, t);
162 x = path_line(x1, x0, t-1);
163 y = 0.001920*x*x - 1.536*x + 337.2;
164 //y = a*x*x + b*x + c;
166 set_actor_position(actor, x, y, actor->z, desktop_plugin);
169 actor->time_start_animation = sec;
172 }else if (actor->visible){
173 actor->visible = FALSE;
174 fprintf(stderr, "destroy moon \n");
175 destroy_hildon_actor(actor);
176 actor->time_start_animation = 0;
183 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
188 //fprintf(stderr, "change sun\n");
190 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
191 if (!actor->visible){
192 actor->visible = TRUE;
193 create_hildon_actor(actor, desktop_plugin);
195 get_sun_pos(&alt, &azm);
196 get_sun_screen_pos(alt, azm, &x, &y);
199 set_actor_position(actor, x, y, actor->z, desktop_plugin);
200 actor->time_start_animation = time(NULL) + 60;
201 }else if (actor->visible){
202 actor->visible = FALSE;
203 destroy_hildon_actor(actor);
204 actor->time_start_animation = 0;
211 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
213 gint x0 = -300, y0 = 225, scale0 = 100,
214 x1 = 800, y1 = 162, scale1 = 130,
221 //fprintf(stderr, "change tram\n");
222 gettimeofday(&tvb, NULL);
227 if (!actor->visible){
228 actor->visible = TRUE;
229 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
231 g_free(actor->filename);
232 actor->filename = g_strdup("tram_dark.png");
235 g_free(actor->filename);
236 actor->filename = g_strdup("tram.png");
238 create_hildon_actor(actor, desktop_plugin);
240 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
241 x = path_line(x0, x1, t);
242 y = path_line(y0, y1, t);
243 scale = path_line(scale0, scale1, t);
244 set_actor_position(actor, x, y, actor->z, desktop_plugin);
245 set_actor_scale(actor, (double)scale/100, (double)scale/100);
248 actor->visible = FALSE;
249 destroy_hildon_actor(actor);
250 actor->time_start_animation = sec + fast_rnd(60);
255 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
257 gint x0 = 620, y0 = 233,
265 gettimeofday(&tvb, NULL);
269 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
271 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
272 if (actor->time_start_animation == 0){
273 actor->time_start_animation = sec + fast_rnd(180);
277 if (!actor->visible){
278 actor->visible = TRUE;
279 create_hildon_actor(actor, desktop_plugin);
281 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
282 x = path_line(x0, x1, t);
283 y = path_line(y0, y1, t);
284 //scale = path_line(scale0, scale1, t);
285 set_actor_position(actor, x, y, actor->z, desktop_plugin);
288 actor->visible = FALSE;
289 destroy_hildon_actor(actor);
290 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT)
291 actor->time_start_animation = 0;
293 actor->time_start_animation = sec + fast_rnd(180);
299 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
301 gint x0 = -actor->width, y0 = 45,
309 gettimeofday(&tvb, NULL);
313 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
314 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
315 if (actor->time_start_animation == 0){
316 actor->time_start_animation = sec + fast_rnd(180);
320 if (!actor->visible){
321 actor->visible = TRUE;
322 create_hildon_actor(actor, desktop_plugin);
325 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
326 x = path_line(x0, x1, t);
327 y = path_line(y0, y1, t);
328 //scale = path_line(scale0, scale1, t);
329 set_actor_position(actor, x, y, actor->z, desktop_plugin);
332 actor->visible = FALSE;
333 destroy_hildon_actor(actor);
334 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT)
335 actor->time_start_animation = 0;
337 actor->time_start_animation = sec + fast_rnd(180);
343 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
345 gint x0, y0 = 300, scale0 = 100,
346 x1, y1 = -actor->height, scale1 = 150,
354 //fprintf(stderr, "change cloud\n");
355 gettimeofday(&tvb, NULL);
360 if (!actor->visible){
361 actor->visible = TRUE;
362 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
363 newfile = g_strdup_printf("%s_dark.png", actor->name);
365 newfile = g_strdup_printf("%s.png", actor->name);
368 g_free(actor->filename);
369 actor->filename = newfile;
371 create_hildon_actor(actor, desktop_plugin);
373 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
375 if (desktop_plugin->priv->scene->wind_orientation == 1){
384 x = path_line(x0, x1, t);
385 y = -desktop_plugin->priv->scene->wind_angle * (x - x0) + actor->y;
386 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
388 set_actor_position(actor, x, y, actor->z, desktop_plugin);
389 set_actor_scale(actor, (double)scale/100, (double)scale/100);
390 if ((y < y1 || y > y0) || t >= 1){
392 actor->visible = FALSE;
393 destroy_hildon_actor(actor);
394 actor->time_start_animation = sec + fast_rnd(300);
395 actor->y = fast_rnd(300);
401 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
403 desktop_plugin->priv->scene->wind_orientation = fast_rnd(2);
404 if (desktop_plugin->priv->scene->wind_orientation == 0) desktop_plugin->priv->scene->wind_orientation = -1;
405 desktop_plugin->priv->scene->wind_angle = (double)(fast_rnd(200) - 100) / 100;
406 actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
407 //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
411 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
413 gint now = time(NULL);
414 if (desktop_plugin->priv->scene->daytime == TIME_DAY){
416 actor->visible = FALSE;
417 destroy_hildon_actor(actor);
419 actor->time_start_animation = 0;
423 create_hildon_actor(actor, desktop_plugin);
424 if (actor->time_start_animation == 0){
425 actor->time_start_animation = now + fast_rnd(30);
431 actor->visible = TRUE;
433 actor->visible = FALSE;
434 set_actor_visible(actor, actor->visible);
435 actor->time_start_animation = now + fast_rnd(60) + 10;
440 change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
442 gint now = time(NULL);
444 a = g_ptr_array_index(actor->child, 0);
449 set_actor_visible(a, a->visible);
451 a = g_ptr_array_index(actor->child, 1);
456 set_actor_visible(a, a->visible);
458 actor->time_start_animation = now + fast_rnd(30) + 10;
462 change_layer(Actor * actor, AWallpaperPlugin *desktop_plugin)
467 if (!desktop_plugin->priv->rich_animation) return;
469 a = g_ptr_array_index(actor->child, 0);
471 if (y > 480) y = -480;
472 set_actor_position(a, a->x, y, a->z, desktop_plugin);
475 a = g_ptr_array_index(actor->child, 1);
477 if (y > 480) y = -480;
478 set_actor_position(a, a->x, y, a->z, desktop_plugin);
481 a = g_ptr_array_index(actor->child, 2);
483 if (y > 480) y = -480;
484 set_actor_position(a, a->x, y, a->z, desktop_plugin);
487 a = g_ptr_array_index(actor->child, 3);
489 if (y > 480) y = -480;
490 set_actor_position(a, a->x, y, a->z, desktop_plugin);
495 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
498 newfile = g_strdup_printf("%s%d.png", actor->name, desktop_plugin->priv->scene->daytime);
500 g_free(actor->filename);
501 actor->filename = newfile;
502 change_hildon_actor(actor, desktop_plugin);
506 change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
510 if (desktop_plugin->priv->right_corner)
511 gtk_widget_destroy(desktop_plugin->priv->right_corner);
512 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
513 THEME_PATH, desktop_plugin->priv->theme, desktop_plugin->priv->scene->daytime);
514 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
515 if (desktop_plugin->priv->right_corner){
516 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
517 gtk_widget_show (desktop_plugin->priv->right_corner);
519 change_static_actor(actor, desktop_plugin);