class_name CardFrame extends Control ## The ornamental border around a card, drawn from the active FrameSet: four ## corners (one picture, mirrored) joined by a repeated edge tile. GradientMap ## recolours the art: its middle greys become the trim colour (the card's own ## colour, else the theme's TRIM) and its black becomes BG_DEEP. A frame set's ## fixed-colour corner pieces are drawn on top by a child, uncoloured. ## ## It's the card's first child and draws around the card's whole rectangle, ## a little outside it (the set's outset), whatever box the container gives it. var _fixed: Control func _init() -> void: mouse_filter = MOUSE_FILTER_IGNORE texture_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS var fs := FrameSet.active if fs and fs.corner_fixed: _fixed = Control.new() _fixed.mouse_filter = MOUSE_FILTER_IGNORE _fixed.use_parent_material = false _fixed.texture_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS _fixed.draw.connect(_draw_fixed) # It must follow the frame's size: a Control only redraws itself when # its own size changes, so a zero-size layer kept the old corners. _fixed.set_anchors_preset(Control.PRESET_FULL_RECT) add_child(_fixed) set_trim(Color(0, 0, 0, 0)) item_rect_changed.connect(_on_rect_changed) ## Recolours the frame; a transparent colour means the theme's TRIM. func set_trim(c: Color) -> void: material = material_for(Style.TRIM if c.a == 0.0 else c) queue_redraw() if _fixed: _fixed.queue_redraw() ## The active frame's material for a trim colour (beaded when none is active). static func material_for(trim: Color) -> ShaderMaterial: return (FrameSet.active if FrameSet.active else FrameSet.beaded()).material_for(trim) ## The frame is drawn around the card's rectangle, so a move inside the card ## (new margins) or a resize redraws both layers. func _on_rect_changed() -> void: queue_redraw() if _fixed: _fixed.queue_redraw() func _frame_rect() -> Rect2: var host := get_parent() as Control return Rect2(-position, host.size).grow(FrameSet.active.outset) func _draw() -> void: var fs := FrameSet.active if fs == null or get_parent() == null: return var r := _frame_rect() fs.draw_corners(self, r, fs.corner) fs.draw_edges(self, r) func _draw_fixed() -> void: var fs := FrameSet.active if fs == null or fs.corner_fixed == null or get_parent() == null: return fs.draw_corners(_fixed, _frame_rect(), fs.corner_fixed)