1 #include <hildon/hildon.h>
4 #include "livewp-common.h"
5 #include "livewp-actor.h"
6 #include "livewp-dbus.h"
15 const gint width = 110;
16 const gint height = 110;
18 typedef struct _Scene1 Scene1;
31 void init_pg(gint *pg)
45 void reinit(AWallpaperPlugin *desktop_plugin)
47 fprintf(stderr, "reinit\n");
54 actor = actors[scene->pg[i]];
55 actor->x = (i%4)*width;
56 actor->y = (i/4)*height;
57 //fprintf(stderr, "x=%d, y=%d\n", actor->x, actor->y);
58 set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
59 //set_actor_position(actor, (i%4)*width, (i/4)*height, 2, desktop_plugin);
61 fprintf(stderr,"end reinit\n");
64 void moving_actor(gint num, gint max, AWallpaperPlugin *desktop_plugin)
66 Actor *actor = actors[scene->pg[scene->bone]];
67 gint x0 = actor->x, y0 = actor->y,
68 x1 = (scene->empty%4)*width, y1 = (scene->empty/4)*height,
70 //x = x0 + (x1-x0)*(max - num)/max;
71 //y = y0 + (y1-y0)*(max - num)/max;
72 x = x0 + (x1-x0)*(max-num)*(max-num)/(max*max);
73 y = y0 + (y1-y0)*(max-num)*(max-num)/(max*max);
74 set_actor_position(actor, x, y, actor->z, desktop_plugin);
78 scene->pg[scene->empty] = scene->pg[scene->bone];
79 scene->pg[scene->bone] = 15;
80 scene->empty = scene->bone;
83 void moving_all(gint num, gint max, AWallpaperPlugin *desktop_plugin)
87 angle = 360*(max - num)*(max-num)/(max*max);
89 if (i%2 == 0) axis = HILDON_AA_X_AXIS;
90 else axis = HILDON_AA_Y_AXIS;
91 set_actor_rotation(actors[i], axis, angle, width/2, height/2, 0);
93 //if (num == (int)max/2){
95 reinit(desktop_plugin);
98 gboolean main_timer(AWallpaperPlugin *desktop_plugin)
100 if (scene->timer_num > 0){
103 moving_actor(scene->timer_num, 10, desktop_plugin);
105 moving_all(scene->timer_num, 20, desktop_plugin);
108 char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
109 //char * accel_filename = "/home/tanya/coord";
111 gint direction = -1, bone;
113 int rs, ax, ay, az, dx, dy;
114 fd = fopen(accel_filename, "r");
116 fprintf(stderr, "cannot open file\n");
119 rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
122 fprintf(stderr, "cannot read information from file\n");
126 //fprintf(stderr, "change obj %i %i %i\n", ax, ay, az);
128 //reinit(desktop_plugin);
130 scene->timer_num = 20;
134 if (abs(ax) - abs(ay) > 300){
137 bone = scene->empty + 1;
138 if (bone % 4 == 0) return TRUE;
142 bone = scene->empty - 1;
143 if (scene->empty % 4 == 0) return TRUE;
146 if (abs(ay) - abs(ax) > 300){
149 bone = scene->empty + 4;
150 if (bone > 15) return TRUE;
154 bone = scene->empty - 4;
155 if (bone < 0) return TRUE;
158 fprintf(stderr, "move %d\n", bone);
160 scene->timer_num = 10;
164 void init_actors(AWallpaperPlugin *desktop_plugin)
168 actor = init_object(desktop_plugin, "background", g_strdup("background.jpg"),
169 -180, -10, 2, 800, 480,
170 TRUE, TRUE, 100, 255,
172 for (i=0; i<15; i++){
173 actors[i] = init_object(desktop_plugin, "bone", g_strdup_printf("%d.png", i+1),
174 0, 0, 2, width, height,
175 TRUE, TRUE, 100, 255,
181 quit_from_program (Animation_WallpaperPrivate *priv)
187 view_state_changed (Animation_WallpaperPrivate *priv)
190 priv->long_timer = g_timeout_add(50, main_timer, priv->desktop_plugin);
192 g_source_remove(priv->long_timer);
197 read_config (Animation_WallpaperPrivate *priv){}
199 reload_scene(AWallpaperPlugin *desktop_plugin){}
201 int main( int argc, char *argv[] )
204 AWallpaperPlugin *desktop_plugin = g_new0 (AWallpaperPlugin, 1);
205 Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1);
206 scene = g_new0(Scene1, 1);
208 gint i, c, window_id=0, view=0;
211 while ((c = getopt(argc, argv, ":v:w:")) != -1){
217 window_id = atoi(optarg);
221 fprintf(stderr, "view=%d window_id=%d\n", view, window_id);
223 hildon_gtk_init (&argc, &argv);
224 g_set_application_name ("fifteen");
225 window = hildon_window_new ();
226 gtk_window_set_title(window,"fifteen");
227 //window->window = window_id;
228 g_signal_connect (G_OBJECT (window), "delete_event",
229 G_CALLBACK (gtk_main_quit), NULL);
230 priv->window = window;
231 priv->theme = g_strdup("Fifteen");
232 priv->xapplet = -180;
234 priv->desktop_plugin = desktop_plugin;
236 desktop_plugin->priv = priv;
238 priv->osso = osso_initialize("org.maemo.livewp", VERSION, TRUE, NULL);
239 livewp_initialize_dbus(priv);
244 //scene->actors = init_actors(desktop_plugin);
245 init_actors(desktop_plugin);
246 scene->timer_num = 0;
247 reinit(desktop_plugin);
248 gtk_widget_show (window);
249 priv->long_timer = g_timeout_add(50, main_timer, desktop_plugin);