This repository has been archived by the owner on Mar 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.js
58 lines (55 loc) · 1.62 KB
/
display.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var Display = Display || {};
Display = function() {
/*
Create Canvas Element
*/
//this.init();
}
Display.prototype = {
init: function() {
var canvas = document.createElement('canvas');
canvas.id = 'solarDisplay';
this.id = canvas.id;
this.ctx = canvas.getContext('2d');
this.surface = new Surface();
document.body.appendChild(canvas);
document.addEventListener('contextmenu', function (e) {
e.preventDefault();
}, false);
},
set_size: function(width, height) {
if (this.get_init()) {
var canvas = document.getElementById(this.id);
this.surface.set_size(width, height);
this.surface.set_ctx(this.ctx);
this.width = width;
this.height = height;
canvas.width = width;
canvas.height = height;
} else {
console.error('DisplayError: cannot set size in set_size: function()');
}
},
setColor: function(color) {
this.surface.setColor(color);
},
get_ctx: function() {
return this.ctx;
},
get_init: function() {
return this.id ? true : false;
},
update: function(surface) {
var surface = surface || this.surface;
if(surface) {
this.clear();
this.ctx.putImageData(this.surface.pixels, 0, 0);
}
},
clear: function(surface) {
this.ctx.clearRect(this.surface.rect.x, this.surface.rect.y, this.surface.width, this.surface.height);
},
blit: function(surface) {
this.surface.blit(surface);
}
}