@@ -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,47 @@ 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
+ [Constants .KNOB_X + shift_top , 0.0 ],
85
+ # [Constants.KNOB_X + Constants.KNOB_Z + shift_top, Constants.KNOB_H],
86
+ # [Constants.KNOB_X + Constants.KNOB_Z + Constants.KNOB_W + shift_top, Constants.KNOB_H],
87
+ # [Constants.KNOB_X + Constants.KNOB_Z * 2 + Constants.KNOB_W + shift_top, 0.0],
88
+ ]
89
+ else :
90
+ stroke_polygon += [
91
+ [shift_top , 0.0 ],
92
+ ]
93
+ if show_top :
94
+ stroke_polygon += [
95
+ [Constants .KNOB_X + Constants .KNOB_Z + shift_top , Constants .KNOB_H ],
96
+ [Constants .KNOB_X + Constants .KNOB_Z + Constants .KNOB_W + shift_top , Constants .KNOB_H ],
97
+ [Constants .KNOB_X + Constants .KNOB_Z * 2 + Constants .KNOB_W + shift_top , 0.0 ],
98
+ ]
99
+ stroke_polygon += [
100
+ [size .x , 0.0 ],
101
+ [size .x , size .y ],
102
+ [Constants .KNOB_X + Constants .KNOB_Z * 2 + Constants .KNOB_W + shift_bottom , size .y ],
103
+ [Constants .KNOB_X + Constants .KNOB_Z + Constants .KNOB_W + shift_bottom , size .y + Constants .KNOB_H ],
104
+ [Constants .KNOB_X + Constants .KNOB_Z + shift_bottom , size .y + Constants .KNOB_H ],
105
+ [Constants .KNOB_X + shift_bottom , size .y ],
106
+ ]
107
+ if shift_bottom == 0 :
108
+ stroke_polygon += [
109
+ [0.0 , size .y ],
110
+ ]
111
+ else :
112
+ stroke_polygon += [
113
+ [shift_bottom , size .y ],
114
+ ]
115
+ if shift_top + shift_bottom == 0 :
116
+ stroke_polygon += [
117
+ [0.0 , 0.0 ],
118
+ ]
119
+
120
+ var packed_fill_polygon = float_array_to_Vector2Array (fill_polygon )
121
+ var packed_stroke_polygon = float_array_to_Vector2Array (stroke_polygon )
122
+ draw_colored_polygon (packed_fill_polygon , color )
123
+ draw_polyline (packed_stroke_polygon , outline_color , Constants .OUTLINE_WIDTH )
0 commit comments