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);
21 rendered: function() {
22 this.canvas = this.$.canvas.hasNode();
23 this.context = this.canvas.getContext('2d');
24 this.resize(window.innerWidth, window.innerHeight);
25 this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
28 for (var i = 0; i < 10; i++) {
29 var img = new Image();
30 img.src = "hacks/Pixelfade/pixelfade" + i + ".gif";
31 this.faders.push(img);
33 this.preferencesChanged();
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) {
59 this.canvas.style.width = w + 'px';
60 this.canvas.style.height = h + 'px';
61 this.canvas.width = w;
62 this.canvas.height = h;
63 this.context.fillColor = 'black';
64 this.context.fillRect(0, 0, w, h);
67 this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
69 preferencesChanged: function() {
70 if (this.background == 'desktop wallpaper') {
71 this.$.wallpaperService.call({
76 this.setStyle('background-image: none; background-color: ' + this.background);
79 canvasClick: function(inSender, inEvent) {
80 clearTimeout(this.fadeInTimer);
81 clearInterval(this.spotTimer);
82 this.spotTimer = setInterval(this.do_fade_spot.bind(this), 3000);
83 this.fader_go(inEvent.clientX, inEvent.clientY);
85 gotWallpaper: function(inSender, inResponse) {
86 enyo.log("got background: " + JSON.stringify(inResponse));
87 this.setStyle('background-image: url(' + inResponse.wallpaper.wallpaperFile + '); background-position: center center');
89 do_fade_spot: function() {
90 var x = Math.floor(Math.random() * this.canvas.width);
91 var y = Math.floor(Math.random() * this.canvas.height);
94 fade_all: function() {
95 this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
96 if (this.fade_val == this.fade_end) {
97 clearInterval(this.timer);
99 if (this.fade_dir == -1)
100 this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
102 this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
104 for (var x = 0; x < this.canvas.width; x += 64) {
105 for (var y = 0; y < this.canvas.height; y += 64) {
106 this.context.drawImage(this.faders[this.fade_val], x, y);
110 this.fade_val += this.fade_dir;
112 fader_go: function(x, y) {
113 this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
114 this.fader_count = 0;
115 this.time_faders(x, y);
116 this.faderptr = new Array(10);
117 for (var i=0; i < 10; i++)
118 this.faderptr[i] = 0;
119 this.t0 = (new Date()).getTime();
120 this.faderRunning = true;
121 clearInterval(this.timer);
122 this.timer = setInterval(this.fader.bind(this), 50);
124 time_faders: function(xpos, ypos) {
125 this.fadertimes = [];
126 for (var y = 0; y < this.canvas.height; y += 64) {
127 for (var x = 0; x < this.canvas.width; x += 64) {
130 this.fadertimes.push({
131 t: 125 - Math.sqrt(xd*xd + yd*yd) / 8,
137 this.fadertimes.sort(function(a, b) { return a.t - b.t });
140 var tnow = (new Date()).getTime();
141 var td = (tnow - this.t0) / 8.0;
142 for (var i = 0; i < 10; i++) {
143 while (this.faderptr[i] < this.fadertimes.length && this.fadertimes[this.faderptr[i]].t < td - i * 10) {
144 var xpos = this.fadertimes[this.faderptr[i]].x;
145 var ypos = this.fadertimes[this.faderptr[i]].y;
146 this.context.clearRect(xpos, ypos, 64, 64);
147 this.context.drawImage(this.faders[i], xpos, ypos);
151 if (this.faderptr[9] >= this.fadertimes.length) {
152 clearTimeout(this.timer);
153 this.fadeInTimer = setTimeout(function() {
157 this.timer = setInterval(this.fade_all.bind(this), 50);