-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofio.canvas.js
47 lines (35 loc) · 1.11 KB
/
ofio.canvas.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
define([
'ofio/ofio',
'ofio/ofio.jquery',
'ofio/ofio.events',
'ofio/ofio.logger'
], function (Ofio) {
var module = new Ofio.Module({
name: 'ofio.canvas',
dependencies: arguments
});
var update_canvas = function () {
var width = this.$el.width();
var height = this.$el.height();
if (this.canvas.width != width || this.canvas.height != height) {
this.canvas.width = width;
this.canvas.height = height;
this.emit('ofio.canvas.update');
}
};
module.init = function () {
if (this.el.tagName.toLowerCase() != 'canvas') {
this.log('`el` is not a canvas', 'warn', module);
}
this.canvas = this.el;
update_canvas.call(this);
this.canvas.width = this.$el.width();
this.canvas.height = this.$el.height();
this.ctx = this.el.getContext('2d');
$(window).resize(update_canvas.bind(this));
};
module.clear_canvas = function () {
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
};
return module;
});