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"
28 init_object(AWallpaperPlugin *desktop_plugin,
40 void (*pfunc_change)(Actor*),
41 void (*pfunc_probability)(Actor*),
46 actor = g_new0(Actor, 1);
51 actor->height = height;
52 actor->visible = visible;
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;
61 create_hildon_actor(actor, desktop_plugin);
64 actor->time_start_animation = 0;
65 actor->duration_animation = 0;
70 destroy_actor(Actor *actor)
74 g_ptr_array_free(actor->child, TRUE);
77 g_free(actor->filename);
80 gtk_widget_destroy(actor->widget);
81 //actor->widget = NULL;
86 path_line(gint x0, gint x1, double t)
89 return ((x1 - x0) * t + x0);
92 set_actor_scale(Actor *actor, double scalex, double scaley)
94 hildon_animation_actor_set_scale(
95 HILDON_ANIMATION_ACTOR(actor->widget),
103 set_actor_visible(Actor *actor, gboolean visible)
105 hildon_animation_actor_set_show(HILDON_ANIMATION_ACTOR(actor->widget), visible);
109 set_actor_position(Actor *actor, gint x, gint y, gint z, AWallpaperPlugin *desktop_plugin)
111 hildon_animation_actor_set_position_full(HILDON_ANIMATION_ACTOR (actor->widget),
112 x-desktop_plugin->priv->xapplet,
113 y-desktop_plugin->priv->yapplet,
118 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
132 a = (double)(y2 - (double)(x2*(y1-y0) + x1*y0 - x0*y1)/(x1-x0))/(x2*(x2-x0-x1)+x0*x1);
133 b = (double)(y1-y0)/(x1-x0) - (double)a*(x0+x1);
134 c = (double)(x1*y0 - x0*y1)/(x1-x0) + (double)a*x0*x1;
135 fprintf(stderr, "a=%f, b=%f, c=%f\n", a, b, c);
137 gettimeofday(&tvb, NULL);
143 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
144 if (!actor->visible){
145 actor->visible = TRUE;
146 phase = get_moon_phase();
147 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
149 g_free(actor->filename);
150 actor->filename = newfile;
151 actor->time_start_animation = sec - fast_rnd(60 * 60);
152 actor->duration_animation = 1 * 60 * 60;
153 create_hildon_actor(actor, desktop_plugin);
156 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
158 x = path_line(x0, x1, t);
160 x = path_line(x1, x0, t-1);
161 y = 0.001920*x*x - 1.536*x + 337.2;
162 //y = a*x*x + b*x + c;
164 set_actor_position(actor, x, y, actor->z, desktop_plugin);
167 actor->time_start_animation = sec;
170 }else if (actor->visible){
171 actor->visible = FALSE;
172 fprintf(stderr, "destroy moon \n");
173 destroy_hildon_actor(actor);
174 actor->time_start_animation = 0;
181 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
186 //fprintf(stderr, "change sun\n");
188 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
189 if (!actor->visible){
190 actor->visible = TRUE;
191 create_hildon_actor(actor, desktop_plugin);
193 get_sun_pos(&alt, &azm);
194 get_sun_screen_pos(alt, azm, &x, &y);
197 set_actor_position(actor, x, y, actor->z, desktop_plugin);
198 actor->time_start_animation = time(NULL) + 60;
199 }else if (actor->visible){
200 actor->visible = FALSE;
201 destroy_hildon_actor(actor);
202 actor->time_start_animation = 0;
209 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
211 gint x0 = -300, y0 = 225, scale0 = 100,
212 x1 = 800, y1 = 162, scale1 = 130,
219 //fprintf(stderr, "change tram\n");
220 gettimeofday(&tvb, NULL);
225 if (!actor->visible){
226 actor->visible = TRUE;
227 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
229 g_free(actor->filename);
230 actor->filename = g_strdup("tram_dark.png");
233 g_free(actor->filename);
234 actor->filename = g_strdup("tram.png");
236 create_hildon_actor(actor, desktop_plugin);
238 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
239 x = path_line(x0, x1, t);
240 y = path_line(y0, y1, t);
241 scale = path_line(scale0, scale1, t);
242 set_actor_position(actor, x, y, actor->z, desktop_plugin);
243 set_actor_scale(actor, (double)scale/100, (double)scale/100);
246 actor->visible = FALSE;
247 destroy_hildon_actor(actor);
248 actor->time_start_animation = sec + fast_rnd(60);
253 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
255 gint x0 = 620, y0 = 233,
263 gettimeofday(&tvb, NULL);
267 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
269 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
270 if (actor->time_start_animation == 0){
271 actor->time_start_animation = sec + fast_rnd(180);
275 if (!actor->visible){
276 actor->visible = TRUE;
277 create_hildon_actor(actor, desktop_plugin);
279 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
280 x = path_line(x0, x1, t);
281 y = path_line(y0, y1, t);
282 //scale = path_line(scale0, scale1, t);
283 set_actor_position(actor, x, y, actor->z, desktop_plugin);
286 actor->visible = FALSE;
287 destroy_hildon_actor(actor);
288 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT)
289 actor->time_start_animation = 0;
291 actor->time_start_animation = sec + fast_rnd(180);
297 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
299 gint x0 = -actor->width, y0 = 45,
307 gettimeofday(&tvb, NULL);
311 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
312 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
313 if (actor->time_start_animation == 0){
314 actor->time_start_animation = sec + fast_rnd(180);
318 if (!actor->visible){
319 actor->visible = TRUE;
320 create_hildon_actor(actor, desktop_plugin);
323 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
324 x = path_line(x0, x1, t);
325 y = path_line(y0, y1, t);
326 //scale = path_line(scale0, scale1, t);
327 set_actor_position(actor, x, y, actor->z, desktop_plugin);
330 actor->visible = FALSE;
331 destroy_hildon_actor(actor);
332 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT)
333 actor->time_start_animation = 0;
335 actor->time_start_animation = sec + fast_rnd(180);
341 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
343 gint x0, y0 = 300, scale0 = 100,
344 x1, y1 = -actor->height, scale1 = 150,
352 //fprintf(stderr, "change cloud\n");
353 gettimeofday(&tvb, NULL);
358 if (!actor->visible){
359 actor->visible = TRUE;
360 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
361 newfile = g_strdup_printf("%s_dark.png", actor->name);
363 newfile = g_strdup_printf("%s.png", actor->name);
366 g_free(actor->filename);
367 actor->filename = newfile;
369 create_hildon_actor(actor, desktop_plugin);
371 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
373 if (desktop_plugin->priv->scene->wind_orientation == 1){
382 x = path_line(x0, x1, t);
383 y = -desktop_plugin->priv->scene->wind_angle * (x - x0) + actor->y;
384 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
386 set_actor_position(actor, x, y, actor->z, desktop_plugin);
387 set_actor_scale(actor, (double)scale/100, (double)scale/100);
388 if ((y < y1 || y > y0) || t >= 1){
390 actor->visible = FALSE;
391 destroy_hildon_actor(actor);
392 actor->time_start_animation = sec + fast_rnd(300);
393 actor->y = fast_rnd(300);
399 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
401 desktop_plugin->priv->scene->wind_orientation = fast_rnd(2);
402 if (desktop_plugin->priv->scene->wind_orientation == 0) desktop_plugin->priv->scene->wind_orientation = -1;
403 desktop_plugin->priv->scene->wind_angle = (double)(fast_rnd(200) - 100) / 100;
404 actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
405 //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
409 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
411 gint now = time(NULL);
412 if (desktop_plugin->priv->scene->daytime == TIME_DAY){
414 actor->visible = FALSE;
415 destroy_hildon_actor(actor);
417 actor->time_start_animation = 0;
421 create_hildon_actor(actor, desktop_plugin);
422 if (actor->time_start_animation == 0){
423 actor->time_start_animation = now + fast_rnd(30);
429 actor->visible = TRUE;
431 actor->visible = FALSE;
432 set_actor_visible(actor, actor->visible);
433 actor->time_start_animation = now + fast_rnd(60) + 10;
438 change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
440 gint now = time(NULL);
442 a = g_ptr_array_index(actor->child, 0);
447 set_actor_visible(a, a->visible);
449 a = g_ptr_array_index(actor->child, 1);
454 set_actor_visible(a, a->visible);
456 actor->time_start_animation = now + fast_rnd(30) + 10;
460 change_layer(Actor * actor, AWallpaperPlugin *desktop_plugin)
462 gint y, speed1 = 8, speed2 = 16;
465 if (!desktop_plugin->priv->rich_animation) return;
467 a = g_ptr_array_index(actor->child, 0);
469 if (y > 480) y = -480;
470 set_actor_position(a, a->x, y, a->z, desktop_plugin);
473 a = g_ptr_array_index(actor->child, 1);
475 if (y > 480) y = -480;
476 set_actor_position(a, a->x, y, a->z, desktop_plugin);
479 a = g_ptr_array_index(actor->child, 2);
481 if (y > 480) y = -480;
482 set_actor_position(a, a->x, y, a->z, desktop_plugin);
485 a = g_ptr_array_index(actor->child, 3);
487 if (y > 480) y = -480;
488 set_actor_position(a, a->x, y, a->z, desktop_plugin);
493 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
496 newfile = g_strdup_printf("%s%d.png", actor->name, desktop_plugin->priv->scene->daytime);
498 g_free(actor->filename);
499 actor->filename = newfile;
500 change_hildon_actor(actor, desktop_plugin);
504 change_static_actor_with_corner(Actor * actor, AWallpaperPlugin *desktop_plugin)
508 if (desktop_plugin->priv->right_corner)
509 gtk_widget_destroy(desktop_plugin->priv->right_corner);
510 snprintf(buffer, sizeof(buffer) - 1, "%s/%s/town%i_right_corner.png", \
511 THEME_PATH, desktop_plugin->priv->theme, desktop_plugin->priv->scene->daytime);
512 desktop_plugin->priv->right_corner = gtk_image_new_from_file (buffer);
513 if (desktop_plugin->priv->right_corner){
514 gtk_fixed_put(GTK_FIXED(desktop_plugin->priv->main_widget), desktop_plugin->priv->right_corner, 0, 0);
515 gtk_widget_show (desktop_plugin->priv->right_corner);
517 change_static_actor(actor, desktop_plugin);