-
Notifications
You must be signed in to change notification settings - Fork 3
/
canvas-tools.js
72 lines (58 loc) · 2.01 KB
/
canvas-tools.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
(function() {
var mod = {};
/**
* window.force.canvas.tools.getAndCreateMainCanvas()
* Simple function trying to retrieve the most logical main canvas and return it,
* and create one if none found
*/
mod.getAndCreateMainCanvas = function (options) {
options = options || {};
var toAppend = false;
// if the document already hold a canvas with an id 'canvas' (Ejecta)
var canvas;
if (window.force.modules.environment.isEjecta()) {
canvas = document.getElementById('canvas');
}
// check if a canvas already exists in the dom
if (!canvas) { // TODO: should check this is really a canvas object instead of checking only if it exists
var elm = document.getElementsByTagName('canvas');
if (elm.length > 1) {
// more than one canvas found
return console.error('mod.getAndCreateMainCanvas > more than 1 canvas is present in the DOM');
} else if (elm.length === 1) {
// one canvas found
canvas = elm[0];
} else {
// no canvas in the DOM, let's create one
var canvas = document.createElement(navigator.isCocoonJS ? 'screencanvas' : 'canvas');
toAppend = true;
}
}
if (options.width) {
canvas.width = options.width;
}
if (options.height) {
canvas.height = options.height;
}
if (toAppend) {
document.body.appendChild(canvas);
}
return canvas;
};
/**
* window.force.canvas.tools.setWallpaper()
* To draw an image or a canvas in another one optimzed (streched + cropped)
* - canvas : the target canvas
* - asset : image or canvas object
* - options : optional
* - width : if set, avoid the target canvas width detection
* - height : if set, avoid the target canvas height detection
*/
mod.drawWallpaper = function (canvas, asset, options) {
}
/*wmin: 0.25
mod.assetSizer = function (srcW, srcH, minWRatio, maxWRatio, minHRatio, maxHRatio) {
}*/
// expose module
window.force.expose('window.force.canvas.tools', mod);
})();