1 |
using System; |
2 |
using System.Collections.Generic; |
3 |
using System.ComponentModel; |
4 |
using System.Data; |
5 |
using System.Drawing; |
6 |
using System.Linq; |
7 |
using System.Text; |
8 |
using System.Windows.Forms; |
9 |
using Microsoft.Xna.Framework; |
10 |
using gr2lib.core.coretypes.implementation; |
11 |
using gr2lib.core.ui.helpers; |
12 |
|
13 |
namespace XNABoneViewer |
14 |
{ |
15 |
public partial class XNABoneViewerFrm : Form |
16 |
{ |
17 |
|
18 |
private List<Bone> bones; |
19 |
//private Transform bonerotation; |
20 |
|
21 |
private CustomColor ActiveBoneJointColor = System.Drawing.Color.Red; |
22 |
private CustomColor InActiveBoneJointColor = System.Drawing.Color.White; |
23 |
|
24 |
private CustomColor ActiveBoneColor = System.Drawing.Color.Blue; |
25 |
private CustomColor InActiveBoneColor = System.Drawing.Color.LimeGreen; |
26 |
|
27 |
private const float Scaler = 1.0f; |
28 |
|
29 |
/// <summary> |
30 |
/// Default Constructor |
31 |
/// </summary> |
32 |
public XNABoneViewerFrm() |
33 |
{ |
34 |
InitializeComponent(); |
35 |
this.pre_init(); |
36 |
this.post_init(); |
37 |
} |
38 |
/// <summary> |
39 |
/// Default Constructor - specifying: bone list |
40 |
/// </summary> |
41 |
public XNABoneViewerFrm(List<Bone> bones) |
42 |
{ |
43 |
InitializeComponent(); |
44 |
this.pre_init(); |
45 |
this.bones = bones; |
46 |
this.post_init(); |
47 |
} |
48 |
|
49 |
private void pre_init() |
50 |
{ |
51 |
this.bones = new List<Bone>(); |
52 |
|
53 |
//this.RotateLeftRight.Maximum = 180; |
54 |
//this.rotateUpDown.Maximum = 180; |
55 |
|
56 |
this.PropGrid.ShowCustomProperties = true; |
57 |
this.PropGrid.ToolbarVisible = false; |
58 |
this.PropGrid.PropertySort = PropertySort.NoSort; |
59 |
} |
60 |
private void post_init() |
61 |
{ |
62 |
//this.bonerotation = this.bones.BoneRotation; |
63 |
//this.bones.Sort(new XNABoneViewer.XNABoneViewerControl.BoneParentIndexComparer()); |
64 |
this.bones.Sort(); |
65 |
|
66 |
foreach (Bone bone in this.bones) |
67 |
{ |
68 |
bonelist.Items.Add(bone.Name); |
69 |
} |
70 |
|
71 |
//this.BoneViewer = new XNABoneViewerControl(this.bones); |
72 |
this.BoneViewer.Bones = this.bones; |
73 |
this.BoneViewer.InitializeData(); |
74 |
// set size of bone points |
75 |
this.BoneViewer.PointSize = 5; |
76 |
|
77 |
//this.MouseWheel += new MouseEventHandler(XNABoneViewerFrm_MouseWheel); |
78 |
//this.BoneViewer.MouseWheel += new MouseEventHandler(XNABoneViewerFrm_MouseWheel); |
79 |
//this.renderSplit.Panel2.MouseWheel += new MouseEventHandler(XNABoneViewerFrm_MouseWheel); |
80 |
|
81 |
if (this.bones.Count <= 0) |
82 |
{ |
83 |
this.chkEnableRender.Checked = false; |
84 |
this.chkEnableRender.Enabled = false; |
85 |
this.btnResetView.Enabled = false; |
86 |
this.RotateLeftRight.Enabled = false; |
87 |
this.rotateUpDown.Enabled = false; |
88 |
this.RotateZ.Enabled = false; |
89 |
this.panLeftRight.Enabled = false; |
90 |
this.PanUpDown.Enabled = false; |
91 |
this.renderInterval.Enabled = false; |
92 |
this.BoneViewer.Enabled = false; |
93 |
this.rotateInOut.Enabled = false; |
94 |
|
95 |
this.txt_renderInterval.Enabled = false; |
96 |
this.txt_rotateInOut.Enabled = false; |
97 |
this.txt_RotateLeftRight.Enabled = false; |
98 |
this.txt_rotateUpDown.Enabled = false; |
99 |
this.txt_RotateZ.Enabled = false; |
100 |
|
101 |
} |
102 |
else |
103 |
{ |
104 |
this.chkEnableRender.Checked = true; |
105 |
this.chkEnableRender.Enabled = true; |
106 |
this.btnResetView.Enabled = true; |
107 |
} |
108 |
|
109 |
} |
110 |
|
111 |
private void renderInterval_ValueChanged(object sender, EventArgs e) |
112 |
{ |
113 |
this.txt_renderInterval.Value = renderInterval.Value; |
114 |
this.BoneViewer.renderInterval = renderInterval.Value; |
115 |
} |
116 |
|
117 |
private void chkEnableRender_CheckedChanged(object sender, EventArgs e) |
118 |
{ |
119 |
this.BoneViewer.EnableRenderer = chkEnableRender.Checked; |
120 |
} |
121 |
|
122 |
private void bonelist_SelectedIndexChanged(object sender, EventArgs e) |
123 |
{ |
124 |
try { this.PropGrid.Item.Clear(); this.PropGrid.SelectedObject = null; } |
125 |
catch { } |
126 |
|
127 |
Bone bone = new Bone(); |
128 |
try { bone = this.bones[this.bonelist.SelectedIndex]; } |
129 |
catch { } |
130 |
|
131 |
|
132 |
foreach (Bone b in this.bones) |
133 |
{ |
134 |
if (b.BonePropertyData.BoneJointColor.ToArgb() == ActiveBoneJointColor.ToArgb()) |
135 |
{ |
136 |
b.BonePropertyData.BoneJointColor = InActiveBoneJointColor; |
137 |
} |
138 |
if (b.BonePropertyData.BoneColor.ToArgb() == ActiveBoneColor.ToArgb()) |
139 |
{ |
140 |
b.BonePropertyData.BoneColor = InActiveBoneColor; |
141 |
} |
142 |
} |
143 |
|
144 |
if (bone.BonePropertyData.BoneJointColor.ToArgb() == InActiveBoneJointColor.ToArgb()) |
145 |
{ |
146 |
bone.BonePropertyData.BoneJointColor = ActiveBoneJointColor; |
147 |
} |
148 |
if (bone.BonePropertyData.BoneColor.ToArgb() == InActiveBoneColor.ToArgb()) |
149 |
{ |
150 |
bone.BonePropertyData.BoneColor = ActiveBoneColor; |
151 |
} |
152 |
|
153 |
this.PropGrid.Item.Add("name", bone, false, "category", "description", true); |
154 |
this.PropGrid.Item[this.PropGrid.Item.Count - 1].IsBrowsable = true; |
155 |
this.PropGrid.Item[this.PropGrid.Item.Count - 1].BrowsableLabelStyle = PropertyGridEx.BrowsableTypeConverter.LabelStyle.lsNormal; |
156 |
|
157 |
this.PropGrid.SelectedObject = this.PropGrid.Item; |
158 |
this.PropGrid.ExpandAllGridItems(); |
159 |
} |
160 |
|
161 |
private void RotateLeftRight_ValueChanged(object sender, EventArgs e) |
162 |
{ |
163 |
txt_RotateLeftRight.Value = RotateLeftRight.Value; |
164 |
this.BoneViewer.ApplyRotationScale(rotateUpDown.Value, RotateLeftRight.Value, RotateZ.Value, (float)(rotateInOut.Value * Scaler)); |
165 |
} |
166 |
|
167 |
private void rotateUpDown_ValueChanged(object sender, EventArgs e) |
168 |
{ |
169 |
this.txt_rotateUpDown.Value = this.rotateUpDown.Value; |
170 |
this.BoneViewer.ApplyRotationScale(rotateUpDown.Value, RotateLeftRight.Value, RotateZ.Value, (float)(rotateInOut.Value * Scaler)); |
171 |
} |
172 |
|
173 |
private void btnResetView_Click(object sender, EventArgs e) |
174 |
{ |
175 |
//this.BoneViewer.ApplyRotationScale(0, 0, 0, 1); |
176 |
rotateUpDown.Value = 0; |
177 |
RotateLeftRight.Value = 0; |
178 |
RotateZ.Value = 0; |
179 |
rotateInOut.Value = 1; |
180 |
panLeftRight.Value = (BoneViewer.Width * 2) / 2; |
181 |
PanUpDown.Value = (BoneViewer.Height * 2) / 2; |
182 |
|
183 |
this.BoneViewer.ApplyRotationScale(0, 0, 0, 1); |
184 |
this.BoneViewer.ResetPan(); |
185 |
|
186 |
} |
187 |
|
188 |
private void RotateZ_ValueChanged(object sender, EventArgs e) |
189 |
{ |
190 |
txt_RotateZ.Value = RotateZ.Value; |
191 |
this.BoneViewer.ApplyRotationScale(rotateUpDown.Value, RotateLeftRight.Value, RotateZ.Value, (float)(rotateInOut.Value * Scaler)); |
192 |
} |
193 |
|
194 |
private void rotateInOut_ValueChanged(object sender, EventArgs e) |
195 |
{ |
196 |
txt_rotateInOut.Value = rotateInOut.Value * Scaler; |
197 |
this.BoneViewer.ApplyRotationScale(rotateUpDown.Value, RotateLeftRight.Value, RotateZ.Value, (float)(rotateInOut.Value * Scaler)); |
198 |
} |
199 |
|
200 |
private void panLeftRight_ValueChanged(object sender, EventArgs e) |
201 |
{ |
202 |
int Width = BoneViewer.Width * 2; |
203 |
int Height = BoneViewer.Height * 2; |
204 |
int Middle_Width = Width / 2; |
205 |
int Middle_Height = Height / 2; |
206 |
float LeftRightPan = 0; |
207 |
float UpDownPan = 0; |
208 |
float Correction = 0.015625f; |
209 |
LeftRightPan = (panLeftRight.Value - Middle_Width) * Correction; |
210 |
UpDownPan = (PanUpDown.Value - Middle_Height) * Correction; |
211 |
this.BoneViewer.Pan((LeftRightPan * -1.0f) / 2.5f, (UpDownPan) / 2.5f); |
212 |
} |
213 |
|
214 |
private void PanUpDown_ValueChanged(object sender, EventArgs e) |
215 |
{ |
216 |
int Width = BoneViewer.Width * 2; |
217 |
int Height = BoneViewer.Height * 2; |
218 |
int Middle_Width = Width / 2; |
219 |
int Middle_Height = Height / 2; |
220 |
float LeftRightPan = 0; |
221 |
float UpDownPan = 0; |
222 |
float Correction = 0.015625f; |
223 |
LeftRightPan = (panLeftRight.Value - Middle_Width) * Correction; |
224 |
UpDownPan = (PanUpDown.Value - Middle_Height) * Correction; |
225 |
this.BoneViewer.Pan((LeftRightPan * -1.0f) / 2.5f, (UpDownPan) / 2.5f); |
226 |
} |
227 |
|
228 |
|
229 |
|
230 |
private void txt_rotateUpDown_ValueChanged(object value) |
231 |
{ |
232 |
try { this.rotateUpDown.Value = (int)(Convert.ToInt32(value)); } |
233 |
catch { try { this.rotateUpDown.Value = (int)(Convert.ToSingle(value)); } catch { this.rotateUpDown.Value = this.rotateUpDown.Minimum; this.txt_rotateUpDown.Value = this.rotateUpDown.Minimum; this.txt_rotateUpDown.Value = this.rotateUpDown.Minimum; } } |
234 |
} |
235 |
|
236 |
private void txt_renderInterval_ValueChanged(object value) |
237 |
{ |
238 |
try { this.renderInterval.Value = (int)(Convert.ToInt32(value)); } |
239 |
catch { try { this.renderInterval.Value = (int)(Convert.ToSingle(value)); } catch { this.renderInterval.Value = this.renderInterval.Minimum; this.txt_renderInterval.Value = this.renderInterval.Minimum; } } |
240 |
} |
241 |
|
242 |
private void txt_RotateLeftRight_ValueChanged(object value) |
243 |
{ |
244 |
try { this.RotateLeftRight.Value = (int)(Convert.ToInt32(value)); } |
245 |
catch { try { this.RotateLeftRight.Value = (int)(Convert.ToSingle(value)); } catch { this.RotateLeftRight.Value = this.RotateLeftRight.Minimum; this.txt_RotateLeftRight.Value = this.RotateLeftRight.Minimum; } } |
246 |
} |
247 |
|
248 |
private void txt_RotateZ_ValueChanged(object value) |
249 |
{ |
250 |
try { this.RotateZ.Value = (int)(Convert.ToInt32(value)); } |
251 |
catch { try { this.RotateZ.Value = (int)(Convert.ToSingle(value)); } catch { this.RotateZ.Value = this.RotateZ.Minimum; this.txt_RotateZ.Value = this.RotateZ.Minimum; } } |
252 |
} |
253 |
|
254 |
private void txt_rotateInOut_ValueChanged(object value) |
255 |
{ |
256 |
try { this.rotateInOut.Value = (int)(Convert.ToInt32(value) / Scaler); } |
257 |
catch { try { this.rotateInOut.Value = (int)(Convert.ToSingle(value) / Scaler); } catch { this.rotateInOut.Value = this.rotateInOut.Minimum; this.txt_rotateInOut.Value = this.rotateInOut.Minimum; } } |
258 |
} |
259 |
|
260 |
private void XNABoneViewerFrm_Load(object sender, EventArgs e) |
261 |
{ |
262 |
txt_renderInterval.Value = renderInterval.Value; |
263 |
txt_rotateUpDown.Value = rotateUpDown.Value; |
264 |
txt_RotateLeftRight.Value = RotateLeftRight.Value; |
265 |
txt_RotateZ.Value = RotateZ.Value; |
266 |
txt_rotateInOut.Value = rotateInOut.Value; |
267 |
|
268 |
panLeftRight.Maximum = (BoneViewer.Width*2); |
269 |
panLeftRight.Minimum = 0; |
270 |
panLeftRight.Value = (BoneViewer.Width*2) / 2; |
271 |
PanUpDown.Maximum = (BoneViewer.Height*2); |
272 |
PanUpDown.Minimum = 0; |
273 |
PanUpDown.Value = (BoneViewer.Height * 2) / 2; |
274 |
|
275 |
this.BoneViewer.ResetPan(); |
276 |
|
277 |
//ChaosMageX.Granny2.Geom.Quaternion rot = this.bonerotation.Rotation; |
278 |
//Matrix33 scale = this.bonerotation.Scale; |
279 |
|
280 |
//this.rotateUpDown.Value = (int)rot.v.x; |
281 |
//this.RotateLeftRight.Value = (int)rot.v.y; |
282 |
//this.RotateZ.Value = (int)rot.v.z; |
283 |
//this.rotateInOut.Value = (int)(scale.right.x); |
284 |
|
285 |
this.BoneViewer.MouseWheel += new MouseEventHandler(BoneViewer_MouseWheel); |
286 |
|
287 |
} |
288 |
|
289 |
|
290 |
|
291 |
private void BoneViewer_MouseMove(object sender, MouseEventArgs e) |
292 |
{ |
293 |
|
294 |
int Width = BoneViewer.Width; |
295 |
int Height = BoneViewer.Height; |
296 |
|
297 |
int Middle_Width = Width / 2; |
298 |
int Middle_Height = Height / 2; |
299 |
|
300 |
float LeftRightPan = 0; |
301 |
float UpDownPan = 0; |
302 |
|
303 |
float Correction = 0.015625f; |
304 |
|
305 |
System.Windows.Forms.Control source = (System.Windows.Forms.Control)sender; |
306 |
System.Drawing.Point screen = source.PointToScreen(new System.Drawing.Point(e.X, e.Y)); |
307 |
System.Drawing.Point local = BoneViewer.PointToClient(screen); |
308 |
|
309 |
if (e.Button == MouseButtons.Left) |
310 |
{ |
311 |
// Left Button is clicked, pan |
312 |
|
313 |
LeftRightPan = ((local.X - Middle_Width) * Correction);// +this.BoneViewer.Position.Pan.PanLeftRight; |
314 |
UpDownPan = ((local.Y - Middle_Height) * Correction);// +this.BoneViewer.Position.Pan.PanUpDown; |
315 |
this.BoneViewer.Pan((LeftRightPan * -1.0f) / 2.5f, (UpDownPan) / 2.5f); |
316 |
|
317 |
this.BoneViewer.Position.Pan.PanLeftRight = LeftRightPan; |
318 |
this.BoneViewer.Position.Pan.PanUpDown = UpDownPan; |
319 |
Application.DoEvents(); |
320 |
} |
321 |
|
322 |
Application.DoEvents(); |
323 |
} |
324 |
private void BoneViewer_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) |
325 |
{ |
326 |
int numberOfTextLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120; |
327 |
int Value = this.rotateInOut.Minimum; |
328 |
try |
329 |
{ |
330 |
Value = this.rotateInOut.Value; |
331 |
|
332 |
int newValue = (numberOfTextLinesToMove * 1) + this.rotateInOut.Value; |
333 |
if (newValue > this.rotateInOut.Maximum) this.rotateInOut.Value = this.rotateInOut.Maximum; |
334 |
this.rotateInOut.Value = newValue; |
335 |
} |
336 |
catch { this.rotateInOut.Value = Value; } |
337 |
} |
338 |
|
339 |
|
340 |
|
341 |
} |
342 |
} |