Frames: corner pieces redraw on resize; built-in theme pictures get mipmaps
Fixed-colour corner pieces (leaves, rivets, clips, triangles) were drawn by a zero-size layer that never redrew, so after a card changed size they stayed at its old corners. Built-in theme pictures had no mipmaps, so Terminal's 1 px lines flickered when zoomed out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c341790d1a
commit
83800c2f0e
3 changed files with 32 additions and 1 deletions
|
|
@ -78,6 +78,10 @@ func _test_frames_and_threads() -> void:
|
|||
if FrameSet.active and FrameSet.active.corner_fixed:
|
||||
var frame := CardFrame.new()
|
||||
_check(frame._fixed != null, "%s: fixed corner pieces get their own layer" % theme_set["id"])
|
||||
main.add_child(frame)
|
||||
frame.size = Vector2(300, 200)
|
||||
frame.size = Vector2(420, 260)
|
||||
_check(frame._fixed.size == frame.size, "%s: the corner layer follows the frame's size (so it redraws on resize)" % theme_set["id"])
|
||||
frame.free()
|
||||
if ThreadStrip.active:
|
||||
var rid := RenderingServer.canvas_item_create()
|
||||
|
|
|
|||
|
|
@ -22,8 +22,12 @@ func _init() -> void:
|
|||
_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.
|
||||
|
|
@ -39,6 +43,14 @@ 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)
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ static func vec2(value: Variant, fallback: Vector2) -> Vector2:
|
|||
|
||||
static func _load_texture(path: String) -> Texture2D:
|
||||
if path.begins_with("res://") and ResourceLoader.exists(path):
|
||||
return load(path) as Texture2D
|
||||
return _with_mipmaps(load(path) as Texture2D)
|
||||
if not FileAccess.file_exists(path):
|
||||
return null
|
||||
var image := Image.new()
|
||||
|
|
@ -81,6 +81,21 @@ static func _load_texture(path: String) -> Texture2D:
|
|||
return ImageTexture.create_from_image(image)
|
||||
|
||||
|
||||
## Built-in pictures are imported without mipmaps, so thin lines (Terminal's
|
||||
## frame) flicker when the spread is zoomed out. This gives them mipmaps as
|
||||
## user files get, whatever their import settings say.
|
||||
static func _with_mipmaps(texture: Texture2D) -> Texture2D:
|
||||
if texture == null or texture.get_image() == null:
|
||||
return texture
|
||||
var image := texture.get_image()
|
||||
if image.has_mipmaps():
|
||||
return texture
|
||||
if image.is_compressed():
|
||||
image.decompress()
|
||||
image.generate_mipmaps()
|
||||
return ImageTexture.create_from_image(image)
|
||||
|
||||
|
||||
static func _load_sound(path: String) -> AudioStream:
|
||||
if path.begins_with("res://") and ResourceLoader.exists(path):
|
||||
return load(path) as AudioStream
|
||||
|
|
|
|||
Loading…
Reference in a new issue