-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangle.rb
41 lines (35 loc) · 1.3 KB
/
Rectangle.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
class Rectangle
def initialize(window, color)
@window = window
@color = color
end
def mouse_click(mouse_x, mouse_y)
if mouse_x > OFFSET_MIDDLE - 70 && mouse_x <= OFFSET_MIDDLE || mouse_x > WINDOW_SIZE_X - OFFSET_RIGHT
return
end
if mouse_x > OFFSET_MIDDLE
cur_pos_x = OFFSET_MIDDLE
else
cur_pos_x = OFFSET_LEFT
end
width = 41
while cur_pos_x < mouse_x do
cur_pos_x = cur_pos_x + width
end
cur_pos_x = cur_pos_x - width if mouse_x > OFFSET_LEFT
if mouse_y >= WINDOW_SIZE_Y / 2 + OFFSET_BOTTOM
cur_pos_y = WINDOW_SIZE_Y / 2 + OFFSET_BOTTOM
height = (WINDOW_SIZE_Y) / 2 - OFFSET_BOTTOM - OFFSET_TOP
else
cur_pos_y = OFFSET_TOP
height = (WINDOW_SIZE_Y - OFFSET_BOTTOM - OFFSET_TOP) / 2
end
draw_rec(cur_pos_x, cur_pos_y, width, height)
end
def draw_rec(cur_pos_x, cur_pos_y, width, height)
@window.draw_line(cur_pos_x, cur_pos_y, @color, cur_pos_x, cur_pos_y + height, @color, 0)
@window.draw_line(cur_pos_x + width, cur_pos_y, @color, cur_pos_x + width, cur_pos_y + height, @color, 0)
@window.draw_line(cur_pos_x, cur_pos_y, @color, cur_pos_x + width, cur_pos_y, @color, 0)
@window.draw_line(cur_pos_x, cur_pos_y + height, @color, cur_pos_x + width, cur_pos_y + height, @color, 0)
end
end