/*******************************************************************************/
#include "livewp-actor.h"
+static void
+realize (GtkWidget *widget)
+{
+ GdkScreen *screen;
+ screen = gtk_widget_get_screen (widget);
+ gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
+}
+
+static gboolean
+expose_event (GtkWidget *widget,GdkEventExpose *event,
+ gpointer data)
+{
+ cairo_t *cr;
+ GdkPixbuf *pixbuf = (GdkPixbuf *) data;
+
+ cr = gdk_cairo_create(widget->window);
+ if (cr){
+ gdk_cairo_region(cr, event->region);
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
+ cairo_paint(cr);
+ cairo_destroy(cr);
+ }
+ return TRUE;
+}
+
+void
+destroy_hildon_actor(Actor *actor)
+{
+ //fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
+ gtk_widget_destroy(actor->widget);
+ actor->widget = NULL;
+}
+
+void
+create_hildon_actor_text(Actor *actor, AWallpaperPlugin *desktop_plugin)
+{
+ GtkWidget *ha = NULL;
+ GtkWidget *label = NULL;
+
+ ha = hildon_animation_actor_new();
+ label = gtk_label_new(NULL);
+
+ if (label){
+ //g_signal_connect(G_OBJECT(label), "expose_event", G_CALLBACK(expose_event), NULL);
+
+ gtk_container_add (GTK_CONTAINER (ha), label);
+ }
+ realize(ha);
+ gtk_widget_show(label);
+ gtk_widget_show_all(ha);
+
+ /* TO DO check it */
+ /* gdk_flush (); */
+
+ //g_object_set_data(G_OBJECT(ha), "image", image);
+ actor->image = label;
+ hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin->priv->window));
+ actor->widget = ha;
+ set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
+ set_actor_scale(actor, (double)actor->scale/100, (double)actor->scale/100);
+ set_actor_visible(actor, actor->visible);
+}
+
+void
+create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
+{
+ GtkWidget *ha = NULL;
+ GdkPixbuf *pixbuf = NULL;
+ GtkWidget *image = NULL;
+ gchar *str = NULL;
+
+ ha = hildon_animation_actor_new();
+ str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
+ desktop_plugin->priv->theme, actor->filename);
+ pixbuf = gdk_pixbuf_new_from_file_at_size (str,
+ actor->width,
+ actor->height,
+ NULL);
+ /* fprintf(stderr, "create_hildon_actor %s %s\n", actor->name, str); */
+ if (str)
+ g_free(str);
+ if (pixbuf){
+ image = gtk_image_new_from_pixbuf (pixbuf);
+ g_object_unref(G_OBJECT(pixbuf));
+ }
+ if (image){
+ g_signal_connect(G_OBJECT(image), "expose_event",
+ G_CALLBACK(expose_event), pixbuf);
+ gtk_container_add (GTK_CONTAINER (ha), image);
+ }
+ realize(ha);
+ gtk_widget_show_all(ha);
+
+ /* TO DO check it */
+ /* gdk_flush (); */
+
+ //g_object_set_data(G_OBJECT(ha), "image", image);
+ actor->image = image;
+ hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (ha), GTK_WINDOW(desktop_plugin->priv->window));
+
+ actor->widget = ha;
+ set_actor_position(actor, actor->x, actor->y, actor->z, desktop_plugin);
+ set_actor_scale(actor, (double)actor->scale/100, (double)actor->scale/100);
+ set_actor_visible(actor, actor->visible);
+}
+
+void
+change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
+{
+ GtkWidget *image = NULL;
+ GdkPixbuf *pixbuf = NULL;
+ gchar *str = NULL;
+
+ str = g_strdup_printf( "%s/%s/%s", THEME_PATH,
+ desktop_plugin->priv->theme, actor->filename);
+
+ pixbuf = gdk_pixbuf_new_from_file_at_size (str,
+ actor->width,
+ actor->height,
+ NULL);
+ if(str)
+ g_free(str);
+ if (pixbuf){
+ image = gtk_image_new_from_pixbuf (pixbuf);
+ g_object_unref(G_OBJECT(pixbuf));
+ }
+ if (image){
+ g_signal_connect(G_OBJECT(image), "expose_event",
+ G_CALLBACK(expose_event), pixbuf);
+ //if (g_object_get_data(G_OBJECT(actor->widget), "image")){
+ if (actor->image){
+ gtk_container_remove(GTK_CONTAINER(actor->widget), actor->image);
+ }
+ //g_object_set_data(G_OBJECT(actor->widget), "image", image);
+ actor->image = image;
+ gtk_container_add (GTK_CONTAINER (actor->widget), image);
+ realize(actor->widget);
+ gtk_widget_show_all(actor->widget);
+ /* TO DO check it */
+ /* gdk_flush (); */
+
+
+ }
+}
+
Actor*
init_object(AWallpaperPlugin *desktop_plugin,
gchar * name,
void
change_tape(Actor *actor, AWallpaperPlugin *desktop_plugin)
{
- gint x, y,
- speed[4] = {7, 10, 5, 14},
- i;
+ gint x, y, i;
Actor *a;
- double angle = 0;
+
+ if (!desktop_plugin->priv->rich_animation) return;
+ char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
+ //char * accel_filename = "/home/tanya/coord";
+
+ FILE *fd = NULL;
+ int rs, ax, ay, az;
+ fd = fopen(accel_filename, "r");
+ if (fd == NULL){
+ //fprintf(stderr, "cannot open file\n");
+ fd = fopen("/home/user/coord", "r");
+ }
+ rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az);
+ fclose(fd);
+ if (rs != 3){
+ fprintf(stderr, "cannot read information from file\n");
+ return;
+
+ }
+
+ //fprintf(stderr, "change obj %i %i %i angle rad=%f, deg=%f\n", ax, ay, az, atan2(ax, -ay), atan2(ax, -ay)*180/M_PI);
+ int ang = (int)floor(atan2(ay, ax)*180/M_PI);
+ if (ang < 0) ang = 360+ang;
+
if (!desktop_plugin->priv->rich_animation) return;
- for (i=0; i<12; i++){
+ for (i=0; i<16; i++){
a = g_ptr_array_index(actor->child, i);
- x = a->x - cos(angle*M_PI/180)*speed[i/3];
- y = a->y - sin(angle*M_PI/180)*speed[i/3];
- if (x <= -700)
- x = 700*2;
- if (y <= -480)
+ if (a->scale == 100) a->scale = ang;
+ if (abs(a->scale - ang) > 10){
+ if (a->scale > ang){
+ if ((a->scale - ang) < (ang + (360-a->scale))) a->scale--;
+ else a->scale++;
+ }
+ if (a->scale < ang) {
+ if (ang - a->scale < (a->scale+(360-ang))) a->scale++;
+ else a->scale--;
+ }
+ if (a->scale > 360) a->scale = 0;
+ if (a->scale < 0) a->scale = 360;
+ }
+
+ x = a->x - (float)cos(a->scale*M_PI/180)*a->z;
+ y = a->y - (float)sin(a->scale*M_PI/180)*a->z;
+ //x = round(a->x - (float)cos(a->scale*M_PI/180)*a->z);
+ //y = round(a->y - (float)sin(a->scale*M_PI/180)*a->z);
+ //x = a->x - cos(angle)*a->z;
+ //y = a->y - sin(angle)*a->z;
+ if ((a->scale > 270 || a->scale < 90) && x < -a->width*cos(a->scale*M_PI/180)){
+ x = 800;
+ y = fast_rnd(480);
+ }
+ if ((a->scale > 90 && a->scale < 270) && x > 800 - a->width*cos(a->scale*M_PI/180)){
+ x = 0;
+ y = fast_rnd(480);
+ }
+ if (a->scale > 0 && a->scale < 180 && y < -a->width*sin(a->scale*M_PI/180)){
+ y = 480;
+ x = fast_rnd(800);
+ }
+ if (a->scale < 360 && a->scale > 180 && y > 480 - a->width*sin(a->scale*M_PI/180)){
y = 0;
- //set_actor_rotation(a, HILDON_AA_Z_AXIS, angle, -x, -y, 0);
+ x = fast_rnd(800);
+ }
+ //if (i ==0) fprintf(stderr, "x=%d y=%d ang=%d speed=%d\n", x, y, a->scale, a->z);
+ set_actor_rotation(a, HILDON_AA_Z_AXIS, a->scale, 0, 0, 0);
set_actor_position(a, x, y, a->z, desktop_plugin);
a->x = x;
a->y = y;
}
+
}
void