Skip to content

Instantly share code, notes, and snippets.

@YuriSizov
Created July 23, 2025 13:48
Show Gist options
  • Save YuriSizov/3ce532bbc03b5cce084c3dcec4312db1 to your computer and use it in GitHub Desktop.
Save YuriSizov/3ce532bbc03b5cce084c3dcec4312db1 to your computer and use it in GitHub Desktop.
Godot ColorRect's taller, more handsome cousin
@tool
class_name ColorerRect extends Control
enum FillMode {
SOLID,
FRAME,
ZONE,
}
@export var color: Color = Color.WHITE:
set(value):
color = value
queue_redraw()
@export var antialiased: bool = false:
set(value):
antialiased = value
queue_redraw()
@export var fill_mode: FillMode = FillMode.SOLID:
set(value):
fill_mode = value
queue_redraw()
@export_range(-1.0, 20.0, 0.1, "or_greater") var frame_width: float = -1.0:
set(value):
frame_width = value
queue_redraw()
func _draw() -> void:
match fill_mode:
FillMode.SOLID:
draw_rect(Rect2(Vector2.ZERO, size), color, true, -1.0, antialiased)
FillMode.FRAME:
draw_rect(Rect2(Vector2.ZERO, size), color, false, frame_width, antialiased && frame_width >= 0.0)
FillMode.ZONE:
var border_color := color
border_color.a *= 3.0
draw_rect(Rect2(Vector2.ZERO, size), color, true, -1.0, antialiased)
draw_rect(Rect2(Vector2.ZERO, size), border_color, false, frame_width, antialiased && frame_width >= 0.0)
@YuriSizov
Copy link
Author

Godot_v4 3-stable_win64_2025-07-23_15-55-22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment