Skip to content

Commit

Permalink
Adds top knob variant and styles entry block
Browse files Browse the repository at this point in the history
  • Loading branch information
DoomTas3r committed Oct 19, 2024
1 parent 73ba94c commit e45d7d9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
1 change: 1 addition & 0 deletions addons/block_code/ui/blocks/entry_block/entry_block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extends StatementBlock
func _ready():
super()
bottom_snap = null
_background.show_top = true


static func get_block_class():
Expand Down
2 changes: 1 addition & 1 deletion addons/block_code/ui/blocks/entry_block/entry_block.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ layout_mode = 2
mouse_filter = 1
script = ExtResource("2_yrw8l")
color = Color(1, 1, 1, 1)
show_top = false
top_variant = 1

[node name="DragDropArea" parent="VBoxContainer/TopMarginContainer" instance=ExtResource("3_swkpp")]
layout_mode = 2
Expand Down
59 changes: 39 additions & 20 deletions addons/block_code/ui/blocks/utilities/background/background.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var parent_block: Block
set = _set_color

@export var draw_outline: bool = true:
set = _draw_outline
set = _set_draw_outline

@export var show_top: bool = true:
set = _set_show_top
Expand All @@ -27,9 +27,13 @@ var parent_block: Block
@export var shift_bottom: float = 0.0:
set = _set_shift_bottom

## Style of the top knob
@export var top_variant: int = 0:
set = _set_top_variant

## |0|, \1/, /2/, <3>, >4>, v5v, v6^, \7y, /8y
@export var variant: int = 0:
set = _variant
set = _set_variant


func _set_color(new_color):
Expand All @@ -38,7 +42,7 @@ func _set_color(new_color):
queue_redraw()


func _draw_outline(new_outline):
func _set_draw_outline(new_outline):
draw_outline = new_outline
queue_redraw()

Expand All @@ -63,7 +67,12 @@ func _set_shift_bottom(new_shift_bottom):
queue_redraw()


func _variant(new_variant):
func _set_top_variant(new_variant):
top_variant = clamp(new_variant, 0, 1)
queue_redraw()


func _set_variant(new_variant):
variant = clamp(new_variant, 0, 8)
queue_redraw()

Expand All @@ -75,14 +84,27 @@ func _ready():


func _draw():
var top_left_align = Constants.KNOB_X + shift_top
var bottom_left_align = Constants.KNOB_X + shift_bottom
var top_knob = []
var fill_polygon: PackedVector2Array
fill_polygon.append(Vector2(0.0, 0.0))

if show_top:
fill_polygon.append(Vector2(Constants.KNOB_X + shift_top, 0.0))
fill_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + shift_top, Constants.KNOB_H))
fill_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + Constants.KNOB_W + shift_top, Constants.KNOB_H))
fill_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z * 2 + Constants.KNOB_W + shift_top, 0.0))
if top_variant == 1:
var radius = size.y * 2
var clip = 20
var clip_offset_y = sqrt(abs(pow(radius, 2) - pow(radius - clip, 2)))

for pixel_x in range(-radius + clip, radius + 1 - clip, 5):
var pixel_y = (-sqrt(abs(pow(radius, 2) - pow(pixel_x, 2)))) + clip_offset_y
top_knob.append(Vector2(pixel_x + (radius - clip), pixel_y))
else:
top_knob.append(Vector2(top_left_align, 0.0))
top_knob.append(Vector2(top_left_align + Constants.KNOB_Z, Constants.KNOB_H))
top_knob.append(Vector2(top_left_align + Constants.KNOB_Z + Constants.KNOB_W, Constants.KNOB_H))
top_knob.append(Vector2(top_left_align + Constants.KNOB_Z * 2 + Constants.KNOB_W, 0.0))
fill_polygon.append_array(top_knob)

# Right side
if variant > 0:
Expand All @@ -107,10 +129,10 @@ func _draw():
fill_polygon.append(Vector2(size.x, size.y))

if show_bottom:
fill_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z * 2 + Constants.KNOB_W + shift_bottom, size.y))
fill_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + Constants.KNOB_W + shift_bottom, size.y + Constants.KNOB_H))
fill_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + shift_bottom, size.y + Constants.KNOB_H))
fill_polygon.append(Vector2(Constants.KNOB_X + shift_bottom, size.y))
fill_polygon.append(Vector2(bottom_left_align + Constants.KNOB_Z * 2 + Constants.KNOB_W, size.y))
fill_polygon.append(Vector2(bottom_left_align + Constants.KNOB_Z + Constants.KNOB_W, size.y + Constants.KNOB_H))
fill_polygon.append(Vector2(bottom_left_align + Constants.KNOB_Z, size.y + Constants.KNOB_H))
fill_polygon.append(Vector2(bottom_left_align, size.y))

# Left side
if variant > 0:
Expand Down Expand Up @@ -153,10 +175,7 @@ func _draw():
stroke_polygon.append(Vector2(shift_top - (0.0 if not shift_top > 0 else outline_middle), 0.0))

if show_top:
stroke_polygon.append(Vector2(Constants.KNOB_X + shift_top, 0.0))
stroke_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + shift_top, Constants.KNOB_H))
stroke_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + Constants.KNOB_W + shift_top, Constants.KNOB_H))
stroke_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z * 2 + Constants.KNOB_W + shift_top, 0.0))
stroke_polygon.append_array(top_knob)

# Right line
if variant > 0:
Expand All @@ -181,10 +200,10 @@ func _draw():
stroke_polygon.append(Vector2(size.x, size.y))

if show_bottom:
stroke_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z * 2 + Constants.KNOB_W + shift_bottom, size.y))
stroke_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + Constants.KNOB_W + shift_bottom, size.y + Constants.KNOB_H))
stroke_polygon.append(Vector2(Constants.KNOB_X + Constants.KNOB_Z + shift_bottom, size.y + Constants.KNOB_H))
stroke_polygon.append(Vector2(Constants.KNOB_X + shift_bottom, size.y))
stroke_polygon.append(Vector2(bottom_left_align + Constants.KNOB_Z * 2 + Constants.KNOB_W, size.y))
stroke_polygon.append(Vector2(bottom_left_align + Constants.KNOB_Z + Constants.KNOB_W, size.y + Constants.KNOB_H))
stroke_polygon.append(Vector2(bottom_left_align + Constants.KNOB_Z, size.y + Constants.KNOB_H))
stroke_polygon.append(Vector2(bottom_left_align, size.y))

# Left line
if variant > 0:
Expand Down
4 changes: 2 additions & 2 deletions addons/block_code/ui/blocks/utilities/background/gutter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var parent_block: Block

## Variant
@export var variant: bool = 0:
set = _variant
set = _set_variant


func _set_color(new_color):
Expand All @@ -21,7 +21,7 @@ func _set_color(new_color):
queue_redraw()


func _variant(new_variant):
func _set_variant(new_variant):
variant = new_variant
queue_redraw()

Expand Down

0 comments on commit e45d7d9

Please sign in to comment.