-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer.js
89 lines (70 loc) · 1.87 KB
/
layer.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function layer(container_div_id, width, height, parent_div_id) {
this.container_div_id = container_div_id;
this.width = width;
this.height = height;
var use_parent = document.getElementById(parent_div_id);
if (null === use_parent) {
javascript_abort("cant get parent with");
}
/* create container div */
this.container_div = creatediv(container_div_id, "", width, height, 0, 0, use_parent);
/* store canvas elements (test) */
this.canvases = [];
/* init sublayers */
this.sublayers = [];
this.sublayers_count = 0;
}
/**
* @brief clear all sublayers
*/
layer.prototype.clearall = function() {
if (null == this) {
return;
}
for (var key in this.sublayers) {
if(this.sublayers.hasOwnProperty(key)) {
this.clear(key);
console.log("cleared %s", key);
}
}
}
/**
* @brief clear sublayer (canvas)
*/
layer.prototype.clear= function(canvas) {
if (null === canvas || null === this.sublayers[canvas]) {
return;
}
this.sublayers[canvas].clearRect(0, 0, this.width, this.height);
}
/**
* @brief create sublayer(canvas)
*
* @param id
* @param class
* @param width
* @param height
* @param top
* @param bottom
*
* @return sublayer (canvas) element
*/
//layer.prototype.sublayer = function(id, use_class, width, height, left, top) {
layer.prototype.sublayer = function(id, use_class) {
var ret;
this.sublayers_count++;
var width = this.width;
var height = this.height;
var top = 0;
var left = 0; //200 * this.sublayers_count; //0;
ret = create_canvas(id, use_class, width, height,
this.container_div.left + left, this.container_div.top + top,
//document.body, this.sublayers_count);
this.container_div, this.sublayers_count);
//ret.style.position = "absolute"; /* ne raboti otvytre ? */
/* !? fixes scaling problem */
//ret.getContext('2d').scale(1, 0.5);
this.canvases[id] = ret;
this.sublayers[id] = ret.getContext('2d');
return ret;
}