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"
39 const gint width = 110;
40 const gint height = 110;
42 typedef struct _Scene1 Scene1;
55 void init_pg(gint *pg)
69 void reinit(AWallpaperPlugin *desktop_plugin)
71 fprintf(stderr, "reinit\n");
78 actor = actors[scene->pg[i]];
79 actor->x = (i%4)*width;
80 actor->y = (i/4)*height;
81 //fprintf(stderr, "x=%d, y=%d\n", actor->x, actor->y);
82 set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
83 //set_actor_position(actor, (i%4)*width, (i/4)*height, 2, desktop_plugin);
87 void moving_actor(gint num, gint max, AWallpaperPlugin *desktop_plugin)
89 Actor *actor = actors[scene->pg[scene->bone]];
90 gint x0 = actor->x, y0 = actor->y,
91 x1 = (scene->empty%4)*width, y1 = (scene->empty/4)*height,
93 //x = x0 + (x1-x0)*(max - num)/max;
94 //y = y0 + (y1-y0)*(max - num)/max;
95 x = x0 + (x1-x0)*(max-num)*(max-num)/(max*max);
96 y = y0 + (y1-y0)*(max-num)*(max-num)/(max*max);
97 set_actor_position(actor, x, y, actor->z, desktop_plugin);
101 scene->pg[scene->empty] = scene->pg[scene->bone];
102 scene->pg[scene->bone] = 15;
103 scene->empty = scene->bone;
106 void moving_all(gint num, gint max, AWallpaperPlugin *desktop_plugin)
110 angle = 360*(max - num)*(max-num)/(max*max);
111 for (i=0; i<15; i++){
112 if (i%2 == 0) axis = HILDON_AA_X_AXIS;
113 else axis = HILDON_AA_Y_AXIS;
114 set_actor_rotation(actors[i], axis, angle, width/2, height/2, 0);
116 //if (num == (int)max/2){
118 reinit(desktop_plugin);
121 gboolean main_timer(AWallpaperPlugin *desktop_plugin)
123 if (scene->timer_num > 0){
126 moving_actor(scene->timer_num, 10, desktop_plugin);
128 moving_all(scene->timer_num, 15, desktop_plugin);
131 char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
132 //char * accel_filename = "/home/tanya/coord";
134 gint direction = -1, bone;
136 int rs, ax, ay, az, dx, dy;
137 fd = fopen(accel_filename, "r");
139 fprintf(stderr, "cannot open file\n");
142 rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
145 fprintf(stderr, "cannot read information from file\n");
149 //fprintf(stderr, "change obj %i %i %i\n", ax, ay, az);
151 //reinit(desktop_plugin);
153 scene->timer_num = 15;
157 if (abs(ax) - abs(ay) > 300){
160 bone = scene->empty + 1;
161 if (bone % 4 == 0) return TRUE;
165 bone = scene->empty - 1;
166 if (scene->empty % 4 == 0) return TRUE;
169 if (abs(ay) - abs(ax) > 300){
172 bone = scene->empty + 4;
173 if (bone > 15) return TRUE;
177 bone = scene->empty - 4;
178 if (bone < 0) return TRUE;
181 //fprintf(stderr, "move %d\n", bone);
183 scene->timer_num = 10;
187 void init_actors(AWallpaperPlugin *desktop_plugin)
191 actor = init_object(desktop_plugin, "background", g_strdup("background.jpg"),
192 -180, -15, 2, 800, 480,
193 TRUE, TRUE, 100, 255,
195 for (i=0; i<15; i++){
196 actors[i] = init_object(desktop_plugin, "bone", g_strdup_printf("%d.png", i+1),
197 0, 0, 2, width, height,
198 TRUE, TRUE, 100, 255,
204 quit_from_program (Animation_WallpaperPrivate *priv)
210 view_state_changed (Animation_WallpaperPrivate *priv)
212 if (priv->visible && priv->long_timer == 0){
213 priv->long_timer = g_timeout_add(100, main_timer, priv->desktop_plugin);
214 //fprintf(stderr, "visible = 1 timeout_add %d\n", priv->long_timer);
216 //fprintf(stderr, "visible = 0 timer remove %d\n", priv->long_timer);
217 g_source_remove(priv->long_timer);
218 priv->long_timer = 0;
223 read_config (Animation_WallpaperPrivate *priv){}
225 reload_scene(AWallpaperPlugin *desktop_plugin){}
227 int main( int argc, char *argv[] )
230 AWallpaperPlugin *desktop_plugin = g_new0 (AWallpaperPlugin, 1);
231 Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1);
232 scene = g_new0(Scene1, 1);
234 gint i, c, window_id=0, view=0;
237 while ((c = getopt(argc, argv, ":v:w:")) != -1){
243 window_id = atoi(optarg);
247 //fprintf(stderr, "view=%d window_id=%d\n", view, window_id);
249 hildon_gtk_init (&argc, &argv);
250 g_set_application_name ("Fifteen");
251 window = hildon_window_new ();
252 //gtk_window_fullscreen (GTK_WINDOW(window));
253 gtk_window_set_title(window,"Fifteen");
254 gtk_window_set_wmclass(window,"Fifteen_exec","Fifteen_exec");
255 //window->window = window_id;
256 g_signal_connect (G_OBJECT (window), "delete_event",
257 G_CALLBACK (gtk_main_quit), NULL);
258 priv->window = window;
259 priv->theme = g_strdup("Fifteen");
260 priv->xapplet = -180;
262 priv->desktop_plugin = desktop_plugin;
264 priv->long_timer = 0;
265 desktop_plugin->priv = priv;
267 priv->osso = osso_initialize("org.maemo.livewp", VERSION, TRUE, NULL);
268 livewp_initialize_dbus(priv);
273 //scene->actors = init_actors(desktop_plugin);
274 init_actors(desktop_plugin);
275 scene->timer_num = 0;
276 reinit(desktop_plugin);
277 gtk_widget_show (window);
278 //priv->long_timer = g_timeout_add(100, main_timer, desktop_plugin);
279 //fprintf(stderr, "create timer %d\n", priv->long_timer);