1 /* Copyright 2011 The Dominion of Awesome
2 * See COPYING for licensing information */
6 style: "background-color: yellow; background-position: center center",
8 {name: "background", label: "Background", kind: "ListSelector", items: ['desktop wallpaper'].concat(colorList)}
10 background: 'desktop wallpaper',
12 {name: "canvas", nodeTag: "canvas", onclick: "canvasClick"},
13 {name: "wallpaperService", kind: "PalmService",
14 service: 'palm://com.palm.systemservice',
15 method: 'getPreferences',
16 onSuccess: "gotWallpaper"}
19 this.inherited(arguments);
20 this.preferencesChanged();
22 rendered: function() {
23 this.canvas = this.$.canvas.hasNode();
24 this.context = this.canvas.getContext('2d');
25 this.resize(window.innerWidth, window.innerHeight);
26 this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
29 for (var i = 0; i < 10; i++) {
30 var img = new Image();
31 img.src = "hacks/Pixelfade/pixelfade" + i + ".gif";
32 this.faders.push(img);
36 this.resize(window.innerWidth, window.innerHeight);
39 clearInterval(this.timer);
43 this.timer = setInterval(this.fade_all.bind(this), 50);
46 this.spotTimer = setInterval(this.do_fade_spot.bind(this), 3000);
49 clearInterval(this.timer);
51 clearInterval(this.spotTimer);
52 this.spotTimer = null;
53 clearTimeout(this.fadeInTimer);
54 this.fadeInTimer = null;
56 resize: function(w, h) {
57 this.canvas.style.width = w + 'px';
58 this.canvas.style.height = h + 'px';
59 this.canvas.width = w;
60 this.canvas.height = h;
61 this.context.fillColor = 'black';
62 this.context.fillRect(0, 0, w, h);
65 this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
67 preferencesChanged: function() {
68 if (this.background == 'desktop wallpaper') {
69 this.$.wallpaperService.call({
74 this.setStyle('background-image: none; background-color: ' + this.background);
77 canvasClick: function(inSender, inEvent) {
78 clearTimeout(this.fadeInTimer);
79 clearInterval(this.spotTimer);
80 this.spotTimer = setInterval(this.do_fade_spot.bind(this), 3000);
81 this.fader_go(inEvent.clientX, inEvent.clientY);
83 gotWallpaper: function(inSender, inResponse) {
84 enyo.log("got background: " + JSON.stringify(inResponse));
85 this.setStyle('background-image: url(' + inResponse.wallpaper.wallpaperFile + '); background-position: center center');
87 do_fade_spot: function() {
88 var x = Math.floor(Math.random() * this.canvas.width);
89 var y = Math.floor(Math.random() * this.canvas.height);
92 fade_all: function() {
93 this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
94 if (this.fade_val == this.fade_end) {
95 clearInterval(this.timer);
97 if (this.fade_dir == -1)
98 this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
100 this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
102 for (var x = 0; x < this.canvas.width; x += 64) {
103 for (var y = 0; y < this.canvas.height; y += 64) {
104 this.context.drawImage(this.faders[this.fade_val], x, y);
108 this.fade_val += this.fade_dir;
110 fader_go: function(x, y) {
111 this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
112 this.fader_count = 0;
113 this.time_faders(x, y);
114 this.faderptr = new Array(10);
115 for (var i=0; i < 10; i++)
116 this.faderptr[i] = 0;
117 this.t0 = (new Date()).getTime();
118 this.faderRunning = true;
119 clearInterval(this.timer);
120 this.timer = setInterval(this.fader.bind(this), 50);
122 time_faders: function(xpos, ypos) {
123 this.fadertimes = [];
124 for (var y = 0; y < this.canvas.height; y += 64) {
125 for (var x = 0; x < this.canvas.width; x += 64) {
128 this.fadertimes.push({
129 t: 125 - Math.sqrt(xd*xd + yd*yd) / 8,
135 this.fadertimes.sort(function(a, b) { return a.t - b.t });
138 var tnow = (new Date()).getTime();
139 var td = (tnow - this.t0) / 8.0;
140 for (var i = 0; i < 10; i++) {
141 while (this.faderptr[i] < this.fadertimes.length && this.fadertimes[this.faderptr[i]].t < td - i * 10) {
142 var xpos = this.fadertimes[this.faderptr[i]].x;
143 var ypos = this.fadertimes[this.faderptr[i]].y;
144 this.context.clearRect(xpos, ypos, 64, 64);
145 this.context.drawImage(this.faders[i], xpos, ypos);
149 if (this.faderptr[9] >= this.fadertimes.length) {
150 clearTimeout(this.timer);
151 this.fadeInTimer = setTimeout(function() {
155 this.timer = setInterval(this.fade_all.bind(this), 50);