-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawer_dxopal.rb
114 lines (97 loc) · 2.04 KB
/
drawer_dxopal.rb
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
class Drawer
def initialize(ppc)
@ppc = ppc
end
def adjust_px(raw_px)
raw_px.round
end
def window_width
Window.width
end
def window_height
Window.height
end
def real_fps
Window.real_fps
end
def draw_line(x1, y1, x2, y2, color)
Window.draw_line(
adjust_px(x1 * @ppc), adjust_px(y1 * @ppc),
adjust_px(x2 * @ppc), adjust_px(y2 * @ppc),
color
)
end
def draw_line_px(x1, y1, x2, y2, color)
Window.draw_line(
adjust_px(x1), adjust_px(y1),
adjust_px(x2), adjust_px(y2),
color
)
end
def draw_polyline(pts, color, close_path: false)
pts.each_cons(2) { |pt_a, pt_b|
draw_line(
pt_a.x, pt_a.y,
pt_b.x, pt_b.y,
color
)
}
if close_path
pt_l = pts.last
pt_f = pts.first
draw_line(
pt_l.x, pt_l.y,
pt_f.x, pt_f.y,
color
)
end
end
def draw_box(x1, y1, x2, y2, color)
Window.draw_box(
adjust_px(x1 * @ppc), adjust_px(y1 * @ppc),
adjust_px(x2 * @ppc), adjust_px(y2 * @ppc),
color
)
end
def draw_box_fill(x1, y1, x2, y2, color)
Window.draw_box_fill(
adjust_px(x1 * @ppc), adjust_px(y1 * @ppc),
adjust_px(x2 * @ppc), adjust_px(y2 * @ppc),
color
)
end
def draw_box_fill_px(x1, y1, x2, y2, color)
Window.draw_box_fill(
adjust_px(x1), adjust_px(y1),
adjust_px(x2), adjust_px(y2),
color
)
end
def draw_circle(x, y, r, color)
Window.draw_circle(
adjust_px(x * @ppc), adjust_px(y * @ppc),
r * @ppc,
color
)
end
def draw_circle_fill(x, y, r, color)
Window.draw_circle_fill(
adjust_px(x * @ppc), adjust_px(y * @ppc),
r * @ppc,
color
)
end
def create_font(size)
Font.new(size, "monospace")
end
def draw_font(x, y, string, font, option={})
Window.draw_font(
x * @ppc, y * @ppc, string, font, option
)
end
def draw_font_px(x, y, string, font, option={})
Window.draw_font(
x, y, string, font, option
)
end
end