2 * This file is part of Live Wallpaper (livewp)
4 * Copyright (C) 2010 Vlad Vasiliev
5 * Copyright (C) 2010 Tanya Makova
8 * This software is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This software is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this software; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 /*******************************************************************************/
25 #include <hildon/hildon.h>
26 #include "livewp-home-widget.h"
27 #include <libhildondesktop/libhildondesktop.h>
28 #include <gconf/gconf-client.h>
29 #include "livewp-rules.h"
31 #define PLUGIN_NAME "livewp-home-widget.desktop-0"
32 #define GCONF_KEY_POSITION "/apps/osso/hildon-desktop/applets/%s/position"
33 #define GCONF_KEY_MODIFIED "/apps/osso/hildon-desktop/applets/%s/modified"
34 #define GCONF_KEY_VIEW "/apps/osso/hildon-desktop/applets/%s/view"
36 HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_HOME_PLUGIN_ITEM)
38 #define Xstartposition 795
39 #define Ystartposition 430
41 gint xapplet = 0, yapplet = 0;
42 GSList * objects_list = NULL;
46 expose_event (GtkWidget *widget,GdkEventExpose *event,
50 GdkPixbuf *pixbuf = (GdkPixbuf *) data;
52 cr = gdk_cairo_create(widget->window);
53 gdk_cairo_region(cr, event->region);
54 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
55 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.0, 0.0);
61 realize (GtkWidget *widget)
64 screen = gtk_widget_get_screen (widget);
65 gtk_widget_set_colormap (widget, gdk_screen_get_rgba_colormap (screen));
69 init_applet_position(void)
71 /* To Do Must be Only 1 per secund */
72 GSList *position = NULL;
77 GConfClient *gconf_client = gconf_client_get_default ();
78 position_key = g_strdup_printf (GCONF_KEY_POSITION, PLUGIN_NAME);
79 position = gconf_client_get_list (gconf_client,
83 if (position && position->data && position->next->data){
84 xapplet = GPOINTER_TO_INT (position->data);
85 yapplet = GPOINTER_TO_INT (position->next->data);
87 fprintf(stderr,"Not position \n");
88 position = g_slist_prepend (g_slist_prepend (NULL,
89 GINT_TO_POINTER (Ystartposition)),
90 GINT_TO_POINTER (Xstartposition));
91 gconf_client_set_list (gconf_client,
96 xapplet = Xstartposition;
97 yapplet = Ystartposition;
99 g_free (position_key);
100 modified = g_strdup_printf ("%ld", 0);
101 modified_key = g_strdup_printf (GCONF_KEY_MODIFIED, PLUGIN_NAME);
102 gconf_client_set_string (gconf_client,
106 fprintf(stderr,"position %i %i\n",xapplet, yapplet);
107 gconf_client_clear_cache(gconf_client);
108 g_object_unref(gconf_client);
111 actor_set_position_full(GtkWidget *actor, gint x, gint y, gint z)
113 fprintf(stderr, "actor_set_position_full\n");
114 hildon_animation_actor_set_position_full (HILDON_ANIMATION_ACTOR (actor),x-xapplet, y-yapplet, z);
117 GtkWidget* init_object(gchar * name, gint x, gint y, gint z, gint width, gint height)
124 actor = hildon_animation_actor_new();
126 snprintf(str, 255, "/usr/share/anwall/%s.png", name);
127 //fprintf(stderr, "!!!init object !!!!\nname = %s file = %s\n", name, str);
128 pixbuf = gdk_pixbuf_new_from_file_at_size (str,
133 image = gtk_image_new_from_pixbuf (pixbuf);
134 g_object_unref(G_OBJECT(pixbuf));
136 g_signal_connect(G_OBJECT(image), "expose_event",
137 G_CALLBACK(expose_event), pixbuf);
138 gtk_container_add (GTK_CONTAINER (actor), image);
140 pixbuf = gdk_pixbuf_new_from_file_at_size ("/usr/share/anwall/cloud1.png",
145 image = gtk_image_new_from_pixbuf (pixbuf);
146 g_object_unref(G_OBJECT(pixbuf));
148 g_signal_connect(G_OBJECT(image), "expose_event",
149 G_CALLBACK(expose_event), pixbuf);
151 gtk_container_add (GTK_CONTAINER (actor), image);
152 actor_set_position_full(actor, x, y, z);
153 hildon_animation_actor_set_show (actor, 1);
155 gtk_widget_show_all(actor);
156 g_object_set_data(G_OBJECT(actor), "name", name);
157 g_object_set_data(G_OBJECT(actor), "x", x);
158 g_object_set_data(G_OBJECT(actor), "y", y);
159 g_object_set_data(G_OBJECT(actor), "z", z);
160 g_object_set_data(G_OBJECT(actor), "scale", 10);
163 //objects_list = g_slist_append(objects_list, G_OBJECT(actor));
164 //objects_list = g_slist_append(objects_list, G_OBJECT(a));
169 init_scene(GtkWidget *window)
177 scene.window = window;
178 scene.daytime = get_daytime();
179 scene.dynamic_actors = NULL;
180 scene.static_actors = NULL;
182 get_sun_pos(&alt, &azm);
183 get_sun_screen_pos(alt, azm, &x, &y);
184 fprintf(stderr, "init scene\n");
185 actor = init_object("sun", x, y, 20, 88, 88);
186 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), window);
187 scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
188 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
190 actor = init_object("sky", 0, 0, 0, 800, 480);
191 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), window);
192 scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
194 actor = init_object("town", 0, 0, 10, 800, 480);
195 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), window);
196 scene.static_actors = g_slist_append(scene.static_actors, G_OBJECT(actor));
198 actor = init_object("cloud1", 400, 150, 2, 200, 150);
199 hildon_animation_actor_set_parent (HILDON_ANIMATION_ACTOR (actor), window);
200 scene.dynamic_actors = g_slist_append(scene.dynamic_actors, G_OBJECT(actor));
205 example_label_home_applet_realize (GtkWidget *widget)
208 void get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
210 gint y0 = 400;// - уровень горизонта
213 *x = (int)(azm * 800) - 64;
214 *y = (int)((1 - alt) * y0) - 64;
217 void change_actor(GtkWidget * actor)
220 gint x, y, daytime, sc;
223 name = g_object_get_data(G_OBJECT(actor), "name");
224 fprintf(stderr, "change actor %s\n", name);
226 daytime = get_daytime();
227 if (daytime != TIME_NIGHT){
228 hildon_animation_actor_set_show(actor, 1);
229 get_sun_pos(&alt, &azm);
230 get_sun_screen_pos(alt, azm, &x, &y);
231 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
235 if (name == "cloud1"){
236 x = g_object_get_data(G_OBJECT(actor), "x");
237 y = g_object_get_data(G_OBJECT(actor), "y");
238 sc = g_object_get_data(G_OBJECT(actor), "scale");
248 scale = (double)sc / 10;
249 hildon_animation_actor_set_scale(actor, scale, scale);
250 fprintf(stderr, "cloud x=%d y=%d scale=%f", x, y, scale);
251 actor_set_position_full(actor, x, y, g_object_get_data(G_OBJECT(actor), "z"));
252 g_object_set_data(G_OBJECT(actor), "x", x);
253 g_object_set_data(G_OBJECT(actor), "y", y);
254 g_object_set_data(G_OBJECT(actor), "scale", sc);
260 plugin_on_timeout (gpointer data)
262 gint daytime = get_daytime();
264 fprintf(stderr, "on timeout\n");
266 if (scene.daytime == daytime){
267 // change dynamic actors
268 tmp = scene.dynamic_actors;
270 // change static actors
271 tmp = scene.dynamic_actors;
274 change_actor(tmp->data);
275 tmp = g_slist_next(tmp);
278 scene.daytime = daytime;
281 //get_sun_pos(&alt, &azm);
283 GSList * tmp = objects_list;
285 //processing(tmp->data);
287 str = g_object_get_data(G_OBJECT(tmp->data), "name");
288 fprintf(stderr, "object: %s\n", str);
291 //get_sun_screen_pos(alt, azm, &x, &y);
293 //actor_set_position_full(tmp->data, x, y, 20);
294 //g_object_set_data(G_OBJECT(tmp->data), "posX", x);
295 //g_object_set_data(G_OBJECT(tmp->data), "posY", y);
296 //fprintf(stderr, "x = %d y = %d\n", x, y);
297 child = gtk_container_get_children(GTK_CONTAINER (tmp->data));
298 while (child != NULL) {
299 gtk_container_remove(GTK_CONTAINER (tmp->data), child->data);
303 //snprintf(str, 255, "/usr/share/anwall/%s.png", name);
304 //fprintf(stderr, "!!!init object !!!!\nname = %s file = %s\n", name, str);
309 //hildon_animation_actor_set_show(tmp->data, 0);
312 //fprintf(stderr, "--timeout %s\n", a->name);
313 tmp = g_slist_next(tmp);
316 return TRUE; /* keep running this event */
320 animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
323 label = gtk_label_new ("");
324 gtk_widget_show (label);
325 gtk_container_add (GTK_CONTAINER (desktop_plugin), label);
326 init_applet_position();
327 init_scene(desktop_plugin);
328 desktop_plugin->timer = g_timeout_add(1000*10, plugin_on_timeout, desktop_plugin);
332 animation_wallpaper_plugin_class_init (AWallpaperPluginClass *klass) {}
335 animation_wallpaper_plugin_class_finalize (AWallpaperPluginClass *class) {}