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 x = x0 + (x1-x0)*(max-num)*(max-num)/(max*max);
101 y = y0 + (y1-y0)*(max-num)*(max-num)/(max*max);
102 set_actor_position(actor, x, y, actor->z, desktop_plugin);
106 scene->pg[scene->empty] = scene->pg[scene->bone];
107 scene->pg[scene->bone] = 15;
108 scene->empty = scene->bone;
111 void moving_all(gint num, gint max, AWallpaperPlugin *desktop_plugin)
115 angle = 360*(max - num)/max;
116 for (i=0; i<15; i++){
117 if (i%2 == 0) axis = HILDON_AA_Y_AXIS;
118 else axis = HILDON_AA_X_AXIS;
119 set_actor_rotation(actors[i], axis, angle, 0, 0, 0);
121 if (num == (int)max/2){
122 reinit(desktop_plugin);
125 gboolean main_timer(AWallpaperPlugin *desktop_plugin)
127 if (scene->timer_num > 0){
130 moving_actor(scene->timer_num, 10, desktop_plugin);
132 moving_all(scene->timer_num, 20, desktop_plugin);
135 //char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
136 char * accel_filename = "/home/tanya/coord";
138 gint direction = -1, bone;
140 int rs, ax, ay, az, dx, dy;
141 fd = fopen(accel_filename, "r");
143 fprintf(stderr, "cannot open file\n");
146 rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
149 fprintf(stderr, "cannot read information from file\n");
153 //fprintf(stderr, "change obj %i %i %i\n", ax, ay, az);
155 //reinit(desktop_plugin);
157 scene->timer_num = 20;
161 if (abs(ax) - abs(ay) > 300){
164 bone = scene->empty + 1;
165 if (bone % 4 == 0) return TRUE;
169 bone = scene->empty - 1;
170 if (scene->empty % 4 == 0) return TRUE;
173 if (abs(ay) - abs(ax) > 300){
176 bone = scene->empty + 4;
177 if (bone > 15) return TRUE;
181 bone = scene->empty - 4;
182 if (bone < 0) return TRUE;
185 fprintf(stderr, "move %d\n", bone);
187 scene->timer_num = 10;
191 void init_actors(AWallpaperPlugin *desktop_plugin)
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,
203 int main( int argc, char *argv[] )
206 AWallpaperPlugin *desktop_plugin = g_new0 (AWallpaperPlugin, 1);
207 Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1);
208 scene = g_new0(Scene1, 1);
213 hildon_gtk_init (&argc, &argv);
214 g_set_application_name ("Simplest example");
215 window = hildon_window_new ();
216 g_signal_connect (G_OBJECT (window), "delete_event",
217 G_CALLBACK (gtk_main_quit), NULL);
218 priv->window = window;
219 priv->theme = g_strdup("Fifteen");
222 desktop_plugin->priv = priv;
226 //scene->actors = init_actors(desktop_plugin);
227 init_actors(desktop_plugin);
228 scene->timer_num = 0;
229 reinit(desktop_plugin);
230 gtk_widget_show (window);
231 g_timeout_add(100, main_timer, desktop_plugin);