summaryrefslogtreecommitdiff
path: root/src/bin/e_bg.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2005-06-29 14:28:47 +0000
committerCarsten Haitzler <raster@rasterman.com>2005-06-29 14:28:47 +0000
commite314c2cc04886cb05deee1e12c6c7a56cf868fc2 (patch)
tree282b5a27f0855bf24c852fe6ed23b273d0e34abf /src/bin/e_bg.c
parent63fb8f4a129f1ba763d03e4f03fbd77d7ef7b009 (diff)
bg now allows transitions when changing the bg. also a first step to allow
different bg's per desk - not implemented yet tho, but some infrastructure for it SVN revision: 15568
Diffstat (limited to 'src/bin/e_bg.c')
-rw-r--r--src/bin/e_bg.c153
1 files changed, 153 insertions, 0 deletions
diff --git a/src/bin/e_bg.c b/src/bin/e_bg.c
new file mode 100644
index 0000000..a14a913
--- /dev/null
+++ b/src/bin/e_bg.c
@@ -0,0 +1,153 @@
1/*
2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3 */
4#include "e.h"
5
6/* local subsystem functions */
7static int _e_bg_animator(void *data);
8
9/* local subsystem globals */
10
11/* externally accessible functions */
12void
13e_bg_zone_update(E_Zone *zone, E_Bg_Transition transition)
14{
15 Evas_Object *o;
16
17 if (transition == E_BG_TRANSITION_START)
18 {
19 zone->bg_transition_mode = e_config->desktop_bg_start_transition;
20 zone->bg_transition_time = e_config->desktop_bg_start_transition_time;
21 }
22 else if (transition == E_BG_TRANSITION_DESK)
23 {
24 zone->bg_transition_mode = e_config->desktop_bg_desk_transition;
25 zone->bg_transition_time = e_config->desktop_bg_desk_transition_time;
26 }
27 else if (transition == E_BG_TRANSITION_CHANGE)
28 {
29 zone->bg_transition_mode = e_config->desktop_bg_change_transition;
30 zone->bg_transition_time = e_config->desktop_bg_change_transition_time;
31 }
32 if ((zone->bg_transition_mode == E_BG_TRANSITION_MODE_NONE) ||
33 (zone->bg_transition_time == 0.0))
34 transition = E_BG_TRANSITION_NONE;
35 if (zone->bg_transition_mode == E_BG_TRANSITION_MODE_RANDOM)
36 {
37 zone->bg_transition_mode =
38 (rand() % (E_BG_TRANSITION_MODE_LAST - E_BG_TRANSITION_MODE_RANDOM))
39 + E_BG_TRANSITION_MODE_RANDOM + 1;
40 if (zone->bg_transition_mode <= E_BG_TRANSITION_MODE_RANDOM)
41 zone->bg_transition_mode = E_BG_TRANSITION_MODE_RANDOM + 1;
42 else if (zone->bg_transition_mode >= E_BG_TRANSITION_MODE_LAST)
43 zone->bg_transition_mode = E_BG_TRANSITION_MODE_LAST - 1;
44 }
45 if (transition == E_BG_TRANSITION_NONE)
46 {
47 if (zone->bg_object)
48 {
49 evas_object_del(zone->bg_object);
50 zone->bg_object = NULL;
51 }
52 }
53 if (transition != E_BG_TRANSITION_NONE)
54 {
55 if (zone->bg_object)
56 {
57 if (zone->prev_bg_object)
58 evas_object_del(zone->prev_bg_object);
59 zone->prev_bg_object = zone->bg_object;
60 zone->bg_object = NULL;
61 }
62 }
63 o = edje_object_add(zone->container->bg_evas);
64 zone->bg_object = o;
65 evas_object_data_set(o, "e_zone", zone);
66 evas_object_move(o, zone->x, zone->y);
67 evas_object_resize(o, zone->w, zone->h);
68
69 /* FIXME: check config and look for a special bg for the current desk */
70 if (!edje_object_file_set(o,
71 e_config->desktop_default_background,
72 "desktop/background"))
73 {
74 e_theme_edje_object_set(o, "base/theme/background",
75 "desktop/background");
76 }
77 evas_object_layer_set(o, -1);
78 evas_object_lower(o);
79
80 evas_object_clip_set(o, zone->bg_clip_object);
81 evas_object_show(o);
82
83 if (zone->prev_bg_object)
84 {
85 const char *pfile = "", *pgroup = "", *file = "", *group = "";
86
87 edje_object_file_get(zone->prev_bg_object, &pfile, &pgroup);
88 edje_object_file_get(zone->bg_object, &file, &group);
89 if ((pfile) && (file) && (!strcmp(pfile, file)) &&
90 (pgroup) && (group) && (!strcmp(pgroup, group)))
91 {
92 evas_object_del(zone->prev_bg_object);
93 zone->prev_bg_object = NULL;
94 return;
95 }
96 }
97
98 if (transition != E_BG_TRANSITION_NONE)
99 {
100 if (!zone->bg_animator)
101 zone->bg_animator= ecore_animator_add(_e_bg_animator, zone);
102 zone->bg_set_time = ecore_time_get();
103 }
104}
105
106/* local subsystem functions */
107
108static int
109_e_bg_animator(void *data)
110{
111 E_Zone *zone;
112 double t;
113 int a;
114
115 zone = data;
116 /* t is an animating INDEX 0.0 - 1.0, it is used as a lookup into
117 * the effect. 1.0 == finished */
118 t = (ecore_time_get() - zone->bg_set_time) / zone->bg_transition_time;
119 if (t < 0.0) t = 0.0;
120 else if (t > 1.0) t = 1.0;
121
122 if (zone->bg_transition_mode == E_BG_TRANSITION_MODE_FADE)
123 {
124 a = (1.0 - t) * 255.0;
125 if (a < 0) a = 0;
126 else if (a > 255) a = 255;
127 evas_object_color_set(zone->prev_bg_object,
128 255, 255, 255, a);
129 }
130 else if (zone->bg_transition_mode == E_BG_TRANSITION_MODE_SINUSOUDAL_FADE)
131 {
132 double t2;
133
134 t2 = (1.0 - cos(t * M_PI)) / 2.0;
135
136 a = (1.0 - t2) * 255.0;
137 if (a < 0) a = 0;
138 else if (a > 255) a = 255;
139 evas_object_color_set(zone->prev_bg_object,
140 255, 255, 255, a);
141 }
142
143 /* if we still animate.. */
144 if (t < 1.0) return 1;
145
146 if (zone->prev_bg_object)
147 {
148 evas_object_del(zone->prev_bg_object);
149 zone->prev_bg_object = NULL;
150 }
151 zone->bg_animator = NULL;
152 return 0;
153}