Created
July 23, 2025 13:48
-
-
Save YuriSizov/3ce532bbc03b5cce084c3dcec4312db1 to your computer and use it in GitHub Desktop.
Godot ColorRect's taller, more handsome cousin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
Author
YuriSizov
commented
Jul 23, 2025

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