Skip to content

Commit 745e88b

Browse files
committed
Blocks UI: Start drawing outlines
1 parent acea6d0 commit 745e88b

File tree

2 files changed

+62
-12
lines changed

2 files changed

+62
-12
lines changed

addons/block_code/ui/blocks/utilities/background/background.gd

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const Constants = preload("res://addons/block_code/ui/constants.gd")
66
@export var color: Color:
77
set = _set_color
88

9+
@export var outline_color: Color:
10+
set = _set_outline_color
11+
912
@export var show_top: bool = true:
1013
set = _set_show_top
1114

@@ -23,6 +26,11 @@ func _set_color(new_color):
2326
queue_redraw()
2427

2528

29+
func _set_outline_color(new_outline_color):
30+
outline_color = new_outline_color
31+
queue_redraw()
32+
33+
2634
func _set_show_top(new_show_top):
2735
show_top = new_show_top
2836
queue_redraw()
@@ -47,12 +55,18 @@ func float_array_to_Vector2Array(coords: Array) -> PackedVector2Array:
4755

4856

4957
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 += [
5670
[size.x, 0.0],
5771
[size.x, size.y],
5872
[Constants.KNOB_X + Constants.KNOB_Z * 2 + Constants.KNOB_W + shift_bottom, size.y],
@@ -63,9 +77,44 @@ func _draw():
6377
[0.0, 0.0],
6478
]
6579

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)

addons/block_code/ui/constants.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ const KNOB_W = 20.0
55
const KNOB_H = 5.0
66
const KNOB_Z = 5.0
77
const CONTROL_MARGIN = 20.0
8+
const OUTLINE_WIDTH = 3.0

0 commit comments

Comments
 (0)