更改Bounds属性为GetBounds方法

This commit is contained in:
ww-rm
2025-04-15 11:23:11 +08:00
parent 15bc2dc3b8
commit 09dd220abf
9 changed files with 78 additions and 99 deletions

View File

@@ -475,7 +475,7 @@ namespace SpineViewer.Controls
foreach (int i in SpineListView.SelectedIndices) foreach (int i in SpineListView.SelectedIndices)
{ {
if (spines[i].IsHidden) continue; if (spines[i].IsHidden) continue;
if (!spines[i].Bounds.Contains(src)) continue; if (!spines[i].GetBounds().Contains(src)) continue;
hit = true; hit = true;
break; break;
} }
@@ -492,7 +492,7 @@ namespace SpineViewer.Controls
for (int i = 0; i < spines.Count; i++) for (int i = 0; i < spines.Count; i++)
{ {
if (spines[i].IsHidden) continue; if (spines[i].IsHidden) continue;
if (!spines[i].Bounds.Contains(src)) continue; if (!spines[i].GetBounds().Contains(src)) continue;
hit = true; hit = true;
@@ -514,7 +514,7 @@ namespace SpineViewer.Controls
for (int i = 0; i < spines.Count; i++) for (int i = 0; i < spines.Count; i++)
{ {
if (spines[i].IsHidden) continue; if (spines[i].IsHidden) continue;
if (!spines[i].Bounds.Contains(src)) continue; if (!spines[i].GetBounds().Contains(src)) continue;
SpineListView.SelectedIndices.Add(i); SpineListView.SelectedIndices.Add(i);
break; break;

View File

@@ -188,54 +188,51 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; } public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds protected override RectangleF getBounds()
{ {
get float[] temp = new float[8];
var drawOrderItems = skeleton.DrawOrder;
float minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue;
for (int i = 0, n = skeleton.DrawOrder.Count; i < n; i++)
{ {
float[] temp = new float[8]; Slot slot = drawOrderItems[i];
var drawOrderItems = skeleton.DrawOrder; int verticesLength = 0;
float minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue; float[] vertices = null;
for (int i = 0, n = skeleton.DrawOrder.Count; i < n; i++) Attachment attachment = slot.Attachment;
var regionAttachment = attachment as RegionAttachment;
if (regionAttachment != null)
{ {
Slot slot = drawOrderItems[i]; verticesLength = 8;
int verticesLength = 0; vertices = temp;
float[] vertices = null; if (vertices.Length < 8) vertices = temp = new float[8];
Attachment attachment = slot.Attachment; regionAttachment.ComputeWorldVertices(slot.Bone, temp);
var regionAttachment = attachment as RegionAttachment; }
if (regionAttachment != null) else
{
var meshAttachment = attachment as MeshAttachment;
if (meshAttachment != null)
{ {
verticesLength = 8; MeshAttachment mesh = meshAttachment;
verticesLength = mesh.Vertices.Length;
vertices = temp; vertices = temp;
if (vertices.Length < 8) vertices = temp = new float[8]; if (vertices.Length < verticesLength) vertices = temp = new float[verticesLength];
regionAttachment.ComputeWorldVertices(slot.Bone, temp); mesh.ComputeWorldVertices(slot, temp);
} }
else }
{
var meshAttachment = attachment as MeshAttachment; if (vertices != null)
if (meshAttachment != null) {
{ for (int ii = 0; ii < verticesLength; ii += 2)
MeshAttachment mesh = meshAttachment; {
verticesLength = mesh.Vertices.Length; float vx = vertices[ii], vy = vertices[ii + 1];
vertices = temp; minX = Math.Min(minX, vx);
if (vertices.Length < verticesLength) vertices = temp = new float[verticesLength]; minY = Math.Min(minY, vy);
mesh.ComputeWorldVertices(slot, temp); maxX = Math.Max(maxX, vx);
} maxY = Math.Max(maxY, vy);
}
if (vertices != null)
{
for (int ii = 0; ii < verticesLength; ii += 2)
{
float vx = vertices[ii], vy = vertices[ii + 1];
minX = Math.Min(minX, vx);
minY = Math.Min(minY, vy);
maxX = Math.Max(maxX, vx);
maxY = Math.Max(maxY, vy);
}
} }
} }
return new RectangleF(minX, minY, maxX - minX, maxY - minY);
} }
return new RectangleF(minX, minY, maxX - minX, maxY - minY);
} }
protected override void update(float delta) protected override void update(float delta)
@@ -503,7 +500,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds) if (debugBounds)
{ {
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor }; var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
var b = bounds; var b = getBounds();
vt.Position.X = b.Left; vt.Position.X = b.Left;
vt.Position.Y = b.Top; vt.Position.Y = b.Top;

View File

@@ -187,14 +187,11 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; } public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds protected override RectangleF getBounds()
{ {
get float[] _ = [];
{ skeleton.GetBounds(out var x, out var y, out var w, out var h, ref _);
float[] _ = []; return new RectangleF(x, y, w, h);
skeleton.GetBounds(out var x, out var y, out var w, out var h, ref _);
return new RectangleF(x, y, w, h);
}
} }
protected override void update(float delta) protected override void update(float delta)
@@ -489,7 +486,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds) if (debugBounds)
{ {
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor }; var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
var b = bounds; var b = getBounds();
vt.Position.X = b.Left; vt.Position.X = b.Left;
vt.Position.Y = b.Top; vt.Position.Y = b.Top;

View File

@@ -159,14 +159,11 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; } public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds protected override RectangleF getBounds()
{ {
get float[] _ = [];
{ skeleton.GetBounds(out var x, out var y, out var w, out var h, ref _);
float[] _ = []; return new RectangleF(x, y, w, h);
skeleton.GetBounds(out var x, out var y, out var w, out var h, ref _);
return new RectangleF(x, y, w, h);
}
} }
protected override void update(float delta) protected override void update(float delta)
@@ -461,7 +458,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds) if (debugBounds)
{ {
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor }; var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
var b = bounds; var b = getBounds();
vt.Position.X = b.Left; vt.Position.X = b.Left;
vt.Position.Y = b.Top; vt.Position.Y = b.Top;

View File

@@ -167,14 +167,11 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; } public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds protected override RectangleF getBounds()
{ {
get float[] _ = [];
{ skeleton.GetBounds(out var x, out var y, out var w, out var h, ref _);
float[] _ = []; return new RectangleF(x, y, w, h);
skeleton.GetBounds(out var x, out var y, out var w, out var h, ref _);
return new RectangleF(x, y, w, h);
}
} }
protected override void update(float delta) protected override void update(float delta)
@@ -469,7 +466,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds) if (debugBounds)
{ {
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor }; var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
var b = bounds; var b = getBounds();
vt.Position.X = b.Left; vt.Position.X = b.Left;
vt.Position.Y = b.Top; vt.Position.Y = b.Top;

View File

@@ -163,14 +163,11 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; } public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds protected override RectangleF getBounds()
{ {
get float[] _ = [];
{ skeleton.GetBounds(out var x, out var y, out var w, out var h, ref _);
float[] _ = []; return new RectangleF(x, y, w, h);
skeleton.GetBounds(out var x, out var y, out var w, out var h, ref _);
return new RectangleF(x, y, w, h);
}
} }
protected override void update(float delta) protected override void update(float delta)
@@ -465,7 +462,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds) if (debugBounds)
{ {
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor }; var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
var b = bounds; var b = getBounds();
vt.Position.X = b.Left; vt.Position.X = b.Left;
vt.Position.Y = b.Top; vt.Position.Y = b.Top;

View File

@@ -163,14 +163,11 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; } public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds protected override RectangleF getBounds()
{ {
get float[] _ = [];
{ skeleton.GetBounds(out var x, out var y, out var w, out var h, ref _);
float[] _ = []; return new RectangleF(x, y, w, h);
skeleton.GetBounds(out var x, out var y, out var w, out var h, ref _);
return new RectangleF(x, y, w, h);
}
} }
protected override void update(float delta) protected override void update(float delta)
@@ -465,7 +462,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds) if (debugBounds)
{ {
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor }; var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
var b = bounds; var b = getBounds();
vt.Position.X = b.Left; vt.Position.X = b.Left;
vt.Position.Y = b.Top; vt.Position.Y = b.Top;

View File

@@ -163,14 +163,11 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; } public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds protected override RectangleF getBounds()
{ {
get float[] _ = [];
{ skeleton.GetBounds(out var x, out var y, out var w, out var h, ref _);
float[] _ = []; return new RectangleF(x, y, w, h);
skeleton.GetBounds(out var x, out var y, out var w, out var h, ref _);
return new RectangleF(x, y, w, h);
}
} }
protected override void update(float delta) protected override void update(float delta)
@@ -465,7 +462,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds) if (debugBounds)
{ {
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor }; var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
var b = bounds; var b = getBounds();
vt.Position.X = b.Left; vt.Position.X = b.Left;
vt.Position.Y = b.Top; vt.Position.Y = b.Top;

View File

@@ -83,7 +83,7 @@ namespace SpineViewer.Spine
// 除此之外, 似乎还和 tex 的 Dispose 有关 // 除此之外, 似乎还和 tex 的 Dispose 有关
// 如果不对 tex 进行 Dispose, 那么不管是否 Draw 都正常不会死锁 // 如果不对 tex 进行 Dispose, 那么不管是否 Draw 都正常不会死锁
var tex = new SFML.Graphics.RenderTexture(PREVIEW_WIDTH, PREVIEW_HEIGHT); var tex = new SFML.Graphics.RenderTexture(PREVIEW_WIDTH, PREVIEW_HEIGHT);
using var view = bounds.GetView(PREVIEW_WIDTH, PREVIEW_HEIGHT); using var view = getBounds().GetView(PREVIEW_WIDTH, PREVIEW_HEIGHT);
tex.SetView(view); tex.SetView(view);
tex.Clear(SFML.Graphics.Color.Transparent); tex.Clear(SFML.Graphics.Color.Transparent);
tex.Draw(this); tex.Draw(this);
@@ -163,12 +163,6 @@ namespace SpineViewer.Spine
public bool UsePma { get { lock (_lock) return usePma; } set { lock (_lock) usePma = value; } } public bool UsePma { get { lock (_lock) return usePma; } set { lock (_lock) usePma = value; } }
protected bool usePma = false; protected bool usePma = false;
/// <summary>
/// 骨骼包围盒
/// </summary>
public RectangleF Bounds { get { lock (_lock) return bounds; } }
protected abstract RectangleF bounds { get; }
/// <summary> /// <summary>
/// 缩放比例 /// 缩放比例
/// </summary> /// </summary>
@@ -447,6 +441,12 @@ namespace SpineViewer.Spine
/// </summary> /// </summary>
public void ResetAnimationsTime() { lock (_lock) { foreach (var i in getTrackIndices()) setAnimation(i, getAnimation(i)); update(0); } } public void ResetAnimationsTime() { lock (_lock) { foreach (var i in getTrackIndices()) setAnimation(i, getAnimation(i)); update(0); } }
/// <summary>
/// 获取当前状态包围盒
/// </summary>
public RectangleF GetBounds() { lock (_lock) return getBounds(); }
protected abstract RectangleF getBounds();
/// <summary> /// <summary>
/// 更新内部状态 /// 更新内部状态
/// </summary> /// </summary>