-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw-rectangle.js
44 lines (40 loc) · 1.65 KB
/
draw-rectangle.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
class DrawingRectangle extends PaintFunction{
constructor(contextReal,contextDraft){
super();
this.contextReal = contextReal;
this.contextDraft = contextDraft;
}
onMouseDown(coord,event){
this.contextDraft.strokeStyle = rgbaColorFill;
this.contextDraft.lineWidth = 5;
this.contextDraft.fillStyle = rgbaColor;
this.origX = coord[0];
this.origY = coord[1];
this.contextDraft.stroke();
}
onDragging(coord,event){
this.contextDraft.strokeStyle = rgbaColorFill;
this.contextDraft.lineWidth = 5;
this.contextDraft.fillStyle = rgbaColor;
this.contextDraft.clearRect(0,0,canvasDraft.width,canvasDraft.height);
this.contextDraft.beginPath();
this.contextDraft.fillRect(this.origX,this.origY,coord[0]- this.origX,coord[1] - this.origY)
this.contextDraft.strokeRect(this.origX,this.origY,coord[0]- this.origX,coord[1] - this.origY)
this.contextDraft.stroke();
this.contextDraft.fill();
}
onMouseMove(){}
onMouseUp(coord){
this.contextReal.strokeStyle = rgbaColorFill;
this.contextReal.lineWidth = 5;
this.contextReal.fillStyle = rgbaColor;
this.contextDraft.clearRect(0,0,canvasDraft.width,canvasDraft.height);
this.contextReal.beginPath();
this.contextReal.fillRect(this.origX,this.origY,coord[0]- this.origX,coord[1] - this.origY)
this.contextDraft.strokeRect(this.origX,this.origY,coord[0]- this.origX,coord[1] - this.origY)
this.contextReal.stroke();
this.contextReal.fill();
}
onMouseLeave(){}
onMouseEnter(){}
}