Skip to content

Commit 4491a12

Browse files
committed
Blocks UI: Start drawing outlines
1 parent acea6d0 commit 4491a12

File tree

2 files changed

+65
-12
lines changed

2 files changed

+65
-12
lines changed

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

Lines changed: 64 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,47 @@ 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+
[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)

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)