@papercraftgames/estragon 0.1.0-beta.26 → 0.1.0-beta.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -137,6 +137,11 @@ func _component(node: Model.Component) -> void:
137
137
  _error("Grid "+name+" requires start, center, end or stretch",attribute.value.span)
138
138
  return
139
139
  var is_color := VisualStyle.registered(resolved.script,name)
140
+ if VisualStyle.supported(resolved.script) and name=="background_texture_mode" and attribute.value is Model.Literal:
141
+ var message := VisualStyle.surface_error(name,attribute.value.value)
142
+ if not message.is_empty():
143
+ _error(message,attribute.value.span)
144
+ return
140
145
  if is_color:
141
146
  _color(attribute)
142
147
  if not file.diagnostics.is_empty(): return
@@ -3,5 +3,5 @@
3
3
  name="Estragon"
4
4
  description="Native Gogo/GGX highlighting, compilation and validation before Play."
5
5
  author="Resist Design"
6
- version="0.1.0-beta.26"
6
+ version="0.1.0-beta.27"
7
7
  script="plugin.gd"
@@ -365,7 +365,7 @@ func _apply(desired: Element, record: Mounted) -> void:
365
365
  # do not turn omission into permanent native state or change other props.
366
366
  if VisualStyle.supported(desired.type):
367
367
  for key in record.properties:
368
- if key in Length.BORDER_EDGES and not desired.properties.has(key):
368
+ if (key in Length.BORDER_EDGES or key in VisualStyle.RADII.slice(1)) and not desired.properties.has(key):
369
369
  node.set(key,"auto")
370
370
  writes += 1
371
371
  if Profile.is_enabled(): Profile.add("property_writes")
@@ -645,6 +645,9 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
645
645
  var native: String = desired.type if desired.type is String else desired.type.get_instance_base_type()
646
646
  if not properties.has(key) or not NativeAttributes.writable(native,desired.type,str(key),properties[key]): return _invalid_attribute(desired,str(key),"unknown, read-only or reserved native property")
647
647
  var value = desired.properties[key]
648
+ if VisualStyle.supported(desired.type) and key in VisualStyle.SURFACE:
649
+ var message := VisualStyle.surface_error(key,value)
650
+ if not message.is_empty(): return _invalid_attribute(desired,str(key),message)
648
651
  if key=="align_self" and StackContract.self_registered(desired.type):
649
652
  var message := StackContract.error(key,value,"")
650
653
  if not message.is_empty(): return _invalid_attribute(desired,str(key),message)
@@ -12,6 +12,11 @@ const ESTRAGON_GAPS_2D := true
12
12
  const ESTRAGON_SCROLL_2D := true
13
13
  const Scroll = preload("internal/scroll_2d.gd")
14
14
  var _scroll
15
+ @export var clip_content: bool = false:
16
+ set(value):
17
+ if clip_content==value: return
18
+ clip_content = value
19
+ _clip_changed()
15
20
  @export var horizontal_scroll: bool = false:
16
21
  set(value):
17
22
  if horizontal_scroll==value: return
@@ -56,6 +61,56 @@ var _visual_style = VisualStyle.new()
56
61
  const Length = preload("internal/length.gd")
57
62
  var lengths = Length.new()
58
63
  const ESTRAGON_VISUAL_STYLE := true
64
+ @export var background_texture: Texture2D:
65
+ set(value):
66
+ if value==background_texture: return
67
+ background_texture = value
68
+ _visual_style.set_texture(value)
69
+ _queue_style_redraw()
70
+ @export_enum("stretch", "tile") var background_texture_mode: String = "stretch":
71
+ set(value):
72
+ if value==background_texture_mode: return
73
+ var message := VisualStyle.surface_error("background_texture_mode",value)
74
+ if not message.is_empty():
75
+ push_error("Estragon surface: "+message)
76
+ return
77
+ background_texture_mode = value
78
+ _visual_style.set_texture_mode(value)
79
+ _queue_style_redraw()
80
+ var corner_radius: Variant = 0.0:
81
+ set(value):
82
+ if is_same(corner_radius,value) or not _assign_radius("corner_radius",value): return
83
+ corner_radius = value
84
+ _queue_style_redraw()
85
+ var corner_radius_top_left: Variant = "auto":
86
+ set(value):
87
+ if is_same(corner_radius_top_left,value) or not _assign_radius("corner_radius_top_left",value): return
88
+ corner_radius_top_left = value
89
+ _queue_style_redraw()
90
+ var corner_radius_top_right: Variant = "auto":
91
+ set(value):
92
+ if is_same(corner_radius_top_right,value) or not _assign_radius("corner_radius_top_right",value): return
93
+ corner_radius_top_right = value
94
+ _queue_style_redraw()
95
+ var corner_radius_bottom_right: Variant = "auto":
96
+ set(value):
97
+ if is_same(corner_radius_bottom_right,value) or not _assign_radius("corner_radius_bottom_right",value): return
98
+ corner_radius_bottom_right = value
99
+ _queue_style_redraw()
100
+ var corner_radius_bottom_left: Variant = "auto":
101
+ set(value):
102
+ if is_same(corner_radius_bottom_left,value) or not _assign_radius("corner_radius_bottom_left",value): return
103
+ corner_radius_bottom_left = value
104
+ _queue_style_redraw()
105
+ func _assign_radius(name: String, value) -> bool:
106
+ var parsed := Length.parse(value,Length.domain(name))
107
+ _visual_style.parse_count += 1
108
+ if parsed.has("error"):
109
+ push_error("Estragon surface '"+name+"': "+parsed.error)
110
+ return false
111
+ _visual_style.radii[name] = parsed
112
+ _visual_style.sync_viewport()
113
+ return true
59
114
  var background_color: Variant = "transparent":
60
115
  set(value):
61
116
  if is_same(background_color,value) or not _style_supported() or not _visual_style.assign("background_color",value): return
@@ -223,6 +278,7 @@ func _get_property_list() -> Array[Dictionary]:
223
278
  var properties := Length.properties(["width","height","min_width","min_height","max_width","max_height","x","y","gap","padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"])
224
279
  properties.append_array(Length.properties(["row_gap","column_gap"]))
225
280
  if VisualStyle.supported(get_script()): properties.append_array(Length.properties(["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width","background_color","border_color"]))
281
+ if VisualStyle.supported(get_script()): properties.append_array(Length.properties(VisualStyle.RADII))
226
282
  return properties
227
283
  static func valid_length(value) -> bool:
228
284
  return Length.valid(value,"extent")
@@ -265,6 +321,17 @@ func _scroll_changed() -> void:
265
321
  if _scroll==null and (horizontal_scroll or vertical_scroll): _scroll = Scroll.new(self)
266
322
  _changed()
267
323
  if _scroll!=null and is_inside_tree(): _scroll.start()
324
+ func _clip_changed() -> void:
325
+ if _scroll==null and clip_content: _scroll = Scroll.new(self)
326
+ if layout==null: return
327
+ layout.model.clips_content = clip_content
328
+ if _scroll!=null and is_inside_tree(): _scroll.start()
329
+ # Only overflow observers need a refresh, not the existing layout slots.
330
+ var coordinator = layout.parent_coordinator()
331
+ while coordinator!=null:
332
+ var node = coordinator._host.get_ref()
333
+ if node!=null and "_scroll" in node and node._scroll!=null: node._scroll.refresh()
334
+ coordinator = coordinator.parent_coordinator()
268
335
  func _composition_child_parent() -> Node:
269
336
  return _scroll.child_parent() if _scroll!=null and is_instance_valid(_scroll.child_parent()) else self
270
337
  func _composition_is_private(child: Node) -> bool:
@@ -294,12 +361,15 @@ func _enter_tree() -> void:
294
361
  # cannot accidentally bypass the shared style. Legacy widget painters
295
362
  # explicitly opt out of S01 styles and remain untouched until S02.
296
363
  if VisualStyle.supported(get_script()) and not draw.is_connected(_paint_visual_style): draw.connect(_paint_visual_style)
297
- if _scroll==null and (horizontal_scroll or vertical_scroll or get_node_or_null("_EstragonViewport")!=null): _scroll = Scroll.new(self)
364
+ _visual_style.start(self)
365
+ layout.model.clips_content = clip_content
366
+ if _scroll==null and (clip_content or horizontal_scroll or vertical_scroll or get_node_or_null("_EstragonViewport")!=null): _scroll = Scroll.new(self)
298
367
  if _scroll!=null: _scroll.start()
299
368
  layout.changed()
300
369
  layout.start()
301
370
 
302
371
  func _exit_tree() -> void:
372
+ _visual_style.stop()
303
373
  if _scroll!=null: _scroll.stop()
304
374
  if draw.is_connected(_paint_visual_style): draw.disconnect(_paint_visual_style)
305
375
  layout.stop()
@@ -321,8 +391,10 @@ func apply_layout_position(offset: Vector3) -> void:
321
391
 
322
392
  func apply_layout_size(size: Vector3) -> void:
323
393
  var next := Vector2(size.x,size.y)
324
- if next!=_layout_size: _queue_style_redraw()
394
+ var size_changed := next!=_layout_size
325
395
  _layout_size = next
396
+ var surface_changed := _prepare_surface()
397
+ if size_changed or surface_changed: _queue_style_redraw()
326
398
  _content_extent = layout.model.content_extent()
327
399
  # Explicit invalidation also restores a native position edited externally.
328
400
  if layout.parent_coordinator() != null: layout._place(layout.model.offset)
@@ -334,8 +406,17 @@ func _margin_insets() -> Vector4:
334
406
  return layout.model.margin
335
407
 
336
408
  func _queue_style_redraw() -> void:
409
+ if layout!=null: _prepare_surface()
337
410
  _visual_style.redraw_count += 1
338
411
  queue_redraw()
412
+ func _prepare_surface() -> bool:
413
+ var resolved := Vector4.ZERO
414
+ var viewport: Vector2 = get_viewport_rect().size if is_inside_tree() else layout.model.viewport_size
415
+ for index in range(4):
416
+ var spec: Dictionary = _visual_style.radii.get(VisualStyle.RADII[index+1],{"unit":"auto","value":0.0})
417
+ if spec.unit=="auto": spec = _visual_style.radii.get("corner_radius",{"unit":"native","value":0.0})
418
+ resolved[index] = Length.resolve(spec,minf(layout_size.x,layout_size.y),viewport)
419
+ return _visual_style.prepare(layout_size,layout.model.border,resolved)
339
420
  func _paint_visual_style() -> void:
340
421
  _visual_style.paint(self,layout_size,layout.model.border,get_background_color())
341
422
  func get_background_color() -> Color:
@@ -146,7 +146,7 @@ func changed() -> void:
146
146
  model.set_align_self(host.align_self if _dimension==2 and "align_self" in host else "auto")
147
147
  if "lengths" in host:
148
148
  for property in host._get_property_list():
149
- if not Core.Length.domain(property.name).is_empty() and not host.lengths.specs.has(property.name): host.lengths.assign(property.name,host.get(property.name),Core.Length.domain(property.name,host.get_script()))
149
+ if not property.name in Core.Length.VisualStyle.RADII and not Core.Length.domain(property.name).is_empty() and not host.lengths.specs.has(property.name): host.lengths.assign(property.name,host.get(property.name),Core.Length.domain(property.name,host.get_script()))
150
150
  model.set_lengths(host.lengths.specs,host.grow,host.stretch,host.pixels_per_unit if _dimension==3 else 1.0,options.axis,host._default_padding() if host.has_method("_default_padding") else Vector4.ZERO)
151
151
  model.configure(host.requested_extent(),model.gap,host.center,options.axis,options.fill,options.intrinsic,model.padding if "lengths" in host else options.get("padding",Vector4.ZERO),model.margin if "lengths" in host else options.get("margin",Vector4.ZERO))
152
152
  else: model.configure(host.requested_extent(), host.gap, host.center)
@@ -36,6 +36,7 @@ var policy_result: Dictionary = {}
36
36
  var strategy := "stack"
37
37
  # Viewport decoration; never replaces Stack/Wrap/Grid.
38
38
  var scroll_axes := Vector2.ZERO
39
+ var clips_content := false
39
40
  var align_content := "start"
40
41
  var physical_gaps := Vector2.ZERO
41
42
  var gap: float = 0.0
@@ -344,7 +345,7 @@ func measure_allocated(extent: Vector3, authority: Vector3) -> void:
344
345
 
345
346
  func overflow_extent() -> Vector3:
346
347
  # Ancestors see the clipped participant's viewport, not its hidden content.
347
- if scroll_axes!=Vector2.ZERO: return size
348
+ if clips_content or scroll_axes!=Vector2.ZERO: return size
348
349
  var result := size
349
350
  for index in range(3): result[index] = maxf(result[index],natural_extent[index])
350
351
  for child in children:
@@ -16,6 +16,7 @@ const EDGES := ["padding","padding_top","padding_right","padding_bottom","paddin
16
16
  var specs: Dictionary = {}
17
17
  var parse_count := 0
18
18
  static func domain(name: String, script = null) -> String:
19
+ if name in VisualStyle.RADII: return "inset" if name=="corner_radius" else "edge"
19
20
  if name in ["row_gap","column_gap"]: return "edge"
20
21
  if name=="padding" and VisualStyle.marked(script,"ESTRAGON_BUTTON_STYLE"): return "edge"
21
22
  if name in DIMENSIONS: return "extent"
@@ -27,6 +28,7 @@ static func domain(name: String, script = null) -> String:
27
28
  return "inset" if name=="gap" else ""
28
29
  static func registered(type, name: String) -> bool:
29
30
  if domain(name).is_empty() or not type is Script: return false
31
+ if name in VisualStyle.RADII: return VisualStyle.supported(type)
30
32
  if (name in MINIMUMS or name in MAXIMUMS) and not VisualStyle.marked(type,"ESTRAGON_MINIMUMS_2D"): return false
31
33
  if name in ["row_gap","column_gap"] and not VisualStyle.marked(type,"ESTRAGON_GAPS_2D"): return false
32
34
  if name=="border_width" or name in BORDER_EDGES:
@@ -19,7 +19,7 @@ static func valid_offset(value) -> bool:
19
19
  func _ensure_viewport() -> void:
20
20
  if is_instance_valid(_clip):
21
21
  Hosts.add(_content,host.layout)
22
- if enabled(): _input_guard.start(_content)
22
+ if clipping(): _input_guard.start(_content)
23
23
  return
24
24
  _clip = host.get_node_or_null("_EstragonViewport")
25
25
  if _clip==null:
@@ -78,13 +78,13 @@ func _adopt_content(child: Node) -> void:
78
78
  if is_instance_valid(focus) and focus.is_inside_tree(): focus.grab_focus()
79
79
  host.layout._sync()
80
80
  func start() -> void:
81
- if not enabled() and not is_instance_valid(_clip) and host.get_node_or_null("_EstragonViewport")==null: return
81
+ if not clipping() and not is_instance_valid(_clip) and host.get_node_or_null("_EstragonViewport")==null: return
82
82
  _ensure_viewport()
83
83
  for child in host.get_children():
84
84
  if not is_private(child): _adopt_content(child)
85
85
  if not host.child_entered_tree.is_connected(_external_child): host.child_entered_tree.connect(_external_child)
86
- _clip.clip_contents = enabled()
87
- if enabled(): _input_guard.start(_content)
86
+ _clip.clip_contents = clipping()
87
+ if clipping(): _input_guard.start(_content)
88
88
  else: _input_guard.stop()
89
89
  # Re-entry/scene reload must retain offsets until children and the existing
90
90
  # coordinator are active again. Their arranged signal refreshes the viewport.
@@ -98,6 +98,8 @@ func child_parent() -> Node:
98
98
  return _content
99
99
  func enabled() -> bool:
100
100
  return host.horizontal_scroll or host.vertical_scroll
101
+ func clipping() -> bool:
102
+ return host.clip_content or enabled()
101
103
  func _external_child(child: Node) -> void:
102
104
  if not is_private(child): _adopt_later.call_deferred(weakref(child))
103
105
  func _adopt_later(reference: WeakRef) -> void:
@@ -2,6 +2,23 @@
2
2
  extends RefCounted
3
3
  ## Local values and native paint only. No parent lookup, cascade or Nodes.
4
4
  const COLORS := ["background_color","border_color","hover_background_color","pressed_background_color","disabled_background_color","checked_background_color"]
5
+ const RADII := ["corner_radius","corner_radius_top_left","corner_radius_top_right","corner_radius_bottom_right","corner_radius_bottom_left"]
6
+ const SURFACE := ["background_texture","background_texture_mode"]
7
+ var radii: Dictionary = {}
8
+ var texture: Texture2D
9
+ var texture_mode := "stretch"
10
+ var _canvas_texture: CanvasTexture
11
+ var _gradient: Gradient
12
+ var _host: WeakRef
13
+ var _viewport: Viewport
14
+ var _cache_key: Array = []
15
+ var _outer := PackedVector2Array()
16
+ var _inner := PackedVector2Array()
17
+ var _uv := PackedVector2Array()
18
+ var _border_mesh: ArrayMesh
19
+ var _rounded := false
20
+ var geometry_count := 0
21
+ var resource_notifications := 0
5
22
  var colors := {"background_color":Color.TRANSPARENT,"border_color":Color.TRANSPARENT,"hover_background_color":Color("#705a9e"),"pressed_background_color":Color("#302440"),"disabled_background_color":Color("#38343f"),"checked_background_color":Color("#227a60")}
6
23
  var parse_count := 0
7
24
  var draw_count := 0
@@ -24,7 +41,165 @@ static func supported(script) -> bool:
24
41
  current = current.get_base_script()
25
42
  return has_api(script)
26
43
  static func property(name: String) -> bool:
27
- return name in COLORS or name in ["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width"]
44
+ return name in COLORS or name in RADII or name in SURFACE or name in ["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width"]
45
+ static func surface_error(name: String, value) -> String:
46
+ if name=="background_texture" and value!=null and not value is Texture2D: return "background_texture requires Texture2D or null"
47
+ if name=="background_texture_mode" and (not value is String or value not in ["stretch","tile"]): return "background_texture_mode requires stretch or tile"
48
+ return ""
49
+ func start(host: Node) -> void:
50
+ _host = weakref(host)
51
+ _connect_texture()
52
+ sync_viewport()
53
+ func stop() -> void:
54
+ _disconnect_texture()
55
+ if _viewport!=null and _viewport.size_changed.is_connected(_viewport_changed): _viewport.size_changed.disconnect(_viewport_changed)
56
+ _viewport = null
57
+ _host = null
58
+ func sync_viewport() -> void:
59
+ var relative := false
60
+ for spec in radii.values():
61
+ if spec.unit in ["vw","vh","vmin","vmax"]: relative = true
62
+ var host = _host.get_ref() if _host!=null else null
63
+ var viewport: Viewport = host.get_viewport() if relative and host!=null and host.is_inside_tree() else null
64
+ if viewport==_viewport: return
65
+ if _viewport!=null and _viewport.size_changed.is_connected(_viewport_changed): _viewport.size_changed.disconnect(_viewport_changed)
66
+ _viewport = viewport
67
+ if _viewport!=null: _viewport.size_changed.connect(_viewport_changed)
68
+ func _viewport_changed() -> void:
69
+ var host = _host.get_ref() if _host!=null else null
70
+ if host!=null: host._queue_style_redraw()
71
+ func _disconnect_texture() -> void:
72
+ if texture!=null and texture.changed.is_connected(_resource_changed): texture.changed.disconnect(_resource_changed)
73
+ if _gradient!=null and _gradient.changed.is_connected(_resource_changed): _gradient.changed.disconnect(_resource_changed)
74
+ _gradient = null
75
+ func _connect_texture() -> void:
76
+ if _host==null or _host.get_ref()==null or texture==null: return
77
+ if not texture.changed.is_connected(_resource_changed): texture.changed.connect(_resource_changed)
78
+ var gradient: Gradient = texture.gradient if texture is GradientTexture2D else null
79
+ if _gradient!=gradient:
80
+ if _gradient!=null and _gradient.changed.is_connected(_resource_changed): _gradient.changed.disconnect(_resource_changed)
81
+ _gradient = gradient
82
+ if _gradient!=null: _gradient.changed.connect(_resource_changed)
83
+ func set_texture(value: Texture2D) -> void:
84
+ _disconnect_texture()
85
+ texture = value
86
+ _rebuild_texture()
87
+ _connect_texture()
88
+ func _rebuild_texture() -> void:
89
+ _canvas_texture = null
90
+ if texture!=null:
91
+ _canvas_texture = texture.duplicate() if texture is CanvasTexture else CanvasTexture.new()
92
+ if not texture is CanvasTexture: _canvas_texture.diffuse_texture = texture
93
+ _canvas_texture.texture_repeat = CanvasItem.TEXTURE_REPEAT_ENABLED if texture_mode=="tile" else CanvasItem.TEXTURE_REPEAT_DISABLED
94
+ _cache_key = []
95
+ func set_texture_mode(value: String) -> void:
96
+ texture_mode = value
97
+ if _canvas_texture!=null: _canvas_texture.texture_repeat = CanvasItem.TEXTURE_REPEAT_ENABLED if value=="tile" else CanvasItem.TEXTURE_REPEAT_DISABLED
98
+ _cache_key = []
99
+ func _resource_changed() -> void:
100
+ resource_notifications += 1
101
+ _connect_texture()
102
+ _rebuild_texture()
103
+ var host = _host.get_ref() if _host!=null else null
104
+ if host!=null: host._queue_style_redraw()
105
+
106
+ # Fixed 16 chords per quarter arc; fractional coordinates never round to native
107
+ # StyleBoxFlat integer border widths. Contours/UVs/mesh persist between draws.
108
+ func _contour(rect: Rect2, horizontal: Vector4, vertical: Vector4) -> PackedVector2Array:
109
+ var points := PackedVector2Array()
110
+ var centers := [rect.position+Vector2(horizontal.x,vertical.x),rect.position+Vector2(rect.size.x-horizontal.y,vertical.y),rect.end-Vector2(horizontal.z,vertical.z),rect.position+Vector2(horizontal.w,rect.size.y-vertical.w)]
111
+ for corner in range(4):
112
+ for step in range(17):
113
+ var angle := PI+corner*PI/2+step*PI/32
114
+ points.append(centers[corner]+Vector2(cos(angle)*horizontal[corner],sin(angle)*vertical[corner]))
115
+ return points
116
+ func _unique(points: PackedVector2Array) -> PackedVector2Array:
117
+ var result := PackedVector2Array()
118
+ for point in points:
119
+ if result.is_empty() or not result[-1].is_equal_approx(point): result.append(point)
120
+ if result.size()>1 and result[0].is_equal_approx(result[-1]): result.remove_at(result.size()-1)
121
+ return result
122
+ func _ray_edge(center: Vector2, direction: Vector2, contour: PackedVector2Array) -> Vector2:
123
+ var distance := INF
124
+ for index in range(contour.size()):
125
+ var point: Vector2 = contour[index]-center
126
+ var edge: Vector2 = contour[(index+1)%contour.size()]-contour[index]
127
+ var denominator := direction.cross(edge)
128
+ if absf(denominator)<1e-10: continue
129
+ var along := point.cross(edge)/denominator
130
+ var across := point.cross(direction)/denominator
131
+ if along>=-0.001 and across>=-0.001 and across<=1.001: distance = minf(distance,maxf(0,along))
132
+ return center+direction*distance
133
+ func _ring() -> void:
134
+ # Both contours are convex. Rays through the union of their vertices form
135
+ # nonoverlapping bands even when extreme asymmetric insets clip a corner.
136
+ var center := Vector2.ZERO
137
+ for point in _inner: center += point
138
+ center /= _inner.size()
139
+ var angles: Array = []
140
+ for contour in [_outer,_inner]:
141
+ for point in contour: angles.append((point-center).angle())
142
+ angles.sort()
143
+ var outside := PackedVector2Array()
144
+ var inside := PackedVector2Array()
145
+ for angle in angles:
146
+ var direction := Vector2(cos(angle),sin(angle))
147
+ outside.append(_ray_edge(center,direction,_outer))
148
+ inside.append(_ray_edge(center,direction,_inner))
149
+ var vertices := PackedVector3Array()
150
+ for index in range(angles.size()):
151
+ var next := (index+1)%angles.size()
152
+ for point in [outside[index],outside[next],inside[next],outside[index],inside[next],inside[index]]: vertices.append(Vector3(point.x,point.y,0))
153
+ var arrays := []
154
+ arrays.resize(Mesh.ARRAY_MAX)
155
+ arrays[Mesh.ARRAY_VERTEX] = vertices
156
+ _border_mesh = ArrayMesh.new()
157
+ _border_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES,arrays)
158
+ func prepare(extent: Vector2, border: Vector4, resolved: Vector4) -> bool:
159
+ var key := [extent,border,resolved,texture_mode,texture.get_size() if texture!=null else Vector2.ZERO]
160
+ if key==_cache_key: return false
161
+ _cache_key = key
162
+ _rounded = resolved!=Vector4.ZERO
163
+ _outer = PackedVector2Array()
164
+ _inner = PackedVector2Array()
165
+ _uv = PackedVector2Array()
166
+ _border_mesh = null
167
+ if not _rounded and texture==null: return false # Exact S01/S02 fast path.
168
+ geometry_count += 1
169
+ if extent.x<=0 or extent.y<=0: return true
170
+ var radius := resolved
171
+ var scale := 1.0
172
+ for edge in [[extent.x,radius.x+radius.y],[extent.x,radius.w+radius.z],[extent.y,radius.x+radius.w],[extent.y,radius.y+radius.z]]:
173
+ if edge[1]>0: scale = minf(scale,edge[0]/edge[1])
174
+ radius *= scale
175
+ var left := minf(border.x,extent.x)
176
+ var right := minf(border.z,maxf(0,extent.x-left))
177
+ var top := minf(border.y,extent.y)
178
+ var bottom := minf(border.w,maxf(0,extent.y-top))
179
+ var inner_rect := Rect2(left,top,maxf(0,extent.x-left-right),maxf(0,extent.y-top-bottom))
180
+ var outer := _contour(Rect2(Vector2.ZERO,extent),radius,radius)
181
+ _outer = _unique(outer)
182
+ if inner_rect.size.x<=0 or inner_rect.size.y<=0: return true
183
+ var rx := Vector4(maxf(0,radius.x-left),maxf(0,radius.y-right),maxf(0,radius.z-right),maxf(0,radius.w-left))
184
+ var ry := Vector4(maxf(0,radius.x-top),maxf(0,radius.y-top),maxf(0,radius.z-bottom),maxf(0,radius.w-bottom))
185
+ var inner_scale := 1.0
186
+ for edge in [[inner_rect.size.x,rx.x+rx.y],[inner_rect.size.x,rx.w+rx.z],[inner_rect.size.y,ry.x+ry.w],[inner_rect.size.y,ry.y+ry.z]]:
187
+ if edge[1]>0: inner_scale = minf(inner_scale,edge[0]/edge[1])
188
+ rx *= inner_scale
189
+ ry *= inner_scale
190
+ var inner := _contour(inner_rect,rx,ry)
191
+ _inner = _unique(inner)
192
+ if _rounded:
193
+ var intersection := Geometry2D.intersect_polygons(_outer,_inner)
194
+ _inner = _unique(intersection[0]) if not intersection.is_empty() else PackedVector2Array()
195
+ if _inner.size()<3: return true
196
+ if texture!=null:
197
+ var basis := texture.get_size() if texture_mode=="tile" else inner_rect.size
198
+ basis = Vector2(maxf(1,basis.x),maxf(1,basis.y))
199
+ for point in _inner: _uv.append((point-inner_rect.position)/basis)
200
+ if _rounded and border!=Vector4.ZERO:
201
+ _ring()
202
+ return true
28
203
  static func registered(script, name: String) -> bool:
29
204
  if not supported(script): return false
30
205
  if name in ["background_color","border_color"]: return true
@@ -61,7 +236,18 @@ func _rect(canvas: CanvasItem, rect: Rect2, color: Color) -> void:
61
236
  func paint(canvas: CanvasItem, extent: Vector2, border: Vector4, background: Color) -> void:
62
237
  draw_count += 1
63
238
  if extent.x<=0 or extent.y<=0: return
239
+ if _rounded:
240
+ if background.a>0:
241
+ canvas.draw_colored_polygon(_outer,background)
242
+ command_count += 1
243
+ _paint_texture(canvas)
244
+ if colors.border_color.a>0 and border!=Vector4.ZERO:
245
+ if _border_mesh!=null: canvas.draw_mesh(_border_mesh,null,Transform2D.IDENTITY,colors.border_color)
246
+ else: canvas.draw_colored_polygon(_outer,colors.border_color)
247
+ command_count += 1
248
+ return
64
249
  _rect(canvas,Rect2(Vector2.ZERO,extent),background)
250
+ _paint_texture(canvas)
65
251
  # Filled strips stay inside the border-box, including fractional/huge edges.
66
252
  # Top/bottom own the corners; side strips never double-blend those pixels.
67
253
  var left := minf(border.x,extent.x)
@@ -73,3 +259,7 @@ func paint(canvas: CanvasItem, extent: Vector2, border: Vector4, background: Col
73
259
  _rect(canvas,Rect2(0,extent.y-bottom,extent.x,bottom),color)
74
260
  _rect(canvas,Rect2(0,top,left,maxf(0,extent.y-top-bottom)),color)
75
261
  _rect(canvas,Rect2(extent.x-right,top,right,maxf(0,extent.y-top-bottom)),color)
262
+ func _paint_texture(canvas: CanvasItem) -> void:
263
+ if _canvas_texture==null or _inner.size()<3: return
264
+ canvas.draw_colored_polygon(_inner,Color.WHITE,_uv,_canvas_texture)
265
+ command_count += 1
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  "tag": "beta",
30
30
  "registry": "https://registry.npmjs.org/"
31
31
  },
32
- "version": "0.1.0-beta.26"
32
+ "version": "0.1.0-beta.27"
33
33
  }