30 lines
1.1 KiB
GDScript
30 lines
1.1 KiB
GDScript
class_name SketchBox
|
|
extends StyleBox
|
|
## A StyleBox in the HUD's hand-drawn look (Sketch), for the menus built from Controls
|
|
## (UiTheme.sketch): a wobbly fill and a sketched outline (either can be left out), or, as a rule,
|
|
## one pen line across the middle (an HSeparator's). Each box's wobble is seeded from its rect,
|
|
## so boxes differ from each other and each stays put.
|
|
|
|
var fill := Color(0, 0, 0, 0)
|
|
var ink := Sketch.INK
|
|
var width := 2.5
|
|
var as_rule := false
|
|
## How far past the rect it's drawn (a focus frame around a button).
|
|
var grow := 0.0
|
|
|
|
|
|
func _init(p_fill: Color = Color(0, 0, 0, 0), p_ink: Color = Sketch.INK, p_width: float = 2.5, p_rule: bool = false) -> void:
|
|
fill = p_fill
|
|
ink = p_ink
|
|
width = p_width
|
|
as_rule = p_rule
|
|
|
|
|
|
func _draw(to_canvas_item: RID, p_rect: Rect2) -> void:
|
|
var rect := p_rect.grow(grow)
|
|
var seed := fmod(rect.position.x * 0.013 + rect.position.y * 0.007 + rect.size.x * 0.011, 97.0)
|
|
if as_rule:
|
|
var y := rect.get_center().y
|
|
Sketch.line(to_canvas_item, Vector2(rect.position.x, y), Vector2(rect.end.x, y), ink, width, seed)
|
|
return
|
|
Sketch.box(to_canvas_item, rect, fill, ink, width, seed)
|