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);
63 void moving_actor(gint num, gint max, AWallpaperPlugin *desktop_plugin)
65 Actor *actor = actors[scene->pg[scene->bone]];
66 gint x0 = actor->x, y0 = actor->y,
67 x1 = (scene->empty%4)*width, y1 = (scene->empty/4)*height,
69 //x = x0 + (x1-x0)*(max - num)/max;
70 //y = y0 + (y1-y0)*(max - num)/max;
71 x = x0 + (x1-x0)*(max-num)*(max-num)/(max*max);
72 y = y0 + (y1-y0)*(max-num)*(max-num)/(max*max);
73 set_actor_position(actor, x, y, actor->z, desktop_plugin);
77 scene->pg[scene->empty] = scene->pg[scene->bone];
78 scene->pg[scene->bone] = 15;
79 scene->empty = scene->bone;
82 void moving_all(gint num, gint max, AWallpaperPlugin *desktop_plugin)
86 angle = 360*(max - num)*(max-num)/(max*max);
88 if (i%2 == 0) axis = HILDON_AA_X_AXIS;
89 else axis = HILDON_AA_Y_AXIS;
90 set_actor_rotation(actors[i], axis, angle, width/2, height/2, 0);
92 //if (num == (int)max/2){
94 reinit(desktop_plugin);
97 gboolean main_timer(AWallpaperPlugin *desktop_plugin)
99 if (scene->timer_num > 0){
102 moving_actor(scene->timer_num, 10, desktop_plugin);
104 moving_all(scene->timer_num, 20, desktop_plugin);
107 //char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
108 char * accel_filename = "/home/tanya/coord";
110 gint direction = -1, bone;
112 int rs, ax, ay, az, dx, dy;
113 fd = fopen(accel_filename, "r");
115 fprintf(stderr, "cannot open file\n");
118 rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
121 fprintf(stderr, "cannot read information from file\n");
125 //fprintf(stderr, "change obj %i %i %i\n", ax, ay, az);
127 //reinit(desktop_plugin);
129 scene->timer_num = 20;
133 if (abs(ax) - abs(ay) > 300){
136 bone = scene->empty + 1;
137 if (bone % 4 == 0) return TRUE;
141 bone = scene->empty - 1;
142 if (scene->empty % 4 == 0) return TRUE;
145 if (abs(ay) - abs(ax) > 300){
148 bone = scene->empty + 4;
149 if (bone > 15) return TRUE;
153 bone = scene->empty - 4;
154 if (bone < 0) return TRUE;
157 //fprintf(stderr, "move %d\n", bone);
159 scene->timer_num = 10;
163 void init_actors(AWallpaperPlugin *desktop_plugin)
167 actor = init_object(desktop_plugin, "background", g_strdup("background.jpg"),
168 -180, -15, 2, 800, 480,
169 TRUE, TRUE, 100, 255,
171 for (i=0; i<15; i++){
172 actors[i] = init_object(desktop_plugin, "bone", g_strdup_printf("%d.png", i+1),
173 0, 0, 2, width, height,
174 TRUE, TRUE, 100, 255,
180 quit_from_program (Animation_WallpaperPrivate *priv)
186 view_state_changed (Animation_WallpaperPrivate *priv)
188 if (priv->visible && priv->long_timer == 0){
189 priv->long_timer = g_timeout_add(50, main_timer, priv->desktop_plugin);
190 //fprintf(stderr, "visible = 1 timeout_add %d\n", priv->long_timer);
192 //fprintf(stderr, "visible = 0 timer remove %d\n", priv->long_timer);
193 g_source_remove(priv->long_timer);
194 priv->long_timer = 0;
199 read_config (Animation_WallpaperPrivate *priv){}
201 reload_scene(AWallpaperPlugin *desktop_plugin){}
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);
210 gint i, c, window_id=0, view=0;
213 while ((c = getopt(argc, argv, ":v:w:")) != -1){
219 window_id = atoi(optarg);
223 //fprintf(stderr, "view=%d window_id=%d\n", view, window_id);
225 hildon_gtk_init (&argc, &argv);
226 g_set_application_name ("Fifteen");
227 window = hildon_window_new ();
228 //gtk_window_fullscreen (GTK_WINDOW(window));
229 gtk_window_set_title(window,"Fifteen");
230 gtk_window_set_wmclass(window,"Fifteen_exec","Fifteen_exec");
231 //window->window = window_id;
232 g_signal_connect (G_OBJECT (window), "delete_event",
233 G_CALLBACK (gtk_main_quit), NULL);
234 priv->window = window;
235 priv->theme = g_strdup("Fifteen");
236 priv->xapplet = -180;
238 priv->desktop_plugin = desktop_plugin;
240 priv->long_timer = 0;
241 desktop_plugin->priv = priv;
243 priv->osso = osso_initialize("org.maemo.livewp", VERSION, TRUE, NULL);
244 livewp_initialize_dbus(priv);
249 //scene->actors = init_actors(desktop_plugin);
250 init_actors(desktop_plugin);
251 scene->timer_num = 0;
252 reinit(desktop_plugin);
253 gtk_widget_show (window);
254 priv->long_timer = g_timeout_add(50, main_timer, desktop_plugin);
255 //fprintf(stderr, "create timer %d\n", priv->long_timer);