2026-11-11 08:36:13 -06:00
|
|
|
class_name GroupMark
|
|
|
|
|
extends Control
|
2026-11-14 13:55:46 -06:00
|
|
|
## The top-right corner of a card in a group: a filled corner tab in the
|
|
|
|
|
## group's colour (its own, else DEFAULT_COLOR), with an outline that stands
|
|
|
|
|
## out from it, so members are easy to tell from cards that only lie inside
|
|
|
|
|
## the group's frame. The same tab, in the group's own colour, marks a
|
|
|
|
|
## collapsed group. It looks the same in every theme, so a theme change
|
|
|
|
|
## doesn't change how groups look.
|
2026-11-11 08:36:13 -06:00
|
|
|
##
|
2026-11-14 13:55:46 -06:00
|
|
|
## Like CardFrame it draws over the host's whole rectangle, whatever box the
|
|
|
|
|
## container gives it.
|
2026-11-11 08:36:13 -06:00
|
|
|
|
2026-11-14 13:55:46 -06:00
|
|
|
## The colour of a group without a colour of its own, in every theme.
|
|
|
|
|
const DEFAULT_COLOR := Color("#3a7bd5")
|
|
|
|
|
## How far the tab runs along each edge, and its outline's width.
|
|
|
|
|
const SIZE := 22.0
|
|
|
|
|
const OUTLINE := 2.0
|
2026-11-11 08:36:13 -06:00
|
|
|
|
|
|
|
|
var _color := Color(0, 0, 0, 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _init() -> void:
|
|
|
|
|
mouse_filter = MOUSE_FILTER_IGNORE
|
|
|
|
|
texture_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
|
|
|
|
|
visible = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## The colour of a group's mark and border.
|
|
|
|
|
static func color_of(g: TableGroup) -> Color:
|
2026-11-14 13:55:46 -06:00
|
|
|
return Color.from_string(g.color, DEFAULT_COLOR) if g.color != "" else DEFAULT_COLOR
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## A colour that stands out against `fill`: near-black on light colours,
|
|
|
|
|
## white on dark ones.
|
|
|
|
|
static func outline_for(fill: Color) -> Color:
|
|
|
|
|
return Color(0.08, 0.06, 0.1) if fill.get_luminance() > 0.55 else Color(1, 1, 1, 0.95)
|
2026-11-11 08:36:13 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
## Shows the mark for the card's group, or hides it (null).
|
|
|
|
|
func show_for(g: TableGroup) -> void:
|
|
|
|
|
var c := color_of(g) if g else Color(0, 0, 0, 0)
|
|
|
|
|
if c == _color and visible == (g != null):
|
|
|
|
|
return
|
|
|
|
|
_color = c
|
|
|
|
|
visible = g != null
|
|
|
|
|
queue_redraw()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _draw() -> void:
|
|
|
|
|
var host := get_parent() as Control
|
|
|
|
|
if host == null:
|
|
|
|
|
return
|
|
|
|
|
var r := Rect2(-position, host.size)
|
2026-11-14 13:55:46 -06:00
|
|
|
var corner := Vector2(r.end.x, r.position.y)
|
|
|
|
|
var tab := PackedVector2Array([corner, corner + Vector2(-SIZE, 0), corner + Vector2(0, SIZE)])
|
|
|
|
|
draw_colored_polygon(tab, _color)
|
|
|
|
|
var edge := outline_for(_color)
|
|
|
|
|
draw_polyline(PackedVector2Array([corner + Vector2(-SIZE, 0), corner + Vector2(0, SIZE)]), edge, OUTLINE, true)
|
|
|
|
|
draw_polyline(PackedVector2Array([corner + Vector2(-SIZE, 0), corner, corner + Vector2(0, SIZE)]), edge, OUTLINE, true)
|