This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
MoveNodeEditor.cs
79 lines (69 loc) · 2.21 KB
/
MoveNodeEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnyCAD.Platform;
namespace AnyCAD.Basic
{
class MoveNodeEditor : AnyCAD.Platform.CustomEditor
{
private Vector3 m_StartPos = new Vector3();
private EditStep m_Step = 0;
private SceneNode m_TargetNode = null;
private Matrix4 m_InitTrf = null;
enum EditStep
{
ES_PickNode,
ES_BeginMove,
};
public override void OnStartEvent()
{
}
public override void OnExitEvent()
{
}
public override void OnButtonDownEvent(InputEvent evt)
{
Renderer renderer = GetRenderer();
if (m_Step == EditStep.ES_PickNode)
{
if (renderer.Select(true) > 0)
{
SelectedShapeQuery query = new SelectedShapeQuery();
renderer.QuerySelection(query);
m_TargetNode = query.GetRootNode();
if (m_TargetNode != null)
{
m_Step = EditStep.ES_BeginMove;
m_InitTrf = m_TargetNode.GetTransform();
}
}
}
else
{
m_StartPos = ToWorldPoint(evt.GetMousePosition());
}
}
public override void OnButtonUpEvent(InputEvent evt)
{
m_Step = EditStep.ES_PickNode;
GetRenderer().ClearSelection();
GetRenderer().RequestDraw(1);
}
public override void OnMouseMoveEvent(InputEvent evt)
{
if (m_Step == EditStep.ES_PickNode)
{
Vector2 pt = evt.GetMousePosition();
GetRenderer().Highlight((int)pt.X, (int)pt.Y);
}
else
{
Vector3 endPt = ToWorldPoint(evt.GetMousePosition());
Matrix4 trf = GlobalInstance.MatrixBuilder.MakeTranslate(endPt - m_StartPos);
m_TargetNode.SetTransform(GlobalInstance.MatrixBuilder.Multiply(m_InitTrf, trf));
GetRenderer().RequestDraw(1);
}
}
}
}