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 path_line(gint x0, gint x1, double t)
75 return ((x1 - x0) * t + x0);
79 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
93 a = (double)(y2 - (double)(x2*(y1-y0) + x1*y0 - x0*y1)/(x1-x0))/(x2*(x2-x0-x1)+x0*x1);
94 b = (double)(y1-y0)/(x1-x0) - (double)a*(x0+x1);
95 c = (double)(x1*y0 - x0*y1)/(x1-x0) + (double)a*x0*x1;
96 fprintf(stderr, "a=%f, b=%f, c=%f\n", a, b, c);
98 gettimeofday(&tvb, NULL);
104 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
105 if (!actor->visible){
106 actor->visible = TRUE;
107 phase = get_moon_phase();
108 newfile = g_strdup_printf( "%s%d.png", actor->name, phase);
110 g_free(actor->filename);
111 actor->filename = newfile;
112 actor->time_start_animation = sec - fast_rnd(60 * 60);
113 actor->duration_animation = 1 * 60 * 60;
114 create_hildon_actor(actor, desktop_plugin);
117 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
119 x = path_line(x0, x1, t);
121 x = path_line(x1, x0, t-1);
122 y = 0.001920*x*x - 1.536*x + 337.2;
123 //y = a*x*x + b*x + c;
125 actor_set_position_full(actor->widget, x, y, actor->z);
128 actor->time_start_animation = sec;
131 }else if (actor->visible){
132 actor->visible = FALSE;
133 fprintf(stderr, "destroy moon \n");
134 destroy_hildon_actor(actor);
135 actor->time_start_animation = 0;
142 change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
147 //fprintf(stderr, "change sun\n");
149 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
150 if (!actor->visible){
151 actor->visible = TRUE;
152 create_hildon_actor(actor, desktop_plugin);
154 get_sun_pos(&alt, &azm);
155 get_sun_screen_pos(alt, azm, &x, &y);
158 actor_set_position_full(actor->widget, x, y, actor->z);
159 actor->time_start_animation = time(NULL) + 60;
160 }else if (actor->visible){
161 actor->visible = FALSE;
162 destroy_hildon_actor(actor);
163 actor->time_start_animation = 0;
170 change_tram(Actor * actor, AWallpaperPlugin *desktop_plugin)
172 gint x0 = -300, y0 = 225, scale0 = 100,
173 x1 = 800, y1 = 162, scale1 = 130,
180 //fprintf(stderr, "change tram\n");
181 gettimeofday(&tvb, NULL);
186 if (!actor->visible){
187 actor->visible = TRUE;
188 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
190 g_free(actor->filename);
191 actor->filename = g_strdup("tram_dark.png");
194 g_free(actor->filename);
195 actor->filename = g_strdup("tram.png");
197 create_hildon_actor(actor, desktop_plugin);
199 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
200 x = path_line(x0, x1, t);
201 y = path_line(y0, y1, t);
202 scale = path_line(scale0, scale1, t);
203 actor_set_position_full(actor->widget, x, y, actor->z);
204 set_actor_scale(actor, (double)scale/100, (double)scale/100);
207 actor->visible = FALSE;
208 destroy_hildon_actor(actor);
209 actor->time_start_animation = sec + fast_rnd(60);
214 change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
216 gint x0 = 620, y0 = 233,
224 gettimeofday(&tvb, NULL);
228 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
230 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
231 if (actor->time_start_animation == 0){
232 actor->time_start_animation = sec + fast_rnd(180);
236 if (!actor->visible){
237 actor->visible = TRUE;
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 actor_set_position_full(actor->widget, x, y, actor->z);
247 actor->visible = FALSE;
248 destroy_hildon_actor(actor);
249 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT)
250 actor->time_start_animation = 0;
252 actor->time_start_animation = sec + fast_rnd(180);
258 change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
260 gint x0 = -actor->width, y0 = 45,
268 gettimeofday(&tvb, NULL);
272 // fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
273 if (desktop_plugin->priv->scene->daytime != TIME_NIGHT){
274 if (actor->time_start_animation == 0){
275 actor->time_start_animation = sec + fast_rnd(180);
279 if (!actor->visible){
280 actor->visible = TRUE;
281 create_hildon_actor(actor, desktop_plugin);
284 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
285 x = path_line(x0, x1, t);
286 y = path_line(y0, y1, t);
287 //scale = path_line(scale0, scale1, t);
288 actor_set_position_full(actor->widget, x, y, actor->z);
291 actor->visible = FALSE;
292 destroy_hildon_actor(actor);
293 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT)
294 actor->time_start_animation = 0;
296 actor->time_start_animation = sec + fast_rnd(180);
302 change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
304 gint x0, y0 = 300, scale0 = 100,
305 x1, y1 = -actor->height, scale1 = 150,
313 //fprintf(stderr, "change cloud\n");
314 gettimeofday(&tvb, NULL);
319 if (!actor->visible){
320 actor->visible = TRUE;
321 if (desktop_plugin->priv->scene->daytime == TIME_NIGHT){
322 newfile = g_strdup_printf("%s_dark.png", actor->name);
324 newfile = g_strdup_printf("%s.png", actor->name);
327 g_free(actor->filename);
328 actor->filename = newfile;
330 create_hildon_actor(actor, desktop_plugin);
332 t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
334 if (desktop_plugin->priv->scene->wind_orientation == 1){
343 x = path_line(x0, x1, t);
344 y = -desktop_plugin->priv->scene->wind_angle * (x - x0) + actor->y;
345 scale = path_line(scale0, scale1, (double)(y - y0)/(y1 - y0));
347 actor_set_position_full(actor->widget, x, y, actor->z);
348 set_actor_scale(actor, (double)scale/100, (double)scale/100);
349 if ((y < y1 || y > y0) || t >= 1){
351 actor->visible = FALSE;
352 destroy_hildon_actor(actor);
353 actor->time_start_animation = sec + fast_rnd(300);
354 actor->y = fast_rnd(300);
360 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
362 desktop_plugin->priv->scene->wind_orientation = fast_rnd(2);
363 if (desktop_plugin->priv->scene->wind_orientation == 0) desktop_plugin->priv->scene->wind_orientation = -1;
364 desktop_plugin->priv->scene->wind_angle = (double)(fast_rnd(200) - 100) / 100;
365 actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
366 //fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
370 change_window1(Actor * actor, AWallpaperPlugin *desktop_plugin)
372 gint now = time(NULL);
373 if (desktop_plugin->priv->scene->daytime == TIME_DAY){
375 actor->visible = FALSE;
376 destroy_hildon_actor(actor);
378 actor->time_start_animation = 0;
382 create_hildon_actor(actor, desktop_plugin);
383 if (actor->time_start_animation == 0){
384 actor->time_start_animation = now + fast_rnd(30);
390 actor->visible = TRUE;
392 actor->visible = FALSE;
393 set_actor_visible(actor, actor->visible);
394 actor->time_start_animation = now + fast_rnd(60) + 10;
399 change_signal(Actor * actor, AWallpaperPlugin *desktop_plugin)
401 gint now = time(NULL);
403 a = g_ptr_array_index(actor->child, 0);
408 set_actor_visible(a, a->visible);
410 a = g_ptr_array_index(actor->child, 1);
415 set_actor_visible(a, a->visible);
417 actor->time_start_animation = now + fast_rnd(30) + 10;
421 set_actor_scale(Actor *actor, double scalex, double scaley)
423 hildon_animation_actor_set_scale(
424 HILDON_ANIMATION_ACTOR(actor->widget),
432 set_actor_visible(Actor *actor, gboolean visible)
434 hildon_animation_actor_set_show(HILDON_ANIMATION_ACTOR(actor->widget), visible);