增加左键功能

This commit is contained in:
ww-rm
2025-02-28 21:49:44 +08:00
parent c369361b9f
commit f221249575
2 changed files with 23 additions and 7 deletions

View File

@@ -36,9 +36,9 @@ namespace SpineViewer
/// </summary> /// </summary>
private void Insert(int index = -1) private void Insert(int index = -1)
{ {
// 如果索引无效则插在末尾 // 如果索引无效则插在开头
if (index < 0 || index > spines.Count) if (index < 0 || index > spines.Count)
index = spines.Count; index = 0;
var dialog = new OpenSpineDialog(); var dialog = new OpenSpineDialog();
if (dialog.ShowDialog() != DialogResult.OK) if (dialog.ShowDialog() != DialogResult.OK)

View File

@@ -86,6 +86,9 @@ namespace SpineViewer
private SFML.System.Vector2f? draggingSrc = null; private SFML.System.Vector2f? draggingSrc = null;
private Spine.Spine? draggingSpine = null; private Spine.Spine? draggingSpine = null;
/// <summary>
/// 安全获取 Spine 列表
/// </summary>
private Spine.Spine[] Spines private Spine.Spine[] Spines
{ {
get get
@@ -305,6 +308,7 @@ namespace SpineViewer
// 右键优先级高, 进入画面拖动模式, 需要重新记录源点 // 右键优先级高, 进入画面拖动模式, 需要重新记录源点
if ((e.Button & MouseButtons.Right) != 0) if ((e.Button & MouseButtons.Right) != 0)
{ {
draggingSpine = null;
draggingSrc = RenderWindow.MapPixelToCoords(new(e.X, e.Y)); draggingSrc = RenderWindow.MapPixelToCoords(new(e.X, e.Y));
Cursor = Cursors.Hand; Cursor = Cursors.Hand;
} }
@@ -312,6 +316,15 @@ namespace SpineViewer
else if ((e.Button & MouseButtons.Left) != 0 && (MouseButtons & MouseButtons.Right) == 0) else if ((e.Button & MouseButtons.Left) != 0 && (MouseButtons & MouseButtons.Right) == 0)
{ {
draggingSrc = RenderWindow.MapPixelToCoords(new(e.X, e.Y)); draggingSrc = RenderWindow.MapPixelToCoords(new(e.X, e.Y));
var src = new PointF(((SFML.System.Vector2f)draggingSrc).X, ((SFML.System.Vector2f)draggingSrc).Y);
foreach (var spine in Spines)
{
if (spine.Bounds.Contains(src))
{
draggingSpine = spine;
break;
}
}
} }
} }
@@ -322,15 +335,18 @@ namespace SpineViewer
var src = (SFML.System.Vector2f)draggingSrc; var src = (SFML.System.Vector2f)draggingSrc;
var dst = RenderWindow.MapPixelToCoords(new(e.X, e.Y)); var dst = RenderWindow.MapPixelToCoords(new(e.X, e.Y));
var delta = dst - src; var _delta = dst - src;
var delta = new SizeF(_delta.X, _delta.Y);
if ((e.Button & MouseButtons.Right) != 0) if ((e.Button & MouseButtons.Right) != 0)
{ {
Center -= new SizeF(delta.X, delta.Y); Center -= delta;
} }
else if ((e.Button & MouseButtons.Left) != 0) else if ((e.Button & MouseButtons.Left) != 0)
{ {
// TODO: 移动 Spine if (draggingSpine is not null)
draggingSpine.Position += delta;
draggingSrc = dst;
} }
} }
@@ -339,8 +355,8 @@ namespace SpineViewer
// 右键高优先级, 结束画面拖动模式 // 右键高优先级, 结束画面拖动模式
if ((e.Button & MouseButtons.Right) != 0) if ((e.Button & MouseButtons.Right) != 0)
{ {
draggingSrc = null;
draggingSpine = null; draggingSpine = null;
draggingSrc = null;
Cursor = Cursors.Default; Cursor = Cursors.Default;
PropertyGrid?.Refresh(); PropertyGrid?.Refresh();
} }
@@ -361,7 +377,7 @@ namespace SpineViewer
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{ {
RenderWindow.SetActive(true); RenderWindow.SetActive(true);
float delta = 0; float delta;
while (!backgroundWorker.CancellationPending) while (!backgroundWorker.CancellationPending)
{ {