1 #include <hildon/hildon.h>
3 #include "livewp-common.h"
4 #include "livewp-actor.h"
5 #include "livewp-dbus.h"
14 const gint width = 200;
15 const gint height = 120;
17 typedef struct _Scene1 Scene1;
30 void init_pg(gint *pg)
44 void reinit(AWallpaperPlugin *desktop_plugin)
46 fprintf(stderr, "reinit\n");
53 actor = actors[scene->pg[i]];
54 actor->x = (i%4)*width;
55 actor->y = (i/4)*height;
56 //fprintf(stderr, "x=%d, y=%d\n", actor->x, actor->y);
57 set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
58 //set_actor_position(actor, (i%4)*width, (i/4)*height, 2, desktop_plugin);
62 void moving_actor(gint num, gint max, AWallpaperPlugin *desktop_plugin)
64 Actor *actor = actors[scene->pg[scene->bone]];
65 gint x0 = actor->x, y0 = actor->y,
66 x1 = (scene->empty%4)*width, y1 = (scene->empty/4)*height,
68 //x = x0 + (x1-x0)*(max - num)/max;
69 //y = y0 + (y1-y0)*(max - num)/max;
70 x = x0 + (x1-x0)*(max-num)*(max-num)/(max*max);
71 y = y0 + (y1-y0)*(max-num)*(max-num)/(max*max);
72 set_actor_position(actor, x, y, actor->z, desktop_plugin);
76 scene->pg[scene->empty] = scene->pg[scene->bone];
77 scene->pg[scene->bone] = 15;
78 scene->empty = scene->bone;
81 void moving_all(gint num, gint max, AWallpaperPlugin *desktop_plugin)
85 angle = 180*(max - num)*(max-num)/(max*max);
87 if (i%2 == 0) axis = HILDON_AA_X_AXIS;
88 else axis = HILDON_AA_Y_AXIS;
89 set_actor_rotation(actors[i], axis, angle, width/2, height/2, 0);
91 //if (num == (int)max/2){
93 reinit(desktop_plugin);
96 gboolean main_timer(AWallpaperPlugin *desktop_plugin)
98 if (scene->timer_num > 0){
101 moving_actor(scene->timer_num, 10, desktop_plugin);
103 moving_all(scene->timer_num, 20, desktop_plugin);
106 //char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
107 char * accel_filename = "/home/tanya/coord";
109 gint direction = -1, bone;
111 int rs, ax, ay, az, dx, dy;
112 fd = fopen(accel_filename, "r");
114 fprintf(stderr, "cannot open file\n");
117 rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
120 fprintf(stderr, "cannot read information from file\n");
124 //fprintf(stderr, "change obj %i %i %i\n", ax, ay, az);
126 //reinit(desktop_plugin);
128 scene->timer_num = 20;
132 if (abs(ax) - abs(ay) > 300){
135 bone = scene->empty + 1;
136 if (bone % 4 == 0) return TRUE;
140 bone = scene->empty - 1;
141 if (scene->empty % 4 == 0) return TRUE;
144 if (abs(ay) - abs(ax) > 300){
147 bone = scene->empty + 4;
148 if (bone > 15) return TRUE;
152 bone = scene->empty - 4;
153 if (bone < 0) return TRUE;
156 fprintf(stderr, "move %d\n", bone);
158 scene->timer_num = 10;
162 void init_actors(AWallpaperPlugin *desktop_plugin)
166 for (i=0; i<15; i++){
167 actors[i] = init_object(desktop_plugin, "bone", g_strdup_printf("%d.png", i+1),
168 0, 0, 2, width, height,
169 TRUE, TRUE, 100, 255,
175 quit_from_program (Animation_WallpaperPrivate *priv)
181 view_state_changed (Animation_WallpaperPrivate *priv)
184 priv->long_timer = g_timeout_add(100, main_timer, priv->desktop_plugin);
186 g_source_remove(priv->long_timer);
191 read_config (Animation_WallpaperPrivate *priv){}
193 reload_scene(AWallpaperPlugin *desktop_plugin){}
195 int main( int argc, char *argv[] )
198 AWallpaperPlugin *desktop_plugin = g_new0 (AWallpaperPlugin, 1);
199 Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1);
200 scene = g_new0(Scene1, 1);
207 hildon_gtk_init (&argc, &argv);
208 g_set_application_name ("Simplest example");
209 window = hildon_window_new ();
210 g_signal_connect (G_OBJECT (window), "delete_event",
211 G_CALLBACK (gtk_main_quit), NULL);
212 priv->window = window;
213 priv->theme = g_strdup("Fifteen");
216 priv->desktop_plugin = desktop_plugin;
217 desktop_plugin->priv = priv;
219 priv->osso = osso_initialize("org.maemo.livewp", VERSION, TRUE, NULL);
220 livewp_initialize_dbus(priv);
225 //scene->actors = init_actors(desktop_plugin);
226 init_actors(desktop_plugin);
227 scene->timer_num = 0;
228 reinit(desktop_plugin);
229 gtk_widget_show (window);
230 priv->long_timer = g_timeout_add(100, main_timer, desktop_plugin);