/
JBox.jl
119 lines (109 loc) · 3.33 KB
/
JBox.jl
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
function _JBox(
cornerpoint1::Point,
cornerpoint2::Point,
color,
action::Symbol,
vertices::Bool,
)
sethue(color)
verts = box(cornerpoint1, cornerpoint2, action, vertices = vertices)
return verts[2]
end
function _JBox(points::Array, color, action::Symbol, vertices::Bool)
sethue(color)
verts = box(points, action, vertices = vertices)
return verts[2]
end
function _JBox(pt::Point, width::Real, height::Real, color, action::Symbol, vertices::Bool)
sethue(color)
box(pt, width, height, action, vertices = vertices)
return Point(pt.x - width / 2, pt.y + height / 2)
end
function _JBox(
pt::Point,
width::Real,
height::Real,
cornerradius::Float64,
color,
action::Symbol,
)
sethue(color)
box(pt, width, height, cornerradius, action)
return Point(pt.x - width / 2, pt.y + height / 2)
end
"""
JBox(cornerpoint1::Point, cornerpoint2::Point; color="black", action=:stroke, vertices=false)
Create a box (rectangle) between two points and do an action.
Returns the top left corner point of the box.
"""
JBox(
cornerpoint1::Point,
cornerpoint2::Point;
color = "black",
action = :stroke,
vertices = false,
) =
(
args...;
cornerpoint1 = cornerpoint1,
cornerpoint2 = cornerpoint2,
color = color,
action = action,
vertices = vertices,
) -> _JBox(cornerpoint1, cornerpoint2, color, action, vertices)
"""
JBox(points::Array; color="black", action=:stroke, vertices=false)
Create a box/rectangle using the first two points of an array of Points to defined opposite corners.
Returns the top left corner point of the box.
"""
JBox(points::Array; color = "black", action = :stroke, vertices = false) =
(args...; points = points, color = color, action = action, vertices = vertices) ->
_JBox(points, color, action, vertices)
"""
JBox(pt::Point, width::Real, height::Real; color="black", action=:stroke, vertices=false)
Create a box/rectangle centered at point pt with width and height. Use vertices=true to return an array of the four corner points rather than draw the box.
"""
JBox(
pt::Point,
width::Real,
height::Real;
color = "black",
action = :stroke,
vertices = false,
) =
(
args...;
pt = pt,
width = width,
height = height,
color = color,
action = action,
vertices = vertices,
) -> _JBox(pt, width, height, color, action, vertices)
"""
JBox(x::Int64, y::Int64, width::Real, height::Real; color="black", action=:stroke)
Create a box/rectangle centered at point x/y with width and height.
"""
JBox(x::Int64, y::Int64, width::Real, height::Real; color = "black", action = :stroke) =
JBox(Point(x, y), width, height, color = color, action = action)
"""
JBox(pt::Point, width::Real, height::Real, cornerradius::Float64; color="black", action=:stroke)
Draw a box/rectangle centered at point pt with width and height and round each corner by cornerradius.
"""
JBox(
pt::Point,
width::Real,
height::Real,
cornerradius::Float64;
color = "black",
action = :stroke,
) =
(
args...;
pt = pt,
width = width,
height = height,
cornerradius = cornerradius,
color = color,
action = action,
) -> _JBox(pt, width, height, cornerradius, color, action)