-
Notifications
You must be signed in to change notification settings - Fork 86
/
dom.js
109 lines (98 loc) · 2.41 KB
/
dom.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
class QLineStyle {
constructor(width, color) {
this.width = width
this.color = color
}
}
class QLine {
constructor(point1, point2, lineStyle) {
this.pt1 = point1
this.pt2 = point2
this.lineStyle = lineStyle
}
onpaint(ctx) {
let lineStyle = this.lineStyle
ctx.lineWidth = lineStyle.width
ctx.strokeStyle = lineStyle.color
ctx.beginPath()
ctx.moveTo(this.pt1.x, this.pt1.y)
ctx.lineTo(this.pt2.x, this.pt2.y)
ctx.stroke()
}
}
class QRect {
constructor(r, lineStyle) {
this.x = r.x
this.y = r.y
this.width = r.width
this.height = r.height
this.lineStyle = lineStyle
}
onpaint(ctx) {
let lineStyle = this.lineStyle
ctx.lineWidth = lineStyle.width
ctx.strokeStyle = lineStyle.color
ctx.beginPath()
ctx.rect(this.x, this.y, this.width, this.height)
ctx.stroke()
}
}
class QEllipse {
constructor(x, y, radiusX, radiusY, lineStyle) {
this.x = x
this.y = y
this.radiusX = radiusX
this.radiusY = radiusY
this.lineStyle = lineStyle
}
onpaint(ctx) {
let lineStyle = this.lineStyle
ctx.lineWidth = lineStyle.width
ctx.strokeStyle = lineStyle.color
ctx.beginPath()
ctx.ellipse(this.x, this.y, this.radiusX, this.radiusY, 0, 0, 2 * Math.PI)
ctx.stroke()
}
}
class QPath {
constructor(points, close, lineStyle) {
this.points = points
this.close = close
this.lineStyle = lineStyle
}
onpaint(ctx) {
let n = this.points.length
if (n < 1) {
return
}
let points = this.points
let lineStyle = this.lineStyle
ctx.lineWidth = lineStyle.width
ctx.strokeStyle = lineStyle.color
ctx.beginPath()
ctx.moveTo(points[0].x, points[0].y)
for (let i = 1; i < n; i++) {
ctx.lineTo(points[i].x, points[i].y)
}
if (this.close) {
ctx.closePath()
}
ctx.stroke()
}
}
class QPaintDoc {
constructor() {
this.shapes = []
}
addShape(shape) {
if (shape != null) {
this.shapes.push(shape)
}
}
onpaint(ctx) {
let shapes = this.shapes
for (let i in shapes) {
shapes[i].onpaint(ctx)
}
}
}