1 #include <hildon/hildon.h>
3 #include "livewp-common.h"
4 #include "livewp-actor.h"
13 const gint width = 200;
14 const gint height = 120;
16 typedef struct _Scene1 Scene1;
29 void init_pg(gint *pg)
44 gint move(gint direction, AWallpaperPlugin *desktop_plugin)
51 if (bone > 15) return -1;
55 if (empty % 4 == 0) return -1;
59 if (bone < 0) return -1;
63 if (bone % 4 == 0) return -1;
65 //actor = actors[pg[bone]];
67 //set_actor_position(actor, (empty%4)*width, (empty/4)*height, actor->z, desktop_plugin);
68 //pg[empty] = pg[bone];
74 void reinit(AWallpaperPlugin *desktop_plugin)
76 fprintf(stderr, "reinit\n");
83 actor = actors[scene->pg[i]];
84 actor->x = (i%4)*width;
85 actor->y = (i/4)*height;
86 //fprintf(stderr, "x=%d, y=%d\n", actor->x, actor->y);
87 set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
88 //set_actor_position(actor, (i%4)*width, (i/4)*height, 2, desktop_plugin);
92 void moving_actor(gint num, gint max, AWallpaperPlugin *desktop_plugin)
94 Actor *actor = actors[scene->pg[scene->bone]];
95 gint x0 = actor->x, y0 = actor->y,
96 x1 = (scene->empty%4)*width, y1 = (scene->empty/4)*height,
98 x = x0 + (x1-x0)*(max - num)/max;
99 y = y0 + (y1-y0)*(max - num)/max;
100 set_actor_position(actor, x, y, actor->z, desktop_plugin);
104 scene->pg[scene->empty] = scene->pg[scene->bone];
105 scene->pg[scene->bone] = 15;
106 scene->empty = scene->bone;
109 void moving_all(gint num, gint max, AWallpaperPlugin *desktop_plugin)
113 for (i=0; i<15; i++){
116 gboolean main_timer(AWallpaperPlugin *desktop_plugin)
118 if (scene->timer_num > 0){
121 moving_actor(scene->timer_num, 10, desktop_plugin);
124 char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
125 //char * accel_filename = "/home/tanya/coord";
127 gint direction = -1, bone;
129 int rs, ax, ay, az, dx, dy;
130 fd = fopen(accel_filename, "r");
132 fprintf(stderr, "cannot open file\n");
135 rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
138 fprintf(stderr, "cannot read information from file\n");
142 //fprintf(stderr, "change obj %i %i %i\n", ax, ay, az);
144 reinit(desktop_plugin);
146 scene->timer_num = 10;
150 if (abs(ax) - abs(ay) > 300){
153 bone = scene->empty + 1;
154 if (bone % 4 == 0) return TRUE;
158 bone = scene->empty - 1;
159 if (scene->empty % 4 == 0) return TRUE;
162 if (abs(ay) - abs(ax) > 300){
165 bone = scene->empty + 4;
166 if (bone > 15) return TRUE;
170 bone = scene->empty - 4;
171 if (bone < 0) return TRUE;
174 fprintf(stderr, "move %d\n", bone);
176 scene->timer_num = 10;
180 void init_actors(AWallpaperPlugin *desktop_plugin)
184 for (i=0; i<15; i++){
185 actors[i] = init_object(desktop_plugin, "bone", g_strdup_printf("%d.png", i+1),
186 0, 0, 2, width, height,
187 TRUE, TRUE, 100, 255,
192 int main( int argc, char *argv[] )
195 AWallpaperPlugin *desktop_plugin = g_new0 (AWallpaperPlugin, 1);
196 Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1);
197 scene = g_new0(Scene1, 1);
202 hildon_gtk_init (&argc, &argv);
203 g_set_application_name ("Simplest example");
204 window = hildon_window_new ();
205 g_signal_connect (G_OBJECT (window), "delete_event",
206 G_CALLBACK (gtk_main_quit), NULL);
207 priv->window = window;
208 priv->theme = g_strdup("Fifteen");
211 desktop_plugin->priv = priv;
215 //scene->actors = init_actors(desktop_plugin);
216 init_actors(desktop_plugin);
217 scene->timer_num = 0;
218 reinit(desktop_plugin);
219 gtk_widget_show (window);
220 g_timeout_add(100, main_timer, desktop_plugin);