/
overlay.js
221 lines (173 loc) · 6.68 KB
/
overlay.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
function Overlay(rune)
{
Module.call(this,rune);
this.color = new Color("#ffffff");
// draw
this.draw = function(position,rect)
{
if(!this.layer){ this.create_layer(true); this.layer.is_blinking = true; }
if(!position){ position = new Position("0,0"); }
this.layer.clear();
if(rect){
this.draw_rect(position,rect);
}
else if(position.x !== 0 && position.y !== 0){
this.draw_pointer(position);
}
else if(position.x !== 0 ){
this.draw_vertical_line(position);
}
else if(position.y !== 0 ){
this.draw_horizontal_line(position);
}
}
this.draw_rect = function(position = new Position(0,0),rect)
{
if(!position || !rect){ return; }
this.context().beginPath();
position.normalize(rect);
this.context().moveTo(position.x,position.y);
this.context().lineTo(position.x + rect.width,position.y);
this.context().lineTo(position.x + rect.width,position.y + rect.height);
this.context().lineTo(position.x,position.y + rect.height);
this.context().lineTo(position.x,position.y);
// Limits
this.context().moveTo(position.x + (rect.width/2),position.y-2);
this.context().lineTo(position.x + (rect.width/2),position.y+2);
this.context().moveTo(position.x + (rect.width/2),position.y + rect.height-2);
this.context().lineTo(position.x + (rect.width/2),position.y + rect.height+2);
this.context().moveTo(position.x + rect.width-2,position.y + (rect.height/2));
this.context().lineTo(position.x + rect.width+2,position.y + (rect.height/2));
this.context().moveTo(position.x+2,position.y + (rect.height/2));
this.context().lineTo(position.x-2,position.y + (rect.height/2));
// Center
var radius = 3;
var radius_2 = 4;
this.context().moveTo(position.x + (rect.width/2) + radius,position.y + (rect.height/2));
this.context().lineTo(position.x + (rect.width/2) + radius_2,position.y + (rect.height/2));
this.context().moveTo(position.x + (rect.width/2) - radius,position.y + (rect.height/2));
this.context().lineTo(position.x + (rect.width/2) - radius_2,position.y + (rect.height/2));
this.context().moveTo(position.x + (rect.width/2),position.y + (rect.height/2) + radius);
this.context().lineTo(position.x + (rect.width/2),position.y + (rect.height/2) + radius_2);
this.context().moveTo(position.x + (rect.width/2),position.y + (rect.height/2) - radius);
this.context().lineTo(position.x + (rect.width/2),position.y + (rect.height/2) - radius_2);
this.context().lineCap="square";
this.context().lineWidth = 2;
this.context().strokeStyle = "#000000";
this.context().stroke();
this.context().lineCap="round";
this.context().lineWidth = 1;
this.context().strokeStyle = "#ffffff";
this.context().stroke();
this.context().closePath();
}
this.draw_pointer = function(position)
{
this.context().beginPath();
this.context().moveTo(position.x + 2,position.y);
this.context().lineTo(position.x + 5,position.y);
this.context().moveTo(position.x,position.y + 2);
this.context().lineTo(position.x,position.y + 5);
this.context().moveTo(position.x - 2,position.y);
this.context().lineTo(position.x - 5,position.y);
this.context().moveTo(position.x,position.y - 2);
this.context().lineTo(position.x,position.y - 5);
this.context().lineCap="square";
this.context().lineWidth = 2;
this.context().strokeStyle = "#000000";
this.context().stroke();
this.context().lineCap="round";
this.context().lineWidth = 1;
this.context().strokeStyle = "#ffffff";
this.context().stroke();
this.context().closePath();
}
this.draw_line = function(position,to)
{
this.context().beginPath();
this.context().moveTo(position.x,position.y);
this.context().lineTo(to.x,to.y);
this.context().lineCap="square";
this.context().lineWidth = 2;
this.context().strokeStyle = "#000000";
this.context().stroke();
this.context().lineCap="round";
this.context().lineWidth = 1;
this.context().strokeStyle = "#ffffff";
this.context().stroke();
this.context().closePath();
}
this.draw_circle = function(position,radius = 5)
{
this.context().beginPath();
this.context().arc(position.x, position.y, radius, 0, 2 * Math.PI, false);
this.context().lineCap="square";
this.context().lineWidth = 2;
this.context().strokeStyle = "#000000"
this.context().stroke();
this.context().lineCap="round";
this.context().lineWidth = 1;
this.context().strokeStyle = "#ffffff"
this.context().stroke();
this.context().closePath();
}
this.draw_cross = function(position,radius = 5)
{
this.context().beginPath();
this.context().moveTo(position.x+(radius-2),position.y);
this.context().lineTo(position.x+radius,position.y);
this.context().moveTo(position.x-(radius-2),position.y);
this.context().lineTo(position.x-radius,position.y);
this.context().moveTo(position.x,position.y+(radius-2));
this.context().lineTo(position.x,position.y+radius);
this.context().moveTo(position.x,position.y-(radius-2));
this.context().lineTo(position.x,position.y-radius);
this.context().lineCap="square";
this.context().lineWidth = 2;
this.context().strokeStyle = "#000000"
this.context().stroke();
this.context().lineCap="round";
this.context().lineWidth = 1;
this.context().strokeStyle = "#ffffff"
this.context().stroke();
this.context().closePath();
}
this.draw_vertical_line = function(position)
{
this.context().beginPath();
this.context().moveTo(position.x,0);
this.context().lineTo(position.x,ronin.frame.size.height);
this.context().lineCap="square";
this.context().lineWidth = 2;
this.context().strokeStyle = "#000000"
this.context().stroke();
this.context().lineCap="round";
this.context().lineWidth = 1;
this.context().strokeStyle = "#ffffff"
this.context().stroke();
this.context().closePath();
}
this.draw_horizontal_line = function(position)
{
this.context().beginPath();
this.context().moveTo(0,position.y);
this.context().lineTo(ronin.frame.size.width,position.y);
this.context().lineCap="square";
this.context().lineWidth = 2;
this.context().strokeStyle = "#000000"
this.context().stroke();
this.context().lineCap="round";
this.context().lineWidth = 1;
this.context().strokeStyle = "#ffffff"
this.context().stroke();
this.context().closePath();
}
this.clear = function()
{
this.layer.remove(this);
}
this.key_escape = function()
{
if(this.layer){ this.layer.remove(this); }
}
}