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 General Public License
11 * as published by the Free Software Foundation; either version 2 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 <hildon/hildon.h>
28 #include "livewp-common.h"
29 #include "livewp-actor.h"
30 #include "livewp-dbus.h"
32 const gint width = 110;
33 const gint height = 110;
34 const gint timeout = 50;
35 const gint time_bone = 15;
36 const gint time_reload = 20;
38 typedef struct _Scene1 Scene1;
51 void init_pg(gint *pg)
65 void reinit(AWallpaperPlugin *desktop_plugin)
67 fprintf(stderr, "reinit\n");
74 actor = actors[scene->pg[i]];
75 actor->x = (i%4)*width;
76 actor->y = (i/4)*height;
77 //fprintf(stderr, "x=%d, y=%d\n", actor->x, actor->y);
78 set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
79 //set_actor_position(actor, (i%4)*width, (i/4)*height, 2, desktop_plugin);
83 void moving_actor(gint num, gint max, AWallpaperPlugin *desktop_plugin)
85 Actor *actor = actors[scene->pg[scene->bone]];
86 gint x0 = actor->x, y0 = actor->y,
87 x1 = (scene->empty%4)*width, y1 = (scene->empty/4)*height,
89 //x = x0 + (x1-x0)*(max - num)/max;
90 //y = y0 + (y1-y0)*(max - num)/max;
91 x = x0 + (x1-x0)*(max-num)*(max-num)/(max*max);
92 y = y0 + (y1-y0)*(max-num)*(max-num)/(max*max);
93 set_actor_position(actor, x, y, actor->z, desktop_plugin);
97 scene->pg[scene->empty] = scene->pg[scene->bone];
98 scene->pg[scene->bone] = 15;
99 scene->empty = scene->bone;
102 void moving_all(gint num, gint max, AWallpaperPlugin *desktop_plugin)
106 angle = 360*(max - num)*(max-num)/(max*max);
107 for (i=0; i<15; i++){
108 if (i%2 == 0) axis = HILDON_AA_X_AXIS;
109 else axis = HILDON_AA_Y_AXIS;
110 set_actor_rotation(actors[i], axis, angle, width/2, height/2, 0);
112 //if (num == (int)max/2){
114 reinit(desktop_plugin);
117 gboolean main_timer(AWallpaperPlugin *desktop_plugin)
119 if (scene->timer_num > 0){
122 moving_actor(scene->timer_num, time_bone, desktop_plugin);
124 moving_all(scene->timer_num, time_reload, desktop_plugin);
127 char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
128 //char * accel_filename = "/home/tanya/coord";
133 fd = fopen(accel_filename, "r");
135 fprintf(stderr, "cannot open file\n");
138 rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
141 fprintf(stderr, "cannot read information from file\n");
145 //fprintf(stderr, "change obj %i %i %i\n", ax, ay, az);
147 //reinit(desktop_plugin);
149 scene->timer_num = time_reload;
153 if (abs(ax) - abs(ay) > 300){
156 bone = scene->empty + 1;
157 if (bone % 4 == 0) return TRUE;
161 bone = scene->empty - 1;
162 if (scene->empty % 4 == 0) return TRUE;
165 if (abs(ay) - abs(ax) > 300){
168 bone = scene->empty + 4;
169 if (bone > 15) return TRUE;
173 bone = scene->empty - 4;
174 if (bone < 0) return TRUE;
177 //fprintf(stderr, "move %d\n", bone);
179 scene->timer_num = time_bone;
183 void init_actors(AWallpaperPlugin *desktop_plugin)
187 actor = init_object(desktop_plugin, "background", g_strdup("background.jpg"),
188 -180, -15, 2, 800, 480,
189 TRUE, TRUE, 100, 255,
191 for (i=0; i<15; i++){
192 actors[i] = init_object(desktop_plugin, "bone", g_strdup_printf("%d.png", i+1),
193 0, 0, 2, width, height,
194 TRUE, TRUE, 100, 255,
200 quit_from_program (Animation_WallpaperPrivate *priv)
206 view_state_changed (Animation_WallpaperPrivate *priv)
208 if (priv->visible && priv->long_timer == 0){
209 priv->long_timer = g_timeout_add(timeout, (GtkFunction)main_timer, priv->desktop_plugin);
210 //fprintf(stderr, "visible = 1 timeout_add %d\n", priv->long_timer);
212 //fprintf(stderr, "visible = 0 timer remove %d\n", priv->long_timer);
213 g_source_remove(priv->long_timer);
214 priv->long_timer = 0;
219 read_config (Animation_WallpaperPrivate *priv)
224 reload_scene(AWallpaperPlugin *desktop_plugin){}
226 int main( int argc, char *argv[] )
229 AWallpaperPlugin *desktop_plugin = g_new0 (AWallpaperPlugin, 1);
230 Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1);
231 scene = g_new0(Scene1, 1);
232 gint c, window_id=0, view=0;
235 while ((c = getopt(argc, argv, ":v:w:")) != -1){
241 window_id = atoi(optarg);
245 //fprintf(stderr, "view=%d window_id=%d\n", view, window_id);
247 hildon_gtk_init (&argc, &argv);
248 g_set_application_name ("Fifteen");
249 window = hildon_window_new ();
250 //gtk_window_fullscreen (GTK_WINDOW(window));
251 gtk_window_set_title(GTK_WINDOW(window),"Fifteen");
252 gtk_window_set_wmclass(GTK_WINDOW(window),"Fifteen_exec","Fifteen_exec");
253 //window->window = window_id;
254 g_signal_connect (G_OBJECT (window), "delete_event",
255 G_CALLBACK (gtk_main_quit), NULL);
256 priv->window = window;
257 priv->theme = g_strdup("Fifteen");
258 priv->xapplet = -180;
260 priv->desktop_plugin = desktop_plugin;
262 priv->long_timer = 0;
263 desktop_plugin->priv = priv;
265 priv->osso = osso_initialize("org.maemo.livewp", VERSION, TRUE, NULL);
266 livewp_initialize_dbus(priv);
271 //scene->actors = init_actors(desktop_plugin);
272 init_actors(desktop_plugin);
273 scene->timer_num = 0;
274 reinit(desktop_plugin);
275 gtk_widget_show (window);
276 //priv->long_timer = g_timeout_add(100, main_timer, desktop_plugin);
277 //fprintf(stderr, "create timer %d\n", priv->long_timer);