-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathminicanvas.js
124 lines (97 loc) · 2.69 KB
/
minicanvas.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function minicanvas_events(){
minicanvas.onmousedown = function(e){
var left, right, middle;
left = 0;
middle = 1;
right = 2;
if(e.button === left){
mouse.left = true;
if(tool.lockcolordex==false && key.spacebar==false && tool.preventdraw==false && project.lock==false && animation.state==false){
var finalx = Math.floor(mouse.pos.x );
var finaly = Math.floor(mouse.pos.y );
var lastfinalx = Math.floor(mouse.lastpos.x );
var lastfinaly = Math.floor(mouse.lastpos.y );
if(key.shift==true){
lastfinalx = mouse.lastclick.x;
lastfinaly = mouse.lastclick.y;
mouse.lastclick.x = finalx;
mouse.lastclick.y = finaly;
//console.log(lastfinalx+","+lastfinaly);
}
if(mouse.tool=='tile'){
if(key.alt && mouse.canvas==minicanvas){
tile.set.x = tile.map[tile.layer][tile.x][tile.y].x;
tile.set.y = tile.map[tile.layer][tile.x][tile.y].y;
}else{
tile.map[tile.layer][tile.x][tile.y] = {x:tile.set.x, y:tile.set.y};
}
}else if(mouse.tool=='erasetile'){
tile.map[tile.layer][tile.x][tile.y] = {x:-1, y:-1};
}
}
}
else if(e.button === right){
mouse.right = true;
if(e.ctrlKey){
}
}
else if(e.button === middle){
mouse.middle = true;
}
e.preventDefault();
}
minicanvas.onmouseup = function(e){
var left, right, middle;
left = 0;
middle = 1;
right = 2;
getMousePos(minicanvas, e);
mouse.direction=0;
if(e.button === left){
mouse.left = false;
updatePen();
if(tool.lockcolordex==false && tool.preventdraw==false && project.lock==false && animation.state==false){
}
}
else if(e.button === right){
mouse.right = false;
}
else if(e.button === middle){
mouse.middle = false;
}
}
minicanvas.onmouseover = function (e) {
mouse.canvas = minicanvas;
mouse.context = minicontext;
minicanvas.focus();
};
minicanvas.onmouseout = function (e) {
resetPen();
mouse.direction=0;
if(tool.lockcolordex==false && tool.preventdraw==false && project.lock==false && animation.state==false){
}
mouse.left = false;
mouse.right = false;
mouse.middle = false;
if(key.spacebar==false)tool.preventdraw=false;
};
minicanvas.onmousemove = function (e) {
getMousePos(minicanvas, e);
if(mouse.left){
mouse.dragged = true;
}
e.preventDefault();
};
minicanvas.onclick = function(e){
getMousePos(minicanvas, e);
if(e.ctrlKey){
}
};
//ONCLICK DOESNT DETECT RIGHT CLICKS BECAUSE RIGHTCLICKS CALL THE ONCONTEXTMENU EVENT INSTEAD.. preventdefault stops the menu from showing
minicanvas.oncontextmenu = function (e) {
getMousePos(minicanvas, e);
if(e.ctrlKey){
}
e.preventDefault();
};
}