forked from ansonl/SCIAF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmselection.js
125 lines (112 loc) · 3.42 KB
/
mselection.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
125
var mouseDown = 0;
var boxSelection = 0;
document.onmousedown = mouseDownEvent;
document.getElementById('map').onmouseup = mouseUpEvent;
document.getElementById('map').onmousemove = mouseMovedEvent;
function mouseDownEvent()
{
console.log('mousedown');
mouseDown = 1;
}
function mouseUpEvent()
{
console.log('mouseup');
mouseDown = 0;
//Hide box selection div
document.getElementById('boxselection').style.opacity = 0;
document.getElementById('boxselection').style.width = 10;
document.getElementById('boxselection').style.height = 10;
boxSelection = 0;
console.log('Box Selection ended');
}
function mouseMovedEvent()
{
console.log('mousemoved');
if (mouseDown == 1 && boxSelection == 0)
{
//Show box selection div
new Effect.Move('boxselection', { x: window.event.clientX+window.pageXOffset, y: window.event.clientY+window.pageYOffset, mode: 'absolute',duration:0, transition: Effect.Transitions.linear,fps: 50,queue: { position: 'end', scope: 'cursor', limit:1} });
document.getElementById('boxselection').style.left = window.event.clientX+window.pageXOffset;
document.getElementById('boxselection').style.top = window.event.clientY+window.pageYOffset;
document.getElementById('boxselection').style.opacity = 0.3;
boxSelection = 1;
console.log('Box Selection started');
if(scvid = scv1image)
{
scv1selected=0;
}
if(scvid = scv2image)
{
scv2selected=0;
}
if(scvid = scv3image)
{
scv3selected=0;
}
if(scvid = scv4image)
{
scv4selected=0;
}
}
if (mouseDown == 1 && boxSelection == 1)
{
document.getElementById('boxselection').style.width = window.event.clientX+window.pageXOffset - document.getElementById('boxselection').offsetLeft;
document.getElementById('boxselection').style.height = window.event.clientY+window.pageYOffset - document.getElementById('boxselection').offsetTop;
//for all items in unitArray except item 0
for (unitArrayAmount=unitArray.length-1;unitArrayAmount>=1;unitArrayAmount--)
{
//what is selected unit's element id?
var unitElement = 'scv'+unitArrayAmount+'image';
//check if unit coordinates are in box
if(document.getElementById(unitElement).offsetLeft+36 > document.getElementById('boxselection').offsetLeft+36 && document.getElementById(unitElement).offsetLeft < window.event.clientX+window.pageXOffset && document.getElementById(unitElement).offsetTop+36 > document.getElementById('boxselection').offsetTop && document.getElementById(unitElement).offsetTop+36 < window.event.clientX+window.pageYOffset)
{
console.log('in x of scv' + unitArrayAmount + 'image');
//select appropriate unit
if(unitElement == 'scv1image')
{
scv1selected = 1;
console.log(unitElement);
}
if(unitElement == 'scv2image')
{
scv2selected = 1;
console.log(unitElement);
}
if(unitElement == 'scv3image')
{
scv3selected = 1;
console.log(unitElement);
}
if(unitElement == 'scv4image')
{
scv4selected = 1;
console.log(unitElement);
}
}
else
{
//deselect appropriate unit
if(unitElement == 'scv1image')
{
scv1selected = 0;
console.log(unitElement);
}
if(unitElement == 'scv2image')
{
scv2selected = 0;
console.log(unitElement);
}
if(unitElement == 'scv3image')
{
scv3selected = 0;
console.log(unitElement);
}
if(unitElement == 'scv4image')
{
scv4selected = 0;
console.log(unitElement);
}
}
}
}
}