diff --git a/SpineViewer/Controls/SpinePreviewPanel.cs b/SpineViewer/Controls/SpinePreviewPanel.cs
index 829a298..e4d83e7 100644
--- a/SpineViewer/Controls/SpinePreviewPanel.cs
+++ b/SpineViewer/Controls/SpinePreviewPanel.cs
@@ -475,7 +475,7 @@ namespace SpineViewer.Controls
foreach (int i in SpineListView.SelectedIndices)
{
if (spines[i].IsHidden) continue;
- if (!spines[i].Bounds.Contains(src)) continue;
+ if (!spines[i].GetBounds().Contains(src)) continue;
hit = true;
break;
}
@@ -492,7 +492,7 @@ namespace SpineViewer.Controls
for (int i = 0; i < spines.Count; i++)
{
if (spines[i].IsHidden) continue;
- if (!spines[i].Bounds.Contains(src)) continue;
+ if (!spines[i].GetBounds().Contains(src)) continue;
hit = true;
@@ -514,7 +514,7 @@ namespace SpineViewer.Controls
for (int i = 0; i < spines.Count; i++)
{
if (spines[i].IsHidden) continue;
- if (!spines[i].Bounds.Contains(src)) continue;
+ if (!spines[i].GetBounds().Contains(src)) continue;
SpineListView.SelectedIndices.Add(i);
break;
diff --git a/SpineViewer/Spine/Implementations/SpineObject/SpineObject21.cs b/SpineViewer/Spine/Implementations/SpineObject/SpineObject21.cs
index 509bf11..4fb840d 100644
--- a/SpineViewer/Spine/Implementations/SpineObject/SpineObject21.cs
+++ b/SpineViewer/Spine/Implementations/SpineObject/SpineObject21.cs
@@ -188,54 +188,51 @@ namespace SpineViewer.Spine.Implementations.SpineObject
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];
- 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++)
+ Slot slot = drawOrderItems[i];
+ int verticesLength = 0;
+ float[] vertices = null;
+ Attachment attachment = slot.Attachment;
+ var regionAttachment = attachment as RegionAttachment;
+ if (regionAttachment != null)
{
- Slot slot = drawOrderItems[i];
- int verticesLength = 0;
- float[] vertices = null;
- Attachment attachment = slot.Attachment;
- var regionAttachment = attachment as RegionAttachment;
- if (regionAttachment != null)
+ verticesLength = 8;
+ vertices = temp;
+ if (vertices.Length < 8) vertices = temp = new float[8];
+ regionAttachment.ComputeWorldVertices(slot.Bone, temp);
+ }
+ else
+ {
+ var meshAttachment = attachment as MeshAttachment;
+ if (meshAttachment != null)
{
- verticesLength = 8;
+ MeshAttachment mesh = meshAttachment;
+ verticesLength = mesh.Vertices.Length;
vertices = temp;
- if (vertices.Length < 8) vertices = temp = new float[8];
- regionAttachment.ComputeWorldVertices(slot.Bone, temp);
- }
- else
- {
- var meshAttachment = attachment as MeshAttachment;
- if (meshAttachment != null)
- {
- MeshAttachment mesh = meshAttachment;
- verticesLength = mesh.Vertices.Length;
- vertices = temp;
- if (vertices.Length < verticesLength) vertices = temp = new float[verticesLength];
- mesh.ComputeWorldVertices(slot, temp);
- }
- }
-
- 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);
- }
+ if (vertices.Length < verticesLength) vertices = temp = new float[verticesLength];
+ mesh.ComputeWorldVertices(slot, temp);
+ }
+ }
+
+ 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)
@@ -503,7 +500,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds)
{
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
- var b = bounds;
+ var b = getBounds();
vt.Position.X = b.Left;
vt.Position.Y = b.Top;
diff --git a/SpineViewer/Spine/Implementations/SpineObject/SpineObject36.cs b/SpineViewer/Spine/Implementations/SpineObject/SpineObject36.cs
index b33ccae..ea59889 100644
--- a/SpineViewer/Spine/Implementations/SpineObject/SpineObject36.cs
+++ b/SpineViewer/Spine/Implementations/SpineObject/SpineObject36.cs
@@ -187,14 +187,11 @@ namespace SpineViewer.Spine.Implementations.SpineObject
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 _);
- return new RectangleF(x, y, w, h);
- }
+ float[] _ = [];
+ 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)
@@ -489,7 +486,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds)
{
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
- var b = bounds;
+ var b = getBounds();
vt.Position.X = b.Left;
vt.Position.Y = b.Top;
diff --git a/SpineViewer/Spine/Implementations/SpineObject/SpineObject37.cs b/SpineViewer/Spine/Implementations/SpineObject/SpineObject37.cs
index 3538fcb..f4c6fb2 100644
--- a/SpineViewer/Spine/Implementations/SpineObject/SpineObject37.cs
+++ b/SpineViewer/Spine/Implementations/SpineObject/SpineObject37.cs
@@ -159,14 +159,11 @@ namespace SpineViewer.Spine.Implementations.SpineObject
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 _);
- return new RectangleF(x, y, w, h);
- }
+ float[] _ = [];
+ 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)
@@ -461,7 +458,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds)
{
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
- var b = bounds;
+ var b = getBounds();
vt.Position.X = b.Left;
vt.Position.Y = b.Top;
diff --git a/SpineViewer/Spine/Implementations/SpineObject/SpineObject38.cs b/SpineViewer/Spine/Implementations/SpineObject/SpineObject38.cs
index 0bb3dc0..8fadf91 100644
--- a/SpineViewer/Spine/Implementations/SpineObject/SpineObject38.cs
+++ b/SpineViewer/Spine/Implementations/SpineObject/SpineObject38.cs
@@ -167,14 +167,11 @@ namespace SpineViewer.Spine.Implementations.SpineObject
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 _);
- return new RectangleF(x, y, w, h);
- }
+ float[] _ = [];
+ 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)
@@ -469,7 +466,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds)
{
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
- var b = bounds;
+ var b = getBounds();
vt.Position.X = b.Left;
vt.Position.Y = b.Top;
diff --git a/SpineViewer/Spine/Implementations/SpineObject/SpineObject40.cs b/SpineViewer/Spine/Implementations/SpineObject/SpineObject40.cs
index 0b4b667..fe19d17 100644
--- a/SpineViewer/Spine/Implementations/SpineObject/SpineObject40.cs
+++ b/SpineViewer/Spine/Implementations/SpineObject/SpineObject40.cs
@@ -163,14 +163,11 @@ namespace SpineViewer.Spine.Implementations.SpineObject
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 _);
- return new RectangleF(x, y, w, h);
- }
+ float[] _ = [];
+ 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)
@@ -465,7 +462,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds)
{
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
- var b = bounds;
+ var b = getBounds();
vt.Position.X = b.Left;
vt.Position.Y = b.Top;
diff --git a/SpineViewer/Spine/Implementations/SpineObject/SpineObject41.cs b/SpineViewer/Spine/Implementations/SpineObject/SpineObject41.cs
index df5cadc..6a1ae27 100644
--- a/SpineViewer/Spine/Implementations/SpineObject/SpineObject41.cs
+++ b/SpineViewer/Spine/Implementations/SpineObject/SpineObject41.cs
@@ -163,14 +163,11 @@ namespace SpineViewer.Spine.Implementations.SpineObject
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 _);
- return new RectangleF(x, y, w, h);
- }
+ float[] _ = [];
+ 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)
@@ -465,7 +462,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds)
{
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
- var b = bounds;
+ var b = getBounds();
vt.Position.X = b.Left;
vt.Position.Y = b.Top;
diff --git a/SpineViewer/Spine/Implementations/SpineObject/Spineobject42.cs b/SpineViewer/Spine/Implementations/SpineObject/Spineobject42.cs
index 135b64d..cdbf38c 100644
--- a/SpineViewer/Spine/Implementations/SpineObject/Spineobject42.cs
+++ b/SpineViewer/Spine/Implementations/SpineObject/Spineobject42.cs
@@ -163,14 +163,11 @@ namespace SpineViewer.Spine.Implementations.SpineObject
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 _);
- return new RectangleF(x, y, w, h);
- }
+ float[] _ = [];
+ 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)
@@ -465,7 +462,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
if (debugBounds)
{
var vt = new SFML.Graphics.Vertex() { Color = BoundsColor };
- var b = bounds;
+ var b = getBounds();
vt.Position.X = b.Left;
vt.Position.Y = b.Top;
diff --git a/SpineViewer/Spine/SpineObject.cs b/SpineViewer/Spine/SpineObject.cs
index 9584df8..2f63b75 100644
--- a/SpineViewer/Spine/SpineObject.cs
+++ b/SpineViewer/Spine/SpineObject.cs
@@ -83,7 +83,7 @@ namespace SpineViewer.Spine
// 除此之外, 似乎还和 tex 的 Dispose 有关
// 如果不对 tex 进行 Dispose, 那么不管是否 Draw 都正常不会死锁
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.Clear(SFML.Graphics.Color.Transparent);
tex.Draw(this);
@@ -163,12 +163,6 @@ namespace SpineViewer.Spine
public bool UsePma { get { lock (_lock) return usePma; } set { lock (_lock) usePma = value; } }
protected bool usePma = false;
- ///
- /// 骨骼包围盒
- ///
- public RectangleF Bounds { get { lock (_lock) return bounds; } }
- protected abstract RectangleF bounds { get; }
-
///
/// 缩放比例
///
@@ -447,6 +441,12 @@ namespace SpineViewer.Spine
///
public void ResetAnimationsTime() { lock (_lock) { foreach (var i in getTrackIndices()) setAnimation(i, getAnimation(i)); update(0); } }
+ ///
+ /// 获取当前状态包围盒
+ ///
+ public RectangleF GetBounds() { lock (_lock) return getBounds(); }
+ protected abstract RectangleF getBounds();
+
///
/// 更新内部状态
///