更改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)
{
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;

View File

@@ -188,9 +188,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds
{
get
protected override RectangleF getBounds()
{
float[] temp = new float[8];
var drawOrderItems = skeleton.DrawOrder;
@@ -236,7 +234,6 @@ namespace SpineViewer.Spine.Implementations.SpineObject
}
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;

View File

@@ -187,15 +187,12 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds
{
get
protected override RectangleF getBounds()
{
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;

View File

@@ -159,15 +159,12 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds
{
get
protected override RectangleF getBounds()
{
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;

View File

@@ -167,15 +167,12 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds
{
get
protected override RectangleF getBounds()
{
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;

View File

@@ -163,15 +163,12 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds
{
get
protected override RectangleF getBounds()
{
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;

View File

@@ -163,15 +163,12 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds
{
get
protected override RectangleF getBounds()
{
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;

View File

@@ -163,15 +163,12 @@ namespace SpineViewer.Spine.Implementations.SpineObject
public override float GetAnimationDuration(string name) { return skeletonData.FindAnimation(name)?.Duration ?? 0f; }
protected override RectangleF bounds
{
get
protected override RectangleF getBounds()
{
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;

View File

@@ -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;
/// <summary>
/// 骨骼包围盒
/// </summary>
public RectangleF Bounds { get { lock (_lock) return bounds; } }
protected abstract RectangleF bounds { get; }
/// <summary>
/// 缩放比例
/// </summary>
@@ -447,6 +441,12 @@ namespace SpineViewer.Spine
/// </summary>
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>