@@ -6,6 +6,9 @@ const Constants = preload("res://addons/block_code/ui/constants.gd")
6
6
@export var color : Color :
7
7
set = _set_color
8
8
9
+ @export var outline_color : Color :
10
+ set = _set_outline_color
11
+
9
12
@export var show_top : bool = true :
10
13
set = _set_show_top
11
14
@@ -23,6 +26,11 @@ func _set_color(new_color):
23
26
queue_redraw ()
24
27
25
28
29
+ func _set_outline_color (new_outline_color ):
30
+ outline_color = new_outline_color
31
+ queue_redraw ()
32
+
33
+
26
34
func _set_show_top (new_show_top ):
27
35
show_top = new_show_top
28
36
queue_redraw ()
@@ -47,12 +55,18 @@ func float_array_to_Vector2Array(coords: Array) -> PackedVector2Array:
47
55
48
56
49
57
func _draw ():
50
- var polygon = [
51
- [0.0 , 0.0 ],
52
- [Constants .KNOB_X + shift_top , 0.0 ],
53
- [Constants .KNOB_X + Constants .KNOB_Z + shift_top , Constants .KNOB_H ],
54
- [Constants .KNOB_X + Constants .KNOB_Z + Constants .KNOB_W + shift_top , Constants .KNOB_H ],
55
- [Constants .KNOB_X + Constants .KNOB_Z * 2 + Constants .KNOB_W + shift_top , 0.0 ],
58
+ if outline_color == Color .BLACK :
59
+ outline_color = color .darkened (0.2 )
60
+
61
+ var fill_polygon = [[0.0 , 0.0 ]]
62
+ if show_top :
63
+ fill_polygon += [
64
+ [Constants .KNOB_X + shift_top , 0.0 ],
65
+ [Constants .KNOB_X + Constants .KNOB_Z + shift_top , Constants .KNOB_H ],
66
+ [Constants .KNOB_X + Constants .KNOB_Z + Constants .KNOB_W + shift_top , Constants .KNOB_H ],
67
+ [Constants .KNOB_X + Constants .KNOB_Z * 2 + Constants .KNOB_W + shift_top , 0.0 ],
68
+ ]
69
+ fill_polygon += [
56
70
[size .x , 0.0 ],
57
71
[size .x , size .y ],
58
72
[Constants .KNOB_X + Constants .KNOB_Z * 2 + Constants .KNOB_W + shift_bottom , size .y ],
@@ -63,9 +77,44 @@ func _draw():
63
77
[0.0 , 0.0 ],
64
78
]
65
79
66
- if ! show_top :
67
- for i in 4 :
68
- polygon .remove_at (1 )
69
-
70
- var packed_polygon = float_array_to_Vector2Array (polygon )
71
- draw_colored_polygon (packed_polygon , color )
80
+ var stroke_polygon = []
81
+ if shift_top == 0 :
82
+ stroke_polygon += [
83
+ [0.0 , 0.0 ],
84
+ ]
85
+ else :
86
+ stroke_polygon += [
87
+ [shift_top , 0.0 ],
88
+ ]
89
+ if show_top :
90
+ stroke_polygon += [
91
+ [Constants .KNOB_X + shift_top , 0.0 ],
92
+ [Constants .KNOB_X + Constants .KNOB_Z + shift_top , Constants .KNOB_H ],
93
+ [Constants .KNOB_X + Constants .KNOB_Z + Constants .KNOB_W + shift_top , Constants .KNOB_H ],
94
+ [Constants .KNOB_X + Constants .KNOB_Z * 2 + Constants .KNOB_W + shift_top , 0.0 ],
95
+ ]
96
+ stroke_polygon += [
97
+ [size .x , 0.0 ],
98
+ [size .x , size .y ],
99
+ [Constants .KNOB_X + Constants .KNOB_Z * 2 + Constants .KNOB_W + shift_bottom , size .y ],
100
+ [Constants .KNOB_X + Constants .KNOB_Z + Constants .KNOB_W + shift_bottom , size .y + Constants .KNOB_H ],
101
+ [Constants .KNOB_X + Constants .KNOB_Z + shift_bottom , size .y + Constants .KNOB_H ],
102
+ [Constants .KNOB_X + shift_bottom , size .y ],
103
+ ]
104
+ if shift_bottom == 0 :
105
+ stroke_polygon += [
106
+ [0.0 , size .y ],
107
+ ]
108
+ else :
109
+ stroke_polygon += [
110
+ [shift_bottom , size .y ],
111
+ ]
112
+ if shift_top + shift_bottom == 0 :
113
+ stroke_polygon += [
114
+ [0.0 , 0.0 ],
115
+ ]
116
+
117
+ var packed_fill_polygon = float_array_to_Vector2Array (fill_polygon )
118
+ var packed_stroke_polygon = float_array_to_Vector2Array (stroke_polygon )
119
+ draw_colored_polygon (packed_fill_polygon , color )
120
+ draw_polyline (packed_stroke_polygon , outline_color , Constants .OUTLINE_WIDTH )
0 commit comments